示例#1
0
        private Dictionary <string, JValue> FieldsCollection(Dictionary <string, JToken> reportedProperties)
        {
            var json            = JToken.Parse(JsonConvert.SerializeObject(reportedProperties));
            var fieldsCollector = new JsonFieldsCollector(json);

            return(fieldsCollector.GetAllFields());
        }
        private void NormalizedReportedProperties(Dictionary <string, JToken> reportedProperties)
        {
            var json            = JToken.Parse(JsonConvert.SerializeObject(reportedProperties));
            var fieldsCollector = new JsonFieldsCollector(json);

            this.ReportedProperties = fieldsCollector.GetAllFields();
        }
示例#3
0
        public async Task <List <DeviceDeploymentStatusServiceModel> > GetDeploymentStatusReport(string id, bool isLatest = true)
        {
            List <DeviceDeploymentStatusServiceModel> deviceDeploymentStatuses = new List <DeviceDeploymentStatusServiceModel>();
            var deploymentDetails = await this.GetAsync(id, true, isLatest);

            if (deploymentDetails != null && deploymentDetails.DeploymentMetrics != null && deploymentDetails.DeploymentMetrics.DeviceStatuses != null && deploymentDetails.DeploymentMetrics.DeviceStatuses.Keys.Count > 0)
            {
                string deviceQuery    = @"deviceId IN [{0}]";
                var    deviceIdsQuery = string.Join(",", deploymentDetails.DeploymentMetrics.DeviceStatuses.Keys.Select(d => $"'{d}'"));
                var    query          = string.Format(deviceQuery, deviceIdsQuery);

                DeviceServiceListModel devices = await this.GetDeviceListAsync(id, query, isLatest);

                foreach (var item in deploymentDetails.DeploymentMetrics.DeviceStatuses)
                {
                    var reportedProperties = devices.Items.First(x => x.Id == item.Key).Twin.ReportedProperties;

                    var json            = JToken.Parse(JsonConvert.SerializeObject(reportedProperties));
                    var fieldsCollector = new JsonFieldsCollector(json);
                    var fields          = fieldsCollector.GetAllFields();
                    deviceDeploymentStatuses.Add(new DeviceDeploymentStatusServiceModel(item.Key, item.Value, fields));
                }
            }

            return(deviceDeploymentStatuses);
        }
        public static async Task Run([EventHubTrigger(eventHubName: "twin-change", Connection = "TwinChangeEventHubConnectionString", ConsumerGroup = "%DeviceDeploymentHistoryConsumerGroup%")] EventData[] events, ILogger log)
        {
            bool        exceptionOccurred = false;
            List <Task> list = new List <Task>();

            foreach (EventData message in events)
            {
                try
                {
                    message.Properties.TryGetValue("tenant", out object tenant);

                    if (tenant != null)
                    {
                        string                      eventData          = Encoding.UTF8.GetString(message.Body.Array);
                        Twin                        twin               = JsonConvert.DeserializeObject <Twin>(eventData);
                        TwinServiceModel            twinServiceModel   = new TwinServiceModel(twin);
                        Dictionary <string, JToken> reportedProperties = twinServiceModel.ReportedProperties;
                        var  json             = JToken.Parse(JsonConvert.SerializeObject(reportedProperties));
                        var  fieldsCollector  = new JsonFieldsCollector(json);
                        var  fields           = fieldsCollector.GetAllFields();
                        bool isFirmWareUpdate = false;
                        foreach (var field in fields)
                        {
                            isFirmWareUpdate = field.Key.Contains(FIRMWARE, StringComparison.OrdinalIgnoreCase);
                            if (isFirmWareUpdate)
                            {
                                break;
                            }
                        }

                        if (isFirmWareUpdate)
                        {
                            message.SystemProperties.TryGetValue("iothub-connection-device-id", out object deviceId);
                            var newTwin = await TenantConnectionHelper.GetRegistry(Convert.ToString(tenant)).GetTwinAsync(deviceId.ToString());

                            var appliedConfigurations = newTwin.Configurations.Where(c => c.Value.Status.Equals(ConfigurationStatus.Applied));
                            if (appliedConfigurations != null && appliedConfigurations.Count() > 0)
                            {
                                DeploymentSyncService service    = new DeploymentSyncService();
                                var appliedDeploymentFromStorage = service.GetDeploymentsByIdFromStorage(Convert.ToString(tenant), appliedConfigurations.Select(ac => ac.Key).ToArray()).Result.FirstOrDefault();
                                await service.SaveDeploymentHistory(Convert.ToString(tenant), appliedDeploymentFromStorage, newTwin);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.LogError($"Error occurrred : {ex.Message} StackTrace: {ex.StackTrace}  Inner Exception: {(string.IsNullOrEmpty(ex.StackTrace) ? string.Empty : ex.StackTrace)}");
                    exceptionOccurred = true;
                }
            }

            if (exceptionOccurred)
            {
                throw new Exception("Function Failed with exception");
            }
        }
示例#5
0
        private static void WriteLines(string file)
        {
            var text            = File.ReadAllText(file);
            var json            = JToken.Parse(text);
            var fieldsCollector = new JsonFieldsCollector(json, AccessModifier.Public);
            var fields          = fieldsCollector.GetAllFields();

            var fileName = Path.GetFileName(file);

            Console.WriteLine($"Filename: {fileName}");
            Console.WriteLine();
            foreach (var field in fields)
            {
                Console.WriteLine($"{field.Key}: '{field.Value}'");
            }

            Console.WriteLine();
        }
示例#6
0
        public SearchResultsViewModel Search(string searchString, bool full = false)
        {
            var res = new SearchResultsViewModel
            {
                Attachments = Mapper.Map <List <Attachment>, List <AttachmentViewModel> >(_unitOfWork.Attachments.GetBy(x => x.Title.ToLower().Contains(searchString.ToLower())).Take(full ? Int32.MaxValue : 3).ToList()),
                Users       = Mapper.Map <List <User>, List <UserViewModel> >(_unitOfWork.Users.GetBy(x => x.Name.ToLower().Contains(searchString.ToLower())).ToList()),
                Projects    = Mapper.Map <List <Project>, List <ProjectViewModel> >(_unitOfWork.Projects.GetBy(x => x.Name.ToLower().Contains(searchString.ToLower()) || x.Description.ToLower().Contains(searchString.ToLower())).Take(full ? Int32.MaxValue : 3).ToList()),
                Ticktes     = Mapper.Map <List <Ticket>, List <TicketViewModel> >(_unitOfWork.Tickets.GetBy(x => x.Title.ToLower().Contains(searchString.ToLower()) || x.Description.ToLower().Contains(searchString.ToLower())).Take(full ? Int32.MaxValue : 3).ToList()),
            };
            var jsonSer = new JavaScriptSerializer();

            res.Templates = new List <TemplateSearchViewModel>();
            foreach (var id in _unitOfWork.Tickets.GetAll().Select(x => x.Id).ToList())
            {
                var templates = _templateService.GetTemplates(id);
                //var tempres = new List<TemplateViewModel>();
                foreach (var item in templates)
                {
                    var json            = JToken.Parse(jsonSer.Serialize(item));
                    var fieldsCollector = new JsonFieldsCollector(json);
                    if (fieldsCollector.GetAllFields().Any(x => x.Value.ToString().ToLower().Contains(searchString.ToLower())))
                    {
                        res.Templates.Add(new TemplateSearchViewModel
                        {
                            Template = item,
                            Ticket   = Mapper.Map <Ticket, TicketViewModel>(_unitOfWork.Tickets.GetById(id))
                        });
                    }
                }

                //var tempres = templates.Where(x => x.GetType().GetProperties().Where(pi => pi.PropertyType == typeof(string) && pi.GetValue(x, null)!=null).Any(y => y.GetValue(x, null).ToString().Contains(searchString)));
                //foreach (var item in tempres)
                //{
                //    res.Templates.Add(new TemplateSearchViewModel
                //    {
                //        Template = item,
                //        Ticket = Mapper.Map<Ticket, TicketViewModel>(_unitOfWork.Tickets.GetById(id))
                //    });
                //}
            }
            return(res);
        }
示例#7
0
        private static void UseJsonFieldsCollector()
        {
            var example  = @"Examples\Example1.JSON";
            var example1 = @"c:\em\test2.json";

            var files = new List <string>
            {
                //example,
                example1
            };

            foreach (var file in files)
            {
                var text            = File.ReadAllText(file);
                var json            = JToken.Parse(text);
                var fieldsCollector = new JsonFieldsCollector(json, AccessModifier.Public);
                var fields          = fieldsCollector.GetAllFields();
                foreach (var field in fields)
                {
                    Console.WriteLine($"{field.Key}: '{field.Value}'");
                }
            }
        }