public void StartRedisListener(SetEventOnRampMessageReceived setEventOnRampMessageReceived) { try { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(Configuration.RedisConnectionString()); ISubscriber sub = redis.GetSubscriber(); sub.Subscribe("*", (channel, message) => { byte[] byteArray = (byte[])message; SkeletonMessage skeletonMessage = SkeletonMessage.DeserializeMessage(byteArray); setEventOnRampMessageReceived(skeletonMessage); }); Thread.Sleep(Timeout.Infinite); } catch (Exception ex) { LogEngine.WriteLog( Configuration.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.DefconOne, Constant.TaskCategoriesEventHubs, ex, EventLogEntryType.Error); } }
// StartService /// <summary> /// Stops the Windows Service. /// </summary> public static void StopService() { if (!IsInstalled()) { return; } using (var controller = new ServiceController(ServiceName)) { try { if (controller.Status != ServiceControllerStatus.Stopped) { controller.Stop(); controller.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10)); } // if } catch (Exception ex) { LogEngine.WriteLog( Configuration.EngineName, "Error in " + MethodBase.GetCurrentMethod().Name, Constant.DefconOne, Constant.TaskCategoriesConsole, ex, EventLogEntryType.Error); Console.ReadLine(); throw; } // try/catch } // usnig }
// Send request component // http://localhost:8000/GrabCaster/SyncSendRequestComponent?ChannelID=*&PointID=*&IDComponent={3C62B951-C353-4899-8670-C6687B6EAEFC} public string SyncSendRequestComponent(string channelId, string pointId, string idComponent) { try { if (Base.Configuration.DisableExternalEventsStreamEngine()) { LogEngine.WriteLog( Base.Configuration.EngineName, "Warning the Device Provider Interface is disable, the GrabCaster point will be able to work in local mode only.", Constant.DefconThree, Constant.TaskCategoriesError, null, EventLogEntryType.Warning); return ("Warning the Device Provider Interface is disable, the GrabCaster point will be able to work in local mode only."); } SyncProvider.SyncSendRequestComponent(channelId, pointId, idComponent); } catch (Exception ex) { LogEngine.WriteLog( Base.Configuration.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.DefconOne, Constant.TaskCategoriesError, ex, EventLogEntryType.Error); return(ex.Message); } return($"Syncronization Executed at {DateTime.Now}."); }
/// <summary> /// The delegate event executed by a event /// </summary> /// <param name="eventType"> /// </param> /// <param name="context"> /// EventActionContext cosa deve essere esuito /// </param> private static void delegateActionEventEmbedded(IEventType eventType, EventActionContext context) { lock (context) { try { //If embedded mode and trigger source == embeddedtrigger then not execute the internal embedded delelegate if (context.BubblingConfiguration.AssemblyClassType != typeof(GrabCaster.Framework.EmbeddedTrigger.EmbeddedTrigger)) { setEventActionEventEmbedded(eventType, context); } } catch (Exception ex) { context.BubblingConfiguration.CorrelationOverride = null; LogEngine.WriteLog( Configuration.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.DefconOne, Constant.TaskCategoriesError, ex, EventLogEntryType.Error); } } }
public static void InitSecondaryPersistProvider() { try { secondaryPersistProviderEnabled = ConfigurationBag.Configuration.SecondaryPersistProviderEnabled; secondaryPersistProviderByteSize = ConfigurationBag.Configuration.SecondaryPersistProviderByteSize; // Load the abrstracte persistent provider var devicePersistentProviderComponent = Path.Combine( ConfigurationBag.Configuration.DirectoryOperativeRootExeName, ConfigurationBag.Configuration.PersistentProviderComponent); // Create the reflection method cached var assemblyPersist = Assembly.LoadFrom(devicePersistentProviderComponent); // Main class logging var assemblyClassDpp = (from t in assemblyPersist.GetTypes() let attributes = t.GetCustomAttributes(typeof(DevicePersistentProviderContract), true) where t.IsClass && attributes != null && attributes.Length > 0 select t).First(); DevicePersistentProvider = Activator.CreateInstance(assemblyClassDpp) as IDevicePersistentProvider; } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesEventHubs, ex, Constant.LogLevelError); } }
/// <summary> /// Execute an embedded trigger /// </summary> /// <param name="componeId"> /// </param> /// <param name="triggerEmbeddedBag"></param> /// <returns> /// The <see cref="string" />. /// </returns> public static byte[] ExecuteEmbeddedTrigger(TriggerEmbeddedBag triggerEmbeddedBag) { try { eventStop = new AutoResetEvent(false); SyncAsyncEventAction = SyncAsyncActionReceived; triggerEmbeddedBag.ActionContext.BubblingObjectBag.SyncronousToken = Guid.NewGuid().ToString(); EventsEngine.SyncAsyncEventsAddDelegate( triggerEmbeddedBag.ActionContext.BubblingObjectBag.SyncronousToken, SyncAsyncActionReceived); EventsEngine.EngineExecuteEmbeddedTrigger(triggerEmbeddedBag); eventStop.WaitOne(); return(_syncronousDataContext); } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); return(null); } }
public void StartRedisListener(SetEventOnRampMessageReceived setEventOnRampMessageReceived) { try { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(ConfigurationBag.Configuration.RedisConnectionString); ISubscriber sub = redis.GetSubscriber(); sub.Subscribe("*", (channel, message) => { byte[] byteArray = message; BubblingObject bubblingObject = BubblingObject.DeserializeMessage(byteArray); setEventOnRampMessageReceived(bubblingObject); }); Thread.Sleep(Timeout.Infinite); } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesEventHubs, ex, Constant.LogLevelError); } }
/// <summary> /// Load the bubbling settings /// </summary> public static void InitializeOffRampEmbedded(ActionEvent delegateEmbedded) { //Load Configuration ConfigurationBag.LoadConfiguration(); LogEngine.WriteLog(ConfigurationBag.EngineName, "Inizialize Off Ramp embedded messaging.", Constant.LogLevelError, Constant.TaskCategoriesError, null, Constant.LogLevelInformation); //Solve App domain environment var current = AppDomain.CurrentDomain; current.AssemblyResolve += HandleAssemblyResolve; int triggers = 0; int events = 0; int components = 0; EventsEngine.InitializeTriggerEngine(); EventsEngine.InitializeEmbeddedEvent(delegateEmbedded); //Load component list configuration EventsEngine.LoadAssemblyComponents(ref triggers, ref events, ref components); //Load event list configuration EventsEngine.RefreshBubblingSetting(false); }
// InstallService /// <summary> /// Uninstalls the Windows Service. /// </summary> public static void UninstallService() { if (!IsInstalled()) { LogEngine.WriteLog( Configuration.EngineName, $"NT Service instance {ServiceName} is not installed.", Constant.DefconOne, Constant.TaskCategoriesConsole, null, EventLogEntryType.Warning); Console.ReadLine(); return; } // if using (var installer = GetInstaller()) { IDictionary state = new Hashtable(); installer.Uninstall(state); LogEngine.WriteLog( Configuration.EngineName, $"Service {ServiceName} Uninstallation completed.", Constant.DefconOne, Constant.TaskCategoriesConsole, null, EventLogEntryType.Information); Console.ReadLine(); } // using }
/// <summary> /// Initialize the onramp engine. /// </summary> /// <param name="onRampPatternComponent"> /// The off ramp pattern component. /// </param> public void Init(string onRampPatternComponent) { // Delegate event for ingestor where ReceiveMessageOnRamp is the event receiveMessageOnRampDelegate = ReceiveMessageOnRamp; LogEngine.WriteLog( ConfigurationBag.EngineName, "Start On Ramp engine.", Constant.LogLevelError, Constant.TaskCategoriesError, null, Constant.LogLevelInformation); // Inizialize the MSPC // Load event up stream external component var eventsUpStreamComponent = Path.Combine( ConfigurationBag.Configuration.DirectoryOperativeRootExeName, ConfigurationBag.Configuration.EventsStreamComponent); // Create the reflection method cached var assembly = Assembly.LoadFrom(eventsUpStreamComponent); // Main class loggingCreateOnRamptream var assemblyClass = (from t in assembly.GetTypes() let attributes = t.GetCustomAttributes(typeof(EventsOnRampContract), true) where t.IsClass && attributes != null && attributes.Length > 0 select t).First(); OnRampStream = Activator.CreateInstance(assemblyClass) as IOnRampStream; OnRampStream.Run(receiveMessageOnRampDelegate); }
public bool CreateEventUpStream() { try { //EH Configuration connectionString = Configuration.AzureNameSpaceConnectionString(); eventHubName = Configuration.GroupEventHubsName(); LogEngine.WriteLog( Configuration.EngineName, $"Event Hubs transfort Type: {Configuration.ServiceBusConnectivityMode()}", Constant.DefconOne, Constant.TaskCategoriesError, null, EventLogEntryType.Information); var builder = new ServiceBusConnectionStringBuilder(connectionString) { TransportType = TransportType.Amqp }; eventHubClient = EventHubClient.CreateFromConnectionString(builder.ToString(), eventHubName); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Execute polling /// </summary> private static void StartTriggerPolling() { //running thread polling var pollingTime = ConfigurationBag.Configuration.EnginePollingTime; try { if (pollingTime == 0) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"EnginePollingTime = 0 - Internal logging system disabled.", Constant.LogLevelError, Constant.TaskCategoriesError, null, Constant.LogLevelWarning); return; } Debug.WriteLine("Start Trigger Polling Cycle", ConsoleColor.Blue); while (ServiceStates.RunPolling) { if (ServiceStates.RestartNeeded) { Debug.WriteLine( "--------------------------------------------------------", ConsoleColor.DarkYellow); Debug.WriteLine("- UPDATE READY - SERVICE NEEDS RESTART -", ConsoleColor.Red); Debug.WriteLine( "--------------------------------------------------------", ConsoleColor.DarkYellow); //ServiceStates.RunPolling = false; return; } ++pollingStep; if (pollingStep > 9) { Debug.WriteLine( $"Execute Trigger Polling {pollingStep} Cycle", ConsoleColor.Blue); pollingStep = 0; } Thread.Sleep(pollingTime); var treadPollingRun = new Thread(EventsEngine.ExecuteBubblingTriggerConfigurationPolling); treadPollingRun.Start(); } } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); } }
/// <summary> /// Sync the local DLL trigger and events to the table storage /// </summary> public static void SyncLocalDLL(AssemblyEvent jitgAssemblyEvent) { try { var BubblingDirectory = Configuration.DirectoryOperativeRoot_ExeName(); var assemblyFile = Path.Combine(BubblingDirectory, string.Concat(jitgAssemblyEvent.Type, "s"), jitgAssemblyEvent.FileName); //Set the primary key, if equal then check the assembly version if (!File.Exists(assemblyFile)) { LogEngine.ConsoleWriteLine("-NEW EVENT RECEIVED-", ConsoleColor.Green); File.WriteAllBytes(assemblyFile, jitgAssemblyEvent.AssemblyContent); LogEngine.ConsoleWriteLine("-NEW EVENT CREATED-", ConsoleColor.Green); } else { //To avoid the lock //Before delete all clones LogEngine.ConsoleWriteLine("-SYNC EVENT-", ConsoleColor.Green); var assembly = Assembly.LoadFile(assemblyFile); var versionOnLocal = assembly.GetName().Version; var versionOnStorage = new Version(jitgAssemblyEvent.Version); if (versionOnStorage.CompareTo(versionOnLocal) > 0) { LogEngine.ConsoleWriteLine( string.Format("-SYNC EVENT TO DO- Local V.{0} Remote V. {1}", versionOnLocal, versionOnStorage), ConsoleColor.Green); var assemblyUpdate = Path.ChangeExtension(assemblyFile, Configuration.General_UpdateFile); File.WriteAllBytes(assemblyUpdate, jitgAssemblyEvent.AssemblyContent); LogEngine.ConsoleWriteLine("-SYNC EVENT DONE-", ConsoleColor.Green); } assembly = null; } } catch (IOException ioException) { LogEngine.ConsoleWriteLine("-SYNC EVENT -", ConsoleColor.Red); } catch (UnauthorizedAccessException unauthorizedAccessException) { LogEngine.ConsoleWriteLine("-SYNC EVENT -", ConsoleColor.Red); } catch (Exception ex) { LogEngine.WriteLog(Configuration.General_Source, string.Format("Error in {0}", MethodBase.GetCurrentMethod().Name), Constant.Error_EventID_High_Critical_, Constant.TaskCategories_, ex, EventLogEntryType.Error); } }
/// <summary> /// TODO The publish. /// </summary> protected virtual void Publish() { var task = new Task( () => { var itemsToPublish = new List <BubblingObject>(); try { if (IsPublishing()) { return; } StartPublishing(); //Debug.WriteLine($"Log start dequeue {this.Count} items!"); BubblingObject item; while (TryDequeue(out item)) { itemsToPublish.Add(item); } } catch (ThreadAbortException tex) { Debug.WriteLine($"Dequeue items failed > {tex.Message}"); LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesError, tex, Constant.LogLevelError); } catch (Exception ex) { Debug.WriteLine($"Dequeue items failed > {ex.Message}"); LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); } finally { //Debug.WriteLine($"Log dequeued {itemsToLog.Count} items"); OnPublish(itemsToPublish); CompletePublishing(); } }); task.Start(); }
/// <summary> /// Persist the message in local file system /// </summary> /// <param name="bubblingObject"> /// </param> /// <param name="eventActionContext"></param> /// <param name="communicationDiretion"> /// The communication Diretion. /// </param> /// <returns> /// The <see cref="bool" />. /// </returns> public static bool PersistMessage(BubblingObject bubblingObject, string MessageId, CommunicationDiretion communicationDiretion) { try { if (!ConfigurationBag.Configuration.EnablePersistingMessaging) { return(true); } var serializedMessage = JsonConvert.SerializeObject(bubblingObject); var directoryDate = string.Concat( DateTime.Now.Year, "\\", DateTime.Now.Month.ToString().PadLeft(2, '0'), "\\", DateTime.Now.Day.ToString().PadLeft(2, '0'), "\\", communicationDiretion.ToString()); var datetimeFile = string.Concat( DateTime.Now.Year, DateTime.Now.Month.ToString().PadLeft(2, '0'), DateTime.Now.Day.ToString().PadLeft(2, '0'), "-", DateTime.Now.Hour.ToString().PadLeft(2, '0'), "-", DateTime.Now.Minute.ToString().PadLeft(2, '0'), "-", DateTime.Now.Second.ToString().PadLeft(2, '0')); var persistingForlder = Path.Combine(ConfigurationBag.Configuration.LocalStorageConnectionString, directoryDate); Directory.CreateDirectory(persistingForlder); var filePersisted = Path.Combine( persistingForlder, string.Concat(datetimeFile, "-", MessageId, ConfigurationBag.MessageFileStorageExtension)); File.WriteAllText(filePersisted, serializedMessage); Debug.WriteLine( "Event persisted - Consistency Transaction Point created.", ConsoleColor.DarkGreen); return(true); } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); return(false); } }
/// <summary> /// TODO The publish. /// </summary> protected virtual void Publish() { var task = new Task( () => { var itemsToLog = new List <T>(); try { if (this.IsPublishing()) { return; } this.StartPublishing(); //LogEngine.DebugWriteLine($"Log start dequeue {this.Count} items!"); T item; while (this.TryDequeue(out item)) { itemsToLog.Add(item); } } catch (ThreadAbortException tex) { LogEngine.DebugWriteLine($"Dequeue items failed > {tex.Message}"); LogEngine.WriteLog( Configuration.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.DefconOne, Constant.TaskCategoriesError, tex, EventLogEntryType.Error); } catch (Exception ex) { LogEngine.DebugWriteLine($"Dequeue items failed > {ex.Message}"); LogEngine.WriteLog( Configuration.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.DefconOne, Constant.TaskCategoriesError, ex, EventLogEntryType.Error); } finally { //LogEngine.DebugWriteLine($"Log dequeued {itemsToLog.Count} items"); this.OnPublish(itemsToLog); this.CompletePublishing(); } }); task.Start(); }
public static byte[] EncryptByteToBytes_Aes(byte[] byteContent) { byte[] encrypted = null; // Create an AesManaged object // with the specified key and IV. try { using (AesManaged aesAlg = new AesManaged()) { byte[] Key = new byte[32]; byte[] IV = new byte[16]; byte[] contentKey = GetSecurityContent_Aes(); Array.Copy(contentKey, 0, Key, 0, 32); Array.Copy(contentKey, 32, IV, 0, 16); aesAlg.Key = Key; aesAlg.IV = IV; // Create a decrytor to perform the stream transform. ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); // Create the streams used for encryption. using (MemoryStream msEncrypt = new MemoryStream()) { using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) { csEncrypt.Write(byteContent, 0, byteContent.Length); csEncrypt.FlushFinalBlock(); encrypted = msEncrypt.ToArray(); msEncrypt.Close(); csEncrypt.Close(); } } } // Return the encrypted bytes from the memory stream. return(encrypted); } catch (Exception ex) { LogEngine.WriteLog(Configuration.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.DefconOne, Constant.TaskCategoriesError, ex, EventLogEntryType.Error); throw ex; } }
public byte[] PersistEventFromStorage(string messageId) { try { var storageAccountName = Configuration.GroupEventHubsStorageAccountName(); var storageAccountKey = Configuration.GroupEventHubsStorageAccountKey(); var connectionString = $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}"; var storageAccount = CloudStorageAccount.Parse(connectionString); var blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. var container = blobClient.GetContainerReference(Configuration.GroupEventHubsName()); // Create the container if it doesn't already exist. container.CreateIfNotExists(); container.SetPermissions( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); // Create the messageid reference var blockBlob = container.GetBlockBlobReference(messageId); blockBlob.FetchAttributes(); var msgByteLength = blockBlob.Properties.Length; var msgContent = new byte[msgByteLength]; for (var i = 0; i < msgByteLength; i++) { msgContent[i] = 0x20; } blockBlob.DownloadToByteArray(msgContent, 0); LogEngine.ConsoleWriteLine( "Event persisted recovered - Consistency Transaction Point restored.", ConsoleColor.DarkGreen); return(msgContent); } catch (Exception ex) { LogEngine.WriteLog( Configuration.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.DefconOne, Constant.TaskCategoriesError, ex, EventLogEntryType.Error); return(null); } }
/// <summary> /// Initialize the onramp engine. /// </summary> /// <param name="offRampPatternComponent"> /// The off ramp pattern component. /// </param> public void Init(string offRampPatternComponent) { if (Configuration.RunLocalOnly()) { LogEngine.WriteLog(Configuration.EngineName, $"This GrabCaster point is configured for local only execution.", Constant.DefconOne, Constant.TaskCategoriesError, null, EventLogEntryType.Warning); return; } // Delegate event for ingestor where ReceiveMessageOnRamp is the event this.receiveMessageOnRampDelegate = this.ReceiveMessageOnRamp; LogEngine.WriteLog( Configuration.EngineName, "Start On Ramp engine.", Constant.DefconOne, Constant.TaskCategoriesError, null, EventLogEntryType.Information); // Inizialize the MSPC // Load event up stream external component var eventsUpStreamComponent = Path.Combine( Configuration.DirectoryOperativeRootExeName(), Configuration.EventsStreamComponent()); // Create the reflection method cached var assembly = Assembly.LoadFrom(eventsUpStreamComponent); // Main class logging var assemblyClass = (from t in assembly.GetTypes() let attributes = t.GetCustomAttributes(typeof(EventsDownStreamContract), true) where t.IsClass && attributes != null && attributes.Length > 0 select t).First(); var classAttributes = assemblyClass.GetCustomAttributes(typeof(EventsDownStreamContract), true); if (classAttributes.Length > 0) { Debug.WriteLine("EventsDownStreamContract - methodRun caller"); methodRun = assemblyClass.GetMethod("Run"); } classInstance = Activator.CreateInstance(assemblyClass, null); ParametersRet[0] = this.receiveMessageOnRampDelegate; methodRun.Invoke(classInstance, ParametersRet); }
public static void StartEngine() { try { ConfigurationBag.LoadConfiguration(); LogEngine.Init(); Debug.WriteLine( $"Version {Assembly.GetExecutingAssembly().GetName().Version}", ConsoleColor.Green); Debug.WriteLine("--GrabCaster Sevice Initialization--Start Engine.", ConsoleColor.Green); _delegate = delegateActionEventEmbedded; CoreEngine.StartEventEngine(_delegate); engineLoaded = true; Thread.Sleep(Timeout.Infinite); } catch (NotImplementedException ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, "Error in " + MethodBase.GetCurrentMethod().Name, Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, "Error in " + MethodBase.GetCurrentMethod().Name, Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); Environment.Exit(0); } // try/catch finally { //Spool log queues if (LogEngine.QueueAbstractMessage != null) { LogEngine.QueueAbstractMessageOnPublish(LogEngine.QueueAbstractMessage.ToArray().ToList()); } if (LogEngine.QueueConsoleMessage != null) { LogEngine.QueueConsoleMessageOnPublish(LogEngine.QueueConsoleMessage.ToArray().ToList()); } } }
// GetInstaller /// <summary> /// Installs the Windows Service. /// </summary> public static void InstallService() { if (IsInstalled()) { LogEngine.WriteLog( Configuration.EngineName, $"NT Service instance {ServiceName} is already installed.", Constant.DefconOne, Constant.TaskCategoriesConsole, null, EventLogEntryType.Information); Console.ReadLine(); return; } // if using (var installer = GetInstaller()) { IDictionary state = new Hashtable(); try { installer.Install(state); installer.Commit(state); LogEngine.WriteLog( Configuration.EngineName, $"NT Service instance {ServiceName} installation completed.", Constant.DefconOne, Constant.TaskCategoriesConsole, null, EventLogEntryType.Information); Console.ReadLine(); } catch { try { installer.Rollback(state); } catch { // ignored } // try/catch throw; } } }
public void PersistEventToStorage(byte[] messageBody, string messageId) { try { if (Configuration.RunLocalOnly()) { LogEngine.WriteLog(Configuration.EngineName, $"Impossible to use a remote storage provider, this GrabCaster point is configured for local only execution.", Constant.DefconOne, Constant.TaskCategoriesError, null, EventLogEntryType.Warning); return; } var storageAccountName = Configuration.GroupEventHubsStorageAccountName(); var storageAccountKey = Configuration.GroupEventHubsStorageAccountKey(); var connectionString = $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}"; var storageAccount = CloudStorageAccount.Parse(connectionString); var blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. var container = blobClient.GetContainerReference(Configuration.GroupEventHubsName()); // Create the container if it doesn't already exist. container.CreateIfNotExists(); container.SetPermissions( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); // Create the messageid reference var blockBlob = container.GetBlockBlobReference(messageId); blockBlob.UploadFromByteArray(messageBody, 0, messageBody.Length); LogEngine.ConsoleWriteLine( "Event persisted - Consistency Transaction Point created.", ConsoleColor.DarkGreen); } catch (Exception ex) { LogEngine.WriteLog( Configuration.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.DefconOne, Constant.TaskCategoriesError, ex, EventLogEntryType.Error); } }
public static byte[] DecryptByteFromBytes_Aes(byte[] cipherText) { // the decrypted byte array. byte[] deCipherText = new byte[cipherText.Length];; // Create an AesManaged object // with the specified key and IV. try { using (AesManaged aesAlg = new AesManaged()) { byte[] Key = new byte[32]; byte[] IV = new byte[16]; byte[] contentKey = GetSecurityContent_Aes(); Array.Copy(contentKey, 0, Key, 0, 32); Array.Copy(contentKey, 32, IV, 0, 16); aesAlg.Key = Key; aesAlg.IV = IV; // Create a decrytor to perform the stream transform. ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); // Create the streams used for decryption. using (MemoryStream msDecrypt = new MemoryStream(cipherText)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { csDecrypt.Read(deCipherText, 0, deCipherText.Length); msDecrypt.Close(); csDecrypt.Close(); } } } return(deCipherText); } catch (Exception ex) { LogEngine.WriteLog(Configuration.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.DefconOne, Constant.TaskCategoriesError, ex, EventLogEntryType.Error); throw ex; } }
/// <summary> /// Send the request message for the Synconization /// </summary> /// <param name="Partner">Partner request to send</param> public static void SyncSendSyncAvailable() { try { EventUpStream.SendServiceNullMessage(Configuration.MessageDataProperty.SyncAvailable, Configuration.MessageContext__All); } catch (Exception ex) { LogEngine.WriteLog(Configuration.General_Source, string.Format("Error in {0}", MethodBase.GetCurrentMethod().Name), Constant.Error_EventID_High_Critical_, Constant.TaskCategories_, ex, EventLogEntryType.Error); } }
/// <summary> /// Send the request message for the Synconization /// </summary> /// <param name="Partner">Partner request to send</param> public static void SyncSendSyncRequest() { try { OffRampEngine.SendNullMessageOnRamp(Configuration.MessageDataProperty.SyncRequest, Configuration.MessageContext__All); } catch (Exception ex) { LogEngine.WriteLog(Configuration.General_Source, string.Format("Error in {0}", MethodBase.GetCurrentMethod().Name), Constant.Error_EventID_High_Critical_, Constant.TaskCategories_, ex, EventLogEntryType.Error); } }
public void Run(SetEventOnRampMessageReceived setEventOnRampMessageReceived) { try { var myNewThread = new Thread(() => StartRedisListener(setEventOnRampMessageReceived)); myNewThread.Start(); } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesEventHubs, ex, Constant.LogLevelError); } }
public void SendMessage(BubblingObject message) { try { byte[] byteArrayBytes = BubblingObject.SerializeMessage(message); subscriber.Publish("*", byteArrayBytes); } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesEventHubs, ex, Constant.LogLevelError); } }
/// <summary> /// Initialize an embedded trigger /// </summary> /// <param name="componeId"> /// </param> /// <param name="configurationId"></param> /// <param name="componentId"></param> /// <returns> /// The <see cref="string" />. /// </returns> public static TriggerEmbeddedBag InitializeEmbeddedTrigger(string configurationId, string componentId) { try { return(EventsEngine.InitializeEmbeddedTrigger(configurationId, componentId)); } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); return(null); } }
//http://localhost:8000/GrabCaster/Deploy?Configuration=Release&Platform=AnyCpu public string Deploy(string configuration, string platform) { try { string publishingFolder = Path.Combine(ConfigurationBag.DirectoryDeployment(), ConfigurationBag.DirectoryNamePublishing); var regTriggers = new Regex(ConfigurationBag.DeployExtensionLookFor); var deployFiles = Directory.GetFiles(publishingFolder, "*.*", SearchOption.AllDirectories) .Where( path => Path.GetExtension(path) == ".trigger" || Path.GetExtension(path) == ".event" || Path.GetExtension(path) == ".component"); StringBuilder results = new StringBuilder(); foreach (var file in deployFiles) { string projectName = Path.GetFileNameWithoutExtension(publishingFolder + file); string projectType = Path.GetExtension(publishingFolder + file).Replace(".", ""); bool resultOk = Jit.CompilePublishing(projectType, projectName, configuration, platform); if (resultOk) { string message = resultOk ? "without errors" : "with errors"; results.AppendLine( $"{projectName}.{projectType} builded {message} check the {projectName}Build.Log file for more information"); } } return(results.ToString()); } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, $"Error in {MethodBase.GetCurrentMethod().Name}", Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); return(ex.Message); } }
//Send all the configuration bubbling event and triggers public static void SyncSendConfigurationFileList(string DestinationPartner) { try { LogEngine.ConsoleWriteLine( string.Format("SENT BUBBLING EVT/TRG CONF. - to {0}", DestinationPartner), ConsoleColor.Yellow); OffRampEngineSending.SendMessageOnRamp(EventsEngine.SyncConfigurationFileList, Configuration.MessageDataProperty.SyncConfigurationFileListToDo, DestinationPartner, null); } catch (Exception ex) { LogEngine.WriteLog(Configuration.General_Source, string.Format("Error in {0}", MethodBase.GetCurrentMethod().Name), Constant.Error_EventID_High_Critical_, Constant.TaskCategories_, ex, EventLogEntryType.Error); } }