コード例 #1
0
        public static AzureIot LoadAzureIot(string azureIotFile)
        {
            if (!File.Exists(azureIotFile))
            {
                throw new FileNotFoundException();
            }
            var azureIot = new AzureIot();

            try
            {
                XDocument xdocument = XDocument.Load(azureIotFile);
                azureIot.IotHubUri = (xdocument.Element("DataLinkAzureIoT").Attribute("IotHubUri") != null) ?
                                     xdocument.Element("DataLinkAzureIoT").Attribute("IotHubUri").Value : string.Empty;
                azureIot.DeviceId = (xdocument.Element("DataLinkAzureIoT").Attribute("DeviceId") != null) ?
                                    xdocument.Element("DataLinkAzureIoT").Attribute("DeviceId").Value : string.Empty;
                azureIot.DeviceKey = (xdocument.Element("DataLinkAzureIoT").Attribute("DeviceKey") != null) ?
                                     xdocument.Element("DataLinkAzureIoT").Attribute("DeviceKey").Value : string.Empty;
                azureIot.Jobs = new  List <Job>();
                foreach (var x in xdocument.Descendants("Job"))
                {
                    var jobItem = new Job();
                    jobItem.Name      = (x.Attribute("Name") != null) ? x.Attribute("Name").Value : string.Empty;
                    jobItem.CycleTime = (x.Attribute("CycleTime") != null) ? Convert.ToInt32(x.Attribute("CycleTime").Value) : 0;
                    jobItem.Enable    = (x.Attribute("Enable") != null) ? Convert.ToBoolean(x.Attribute("Enable").Value) : false;
                    jobItem.Commands  = new List <Command>();
                    foreach (var y in x.Descendants("Command"))
                    {
                        var commandItem = new Command();
                        commandItem.Name = (y.Attribute("Name") != null) ? y.Attribute("Name").Value : string.Empty;
                        commandItem.Tags = y.Descendants("Tag")
                                           .Select(node => (string)node.Attribute("Name"))
                                           .ToList();
                        commandItem.Job = jobItem;
                        jobItem.Commands.Add(commandItem);
                    }
                    azureIot.Jobs.Add(jobItem);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(azureIot);
        }
コード例 #2
0
 public void LoadSetting()
 {
     _azureIot = Bootstrapper.LoadAzureIot("Data/DataLinkAzureIoT.xml");
 }