static void Main(string[] args) { EventHandler newHandler = new EventHandler(); byte[] array = new byte[100]; EventHandlerContext context = new EventHandlerContext(array, 100); //InternalDbHandler.DBModule internalDB = Utils.Singleton<InternalDbHandler.DBModule>.Instance; //internalDB.GetUserHandler().ShowData(); //UserWrapper user = new UserWrapper("3"); //internalDB.GetUserHandler().InsertUser(user); Console.WriteLine(newHandler.InvokeCommand(context)); CreateWebHostBuilder(args).Build().Run(); }
private bool ValidateContext(EventHandlerContext contextContainer) { if (ReferenceEquals(contextContainer, null)) // useless until EventHandlerContext becomes a class, not a struct { return(false); } if (contextContainer.contextHandler.sizeOfContext == 0) { return(false); } if (ReferenceEquals(contextContainer.contextHandler.context, null)) { return(false); } return(true); }
public bool InvokeCommand(EventHandlerContext handlerContext) // invoke commands between the submodules and also the Core { Console.WriteLine("InvokeCommand execution for subModule Handler"); if (ValidateContext(handlerContext) == false) { return(false); } switch (handlerContext.command) { case EventHandlerFunctions.Init: return(this.Init(handlerContext.contextHandler.context, handlerContext.contextHandler.sizeOfContext)); case EventHandlerFunctions.UnInit: return(UnInit()); case EventHandlerFunctions.RequestCommand: return(RequestCommand(handlerContext.coreCommand, handlerContext.contextHandler.context, handlerContext.contextHandler.sizeOfContext)); case EventHandlerFunctions.EpidemyAlertModule: return(epidemyModule.InvokeCommand(handlerContext.subModuleCommand, handlerContext.contextHandler)); case EventHandlerFunctions.ImageProcessingModule: return(imageModule.InvokeCommand(handlerContext.subModuleCommand, handlerContext.contextHandler)); case EventHandlerFunctions.SymptomLearningModule: return(symptomModule.InvokeCommand(handlerContext.subModuleCommand, handlerContext.contextHandler)); case EventHandlerFunctions.SymptomBasedDetectionModule: return(symptomBasedModule.InvokeCommand(handlerContext.subModuleCommand, handlerContext.contextHandler)); case EventHandlerFunctions.DataBaseModule: return(dbHandler.InvokeCommand(handlerContext.subModuleCommand, handlerContext.contextHandler)); case EventHandlerFunctions.InvokeCommand: return(false); // INvoKE COmMAnD } return(false); }
static void Main(string[] args) { EventHandler newHandler = new EventHandler(); byte[] array = new byte[100]; EventHandlerContext context = new EventHandlerContext(array, 100); while (true) { string command = Console.ReadLine(); if (command == "Exit") { break; } string[] arguments = command.Split(" "); if (arguments.Length != 3) { continue; } if (Enum.IsDefined(typeof(EventHandlerFunctions), arguments[0])) { context.command = (EventHandlerFunctions)Enum.Parse(typeof(EventHandlerFunctions), arguments[0].ToString()); } if (Enum.IsDefined(typeof(SubModuleFunctions), arguments[1])) { context.subModuleCommand = (SubModuleFunctions)Enum.Parse(typeof(SubModuleFunctions), arguments[1].ToString()); } // arguments[2] should be a JSON data - the actual Context; Console.WriteLine(newHandler.InvokeCommand(context)); string raspuns = Encoding.ASCII.GetString(context.contextHandler.answer); Console.WriteLine(raspuns); } newHandler = null; }
public override bool InvokeCommand(SubModuleFunctions command, IContext contextHandler) { Console.WriteLine("InvokeCommand execution for EpidemyAlert subModule"); EpidemyContext subModuleContextHandler = contextHandler as EpidemyContext; switch (command) { case SubModuleFunctions.EpidemyCheckForSpecificAlert: DataBaseContext contextSpecific = new DataBaseContext(); contextSpecific.databaseId = DataBaseDefines.DatabaseDiseases; // the database id; contextSpecific.databaseFunctionId = DataBaseDefines.DiseasesSpecificQueryDisease; // function ID Dictionary <string, string> dictionarySpecific = new Dictionary <string, string>(); // the params dictionarySpecific.Add("x", subModuleContextHandler.x.ToString()); dictionarySpecific.Add("y", subModuleContextHandler.y.ToString()); dictionarySpecific.Add("disease", subModuleContextHandler.specificSearch); contextSpecific.ParametersDictionary = dictionarySpecific; EventHandlerContext commandContextSpecific = new EventHandlerContext(); commandContextSpecific.command = EventHandlerFunctions.DataBaseModule; commandContextSpecific.subModuleCommand = SubModuleFunctions.DataBaseQueryData; commandContextSpecific.coreCommand = CoreKnownFunctions.InvalidCommand; commandContextSpecific.contextHandler = contextSpecific; bool resultSpecific = fatherHandler.InvokeCommand(commandContextSpecific); if (!resultSpecific) { return(false); } foreach (KeyValuePair <string, string> entry in contextSpecific.AnswerDictionary) { // Validate each response subModuleContextHandler.AnswerDictionary[entry.Key] = entry.Value; // perechi boala - zona } if (subModuleContextHandler.AnswerDictionary.Count == 0) { return(false); } return(true); case SubModuleFunctions.EpidemyCheckForAlert: DataBaseContext context = new DataBaseContext(); context.databaseId = DataBaseDefines.DatabaseDiseases; // the database id; context.databaseFunctionId = DataBaseDefines.DiseasesFullQuery; // function ID Dictionary <string, string> dictionary = new Dictionary <string, string>(); // the params dictionary.Add("x", subModuleContextHandler.x.ToString()); dictionary.Add("y", subModuleContextHandler.y.ToString()); context.ParametersDictionary = dictionary; EventHandlerContext commandContext = new EventHandlerContext(); commandContext.command = EventHandlerFunctions.DataBaseModule; commandContext.subModuleCommand = SubModuleFunctions.DataBaseQueryData; commandContext.coreCommand = CoreKnownFunctions.InvalidCommand; commandContext.contextHandler = context; bool result = fatherHandler.InvokeCommand(commandContext); if (!result) { return(false); } foreach (KeyValuePair <string, string> entry in context.AnswerDictionary) { // Validate each response subModuleContextHandler.AnswerDictionary[entry.Key] = entry.Value; // perechi boala - zona } if (subModuleContextHandler.AnswerDictionary.Count == 0) { return(false); } return(true); default: return(false); } }