Exemple #1
0
            public static CollectorInner FromJsonObject(JObject obj)
            {
                CollectorInner collector = new CollectorInner();

                foreach (JToken cspToken in obj.Children())
                {
                    if (!(cspToken is JProperty))
                    {
                        continue;
                    }

                    JProperty cspProperty = (JProperty)cspToken;
                    if (cspProperty.Name == JsonLogFileFolder)
                    {
                        collector.logFileFolder = (string)cspProperty.Value;
                    }
                    else if (cspProperty.Name == JsonLogFileName)
                    {
                        collector.logFileName = (string)cspProperty.Value;
                    }
                    else if (cspProperty.Name == JsonLogFileSizeLimitMB)
                    {
                        collector.logFileSizeLimitMB = (int)cspProperty.Value;
                    }
                    else if (cspProperty.Name == JsonTraceMode)
                    {
                        collector.traceMode = TraceModeFromJsonString((string)cspProperty.Value);
                    }
                    else if (cspProperty.Name == JsonStarted)
                    {
                        collector.started = (bool)cspProperty.Value;
                    }
                    else
                    {
                        Provider provider = TryReadProviderFromJson(cspProperty);
                        if (provider != null)
                        {
                            collector.providers.Add(provider);
                        }
                        // We don't throw errors here because we only read the node
                        // we know about. Extra nodes are allowed.
                    }
                }

                return(collector);
            }
Exemple #2
0
            public static CollectorDesiredState FromJsonObject(string name, JObject obj)
            {
                CollectorDesiredState collector = new CollectorDesiredState();

                collector.name = name;
                collector.reportToDeviceTwin = Utils.GetString(obj, CommonDataContract.JsonReportProperties, CommonDataContract.JsonNoString) == CommonDataContract.JsonYesString;

                JToken jApplyProperties = Utils.GetJToken(obj, CommonDataContract.JsonApplyProperties);

                if (jApplyProperties is JObject)
                {
                    collector.applyFromDeviceTwin = true;
                    collector.collectorInner      = CollectorInner.FromJsonObject((JObject)jApplyProperties);
                }
                else
                {
                    collector.applyFromDeviceTwin = false;
                }

                return(collector);
            }