Skip to content

Instantly share code, notes, and snippets.

@rasikag
Created September 24, 2018 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rasikag/7e57b9dc293b51727a36ee7dbae835d3 to your computer and use it in GitHub Desktop.
Save rasikag/7e57b9dc293b51727a36ee7dbae835d3 to your computer and use it in GitHub Desktop.
public class CheckMode
{
private readonly static Lazy<CheckMode> _instance
= new Lazy<CheckMode>(() => new CheckMode(
GlobalHost.ConnectionManager.GetHubContext<ModeChangesUpdateHub>().Clients)
);
private IHubConnectionContext<dynamic> Clients { get; set; }
private static SqlTableDependency<ModeTableProperties> _tableDependency;
public CheckMode()
{
try
{
var mapper = new ModelToTableMapper<ModeTableProperties>();
mapper.AddMapping(s => s.IslandNumber, "intIslandNumber");
mapper.AddMapping(s => s.Product, "strProduct");
mapper.AddMapping(s => s.ProductID, "intProductID");
mapper.AddMapping(s => s.DataMode, "strDataMode");
mapper.AddMapping(s => s.ExpID, "strExpID");
mapper.AddMapping(s => s.Lot, "intLot");
mapper.AddMapping(s => s.ShiftNumber, "intShiftNumber");
mapper.AddMapping(s => s.GoalChange, "dtmGoalChange");
mapper.AddMapping(s => s.HeartBeat, "dtmHeartBeat");
mapper.AddMapping(s => s.ChangeMode, "intChangeMode");
mapper.AddMapping(s => s.RecipeID, "RecipeID");
var updateOfModel = new UpdateOfModel<ModeTableProperties>();
updateOfModel.Add(i => i.DataMode);
_tableDependency = new SqlTableDependency<ModeTableProperties>(
ConfigurationManager.ConnectionStrings["ModeCheckingConnection"].ConnectionString,
"Selection",
mapper: mapper,
updateOf: updateOfModel);
_tableDependency.OnChanged += SqlTableDependency_Changed;
_tableDependency.Start(300);
}
catch (Exception ex)
{
logger.Error("Error Message: " + ex.Message + " Stack Trace: " + ex.StackTrace);
}
}
public static CheckMode Instance
{
get
{
return _instance.Value;
}
}
public CheckMode(IHubConnectionContext<dynamic> clients)
{
this.Clients = clients;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment