Пример #1
0
        public async Task <DependentObjectCheckResult> CheckInUseDeviceWorkflowAsync(string workflowId, EntityHeader org, EntityHeader user)
        {
            var eventSet = await _deviceWorkflowRepo.GetDeviceWorkflowAsync(workflowId);

            await AuthorizeAsync(eventSet, AuthorizeResult.AuthorizeActions.Read, user, org);

            return(await CheckForDepenenciesAsync(eventSet));
        }
        public async Task <InvokeResult> DeleteDeviceConfigurationAsync(string id, EntityHeader org, EntityHeader user)
        {
            var deviceConfiguration = await _deviceConfigRepo.GetDeviceConfigurationAsync(id);

            await AuthorizeAsync(deviceConfiguration, AuthorizeActions.Delete, user, org);
            await ConfirmNoDepenenciesAsync(deviceConfiguration);

            return(InvokeResult.Success);
        }
        public async Task <EntityHeader <StateSet> > GetCustomDeviceStatesAsync(string deviceConfigId, EntityHeader org, EntityHeader user)
        {
            var deviceConfig = await GetDeviceConfigurationAsync(deviceConfigId, org, user);

            return(deviceConfig.CustomStatusType);
        }
        public async Task <IEnumerable <DeviceConfigurationSummary> > GetDeviceConfigurationsForOrgsAsync(string orgId, EntityHeader user)
        {
            await AuthorizeOrgAccessAsync(user, orgId, typeof(DeviceConfiguration));

            return(await _deviceConfigRepo.GetDeviceConfigurationsForOrgAsync(orgId));
        }
        public async Task <InvokeResult> AddDeviceConfigurationAsync(DeviceConfiguration deviceConfiguration, EntityHeader org, EntityHeader user)
        {
            await AuthorizeAsync(deviceConfiguration, AuthorizeActions.Create, user, org);

            ValidationCheck(deviceConfiguration, Actions.Create);
            await _deviceConfigRepo.AddDeviceConfigurationAsync(deviceConfiguration);

            return(InvokeResult.Success);
        }
Пример #6
0
        public async Task <InvokeResult <Sample> > AddSampleAsync(byte[] sampleBytes, string fileName, string contentType, List <string> labelIds, EntityHeader org, EntityHeader user)
        {
            var now = DateTime.UtcNow;

            var timeStamp = now.ToJSONString();

            var file = new FileInfo(fileName);

            var sample = new Sample()
            {
                RowKey                = Guid.NewGuid().ToId(),
                PartitionKey          = org.Id,
                Name                  = file.Name,
                Key                   = $"sample{now.Ticks}",
                FileName              = fileName,
                OwnerOrganizationId   = org.Id,
                OwnerOrganizationName = org.Text,
                ContentType           = contentType,
                ContentSize           = sampleBytes.Length,
                CreatedById           = user.Id,
                CreationDate          = timeStamp,
                LastUpdatedDate       = timeStamp,
                CreatedByName         = user.Text,
                LastUpdatedById       = user.Id,
                LastUpdatedByName     = user.Text,
            };

            await _sampleRepo.AddSampleAsync(sample);

            await _sampleMediaRepo.AddSampleAsync(org.Id, sample.RowKey, sampleBytes);

            await AuthorizeAsync(user, org, "AddSampleAsync", sample);

            foreach (var labelId in labelIds)
            {
                await AddLabelForSampleAsync(sample.RowKey, labelId, org, user);
            }

            return(InvokeResult <Sample> .Create(sample));
        }
        public async Task <InvokeResult <DeviceConfiguration> > LoadFullDeviceConfigurationAsync(string id, EntityHeader org, EntityHeader user)
        {
            var result = new InvokeResult <DeviceConfiguration>();

            var deviceConfiguration = await _deviceConfigRepo.GetDeviceConfigurationAsync(id);

            foreach (var route in deviceConfiguration.Routes)
            {
                await PopulateRoutes(route, org, user);
            }

            if (result.Successful)
            {
                return(InvokeResult <DeviceConfiguration> .Create(deviceConfiguration));
            }

            return(result);
        }
Пример #8
0
        public async Task <InvokeResult> ApplyFirmwareAsync(string deviceRepoId, string deviceUniqueId, string firmwareId, string firmwareRevisionId, EntityHeader org, EntityHeader user)
        {
            if (String.IsNullOrEmpty(deviceRepoId))
            {
                throw new ArgumentNullException(deviceRepoId);
            }
            if (String.IsNullOrEmpty(deviceUniqueId))
            {
                throw new ArgumentNullException(deviceUniqueId);
            }
            if (String.IsNullOrEmpty(firmwareId))
            {
                throw new ArgumentNullException(firmwareId);
            }
            if (String.IsNullOrEmpty(firmwareRevisionId))
            {
                throw new ArgumentNullException(firmwareRevisionId);
            }

            var repo = await _repoManager.GetDeviceRepositoryAsync(deviceRepoId, org, user);

            if (repo == null)
            {
                throw new RecordNotFoundException(nameof(DeviceRepository), deviceRepoId);
            }
            if (EntityHeader.IsNullOrEmpty(repo.Instance))
            {
                return(InvokeResult.FromError("Instance not deployed, can not set property."));
            }

            var firmwareRequest = await _firmwareManager.RequestDownloadLinkAsync(deviceRepoId, deviceUniqueId, firmwareId, firmwareRevisionId, org, user);

            if (!firmwareRequest.Successful)
            {
                return(firmwareRequest.ToInvokeResult());
            }

            var propertyManager = _proxyFactory.Create <IRemotePropertyNamanager>(new ProxySettings()
            {
                InstanceId     = repo.Instance.Id,
                OrganizationId = repo.OwnerOrganization.Id
            });

            return(await propertyManager.SetFirmwareVersionAsync(deviceUniqueId, firmwareRequest.Result.DownloadId));
        }
Пример #9
0
        public async Task <InvokeResult> SendPropertyAsync(string deviceRepoId, string deviceUniqueId, int propertyIndex, EntityHeader org, EntityHeader user)
        {
            var repo = await _repoManager.GetDeviceRepositoryAsync(deviceRepoId, org, user);

            if (EntityHeader.IsNullOrEmpty(repo.Instance))
            {
                return(InvokeResult.FromError("Instance not deployed, can not set property."));
            }

            var propertyManager = _proxyFactory.Create <IRemotePropertyNamanager>(new ProxySettings()
            {
                InstanceId     = repo.Instance.Id,
                OrganizationId = repo.OwnerOrganization.Id
            });

            return(await propertyManager.SendPropertyAsync(deviceUniqueId, propertyIndex));
        }
Пример #10
0
        public async Task <InvokeResult> AddDeviceWorkflowAsync(DeviceWorkflow deviceWorkflow, EntityHeader org, EntityHeader user)
        {
            await AuthorizeAsync(deviceWorkflow, AuthorizeResult.AuthorizeActions.Create, user, org);

            ValidationCheck(deviceWorkflow, Actions.Create);
            await _deviceWorkflowRepo.AddDeviceWorkflowAsync(deviceWorkflow);

            return(InvokeResult.Success);
        }
Пример #11
0
        public async Task <InvokeResult> UpdateStateMachineAsync(StateMachine stateMachine, EntityHeader org, EntityHeader user)
        {
            await AuthorizeAsync(stateMachine, AuthorizeResult.AuthorizeActions.Update, user, org);

            ValidationCheck(stateMachine, Actions.Update);
            stateMachine.LastUpdatedBy   = user;
            stateMachine.LastUpdatedDate = DateTime.Now.ToJSONString();
            await _stateMachineRepo.UpdateStateMachineAsync(stateMachine);

            return(InvokeResult.Success);
        }
Пример #12
0
        public async Task <InvokeResult> AddEventSetAsync(EventSet eventSet, EntityHeader org, EntityHeader user)
        {
            await AuthorizeAsync(eventSet, AuthorizeResult.AuthorizeActions.Create, user, org);

            ValidationCheck(eventSet, Actions.Create);
            await _eventSetRepo.AddEventSetAsync(eventSet);

            return(InvokeResult.Success);
        }
Пример #13
0
        public async Task <DependentObjectCheckResult> CheckInUseEventSetAsync(string eventSetId, EntityHeader org, EntityHeader user)
        {
            var eventSet = await _eventSetRepo.GetEventSetAsync(eventSetId);

            await AuthorizeAsync(eventSet, AuthorizeResult.AuthorizeActions.Read, user, org);

            return(await CheckForDepenenciesAsync(eventSet));
        }
Пример #14
0
        public async Task <DependentObjectCheckResult> CheckInUseStateMachineAsync(string stateMachineId, EntityHeader org, EntityHeader user)
        {
            var stateMachine = await _stateMachineRepo.GetStateMachineAsync(stateMachineId);

            await AuthorizeAsync(stateMachine, AuthorizeResult.AuthorizeActions.Read, user, org);

            return(await CheckForDepenenciesAsync(stateMachine));
        }
Пример #15
0
        public async Task <InvokeResult> AddLabelForSampleAsync(string sampleId, string labelId, EntityHeader org, EntityHeader user)
        {
            var sample = await this._sampleRepo.GetSampleAsync(sampleId, org.Id);

            return(await AddLabelForSampleAsync(sample, labelId, org, user));
        }
Пример #16
0
        public void Validate(ValidationResult result, Actions action)
        {
            //TODO: Needs localizations on error messages
            if (EntityHeader.IsNullOrEmpty(RepositoryType))
            {
                result.AddUserError("Respository Type is a Required Field.");
                return;
            }

            if (RepositoryType?.Value == RepositoryTypes.NuvIoT)
            {
                if (action == Actions.Create)
                {
                    if (DeviceArchiveStorageSettings == null)
                    {
                        result.AddUserError("Device Archive Storage Settings are Required on Insert.");
                    }
                    if (PEMStorageSettings == null)
                    {
                        result.AddUserError("PEM Storage Settings Are Required on Insert.");
                    }
                    if (DeviceStorageSettings == null)
                    {
                        result.AddUserError("Device Storage Settings are Required on Insert.");
                    }
                }
                else if (action == Actions.Update)
                {
                    if (DeviceArchiveStorageSettings == null && String.IsNullOrEmpty(DeviceArchiveStorageSettingsSecureId))
                    {
                        result.AddUserError("Device Archive Storage Settings Or SecureId are Required when updating.");
                    }
                    if (PEMStorageSettings == null && String.IsNullOrEmpty(DeviceArchiveStorageSettingsSecureId))
                    {
                        result.AddUserError("PEM Storage Settings or Secure Id Are Required when updating.");
                    }
                    if (DeviceStorageSettings == null && String.IsNullOrEmpty(DeviceArchiveStorageSettingsSecureId))
                    {
                        result.AddUserError("Device Storage Settings Or Secure Id are Required when updating.");
                    }
                }
            }

            if (RepositoryType.Value == RepositoryTypes.AzureIoTHub)
            {
                if (String.IsNullOrEmpty(ResourceName))
                {
                    result.AddUserError("Resource name which is the name of our Azure IoT Hub is a required field.");
                }
                if (String.IsNullOrEmpty(AccessKeyName))
                {
                    result.AddUserError("Access Key name is a Required field.");
                }

                if (action == Actions.Create && String.IsNullOrEmpty(AccessKey))
                {
                    result.AddUserError("Access Key is a Required field when adding a repository of type Azure IoT Hub");
                }
                if (action == Actions.Update && String.IsNullOrEmpty(AccessKey) && String.IsNullOrEmpty(SecureAccessKeyId))
                {
                    result.AddUserError("Access Key or ScureAccessKeyId is a Required when updating a repo of Azure IoT Hub.");
                }


                if (!String.IsNullOrEmpty(AccessKey))
                {
                    if (!AccessKey.IsBase64String())
                    {
                        result.AddUserError("Access Key does not appear to be a Base 64 String.");
                    }
                }
            }
        }
Пример #17
0
        public async Task <InvokeResult> AddLabelForSampleAsync(Sample sample, string labelId, EntityHeader org, EntityHeader user)
        {
            var labelDetails = await _labelRepo.GetLabelAsync(labelId);

            var labels = await _labelSampleRepo.GetLabelsForSampleAsync(sample.RowKey);

            if (labels.Where(lbl => lbl.LabelId == labelId).Any())
            {
                return(InvokeResult.FromError("Label already attached."));
            }

            var label = new SampleLabel()
            {
                RowKey                = $"{sample.RowKey}-{labelId}",
                PartitionKey          = $"{labelId}-{sample.ContentType.Replace("/","-")}",
                SampleId              = sample.RowKey,
                FileName              = sample.FileName,
                ContentSize           = sample.ContentSize,
                ContentType           = sample.ContentType,
                Name                  = sample.Name,
                LabelId               = labelId,
                Label                 = labelDetails.Key,
                CreatedById           = user.Id,
                CreationDate          = DateTime.UtcNow.ToJSONString(),
                OwnerOrganizationId   = org.Id,
                OwnerOrganizationName = org.Text,
            };

            await _sampleLabelRepo.AddSampleLabelAsync(label);

            var labelSample = new LabelSample()
            {
                RowKey       = $"{labelId}-{sample.RowKey}",
                PartitionKey = sample.RowKey,
                Label        = labelDetails.Key,
                LabelId      = labelId,
            };

            await _labelSampleRepo.AddLabelSampleAsync(labelSample);

            return(InvokeResult.Success);
        }
Пример #18
0
        public void Validate(ValidationResult result, Actions action)
        {
            if (action == Actions.Create)
            {
                if (String.IsNullOrEmpty(SharedAccessKey1))
                {
                    result.AddSystemError("Upon creation, Shared Access Key 1 is Required.");
                }

                if (String.IsNullOrEmpty(SharedAccessKey2))
                {
                    result.AddSystemError("Upon creation, Shared Access Key 2 is Required.");
                }
            }

            if (NuvIoTEdition?.Value == NuvIoTEditions.Container)
            {
                if (EntityHeader.IsNullOrEmpty(ContainerRepository))
                {
                    result.AddSystemError("Container Repository Is Required for NuvIoT Container Editions.");
                }

                if (EntityHeader.IsNullOrEmpty(ContainerTag))
                {
                    result.AddSystemError("Container Tag Is Required for NuvIoT Container Editions.");
                }

                if (EntityHeader.IsNullOrEmpty(Size))
                {
                    result.AddSystemError("Image Size is a Required FIeld.");
                }

                if (EntityHeader.IsNullOrEmpty(WorkingStorage))
                {
                    result.AddSystemError("Image Size is a Required FIeld.");
                }
            }
            else if (NuvIoTEdition?.Value == NuvIoTEditions.Cluster)
            {
                if (EntityHeader.IsNullOrEmpty(WorkingStorage))
                {
                    result.AddSystemError("Image Size is a Required FIeld.");
                }
            }

            if (action == Actions.Update)
            {
                if (String.IsNullOrEmpty(SharedAccessKey1) && String.IsNullOrEmpty(SharedAccessKeySecureId1))
                {
                    result.AddSystemError("Upon creation, Shared Access Key 1 or Shared Access Secure Id 1 is Required.");
                }

                if (String.IsNullOrEmpty(SharedAccessKey2) && String.IsNullOrEmpty(SharedAccessKeySecureId2))
                {
                    result.AddSystemError("Upon updates, Shared Access Key 2 or Shared Access Secure Id 2 is Required.");
                }
            }

            if (!EntityHeader.IsNullOrEmpty(PrimaryCacheType) && PrimaryCacheType.Value == CacheTypes.Redis)
            {
                if (EntityHeader.IsNullOrEmpty(PrimaryCache))
                {
                    result.AddSystemError("Must provide primary cache type.");
                }
            }
        }
Пример #19
0
        public async Task Simple_Clone()
        {
            var original = new ParentModel();

            original.OwnerOrganization = EntityHeader.Create(Guid.NewGuid().ToId(), "owner org");
            original.LastUpdatedBy     = EntityHeader.Create(Guid.NewGuid().ToId(), "owner org");
            original.CreatedBy         = original.LastUpdatedBy;
            original.CreationDate      = DateTime.UtcNow.AddDays(-5).ToJSONString();
            original.LastUpdatedDate   = original.CreationDate;
            original.IsPublic          = false;
            original.Name = "orig name";
            original.Key  = "key";

            original.Child2 = new ChildModel2()
            {
                OwnerOrganization = original.OwnerOrganization,
                LastUpdatedBy     = original.LastUpdatedBy,
                CreatedBy         = original.CreatedBy,
                Name            = "Some Name",
                Key             = "somekey",
                IsPublic        = true,
                CreationDate    = original.CreationDate,
                Id              = Guid.NewGuid().ToId(),
                LastUpdatedDate = original.LastUpdatedDate,
                GrandChild      = new ChildModel2()
                {
                    OwnerOrganization = original.OwnerOrganization,
                    LastUpdatedBy     = original.LastUpdatedBy,
                    CreatedBy         = original.CreatedBy,
                    Name            = "Some Name",
                    Key             = "somekey",
                    IsPublic        = true,
                    CreationDate    = original.CreationDate,
                    Id              = Guid.NewGuid().ToId(),
                    LastUpdatedDate = original.LastUpdatedDate,
                }
            };

            var originalGrandChildId = original.Child2.GrandChild.Id;

            var user2 = EntityHeader.Create(Guid.NewGuid().ToId(), "new user");
            var org2  = EntityHeader.Create(Guid.NewGuid().ToId(), "other user");

            original.Child1 = new ChildModel1()
            {
                Prop1 = "p1",
                Prop2 = "p2",
                Prop3 = "p3",
            };

            original.Children1 = new List <ChildModel1>();
            original.Children1.Add(new ChildModel1()
            {
                Prop1 = "a", Prop2 = "b", Prop3 = "c"
            });
            original.Children1.Add(new ChildModel1()
            {
                Prop1 = "d", Prop2 = "e", Prop3 = "f"
            });

            var clone = await original.CloneAsync(user2, org2, "DiffObject", "DIffKey");

            Assert.AreEqual("p1", clone.Child1.Prop1);
            Assert.AreEqual("p2", clone.Child1.Prop2);
            Assert.AreEqual("p3", clone.Child1.Prop3);

            Assert.AreEqual(org2.Id, clone.Child2.OwnerOrganization.Id);
            Assert.AreEqual(user2.Id, clone.Child2.CreatedBy.Id);
            Assert.AreEqual(user2.Id, clone.Child2.LastUpdatedBy.Id);

            Assert.AreEqual(2, clone.Children1.Count);
            Assert.IsNotNull(clone.Child2.GrandChild);

            Assert.AreEqual(org2.Id, clone.Child2.GrandChild.OwnerOrganization.Id);
            Assert.AreEqual(user2.Id, clone.Child2.GrandChild.CreatedBy.Id);
            Assert.AreEqual(user2.Id, clone.Child2.GrandChild.LastUpdatedBy.Id);

            Assert.AreNotEqual(original.Child2.Id, clone.Child2.LastUpdatedBy.Id);
            Assert.AreNotEqual(originalGrandChildId, clone.Child2.GrandChild.Id);
        }
Пример #20
0
        public async Task <InvokeResult <byte[]> > GetSampleAsync(string sampleId, EntityHeader org, EntityHeader user)
        {
            // leave this to do a validtion check.
            await GetSampleDetailAsync(sampleId, org, user);

            return(await _sampleMediaRepo.GetSampleAsync(org.Id, sampleId));
        }
        public async Task <InvokeResult> PopulateRoutes(Route route, EntityHeader org, EntityHeader user)
        {
            var fullLoadResult = new InvokeResult();

            var msgLoadResult = await _deviceMessageDefinitionManager.LoadFullDeviceMessageDefinitionAsync(route.MessageDefinition.Id, org, user);

            if (msgLoadResult.Successful)
            {
                route.MessageDefinition.Value = msgLoadResult.Result;
            }
            else
            {
                fullLoadResult.Concat(fullLoadResult);
            }

            foreach (var module in route.PipelineModules)
            {
                switch (module.ModuleType.Value)
                {
                case Pipeline.Admin.Models.PipelineModuleType.InputTranslator:
                {
                    var result = await _pipelineModuleManager.LoadFullInputTranslatorConfigurationAsync(module.Module.Id);

                    if (result.Successful)
                    {
                        module.Module.Value = result.Result;
                    }
                    else
                    {
                        fullLoadResult.Concat(result);
                    }
                }
                break;

                case Pipeline.Admin.Models.PipelineModuleType.DataStream:
                {
                    var result = await _dataStreamManager.LoadFullDataStreamConfigurationAsync(module.Module.Id);

                    if (result.Successful)
                    {
                        module.Module.Value = result.Result;
                    }
                    else
                    {
                        fullLoadResult.Concat(result);
                    }
                }
                break;

                case Pipeline.Admin.Models.PipelineModuleType.Sentinel:
                {
                    var result = await _pipelineModuleManager.LoadFullSentinelConfigurationAsync(module.Module.Id);

                    if (result.Successful)
                    {
                        module.Module.Value = result.Result;
                    }
                    else
                    {
                        fullLoadResult.Concat(result);
                    }
                }
                break;

                case Pipeline.Admin.Models.PipelineModuleType.Workflow:
                {
                    var result = await _deviceAdminManager.LoadFullDeviceWorkflowAsync(module.Module.Id, org, user);

                    if (result.Successful)
                    {
                        module.Module.Value = result.Result;
                        var destModuleConfig = route.PipelineModules.Where(mod => mod.Id == module.PrimaryOutput.Id).FirstOrDefault();

                        if (destModuleConfig.ModuleType.Value == Pipeline.Admin.Models.PipelineModuleType.OutputTranslator)
                        {
                            if (module.PrimaryOutput != null && module.PrimaryOutput.Mappings != null)
                            {
                                for (var idx = 0; idx < module.PrimaryOutput.Mappings.Count; ++idx)
                                {
                                    var mapping = module.PrimaryOutput.Mappings[idx];
                                    if (mapping.Value != null)
                                    {
                                        var mappingValue = JsonConvert.DeserializeObject <OutputCommandMapping>(mapping.Value.ToString());
                                        if (mappingValue != null && !EntityHeader.IsNullOrEmpty(mappingValue.OutgoingDeviceMessage))
                                        {
                                            var outgoingMsgLoadResult = await _deviceMessageDefinitionManager.LoadFullDeviceMessageDefinitionAsync(mappingValue.OutgoingDeviceMessage.Id, org, user);

                                            mappingValue.OutgoingDeviceMessage.Value = outgoingMsgLoadResult.Result;
                                            module.PrimaryOutput.Mappings[idx]       = new KeyValuePair <string, object>(mapping.Key, mappingValue);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        fullLoadResult.Concat(result);
                    }
                }
                break;

                case Pipeline.Admin.Models.PipelineModuleType.OutputTranslator:
                {
                    var result = await _pipelineModuleManager.LoadFullOutputTranslatorConfigurationAsync(module.Module.Id);

                    if (result.Successful)
                    {
                        module.Module.Value = result.Result;
                    }
                    else
                    {
                        fullLoadResult.Concat(result);
                    }
                }
                break;

                case Pipeline.Admin.Models.PipelineModuleType.Transmitter:
                {
                    var result = await _pipelineModuleManager.LoadFullTransmitterConfigurationAsync(module.Module.Id);

                    if (result.Successful)
                    {
                        module.Module.Value = result.Result;
                    }
                    else
                    {
                        fullLoadResult.Concat(result);
                    }
                }
                break;

                case Pipeline.Admin.Models.PipelineModuleType.Custom:
                {
                    var result = await _pipelineModuleManager.LoadFullCustomPipelineModuleConfigurationAsync(module.Module.Id);

                    if (result.Successful)
                    {
                        module.Module.Value = result.Result;
                    }
                    else
                    {
                        fullLoadResult.Concat(result);
                    }
                }
                break;
                }
            }

            return(fullLoadResult);
        }
Пример #22
0
        public async Task <SampleDetail> GetSampleDetailAsync(string sampleId, EntityHeader org, EntityHeader user)
        {
            var sample = await _sampleRepo.GetSampleAsync(sampleId, org.Id);

            var labels = await _labelSampleRepo.GetLabelsForSampleAsync(sampleId);

            var detail = SampleDetail.FromSample(sample);

            detail.Labels = new List <EntityHeader>(labels.Select(lbl => EntityHeader.Create(lbl.LabelId, lbl.Label)));
            await AuthorizeAsync(detail, AuthorizeResult.AuthorizeActions.Read, user, org);

            return(detail);
        }
        public async Task <InvokeResult> PopulateDeviceConfigToDeviceAsync(Device device, EntityHeader instanceEH, EntityHeader org, EntityHeader user)
        {
            Console.WriteLine("Hhhhh...eeerrre");

            var result = new InvokeResult();

            if (EntityHeader.IsNullOrEmpty(instanceEH))
            {
                result.AddSystemError($"Device does not have a valid device configuration Device Id={device.Id}");
                return(result);
            }

            Console.WriteLine("H1");

            var deviceConfig = await GetDeviceConfigurationAsync(device.DeviceConfiguration.Id, org, user);

            if (deviceConfig == null)
            {
                result.AddSystemError($"Could Not Load Device Configuration with Device Configuration {device.DeviceConfiguration.Text}, Id={device.DeviceConfiguration.Id}.");
                return(result);
            }

            var instance = await _deploymentInstanceManager.GetInstanceAsync(instanceEH.Id, org, user);

            Console.WriteLine("H2");

            if (instance != null && instance.Status.Value == DeploymentInstanceStates.Running)
            {
                if (instance.InputCommandSSL)
                {
                    device.DeviceURI = $"https://{instance.DnsHostName}:{instance.InputCommandPort}/devices/{device.Id}";
                }
                else
                {
                    device.DeviceURI = $"http://{instance.DnsHostName}:{instance.InputCommandPort}/devices/{device.Id}";
                }

                var endpoints = new List <InputCommandEndPoint>();
                foreach (var route in deviceConfig.Routes)
                {
                    Console.WriteLine("H3");

                    foreach (var module in route.PipelineModules)
                    {
                        Console.WriteLine("H4");

                        if (module.ModuleType.Value == Pipeline.Admin.Models.PipelineModuleType.Workflow)
                        {
                            Console.WriteLine("H4.1");
                            var wfLoadResult = await _deviceAdminManager.LoadFullDeviceWorkflowAsync(module.Module.Id, org, user);

                            Console.WriteLine("H4.2");
                            if (wfLoadResult.Successful)
                            {
                                Console.WriteLine("H4.3");
                                if (wfLoadResult.Result.Attributes != null)
                                {
                                    foreach (var attribute in wfLoadResult.Result.Attributes)
                                    {
                                        if (device.AttributeMetaData == null)
                                        {
                                            device.AttributeMetaData = new List <DeviceAdmin.Models.Attribute>();
                                        }
                                        if (!device.AttributeMetaData.Where(attr => attr.Key == attribute.Key).Any())
                                        {
                                            device.AttributeMetaData.Add(attribute);
                                        }
                                    }
                                }

                                Console.WriteLine("H4.4");

                                if (wfLoadResult.Result.StateMachines != null)
                                {
                                    if (device.StateMachineMetaData == null)
                                    {
                                        device.StateMachineMetaData = new List <StateMachine>();
                                    }
                                    foreach (var stateMachine in wfLoadResult.Result.StateMachines)
                                    {
                                        if (!device.StateMachineMetaData.Where(attr => attr.Key == stateMachine.Key).Any())
                                        {
                                            device.StateMachineMetaData.Add(stateMachine);
                                        }
                                    }
                                }

                                Console.WriteLine("H4.5");

                                if (wfLoadResult.Result.InputCommands != null)
                                {
                                    foreach (var inputCommand in wfLoadResult.Result.InputCommands)
                                    {
                                        var protocol = instance.InputCommandSSL ? "https://" : "http://";
                                        var endPoint = new InputCommandEndPoint
                                        {
                                            EndPoint     = $"{protocol}{instance.DnsHostName}:{instance.InputCommandPort}/{deviceConfig.Key}/{route.Key}/{wfLoadResult.Result.Key}/{inputCommand.Key}/{device.DeviceId}",
                                            InputCommand = inputCommand
                                        };

                                        if (!endpoints.Where(end => end.EndPoint == endPoint.EndPoint).Any())
                                        {
                                            endpoints.Add(endPoint);
                                        }
                                    }
                                }

                                Console.WriteLine("H43");
                            }
                            else
                            {
                                result.Concat(result);
                            }
                        }
                    }
                }
                device.InputCommandEndPoints = endpoints;
            }
            else
            {
                Console.WriteLine("H21");
                device.InputCommandEndPoints = new List <InputCommandEndPoint>();
                device.AttributeMetaData     = new List <DeviceAdmin.Models.Attribute>();
                device.StateMachineMetaData  = new List <StateMachine>();
            }

            Console.WriteLine("H5");

            if (deviceConfig.Properties != null)
            {
                device.PropertiesMetaData = new List <DeviceAdmin.Models.CustomField>();
                foreach (var prop in deviceConfig.Properties.OrderBy(prop => prop.Order))
                {
                    device.PropertiesMetaData.Add(prop);
                    if (prop.FieldType.Value == DeviceAdmin.Models.ParameterTypes.State)
                    {
                        prop.StateSet.Value = await _deviceAdminManager.GetStateSetAsync(prop.StateSet.Id, org, user);
                    }
                    else if (prop.FieldType.Value == DeviceAdmin.Models.ParameterTypes.ValueWithUnit)
                    {
                        prop.UnitSet.Value = await _deviceAdminManager.GetAttributeUnitSetAsync(prop.UnitSet.Id, org, user);
                    }
                }
            }

            Console.WriteLine("H6");

            return(result);
        }
Пример #24
0
        public async Task <ListResponse <SampleSummary> > GetSamplesForLabelAsync(string labelId, string contentType, EntityHeader org, EntityHeader user, ListRequest request)
        {
            var label = await _labelRepo.GetLabelAsync(labelId);

            await AuthorizeAsync(label, AuthorizeResult.AuthorizeActions.Read, user, org);

            var samples = await _sampleLabelRepo.GetSamplesForLabelAsync(labelId, contentType, request);

            return(new ListResponse <SampleSummary>()
            {
                Model = samples.Model.Select(smp => SampleSummary.FromSampleLabel(smp)),
                NextPartitionKey = samples.NextPartitionKey,
                NextRowKey = samples.NextRowKey,
                PageCount = samples.PageCount,
                PageIndex = samples.PageIndex,
                PageSize = samples.PageSize
            });
        }
        public async Task <DependentObjectCheckResult> CheckDeviceConfigInUseAsync(string id, EntityHeader org, EntityHeader user)
        {
            var deviceConfig = await _deviceConfigRepo.GetDeviceConfigurationAsync(id);

            await AuthorizeAsync(deviceConfig, AuthorizeActions.Read, user, org);

            return(await base.CheckForDepenenciesAsync(deviceConfig));
        }
Пример #26
0
        public async Task <InvokeResult> RemoveLabelFromSampleAsync(string sampleId, string labelId, EntityHeader org, EntityHeader user)
        {
            // this will trigger
            var sample = await GetSampleDetailAsync(sampleId, org, user);

            await AuthorizeAsync(sample, AuthorizeResult.AuthorizeActions.Update, user, org);

            await _labelSampleRepo.RemoveLabelSampleAsync(labelId, sampleId);

            await _sampleLabelRepo.RemoveSampleLabelAsync(labelId, sampleId);

            return(InvokeResult.Success);
        }
        public async Task <DeviceConfiguration> GetDeviceConfigurationAsync(string id, EntityHeader org, EntityHeader user)
        {
            var deviceConfiguration = await _deviceConfigRepo.GetDeviceConfigurationAsync(id);

            await AuthorizeAsync(deviceConfiguration, AuthorizeActions.Read, user, org);

            foreach (var prop in deviceConfiguration.Properties.OrderBy(prop => prop.Order))
            {
                if (prop.FieldType.Value == DeviceAdmin.Models.ParameterTypes.State)
                {
                    prop.StateSet.Value = await _deviceAdminManager.GetStateSetAsync(prop.StateSet.Id, org, user);
                }
                else if (prop.FieldType.Value == DeviceAdmin.Models.ParameterTypes.ValueWithUnit)
                {
                    prop.UnitSet.Value = await _deviceAdminManager.GetAttributeUnitSetAsync(prop.UnitSet.Id, org, user);
                }
            }

            if (!EntityHeader.IsNullOrEmpty(deviceConfiguration.CustomStatusType))
            {
                deviceConfiguration.CustomStatusType.Value = await _deviceAdminManager.GetStateSetAsync(deviceConfiguration.CustomStatusType.Id, org, user);
            }

            return(deviceConfiguration);
        }
Пример #28
0
        public async Task <InvokeResult> UpdateSampleAsync(string sampleId, byte[] sampleBytes, EntityHeader org, EntityHeader user)
        {
            var sample = await GetSampleDetailAsync(sampleId, org, user);

            await AuthorizeAsync(sample, AuthorizeResult.AuthorizeActions.Update, user, org);

            await _sampleMediaRepo.UpdateSampleAsync(org.Id, sample.FileName, sampleBytes);

            return(InvokeResult.Success);
        }
Пример #29
0
 public Task <IEnumerable <TelemetryReportData> > GetForHostAsync(string hostId, string recordType, ListRequest request, EntityHeader org, EntityHeader user)
 {
     throw new NotImplementedException();
 }
Пример #30
0
        public async Task <InvokeResult> DeleteEventSetAsync(string eventSetId, EntityHeader org, EntityHeader user)
        {
            var eventSet = await _eventSetRepo.GetEventSetAsync(eventSetId);

            await AuthorizeAsync(eventSet, AuthorizeResult.AuthorizeActions.Delete, user, org);
            await ConfirmNoDepenenciesAsync(eventSet);

            await _eventSetRepo.DeleteEventSetAsync(eventSetId);

            return(InvokeResult.Success);
        }