예제 #1
0
        ///<summary>
        /// Calls SaveAlertData() to save the data to a file , database or any other storage media based on
        /// storageType
        ///</summary>
        ///<param name="storageType">
        ///Storage type like file, DocumentDB database instance etc.
        /// </param>
        public static void SaveAlertData(IStorageService storageType, string storageId)
        {
            LogUtility.LogInfoFunction("Entered SaveAlertData.");
            if (storageType.GetType() == typeof(FileDataController))
            {
                fetchEndTime = Convert.ToDateTime(UserSettingsHelper.FileGetAlertFetchEndTime(storageId));
                UserSettingsHelper.FileSetAlertFetchStartTime(storageId, fetchEndTime);
                currentTime = DateTime.Now;
                UserSettingsHelper.FileSetAlertFetchEndTime(storageId, currentTime);
            }
            else
            {
                fetchEndTime = Convert.ToDateTime(UserSettingsHelper.GetFetchEndTime(storageId));
                UserSettingsHelper.DocumetDBSetAlertFetchStartTime(storageId, fetchEndTime);
                currentTime = DateTime.Now;
                UserSettingsHelper.SetFetchEndTime(storageId, currentTime);
            }

            List <Alert> alertObjects = GetAlertByDate(fetchEndTime, currentTime);

            if (alertObjects != null)
            {
                storageType.SaveAlertData(alertObjects, storageId);
            }
            else
            {
                LogUtility.LogInfoFunction("No Alert records found.");
            }
            LogUtility.LogInfoFunctionFinished();
        }
예제 #2
0
파일: Start.cs 프로젝트: VeritasOS/arcus
 /// <summary>
 /// Executes the Init method after the elapsed time.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="e"></param>
 private static void OnTimedEvent(Object source, ElapsedEventArgs e)
 {
     LogUtility.LogInfoFunction(string.Format("The Elapsed event was raised at {0}",
                                              e.SignalTime));
     UserSettingsHelper.SetRunTime(DateTime.Now);
     Main.Init();
 }
예제 #3
0
        public async Task SaveJobHistory(List <JobHistory> jobHistoryObject, string documentDBName)
        {
            try
            {
                LogUtility.LogInfoFunction("Entered SaveJobHistory.");
                List <string> list = GetEndpointUrlAndAuthorizationKey(documentDBName);
                EndpointUrl      = list[0];
                AuthorizationKey = list[1];

                using (client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey))
                {
                    //To get or create the documentDB database and JobHistory collection.
                    Init(databaseId, jobHistoryCollectionId);
                    var collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, jobHistoryCollectionId);
                    LogUtility.LogInfoFunction("Pushing Job Histories into DocumentDB.");
                    foreach (JobHistory jobHistory in jobHistoryObject)
                    {
                        //Push job to JobHistoryCollection.
                        await client.CreateDocumentAsync(collectionLink, jobHistory);
                    }
                    LogUtility.LogInfoFunction("Job Histories successfully stored in DocumentDB");
                }
                LogUtility.LogInfoFunction("Setting the Last Update time");
                UserSettingsHelper.SetJobHistoryLastUpdateTime(documentDBName, DateTime.Now);

                LogUtility.LogInfoFunctionFinished();
            }
            catch (Exception e)
            {
                Exception baseException = e.GetBaseException();
                LogUtility.LogInfoFunction("Error:" + e.Message + "Message:" + baseException.Message);
                Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
            }
        }
예제 #4
0
        /// <summary>
        /// Saves the Alerts into the DocumentDB Collection with Id: "AlertCollection"
        /// </summary>
        /// <param name="alertObject">
        /// Contains the Alert data.
        /// </param>
        /// <param name="documentDBName">
        /// The documentDB name to determine to which EndPointUrl the data is to be stored.
        /// </param>
        public void SaveAlertData(List <Alert> alertObject, string documentDBName)
        {
            try
            {
                LogUtility.LogInfoFunction("Entered SaveAlertData.");

                List <string> list = GetEndpointUrlAndAuthorizationKey(documentDBName);
                EndpointUrl      = list[0];
                AuthorizationKey = list[1];

                using (client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey))
                {
                    //To get or create the documentDB database and Alert collection.
                    Init(databaseId, alertCollectionId);
                    var collectionLink = UriFactory.CreateDocumentCollectionUri(databaseId, alertCollectionId);
                    LogUtility.LogInfoFunction("Pushing Alerts into DocumentDB.");
                    foreach (Alert alert in alertObject)
                    {
                        //Push alert to AlertCollection.
                        client.CreateDocumentAsync(collectionLink, alert).Wait();
                    }
                    LogUtility.LogInfoFunction("Alerts successfully stored in DocumentDB");
                }
                LogUtility.LogInfoFunction("Setting the Last Update time");
                UserSettingsHelper.SetLastUpdateTime(documentDBName, DateTime.Now);
                LogUtility.LogInfoFunctionFinished();
            }
            catch (Exception e)
            {
                Exception baseException = e.GetBaseException();
                LogUtility.LogInfoFunction("Error:" + e.Message + "Message:" + baseException.Message);
                Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
            }
        }
예제 #5
0
        ///<summary>
        /// Calls SaveJobHistoryData() to save the data to a file , database or any other storage media based on
        /// StorageType
        ///</summary>
        ///<param name="storageType">
        ///Storage type like file, DocumentDB database instance etc.
        /// </param>
        public static void SaveJobHistoryData(IStorageService storageType, string storageId)
        {
            LogUtility.LogInfoFunction("Entered SaveJobHistoryData.");
            //check the storage type to get the specific data from UserSettings.xml file
            if (storageType.GetType() == typeof(FileDataController))
            {
                LogUtility.LogInfoFunction("The storage type is FileSystem.");
                fetchEndTime = Convert.ToDateTime(UserSettingsHelper.FileGetJobHistoryFetchEndTime(storageId));
                UserSettingsHelper.FileSetJobHistoryFetchStartTime(storageId, fetchEndTime);
                currentTime = DateTime.Now;
                UserSettingsHelper.FileSetJobHistoryFetchEndTime(storageId, currentTime);
            }
            else
            {
                LogUtility.LogInfoFunction("The storage type is DocumentDB.");
                fetchEndTime = Convert.ToDateTime(UserSettingsHelper.GetJobHistoryFetchEndTime(storageId));
                UserSettingsHelper.DocumentDBSetJobHistoryFetchStartTime(storageId, fetchEndTime);
                currentTime = DateTime.Now;
                UserSettingsHelper.SetJobHistoryFetchEndTime(storageId, currentTime);
            }

            //List<JobHistory> jobHistoryObjects = GetJobHistory();
            List <JobHistory> jobHistoryObjects = GetJobHistoryByDate(fetchEndTime, currentTime);

            if (jobHistoryObjects != null)
            {
                LogUtility.LogInfoFunction("Calling  storageType.SaveJobHistoryData(jobHistoryObjects, storageId);");
                storageType.SaveJobHistoryData(jobHistoryObjects, storageId);
            }
            else
            {
                LogUtility.LogInfoFunction("No JobHistory records found.");
            }
            LogUtility.LogInfoFunctionFinished();
        }
예제 #6
0
파일: Main.cs 프로젝트: VeritasOS/arcus
        /// <summary>
        /// Checks if the File system type and DocumentDB type is enabled
        /// and calls the respective handler methods.
        /// </summary>
        public static void Init()
        {
            try
            {
                LogUtility.CheckLogFileEnabled();

                //Get the file Systems that are enabled.
                IEnumerable <BEArcus.Agent.FileSystemType> fileSystems = Configuration.Instance.DataStores.FileSystem.
                                                                         Where(f => f.Enabled);
                LogUtility.LogInfoFunction("Storing data to enbled File Systems");
                IStorageService fileservice = new FileDataController();
                foreach (FileSystemType fileSystem in fileSystems)
                {
                    UserSettingsHelper.CreateFileSystemSettings(fileSystem.Name);
                    AlertController.SaveAlertData(fileservice, fileSystem.Name);
                    JobController.SaveJobData(fileservice, fileSystem.Name);
                    JobHistoryController.SaveJobHistoryData(fileservice, fileSystem.Name);
                    MediaServerController.SaveMediaServerData(fileservice, fileSystem.Name);
                }

                //Get the DocumentDB data store that are enabled.
                IEnumerable <BEArcus.Agent.DocumentDBType> documentDBStreams = Configuration.Instance.DataStores.DocumentDB.
                                                                               Where(d => d.Enabled);
                LogUtility.LogInfoFunction("Storing data to enbled DocumentDB accounts.");
                //IStorageService documentDBService = new DocumentDBDataController();
                foreach (DocumentDBType documentDB in documentDBStreams)
                {
                    UserSettingsHelper.CreateDocumentDBSettings(documentDB.Name);

                    //Decrypt the Authorization Key to check if it was encryped earlier
                    string decrypedAuthorizationKey = SecurityController.Decrypt(documentDB.AuthorizationKey);

                    //Decrypt method returns null if the Authorization key was not Encrypted earlier
                    if (string.IsNullOrEmpty(decrypedAuthorizationKey))
                    {
                        //Encrypt Authorization Key
                        string encryptedAuthorizationKey = SecurityController.Encrypt(documentDB.AuthorizationKey);
                        //Encrypt EndpointUrl
                        string encryptedEndpointUrl = SecurityController.Encrypt(documentDB.EndPointUrl);
                        //Save changes to Configuration.xml
                        SecurityController.UpdateConfiguration(encryptedEndpointUrl, encryptedAuthorizationKey);
                    }
                    IStorageService documentDBService = new DocumentDBDataController();
                    AlertController.SaveAlertData(documentDBService, documentDB.Name);
                    JobController.SaveJobData(documentDBService, documentDB.Name);
                    JobHistoryController.SaveJobHistoryData(documentDBService, documentDB.Name);
                    MediaServerController.SaveMediaServerData(documentDBService, documentDB.Name);
                    PurgeDataController.PurgeAlerts(documentDB.Name);
                    PurgeDataController.PurgeJobHistories(documentDB.Name);
                }
                LogUtility.LogInfoFunctionFinished();
            }
            catch (Exception e)
            {
                Exception baseException = e.GetBaseException();
                LogUtility.LogInfoFunction("Error:" + e.Message + "Message:" + baseException.Message);
                Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
            }
        }
예제 #7
0
        ///<Summary>
        ///Saves the Alerts to a Json file.
        ///</Summary>
        public void SaveAlertData(List <Alert> alertObject, string fileSystemName)
        {
            LogUtility.LogInfoFunction("Entered SaveAlertData.");
            string jsonstr      = JsonHelper.JsonSerializer <List <Alert> >(alertObject);
            string jsonFilePath = GetFileSystemType(fileSystemName).AlertPath;

            LogUtility.LogInfoFunction("Alert:Writing to Json file.");
            System.IO.File.WriteAllText(jsonFilePath, jsonstr);
            UserSettingsHelper.FileSetAlertLastUpdateTime(fileSystemName, DateTime.Now);
            LogUtility.LogInfoFunction(string.Format("Alerts in {0}.", jsonFilePath));
            LogUtility.LogInfoFunctionFinished();
        }
예제 #8
0
        ///<Summary>
        ///Saves JobHistory to a Json file.
        ///</Summary>
        public void SaveJobHistoryData(List <JobHistory> jobHistoryObject, string fileSystemName)
        {
            LogUtility.LogInfoFunction("Entered SaveJobHistoryData.");
            string jsonstr      = JsonHelper.JsonSerializer <List <JobHistory> >(jobHistoryObject);
            string jsonFilePath = GetFileSystemType(fileSystemName).JobHistoryPath;

            LogUtility.LogInfoFunction("JobHistory:Writing to Json file.");
            System.IO.File.WriteAllText(jsonFilePath, jsonstr);
            UserSettingsHelper.FileSetJobHistoryLastUpdateTime(fileSystemName, DateTime.Now);

            LogUtility.LogInfoFunction(string.Format("JobHistories in {0}.", jsonFilePath));
            LogUtility.LogInfoFunctionFinished();
        }