Exemple #1
0
 /// <summary>
 /// Loads the view resource from the specified stream.
 /// </summary>
 public override void LoadResource(ViewResource resource, Stream stream)
 {
     if (resource.Name == nameof(TemplateBindings))
     {
         templateBindings = new TemplateBindings();
         templateBindings.Load(stream);
     }
 }
Exemple #2
0
 /// <summary>
 /// Creates new bindings.
 /// </summary>
 private void NewBindings()
 {
     fileName         = "";
     interfaceDir     = "";
     templateBindings = new TemplateBindings();
     DisplayInterfaceDir();
     DisplayBindings();
     Modified = false;
 }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public SchemeView(View viewEntity)
            : base(viewEntity)
        {
            maxComponentID   = 0;
            templateArgs     = new TemplateArgs(Args);
            templateBindings = null;

            SchemeDoc = new SchemeDocument {
                SchemeView = this
            };
            Components = new SortedList <int, ComponentBase>();
            LoadErrors = new List <string>();
        }
Exemple #4
0
        private bool modified;                     // the bindings were modified


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public FrmMain()
        {
            InitializeComponent();

            exeDir  = Path.GetDirectoryName(Application.ExecutablePath);
            langDir = Path.Combine(exeDir, "Lang");

            templateBindings = null;
            fileName         = "";
            interfaceDir     = "";
            changing         = false;
            modified         = false;
        }
Exemple #5
0
        /// <summary>
        /// Конструктор.
        /// </summary>
        public SchemeView()
            : base()
        {
            maxComponentID   = 0;
            templateArgs     = new TemplateArgs();
            templateBindings = null;

            SchemeDoc = new SchemeDocument()
            {
                SchemeView = this
            };
            Components = new SortedList <int, BaseComponent>();
            LoadErrors = new List <string>();
        }
Exemple #6
0
        /// <summary>
        /// Opens bindings from the specified file.
        /// </summary>
        private void OpenBindings(string fileName)
        {
            this.fileName    = fileName;
            templateBindings = new TemplateBindings();

            if (!templateBindings.Load(fileName, out string errMsg))
            {
                ScadaUiUtils.ShowError(errMsg);
            }

            FindInterfaceDir();
            DisplayInterfaceDir();
            DisplayBindings();
            Modified = false;
        }
Exemple #7
0
        /// <summary>
        /// Загрузить представление из потока.
        /// </summary>
        public override void LoadFromStream(Stream stream)
        {
            // clear the view
            Clear();

            // load component bindings
            if (string.IsNullOrEmpty(templateArgs.BindingFileName))
            {
                templateBindings = null;
            }
            else
            {
                templateBindings = new TemplateBindings();
                templateBindings.Load(System.IO.Path.Combine(
                                          SchemeContext.GetInstance().AppDirs.ConfigDir, templateArgs.BindingFileName));
            }

            // load XML document
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(stream);

            // check data format
            XmlElement rootElem = xmlDoc.DocumentElement;

            if (!rootElem.Name.Equals("SchemeView", StringComparison.OrdinalIgnoreCase))
            {
                throw new ScadaException(SchemePhrases.IncorrectFileFormat);
            }

            // get channel offsets in template mode
            int inCnlOffset   = templateArgs.InCnlOffset;
            int ctrlCnlOffset = templateArgs.CtrlCnlOffset;

            // load scheme document
            if (rootElem.SelectSingleNode("Scheme") is XmlNode schemeNode)
            {
                SchemeDoc.LoadFromXml(schemeNode);

                // установка заголовка представления
                Title = SchemeDoc.Title;

                // добавление входных каналов представления
                foreach (int cnlNum in SchemeDoc.CnlFilter)
                {
                    if (cnlNum > 0)
                    {
                        AddCnlNum(cnlNum + inCnlOffset);
                    }
                }
            }

            // load scheme components
            if (rootElem.SelectSingleNode("Components") is XmlNode componentsNode)
            {
                HashSet <string> errNodeNames = new HashSet <string>(); // имена узлов незагруженных компонентов
                CompManager      compManager  = CompManager.GetInstance();
                LoadErrors.AddRange(compManager.LoadErrors);
                SortedDictionary <int, ComponentBinding> componentBindings = templateBindings?.ComponentBindings;

                foreach (XmlNode compNode in componentsNode.ChildNodes)
                {
                    // создание компонента
                    BaseComponent component = compManager.CreateComponent(compNode, out string errMsg);

                    if (component == null)
                    {
                        component = new UnknownComponent {
                            XmlNode = compNode
                        };
                        if (errNodeNames.Add(compNode.Name))
                        {
                            LoadErrors.Add(errMsg);
                        }
                    }

                    // загрузка компонента и добавление его в представление
                    component.SchemeView = this;
                    component.LoadFromXml(compNode);
                    Components[component.ID] = component;

                    // добавление входных каналов представления
                    if (component is IDynamicComponent dynamicComponent)
                    {
                        if (componentBindings != null &&
                            componentBindings.TryGetValue(component.ID, out ComponentBinding binding))
                        {
                            dynamicComponent.InCnlNum   = binding.InCnlNum;
                            dynamicComponent.CtrlCnlNum = binding.CtrlCnlNum;
                        }
                        else
                        {
                            if (inCnlOffset > 0 && dynamicComponent.InCnlNum > 0)
                            {
                                dynamicComponent.InCnlNum += inCnlOffset;
                            }
                            if (ctrlCnlOffset > 0 && dynamicComponent.CtrlCnlNum > 0)
                            {
                                dynamicComponent.CtrlCnlNum += ctrlCnlOffset;
                            }
                        }

                        AddCnlNum(dynamicComponent.InCnlNum);
                        AddCtrlCnlNum(dynamicComponent.CtrlCnlNum);
                    }

                    // определение макс. идентификатора компонентов
                    if (component.ID > maxComponentID)
                    {
                        maxComponentID = component.ID;
                    }
                }
            }

            // load scheme images
            if (rootElem.SelectSingleNode("Images") is XmlNode imagesNode)
            {
                Dictionary <string, Image> images = SchemeDoc.Images;
                XmlNodeList imageNodes            = imagesNode.SelectNodes("Image");
                foreach (XmlNode imageNode in imageNodes)
                {
                    Image image = new Image();
                    image.LoadFromXml(imageNode);
                    if (!string.IsNullOrEmpty(image.Name))
                    {
                        images[image.Name] = image;
                    }
                }
            }
        }