protected bool CreateDirectory(string cmdText, out string errorMessage, string source) { Dictionary <string, string> cmdParams; errorMessage = string.Empty; // Parse the received string try { cmdParams = clsXMLTools.ParseCommandXML(cmdText); } catch (Exception ex) { errorMessage = "Exception parsing XML command string"; var msg = errorMessage + ": " + cmdText + Environment.NewLine; LogError(msg, ex); mStatusFile.TaskStatus = clsStatusFile.EnumTaskStatus.Failed; mStatusFile.WriteStatusFile(); return(false); } // Make the Directory if (cmdParams == null) { errorMessage = "cmdParams is null; Cannot create Directory"; var msg = errorMessage + " for string " + cmdText; LogError(msg); mStatusFile.TaskStatus = clsStatusFile.EnumTaskStatus.Failed; mStatusFile.WriteStatusFile(); return(false); } try { mStatusFile.TaskStatusDetail = clsStatusFile.EnumTaskStatusDetail.Running_Tool; var dumStr = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "; Package " + cmdParams["package"]; mStatusFile.MostRecentJobInfo = dumStr; mStatusFile.WriteStatusFile(); clsFolderTools.CreateDirectory(mMgrSettings.GetParam("perspective"), cmdParams, source); mStatusFile.JobNumber = 0; mStatusFile.TaskStatusDetail = clsStatusFile.EnumTaskStatusDetail.No_Task; mStatusFile.TaskStatus = clsStatusFile.EnumTaskStatus.No_Task; mStatusFile.WriteStatusFile(); } catch (Exception ex) { errorMessage = "Exception calling clsFolderTools.CreateDirectory"; var msg = errorMessage + " with XML command string: " + cmdText; LogError(msg, ex); mStatusFile.TaskStatus = clsStatusFile.EnumTaskStatus.Failed; mStatusFile.WriteStatusFile(); return(false); } return(true); }
/// <summary> /// Initializes the manager /// </summary> /// <returns>TRUE for success, FALSE for failure</returns> public bool InitMgr() { // Define the default logging info // This will get updated below LogTools.CreateFileLogger(DEFAULT_BASE_LOGFILE_NAME, BaseLogger.LogLevels.DEBUG); // Create a database logger connected to the Manager Control DB // Once the initial parameters have been successfully read, // we remove this logger than make a new one using the connection string read from the Manager Control DB var defaultDmsConnectionString = Properties.Settings.Default.MgrCnfgDbConnectStr; var hostName = System.Net.Dns.GetHostName(); var applicationName = "PkgFolderCreateManager_" + hostName; var defaultDbLoggerConnectionString = DbToolsFactory.AddApplicationNameToConnectionString(defaultDmsConnectionString, applicationName); LogTools.CreateDbLogger(defaultDbLoggerConnectionString, "FolderCreate: " + hostName); // Get the manager settings try { var localSettings = GetLocalManagerSettings(); mMgrSettings = new MgrSettingsDB { TraceMode = false }; RegisterEvents(mMgrSettings); mMgrSettings.CriticalErrorEvent += ErrorEventHandler; var success = mMgrSettings.LoadSettings(localSettings, true); if (!success) { if (string.Equals(mMgrSettings.ErrMsg, MgrSettings.DEACTIVATED_LOCALLY)) { throw new ApplicationException(MgrSettings.DEACTIVATED_LOCALLY); } throw new ApplicationException("Unable to initialize manager settings class: " + mMgrSettings.ErrMsg); } } catch { // Failures are logged by clsMgrSettings to local emergency log file return(false); } // Setup the loggers var logFileNameBase = mMgrSettings.GetParam("LogFilename", "FolderCreate"); BaseLogger.LogLevels logLevel; if (int.TryParse(mMgrSettings.GetParam("DebugLevel"), out var debugLevel)) { logLevel = (BaseLogger.LogLevels)debugLevel; } else { logLevel = BaseLogger.LogLevels.INFO; } LogTools.CreateFileLogger(logFileNameBase, logLevel); // Typically: // Data Source=gigasax;Initial Catalog=DMS_Pipeline;Integrated Security=SSPI; var logCnStr = mMgrSettings.GetParam("ConnectionString"); var moduleName = mMgrSettings.GetParam("ModuleName"); var dbLoggerConnectionString = DbToolsFactory.AddApplicationNameToConnectionString(logCnStr, mMgrSettings.ManagerName); LogTools.CreateDbLogger(dbLoggerConnectionString, moduleName); LogTools.MessageLogged += MessageLoggedHandler; // Make the initial log entry var appVersion = Assembly.GetExecutingAssembly().GetName().Version; var msg = "=== Started Package Folder Creation Manager V" + appVersion + " === "; LogTools.LogMessage(msg); // Setup the message queue mMsgHandler = new clsMessageHandler { BrokerUri = mMgrSettings.GetParam("MessageQueueURI"), CommandQueueName = mMgrSettings.GetParam("ControlQueueName"), BroadcastTopicName = mMgrSettings.GetParam("BroadcastQueueTopic"), StatusTopicName = mMgrSettings.GetParam("MessageQueueTopicMgrStatus"), MgrSettings = mMgrSettings }; if (!mMsgHandler.Init()) { // Most error messages provided by .Init method, but debug message is here for program tracking LogDebug("Message handler init error"); return(false); } LogDebug("Message handler initialized"); // Connect message handler events mMsgHandler.CommandReceived += OnMsgHandler_CommandReceived; mMsgHandler.BroadcastReceived += OnMsgHandler_BroadcastReceived; // Setup the status file class var appPath = PRISM.FileProcessor.ProcessFilesOrDirectoriesBase.GetAppPath(); var fInfo = new FileInfo(appPath); string statusFileNameLoc; if (fInfo.DirectoryName == null) { statusFileNameLoc = "Status.xml"; } else { statusFileNameLoc = Path.Combine(fInfo.DirectoryName, "Status.xml"); } mStatusFile = new clsStatusFile(statusFileNameLoc, mMsgHandler) { LogToMsgQueue = mMgrSettings.GetParam("LogStatusToMessageQueue", false), MgrName = mMgrSettings.ManagerName }; RegisterEvents(mStatusFile); mStatusFile.InitStatusFromFile(); SetStartupStatus(); mStatusFile.WriteStatusFile(); LogDebug("Status file init complete"); // Register the listeners for the message handler mMsgHandler.RegisterListeners(); // Everything worked return(true); }