Пример #1
0
        public IoTEnsembleActiveEnterpriseConfig()
        {
            ActiveEnterprise = new IoTEnsembleChildEnterprise();

            Page = 1;

            PageSize = 10;
        }
Пример #2
0
        public virtual async Task LoadChildEnterprises(IEnterprisesManagementService entMgr, string parentEntLookup,
                                                       IApplicationsIoTService appIoTArch, IIdentityAccessService idMgr)
        {
            var childEntsResp = await entMgr.ListChildEnterprises(parentEntLookup);

            State.EnterpriseConfig.TotalChildEnterprisesCount = childEntsResp.Model?.Count;

            var pagedChildEnts = childEntsResp.Model?.Page(State.EnterpriseConfig.Page, State.EnterpriseConfig.PageSize);

            var iotChildEnts = new List <IoTEnsembleChildEnterprise>();

            await pagedChildEnts.Items.Each(async childEnt =>
            {
                var devicesResp = await appIoTArch.ListEnrolledDevices(childEnt.Lookup);

                var licenses = await idMgr.ListLicensesByUsername(parentEntLookup, childEnt.Name, new List <string>()
                {
                    "iot"
                });

                DateTime?StartDate = null;

                foreach (License token in licenses.Model)
                {
                    if (token.AccessStartDate != null)
                    {
                        StartDate = token.AccessStartDate.UtcDateTime;
                    }
                }

                var iotChildEnt = new IoTEnsembleChildEnterprise()
                {
                    Name        = childEnt.Name,
                    Lookup      = childEnt.Lookup,
                    DeviceCount = devicesResp.Model?.TotalRecords ?? 0,
                    SignUpDate  = StartDate
                };

                iotChildEnt.Devices = devicesResp.Model?.Items?.Select(device =>
                {
                    var devInfo = device.JSONConvert <IoTEnsembleDeviceInfo>();

                    devInfo.DeviceName = devInfo.DeviceID.Replace($"{childEnt.Lookup}-", String.Empty);

                    return(devInfo);
                }).ToList();

                iotChildEnts.Add(iotChildEnt);
            });

            State.EnterpriseConfig.ChildEnterprises = iotChildEnts;
        }