Ejemplo n.º 1
0
        /// <summary>
        /// Fills the list of unused extensions.
        /// </summary>
        private void FillUnusedExtensions()
        {
            try
            {
                lbUnusedExt.BeginUpdate();
                lbUnusedExt.Items.Clear();

                // read all available extensions
                DirectoryInfo dirInfo = new(appData.AppDirs.LibDir);

                if (dirInfo.Exists)
                {
                    foreach (FileInfo fileInfo in
                             dirInfo.EnumerateFiles("Ext*.dll", SearchOption.TopDirectoryOnly))
                    {
                        string extentionCode = ScadaUtils.RemoveFileNameSuffixes(fileInfo.Name);

                        if (!config.ExtensionCodes.Contains(extentionCode))
                        {
                            lbUnusedExt.Items.Add(new ExtentionItem
                            {
                                IsInitialized = false,
                                ExtentionCode = extentionCode,
                                FileName      = fileInfo.FullName
                            });
                        }
                    }
                }
            }
            finally
            {
                lbUnusedExt.EndUpdate();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fills the list of available drivers.
        /// </summary>
        private void FillDriverList()
        {
            try
            {
                lbDrivers.BeginUpdate();
                lbDrivers.Items.Clear();
                DirectoryInfo dirInfo = new(adminContext.AppDirs.LibDir);

                if (dirInfo.Exists)
                {
                    foreach (FileInfo fileInfo in
                             dirInfo.EnumerateFiles("Drv*.View.dll", SearchOption.TopDirectoryOnly))
                    {
                        lbDrivers.Items.Add(new DriverItem
                        {
                            IsInitialized = false,
                            DriverCode    = ScadaUtils.RemoveFileNameSuffixes(fileInfo.Name),
                            FileName      = fileInfo.FullName
                        });
                    }
                }

                if (lbDrivers.Items.Count > 0)
                {
                    lbDrivers.SelectedIndex = 0;
                }
            }
            finally
            {
                lbDrivers.EndUpdate();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fills the list of unused modules.
        /// </summary>
        private void FillUnusedModules()
        {
            try
            {
                lbUnusedModules.BeginUpdate();
                lbUnusedModules.Items.Clear();

                // read all available modules
                DirectoryInfo dirInfo = new(adminContext.AppDirs.LibDir);

                if (dirInfo.Exists)
                {
                    foreach (FileInfo fileInfo in
                             dirInfo.EnumerateFiles("Mod*.View.dll", SearchOption.TopDirectoryOnly))
                    {
                        string moduleCode = ScadaUtils.RemoveFileNameSuffixes(fileInfo.Name);

                        if (!serverConfig.ModuleCodes.Contains(moduleCode))
                        {
                            lbUnusedModules.Items.Add(new ModuleItem
                            {
                                IsInitialized = false,
                                ModuleCode    = moduleCode,
                                FileName      = fileInfo.FullName
                            });
                        }
                    }
                }
            }
            finally
            {
                lbUnusedModules.EndUpdate();
            }
        }
Ejemplo n.º 4
0
        private int lastInfoLength;       // the last info text length


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public DeviceLogic(ICommContext commContext, ILineContext lineContext, DeviceConfig deviceConfig)
        {
            CommContext  = commContext ?? throw new ArgumentNullException(nameof(commContext));
            LineContext  = lineContext ?? throw new ArgumentNullException(nameof(lineContext));
            DeviceConfig = deviceConfig ?? throw new ArgumentNullException(nameof(deviceConfig));
            AppDirs      = commContext.AppDirs;
            Log          = lineContext.LineConfig.LineOptions.DetailedLog ? lineContext.Log : LogStub.Instance;
            AssemblyName asmName = GetType().Assembly.GetName();

            DriverName         = ScadaUtils.RemoveFileNameSuffixes(asmName.Name) + " " + asmName.Version;
            LastRequestOK      = false;
            ReqRetries         = lineContext.LineConfig.LineOptions.ReqRetries;
            IsBound            = lineContext.LineConfig.IsBound && deviceConfig.IsBound;
            DeviceNum          = deviceConfig.DeviceNum;
            Title              = CommUtils.GetDeviceTitle(DeviceNum, deviceConfig.Name);
            NumAddress         = deviceConfig.NumAddress;
            StrAddress         = deviceConfig.StrAddress;
            PollingOptions     = deviceConfig.PollingOptions;
            CanSendCommands    = false;
            ConnectionRequired = false;
            DeviceStatus       = DeviceStatus.Undefined;
            LastSessionTime    = DateTime.MinValue;
            LastCommandTime    = DateTime.MinValue;
            DeviceTags         = new DeviceTags();
            DeviceData         = new DeviceData(deviceConfig.DeviceNum);
            DeviceStats        = new DeviceStats();

            terminated     = false;
            connection     = null;
            lastInfoLength = 0;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the configuration from the specified file.
        /// </summary>
        public bool Load(string fileName, out string errMsg)
        {
            try
            {
                Clear();

                XmlDocument xmlDoc = new();
                xmlDoc.Load(fileName);
                XmlElement rootElem = xmlDoc.DocumentElement;

                if (rootElem.SelectSingleNode("Extensions") is XmlNode modulesNode)
                {
                    HashSet <string> extensionCodes = new();

                    foreach (XmlElement moduleElem in modulesNode.SelectNodes("Extension"))
                    {
                        string moduleCode = ScadaUtils.RemoveFileNameSuffixes(moduleElem.GetAttribute("code"));

                        if (extensionCodes.Add(moduleCode.ToLowerInvariant())) // check uniqueness
                        {
                            ExtensionCodes.Add(moduleCode);
                        }
                    }
                }

                if (rootElem.SelectSingleNode("FileAssociations") is XmlNode fileAssociationsNode)
                {
                    foreach (XmlElement associationElem in fileAssociationsNode.SelectNodes("Association"))
                    {
                        string ext  = associationElem.GetAttrAsString("ext").ToLowerInvariant();
                        string path = associationElem.GetAttrAsString("path");
                        FileAssociations[ext] = path;
                    }
                }

                if (rootElem.SelectSingleNode("ChannelNumberingOptions") is XmlNode channelNumberingOptionsNode)
                {
                    ChannelNumberingOptions.LoadFromXml(channelNumberingOptionsNode);
                }

                if (rootElem.SelectSingleNode("CustomOptions") is XmlNode customOptionsNode)
                {
                    foreach (XmlElement optionGroupElem in customOptionsNode.SelectNodes("OptionGroup"))
                    {
                        OptionList optionList = new();
                        optionList.LoadFromXml(optionGroupElem);
                        CustomOptions[optionGroupElem.GetAttrAsString("name")] = optionList;
                    }
                }

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = ex.BuildErrorMessage(CommonPhrases.LoadConfigError);
                return(false);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads the configuration from the specified reader.
        /// </summary>
        protected override void Load(TextReader reader)
        {
            XmlDocument xmlDoc = new();

            xmlDoc.Load(reader);
            XmlElement rootElem = xmlDoc.DocumentElement;

            if (rootElem.SelectSingleNode("GeneralOptions") is XmlNode generalOptionsNode)
            {
                GeneralOptions.LoadFromXml(generalOptionsNode);
            }

            if (rootElem.SelectSingleNode("ConnectionOptions") is XmlNode connectionOptionsNode)
            {
                ConnectionOptions.LoadFromXml(connectionOptionsNode);
            }

            if (rootElem.SelectSingleNode("LoginOptions") is XmlNode loginOptionsNode)
            {
                LoginOptions.LoadFromXml(loginOptionsNode);
            }

            if (rootElem.SelectSingleNode("DisplayOptions") is XmlNode displayOptionsNode)
            {
                DisplayOptions.LoadFromXml(displayOptionsNode);
            }

            HashSet <string> pluginCodes = new();

            if (rootElem.SelectSingleNode("Plugins") is XmlNode pluginsNode)
            {
                foreach (XmlElement pluginElem in pluginsNode.SelectNodes("Plugin"))
                {
                    string pluginCode = ScadaUtils.RemoveFileNameSuffixes(pluginElem.GetAttribute("code"));

                    if (pluginCodes.Add(pluginCode.ToLowerInvariant())) // check uniqueness
                    {
                        PluginCodes.Add(pluginCode);
                    }
                }
            }


            if (rootElem.SelectSingleNode("PluginAssignment") is XmlNode pluginAssignmentNode)
            {
                PluginAssignment.LoadFromXml(pluginAssignmentNode);
            }

            if (rootElem.SelectSingleNode("CustomOptions") is XmlNode customOptionsNode)
            {
                foreach (XmlElement optionGroupElem in customOptionsNode.SelectNodes("OptionGroup"))
                {
                    OptionList optionList = new();
                    optionList.LoadFromXml(optionGroupElem);
                    CustomOptions[optionGroupElem.GetAttrAsString("name")] = optionList;
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Loads the configuration from the XML node.
        /// </summary>
        public void LoadFromXml(XmlElement xmlElem)
        {
            if (xmlElem == null)
            {
                throw new ArgumentNullException(nameof(xmlElem));
            }

            Active = xmlElem.GetAttrAsBool("active");
            Code   = xmlElem.GetAttrAsString("code");
            Name   = xmlElem.GetAttrAsString("name");
            Driver = ScadaUtils.RemoveFileNameSuffixes(xmlElem.GetAttrAsString("driver"));
            CustomOptions.LoadFromXml(xmlElem);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads the configuration from the specified reader.
        /// </summary>
        protected override void Load(TextReader reader)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(reader);
            XmlElement rootElem = xmlDoc.DocumentElement;

            if (rootElem.SelectSingleNode("GeneralOptions") is XmlNode generalOptionsNode)
            {
                GeneralOptions.LoadFromXml(generalOptionsNode);
            }

            if (rootElem.SelectSingleNode("ListenerOptions") is XmlNode listenerOptionsNode)
            {
                ListenerOptions.LoadFromXml(listenerOptionsNode);
            }

            HashSet <string> moduleCodeSet = new HashSet <string>();

            void AddModuleCode(string moduleCode)
            {
                if (!string.IsNullOrEmpty(moduleCode) && moduleCodeSet.Add(moduleCode.ToLowerInvariant()))
                {
                    ModuleCodes.Add(moduleCode);
                }
            }

            if (rootElem.SelectSingleNode("Modules") is XmlNode modulesNode)
            {
                foreach (XmlElement moduleElem in modulesNode.SelectNodes("Module"))
                {
                    string moduleCode = ScadaUtils.RemoveFileNameSuffixes(moduleElem.GetAttribute("code"));
                    AddModuleCode(moduleCode);
                }
            }

            if (rootElem.SelectSingleNode("Archives") is XmlNode archivesNode)
            {
                foreach (XmlElement archiveElem in archivesNode.SelectNodes("Archive"))
                {
                    ArchiveConfig archiveConfig = new ArchiveConfig();
                    archiveConfig.LoadFromXml(archiveElem);
                    Archives.Add(archiveConfig);

                    if (archiveConfig.Active)
                    {
                        AddModuleCode(archiveConfig.Module);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Loads the configuration from the XML node.
        /// </summary>
        public void LoadFromXml(XmlElement xmlElem)
        {
            if (xmlElem == null)
            {
                throw new ArgumentNullException(nameof(xmlElem));
            }

            Active = xmlElem.GetAttrAsBool("active");
            Code   = xmlElem.GetAttrAsString("code");
            Name   = xmlElem.GetAttrAsString("name");
            Kind   = xmlElem.GetAttrAsEnum("kind", ArchiveKind.Unspecified);
            Module = ScadaUtils.RemoveFileNameSuffixes(xmlElem.GetAttrAsString("module"));
            CustomOptions.LoadFromXml(xmlElem);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Fills the list of the channel types.
        /// </summary>
        private void FillChannelTypeList()
        {
            // fill shared list
            if (sharedChannelTypes == null)
            {
                ValidateInit();
                sharedChannelTypes = new List <ChannelTypeItem>();
                DirectoryInfo dirInfo = new(adminContext.AppDirs.LibDir);

                sharedChannelTypes.Add(new ChannelTypeItem
                {
                    TypeCode = "",
                    TypeName = ExtensionPhrases.UndefinedChannelType,
                    Driver   = ""
                });

                if (dirInfo.Exists)
                {
                    foreach (FileInfo fileInfo in
                             dirInfo.EnumerateFiles("DrvCnl*.View.dll", SearchOption.TopDirectoryOnly))
                    {
                        string driverCode = ScadaUtils.RemoveFileNameSuffixes(fileInfo.Name);

                        if (ExtensionUtils.GetDriverView(adminContext, commApp, driverCode,
                                                         out DriverView driverView, out string message))
                        {
                            if (driverView.CanCreateChannel &&
                                driverView.ChannelTypes is ICollection <ChannelTypeName> channelTypeNames)
                            {
                                foreach (ChannelTypeName channelTypeName in channelTypeNames)
                                {
                                    sharedChannelTypes.Add(new ChannelTypeItem
                                    {
                                        TypeCode = channelTypeName.Code,
                                        TypeName = channelTypeName.Name,
                                        Driver   = driverCode
                                    });
                                }
                            }
                        }
                        else
                        {
                            adminContext.ErrLog.WriteError(message);
                        }
                    }
                }
Ejemplo n.º 11
0
        /// <summary>
        /// Fills the combo box by the modules that support archives.
        /// </summary>
        private void FillModuleComboBox()
        {
            try
            {
                cbModule.BeginUpdate();
                cbModule.Items.Clear();
                DirectoryInfo dirInfo = new(adminContext.AppDirs.LibDir);

                foreach (FileInfo fileInfo in
                         dirInfo.EnumerateFiles("ModArc*.View.dll", SearchOption.TopDirectoryOnly))
                {
                    cbModule.Items.Add(ScadaUtils.RemoveFileNameSuffixes(fileInfo.Name));
                }
            }
            finally
            {
                cbModule.EndUpdate();
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Loads plugins to integrate their pages and controllers into the web application.
 /// </summary>
 private void ConfigureApplicationParts(ApplicationPartManager apm)
 {
     foreach (string fileName in
              Directory.EnumerateFiles(WebContext.AppDirs.ExeDir, "Plg*.dll", SearchOption.TopDirectoryOnly))
     {
         if (WebContext.PluginHolder.ContainsPlugin(
                 ScadaUtils.RemoveFileNameSuffixes(Path.GetFileName(fileName))))
         {
             try
             {
                 Assembly assembly = Assembly.LoadFrom(fileName);
                 apm.ApplicationParts.Add(new CompiledRazorAssemblyPart(assembly));
                 apm.ApplicationParts.Add(new AssemblyPart(assembly));
             }
             catch (Exception ex)
             {
                 WebContext.Log.WriteError(ex, Locale.IsRussian ?
                                           "Ошибка при загрузке части приложения из файла {0}" :
                                           "Error loading application part from file {0}", fileName);
             }
         }
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Loads the configuration from the specified file.
        /// </summary>
        public bool Load(string fileName, out string errMsg)
        {
            try
            {
                SetToDefault();

                if (!File.Exists(fileName))
                {
                    throw new FileNotFoundException(string.Format(CommonPhrases.NamedFileNotFound, fileName));
                }

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);
                XmlElement rootElem = xmlDoc.DocumentElement;

                if (rootElem.SelectSingleNode("GeneralOptions") is XmlNode generalOptionsNode)
                {
                    GeneralOptions.LoadFromXml(generalOptionsNode);
                }

                if (rootElem.SelectSingleNode("ListenerOptions") is XmlNode listenerOptionsNode)
                {
                    ListenerOptions.LoadFromXml(listenerOptionsNode);
                }

                if (rootElem.SelectSingleNode("PathOptions") is XmlNode pathOptionsNode)
                {
                    PathOptions.LoadFromXml(pathOptionsNode);
                }

                HashSet <string> moduleCodes = new HashSet <string>();

                if (rootElem.SelectSingleNode("Modules") is XmlNode modulesNode)
                {
                    foreach (XmlElement moduleElem in modulesNode.SelectNodes("Module"))
                    {
                        string moduleCode = ScadaUtils.RemoveFileNameSuffixes(moduleElem.GetAttribute("code"));

                        if (moduleCodes.Add(moduleCode.ToLowerInvariant())) // check uniqueness
                        {
                            ModuleCodes.Add(moduleCode);
                        }
                    }
                }

                if (rootElem.SelectSingleNode("Archives") is XmlNode archivesNode)
                {
                    foreach (XmlElement archiveElem in archivesNode.SelectNodes("Archive"))
                    {
                        ArchiveConfig archiveConfig = new ArchiveConfig();
                        archiveConfig.LoadFromXml(archiveElem);
                        Archives.Add(archiveConfig);

                        if (archiveConfig.Active && moduleCodes.Add(archiveConfig.Module.ToLowerInvariant()))
                        {
                            ModuleCodes.Add(archiveConfig.Module);
                        }
                    }
                }

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommonPhrases.LoadAppConfigError + ": " + ex.Message;
                return(false);
            }
        }