Пример #1
0
        /// <summary>
        /// Connect to MD SNMP Agent
        /// </summary>;
        /// <param name="module">
        /// Module name
        /// </param>
        /// <param name="processId">
        /// process id
        /// </param>
        /// <returns>
        /// boolean result
        /// </returns>
        public bool Connect(string module, int processId)
        {
            ModuleName = module;
            if (!AgentSingleton.Instance.CheckModuleConfiguration(ModuleName))
            {
                throw new FaultException <ModuleConfigurationFaiure>(new ModuleConfigurationFaiure("Configuration file for module is missing"), new FaultReason("Missing config file"));
            }

            ModuleName    = AgentSingleton.Instance.GetModuleName(ModuleName);
            IsInitialized = true;
            AgentSingleton.Instance.GetLogger(ref mLogger);
            pingManager.CreateNewPinger(module, processId, true);
            mLogger.InfoFormat("Connection is opened from module: {0}", ModuleName);
            return(true);
        }
Пример #2
0
        /// <summary>
        /// The load configuration.
        /// </summary>
        /// <param name="mLogger">
        /// The m Logger.
        /// </param>
        /// <returns>
        /// The <see cref="InfoStorage"/>.
        /// </returns>
        public InfoStorage LoadConfiguration(ILog mLogger)
        {
            mLogger.Info("Starting loading components configuration");
            LocationCurrent = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string pathToConfigFolder = string.Format(@"{0}\{1}\", LocationCurrent, CONFIG_DIR);
            string fullPathToTemp     = string.Format(@"{0}\{1}\{2}\{3}", LocationCurrent, CONFIG_DIR, TEMP_DIR, MODULES_TEMP_FILE_NAME);

            InfoStorage result = null;

            if (Directory.Exists(pathToConfigFolder))
            {
                try
                {
                    TempModuleState temp = null;
                    if (File.Exists(fullPathToTemp))
                    {
                        mLogger.InfoFormat("Temp file {0} exists. Loading it.", MODULES_TEMP_FILE_NAME);
                        try
                        {
                            temp = InfoStorage.FromFile(new TempModuleState(), fullPathToTemp);
                        }
                        catch (Exception exception)
                        {
                            mLogger.ErrorFormat("Temp file {0} is corrupted!", MODULES_TEMP_FILE_NAME);
                            mLogger.Error("Exception: " + exception);
                        }
                    }
                    else
                    {
                        mLogger.Info("There is no temp file. Starting from the scratch");
                    }

                    string[] moduleConfigFiles = Directory.GetFiles(pathToConfigFolder, CONFIG_FILE_EXTENSION);
                    if (moduleConfigFiles.Length > 0)
                    {
                        result = new InfoStorage
                        {
                            ModulesInfo = new List <ModuleInfo>()
                        };

                        foreach (string moduleConfigFile in moduleConfigFiles)
                        {
                            var configFile = new FileInfo(moduleConfigFile);
                            mLogger.DebugFormat("Found config file: {0}", configFile.FullName);
                            try
                            {
                                ModuleInfo module = InfoStorage.FromFile(new ModuleInfo(), configFile.FullName);
                                if (module != null)
                                {
                                    if (temp != null)
                                    {
                                        var tmpModule = temp.ModuleStatus.Find(t => t.Name.Equals(module.Name));
                                        if (tmpModule != null)
                                        {
                                            if (tmpModule.ProcessId != 0 && tmpModule.Status != ModuleStatus.Disconnected.ToString())
                                            {
                                                pingManager.CreateNewPinger(tmpModule.Name, tmpModule.ProcessId, false);
                                            }

                                            module.ProcessId      = tmpModule.ProcessId;
                                            module.Status         = tmpModule.Status;
                                            module.SendAutoFixing = tmpModule.SendAutoFixing;
                                        }
                                        else
                                        {
                                            mLogger.WarnFormat("Temp data for module {0} was not found", module.Name);
                                        }
                                    }

                                    result.ModulesInfo.Add(module);
                                }
                                else
                                {
                                    mLogger.ErrorFormat("File {0} is corrupted!", moduleConfigFile);
                                }
                            }
                            catch (Exception exception)
                            {
                                mLogger.Error("Exception: " + exception);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    mLogger.Error("Exception: " + exception);
                }
            }
            else
            {
                mLogger.ErrorFormat("Modules configuration folder was not found. Path {0} does not exist!", pathToConfigFolder);
            }

            return(result);
        }