Exemplo n.º 1
0
        /// <summary>
        /// Download module configuration
        /// </summary>
        public bool Load(out string errMsg)
        {
            SetToDefault();

            try {
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(FileName);

                // loading export destinations
                var expDestsNode = xmlDoc.DocumentElement.SelectSingleNode("ExportDestinations");
                if (expDestsNode != null)
                {
                    var expDestNodeList = expDestsNode.SelectNodes("ExportDestination");
                    foreach (XmlElement expDestElem in expDestNodeList)
                    {
                        // loading data source
                        DataSource dataSource     = null;
                        var        dataSourceNode = expDestElem.SelectSingleNode("DataSource");

                        if (dataSourceNode != null)
                        {
                            // getting data source type
                            DBTypes dbType;
                            if (!Enum.TryParse <DBTypes>(dataSourceNode.GetChildAsString("DBType"), out dbType))
                            {
                                dbType = DBTypes.Undefined;
                            }

                            // create data source
                            switch (dbType)
                            {
                            case DBTypes.MSSQL:
                                dataSource = new SqlDataSource();
                                break;

                            case DBTypes.Oracle:
                                dataSource = new OraDataSource();
                                break;

                            case DBTypes.PostgreSQL:
                                dataSource = new PgSqlDataSource();
                                break;

                            case DBTypes.MySQL:
                                dataSource = new MySqlDataSource();
                                break;

                            case DBTypes.OLEDB:
                                dataSource = new OleDbDataSource();
                                break;

                            default:
                                dataSource = null;
                                break;
                            }

                            if (dataSource != null)
                            {
                                dataSource.Server           = dataSourceNode.GetChildAsString("Server");
                                dataSource.Database         = dataSourceNode.GetChildAsString("Database");
                                dataSource.User             = dataSourceNode.GetChildAsString("User");
                                dataSource.Password         = dataSourceNode.GetChildAsString("Password");
                                dataSource.ConnectionString = dataSourceNode.GetChildAsString("ConnectionString");

                                if (string.IsNullOrEmpty(dataSource.ConnectionString))
                                {
                                    dataSource.ConnectionString = dataSource.BuildConnectionString();
                                }
                            }
                        }

                        // load export options
                        ExportParams exportParams     = null;
                        var          exportParamsNode = expDestElem.SelectSingleNode("ExportParams");

                        if (dataSource != null && exportParamsNode != null)
                        {
                            exportParams = new ExportParams {
                                ExportCurDataQuery = exportParamsNode.GetChildAsString("ExportCurDataQuery")
                            };
                            exportParams.ExportCurData = !string.IsNullOrEmpty(exportParams.ExportCurDataQuery) &&
                                                         exportParamsNode.GetChildAsBool("ExportCurData");
                            exportParams.ExportArcDataQuery = exportParamsNode.GetChildAsString("ExportArcDataQuery");
                            exportParams.ExportArcData      = !string.IsNullOrEmpty(exportParams.ExportArcDataQuery) &&
                                                              exportParamsNode.GetChildAsBool("ExportArcData");
                            exportParams.ExportEventQuery = exportParamsNode.GetChildAsString("ExportEventQuery");
                            exportParams.ExportEvents     = !string.IsNullOrEmpty(exportParams.ExportEventQuery) &&
                                                            exportParamsNode.GetChildAsBool("ExportEvents");
                        }

                        // creating export destination
                        if (dataSource != null && exportParams != null)
                        {
                            var expDest = new ExportDestination(dataSource, exportParams);
                            ExportDestinations.Add(expDest);
                        }
                    }

                    // sort export destinations
                    ExportDestinations.Sort();
                }

                // loading control channel numbers for manual export
                var manExpNode = xmlDoc.DocumentElement.SelectSingleNode("ManualExport");
                if (manExpNode != null)
                {
                    CurDataCtrlCnlNum = manExpNode.GetChildAsInt("CurDataCtrlCnlNum");
                    ArcDataCtrlCnlNum = manExpNode.GetChildAsInt("ArcDataCtrlCnlNum");
                    EventsCtrlCnlNum  = manExpNode.GetChildAsInt("EventsCtrlCnlNum");
                }

                errMsg = "";
                return(true);
            } catch (FileNotFoundException ex) {
                errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message +
                         Environment.NewLine + ModPhrases.ConfigureModule;
                return(false);
            } catch (Exception ex) {
                errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message;
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Загрузить конфигурацию модуля
        /// </summary>
        public bool Load(out string errMsg)
        {
            SetToDefault();

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(FileName);

                // загрузка назначений экспорта
                XmlNode expDestsNode = xmlDoc.DocumentElement.SelectSingleNode("ExportDestinations");
                if (expDestsNode != null)
                {
                    XmlNodeList expDestNodeList = expDestsNode.SelectNodes("ExportDestination");
                    foreach (XmlElement expDestElem in expDestNodeList)
                    {
                        // загрузка источника данных
                        DataSource dataSource = null;

                        if (expDestElem.SelectSingleNode("DataSource") is XmlNode dataSourceNode)
                        {
                            // получение типа источника данных
                            if (!Enum.TryParse(dataSourceNode.GetChildAsString("DBType"), out DBType dbType))
                            {
                                dbType = DBType.Undefined;
                            }

                            // создание источника данных
                            switch (dbType)
                            {
                            case DBType.MSSQL:
                                dataSource = new SqlDataSource();
                                break;

                            case DBType.Oracle:
                                dataSource = new OraDataSource();
                                break;

                            case DBType.PostgreSQL:
                                dataSource = new PgSqlDataSource();
                                break;

                            case DBType.MySQL:
                                dataSource = new MySqlDataSource();
                                break;

                            case DBType.OLEDB:
                                dataSource = new OleDbDataSource();
                                break;

                            default:
                                dataSource = null;
                                break;
                            }

                            if (dataSource != null)
                            {
                                dataSource.Server           = dataSourceNode.GetChildAsString("Server");
                                dataSource.Database         = dataSourceNode.GetChildAsString("Database");
                                dataSource.User             = dataSourceNode.GetChildAsString("User");
                                dataSource.Password         = ScadaUtils.Decrypt(dataSourceNode.GetChildAsString("Password"));
                                dataSource.ConnectionString = dataSourceNode.GetChildAsString("ConnectionString");

                                if (string.IsNullOrEmpty(dataSource.ConnectionString))
                                {
                                    dataSource.ConnectionString = dataSource.BuildConnectionString();
                                }
                            }
                        }

                        if (dataSource != null &&
                            expDestElem.SelectSingleNode("ExportParams") is XmlNode exportParamsNode)
                        {
                            // загрузка параметров экспорта
                            ExportParams exportParams = new ExportParams();
                            exportParams.LoadFromXml(exportParamsNode);

                            // создание назначения экспорта
                            ExportDestination expDest = new ExportDestination(dataSource, exportParams);
                            ExportDestinations.Add(expDest);
                        }
                    }

                    // сортировка назначений экспорта
                    ExportDestinations.Sort();
                }

                // загрузка номеров каналов управления для экспорта в ручном режиме
                if (xmlDoc.DocumentElement.SelectSingleNode("ManualExport") is XmlNode manExpNode)
                {
                    CurDataCtrlCnlNum = manExpNode.GetChildAsInt("CurDataCtrlCnlNum");
                    ArcDataCtrlCnlNum = manExpNode.GetChildAsInt("ArcDataCtrlCnlNum");
                    EventsCtrlCnlNum  = manExpNode.GetChildAsInt("EventsCtrlCnlNum");
                }

                errMsg = "";
                return(true);
            }
            catch (FileNotFoundException ex)
            {
                errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message +
                         Environment.NewLine + ModPhrases.ConfigureModule;
                return(false);
            }
            catch (Exception ex)
            {
                errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message;
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads saved settings for the <see cref="MultipleDestinationExporter"/> object from the config file if the <see cref="PersistSettings"/> 
        /// property is set to true.
        /// </summary>        
        public void LoadSettings()
        {
            if (m_persistSettings)
            {
                // Ensure that settings category is specified.
                if (string.IsNullOrEmpty(m_settingsCategory))
                    throw new InvalidOperationException("SettingsCategory property has not been set.");

                // Load settings from the specified category.
                ConfigurationFile config = ConfigurationFile.Current;
                CategorizedSettingsElementCollection settings = config.Settings[m_settingsCategory];

                if (settings.Count == 0) return;    // Don't proceed if export destination are not in config file.

                string entryRoot;
                int count;

                ExportDestination destination;
                m_exportTimeout = settings["ExportTimeout", true].ValueAs(m_exportTimeout);
                count = settings["ExportCount", true].ValueAsInt32();
                m_exportDestinations = new List<ExportDestination>(count);

                lock (m_exportDestinations)
                {
                    for (int x = 0; x < count; x++)
                    {
                        entryRoot = string.Format("ExportDestination{0}", x + 1);

                        // Load export destination from configuration entries
                        destination = new ExportDestination();
                        destination.DestinationFile = settings[entryRoot, true].ValueAsString() + settings[string.Format("{0}.FileName", entryRoot), true].ValueAsString();
                        destination.ConnectToShare = settings[string.Format("{0}.ConnectToShare", entryRoot), true].ValueAsBoolean();
                        destination.Domain = settings[string.Format("{0}.Domain", entryRoot), true].ValueAsString();
                        destination.UserName = settings[string.Format("{0}.UserName", entryRoot), true].ValueAsString();
                        destination.Password = settings[string.Format("{0}.Password", entryRoot), true].ValueAsString();

                        // Save new export destination
                        m_exportDestinations.Add(destination);
                    }
                }
            }
        }