示例#1
0
        public IActionResult CreateUarcClients(string filePath)
        {
            XmlConfigViewModel configModel = new XmlConfigViewModel();

            if ((Program.UarcCollector.OpcUaVerbindungen.Count == 0) && (Program.UarcCollector.SqlConnectionString == null))
            {
                try
                {
                    Program.UarcCollector.CreateUarcClientsAndDbWithXml(filePath);
                }
                catch (Exception e)
                {
                    if (e.Message == null)
                    {
                        e = new Exception("UARC-Collector konnte nicht alle OPC UA Verbindungen erstellen. + /n + Überprüfen Sie die Konfigurationsdatei");
                        throw e;
                    }
                    else
                    {
                        throw e;
                    }
                }
            }
            else
            {
                if ((Program.UarcCollector.OpcUaVerbindungen.Count != 0) && (Program.UarcCollector.SqlConnectionString == null))
                {
                    throw new Exception("Es sind bereits Verbindungen und eine Datenbank konfiguriert. + /n + Entfernen Sie diese, um eine neue Konfiguration zu nutzen.");
                }
                else if (Program.UarcCollector.OpcUaVerbindungen.Count != 0)
                {
                    throw new Exception("Es sind bereits Verbindungen konfiguriert. + /n + Entfernen Sie diese, um eine neue Konfiguration zu nutzen.");
                }
                else if (Program.UarcCollector.SqlConnectionString != null)
                {
                    throw new Exception("Es ist bereits eine Datenbank konfiguriert. + /n + Entfernen Sie diese, um eine neue Konfiguration zu nutzen.");
                }
            }

            configModel.Path = filePath;

            return(View(configModel));
        }
        public IActionResult Check(string path)
        {
            XmlConfigViewModel configModel = new XmlConfigViewModel();
            XmlUarcConfig      config      = OpcUaXmlConfigIO.OpcUaXmlConfigFileRead(path);

            try
            {
                OpcUaXmlConfigChecker.FormatAndValidate(config);
            }
            catch
            {
                throw new Exception("Konfigurationsdatei ist nicht korrekt");
            }

            OpcUaXmlConfigIO.OpcUaXmlConfigFileWrite(path, config);;

            configModel.Path = path;

            return(View(configModel));
        }
示例#3
0
        public IActionResult DeleteXmlConfig(string filePath, string exampleFileName)
        {
            XmlConfigViewModel configModel = new XmlConfigViewModel();

            // Delete a file by using File class static method...
            if (System.IO.File.Exists(filePath))
            {
                try
                {
                    System.IO.File.Delete(filePath);
                }
                catch (System.IO.IOException e)
                {
                    throw e;
                }
            }

            configModel.Path           = filePath;
            configModel.ConfigXmlLabel = exampleFileName;

            return(View(configModel));
        }
        public async Task <IActionResult> Upload(IFormFile file)
        {
            string fileName = Path.GetFileName(file.FileName);
            string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "XML Dateien", "Konfiguration", fileName);

            //Wird verwendet im string der View zu übergeben
            XmlConfigViewModel configModel = new XmlConfigViewModel();

            //Temporäres Object um eingebenes Object zuspeichern
            XmlDocument xDoc = new XmlDocument();

            try
            {
                if (file.Length > 0)
                {
                    using (Stream mStream = new MemoryStream())
                    {
                        mStream.Position = 0;
                        await file.CopyToAsync(mStream);

                        mStream.Position = 0;
                        xDoc.Load(mStream);
                    }
                }
                xDoc.Save(filePath);
            }
            catch
            {
                throw new System.IO.IOException("Konfigurationsdatei kann nicht geladen werden oder ist nicht korrekt");
            }

            configModel.Path           = filePath;
            configModel.ConfigXmlLabel = fileName;

            return(View(configModel));
        }