Exemplo n.º 1
0
        private void PushAttributeValues(UicProject project)
        {
            // read and publish


            Console.WriteLine("[HAW DEBUG] Name:" + project.Name);
            Console.WriteLine("[HAW DEBUG] Project Key:" + project.ProjectKey);
            Console.WriteLine("[HAW DEBUG] Description:" + project.Description);
            Console.WriteLine("[HAW DEBUG] Owner:" + project.Owner);
            Console.WriteLine("[HAW DEBUG] Attributes:" + project.Attributes);
            Console.WriteLine("[HAW DEBUG] DataPointsTaks:" + project.DatapointTasks);



            foreach (var attribtueDefinition in project.Attributes)
            {
                try
                {
                    EmbeddedDriverModule edm          = GetEdmFor(attribtueDefinition.Id);
                    AttributeValue       attibutValue = edm.GetValueFor(attribtueDefinition);
                    _communicationAgent.Push(attibutValue);

                    //Set Asynchronous EDM Calbbacks if necessary
                    edm.SetAttributeCallback(attribtueDefinition, attributeValue => _communicationAgent.Push(attributeValue));
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Could not push attribute value for: " + attribtueDefinition);
                }
            }
        }
        public void Initialize(string serialId, UicProject project, List <EmbeddedDriverModule> edms)
        {
            AzureProvisioningAgent provisioningAgent = new AzureProvisioningAgent(_hubConfiguration, _loggerFactory);

            foreach (var edm in edms)
            {
                string device_id;
                if (provisioningAgent.TryGetDevice(edm.Identifier.Id.ToString(), out device_id))
                {
                    _logger.Debug("linking datapoints and attributes from EDM {0} to device {1}",
                                  edm.Identifier.Uri, device_id);
                    foreach (var cap in edm.GetCapability().DatapointDefinitions)
                    {
                        _datapointMappings.Add(cap.Id, device_id);
                    }
                    foreach (var cap in edm.GetCapability().AttributeDefinitions)
                    {
                        _attributeMappings.Add(cap.Id, device_id);
                    }
                }
                else
                {
                    _logger.Warning("EDM provisioning failed for {0}:{1}",
                                    edm.Identifier.Uri, edm.Identifier.Id);
                }
            }
        }
Exemplo n.º 3
0
        internal string GetGatewayProject(M2MgoCloudAgentConfiguration config, UicProject project)
        {
            return(_userTokenWebApiWrapper.RetryWithTokenUpdate(config, () => {
                var request =
                    (HttpWebRequest)WebRequest.Create(config.BaseUrl + "api/gatewayProject/" +
                                                      project.CustomerForeignKey.ToString("D") + "/" +
                                                      config.SgetGatewayTypeId.ToString("D") + "/" + project.ProjectKey);
                request.Method = "GET";

                string executeRequest = _webApiRequestExecutor.ExecuteRequest(request, string.Empty, _userTokenWebApiWrapper.GetToken(), _logger);
                return executeRequest;
            }));
        }
Exemplo n.º 4
0
        private string GernerateApplianceSerialKey(UicProject project)
        {
            string serialKey;
            var    eapiEdm = GetEdmFor(BOARD_IDENTIFIER_DEFINITION_ID);

            if (eapiEdm == null)
            {
                serialKey = Environment.MachineName;
            }
            else
            {
                serialKey = eapiEdm.GetValueFor(eapiEdm.GetCapability().AttributeDefinitions.Single(a => a.Id == BOARD_IDENTIFIER_DEFINITION_ID)).Value.ToString();
            }

            return(serialKey + "." + project.ProjectKey);
        }
Exemplo n.º 5
0
        internal BlueprintDto GetProjectBlueprintDto(UicProject project, Guid domainId)
        {
            var commands   = new List <CommandDto>();
            var attributes = new List <Attribute>();
            var sensors    = new List <Sensor>();

            if (project.Attributes != null)
            {
                foreach (AttributeDefinition attribute in project.Attributes)
                {
                    attributes.Add(GetAttributesOf(attribute));
                }
                attributes.Add(new Attribute
                {
                    Description = "Matching Anchor for autoomatic dashboard over gatway datasource",
                    Name        = M2mgoGatewayBlueprintTranslator.AttributeKeySerialId
                });
            }

            if (project.DatapointTasks != null)
            {
                foreach (var datapointTask in project.DatapointTasks)
                {
                    Sensor sensor = GetSensorsOf(datapointTask);
                    sensors.Add(sensor);
                    AddDistinctCommand(commands, datapointTask);
                }
            }

            var blueprint = new BlueprintDto
            {
                Commands         = commands,
                Attributes       = attributes,
                Sensors          = sensors,
                DomainIdentifier = new Identifier {
                    ID = domainId
                },
                Name       = GetBlueprintNameFrom(project),
                Label      = GetBlueprintNameFrom(project),
                Code       = GetBlueprintCodeFrom(project),
                MaxDevices = 50,
            };

            return(blueprint);
        }
Exemplo n.º 6
0
        public void Initialize(string serialId, UicProject project, List <EmbeddedDriverModule> edms)
        {
            _edms = edms;

            List <EDMWrapper> edmWrappers = new List <EDMWrapper>();

            foreach (EmbeddedDriverModule element in edms)
            {
                //building of ther maps
                BuildEdmMap(element.GetCapability());

                // edms must be converted in a actual type to serialize the capabilities
                edmWrappers.Add(new EDMWrapper(element));
            }



            RESTClient.RESTClient.Initialize(serialId, DataAndAttributeValueWrapper.GetJSON(edmWrappers), _logger);
        }
Exemplo n.º 7
0
        public void Initialize(EmbeddedDriverModule[] embeddedDriverModules)
        {
            _initializedEDMs = new List <EmbeddedDriverModule>();
            _logger.Information("Initialize");
            foreach (EmbeddedDriverModule edm in embeddedDriverModules)
            {
                try
                {
                    edm.Initialize();
                    EdmCapability edmCapability = edm.GetCapability();
                    BuildEdmMap(edm, edmCapability);
                    _initializedEDMs.Add(edm);
                }
                catch (Exception e)
                {
                    _logger.Error(e, $"Initializating of EDM {edm.Identifier.Uri} failed");
                }
            }

            _projectAgent.Initialize(_initializedEDMs.ToArray());

            if (_uicConfiguartion.IsEdmSnychronizationEnabled)
            {
                foreach (EmbeddedDriverModule edm in _initializedEDMs)
                {
                    _projectAgent.Synchronize(edm.GetCapability());
                }
            }



            UicProject project = LoadUicProject();

            SerialId = GernerateApplianceSerialKey(project);

            _communicationAgent.Initialize(SerialId, project, _initializedEDMs);
            _communicationAgent.Connect(CloudAgentCommandHandler);

            PushAttributeValues(project);

            StartDatapointMonitoring(project);
        }
Exemplo n.º 8
0
        private void PushAttributeValues(UicProject project)
        {
            // read and publish
            foreach (var attribtueDefinition in project.Attributes)
            {
                try
                {
                    EmbeddedDriverModule edm          = GetEdmFor(attribtueDefinition.Id);
                    AttributeValue       attibutValue = edm.GetValueFor(attribtueDefinition);
                    _communicationAgent.Push(attibutValue);

                    //Set Asynchronous EDM Calbbacks if necessary
                    edm.SetAttributeCallback(attribtueDefinition, attributeValue => _communicationAgent.Push(attributeValue));
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Could not push attribute value for: " + attribtueDefinition);
                }
            }
        }
Exemplo n.º 9
0
        private void StartDatapointMonitoring(UicProject project)
        {
            var dataPointEvaluatorProvider = new DataPointEvaluatorProvider();

            foreach (ProjectDatapointTask datapointTask in project.DatapointTasks)
            {
                try
                {
                    EmbeddedDriverModule edm = GetEdmFor(datapointTask.Definition.Id);

                    _datapointMonitors.Add(new DatapointMonitor(datapointTask, dataPointEvaluatorProvider, this, _loggerFactory.GetLoggerFor("DatapointMonitor-" + datapointTask.Definition.Label), edm));

                    //Set Asynchronous EDM Calbbacks if necessary
                    edm.SetDatapointCallback(datapointTask, datapointValue => new Thread(() => _communicationAgent.Push(datapointValue)).Start());
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Could not start datapoint monitoring for : " + datapointTask);
                }
            }
        }
Exemplo n.º 10
0
        public void Initialize(string serialId, UicProject project, List <EmbeddedDriverModule> edms)
        {
            WebApiRequestExecutor       webApiRequestExecutor  = new WebApiRequestExecutor();
            M2mgoUserTokenWebApiWrapper userTokenWebApiWrapper = new M2mgoUserTokenWebApiWrapper(_serializer, webApiRequestExecutor, _loggerFactory.GetLoggerFor(typeof(M2mgoUserTokenWebApiWrapper)));
            var m2MgoGatewayProjectWebApiWrapper     = new M2mgoGatewayProjectWebApiWrapper(_serializer, _loggerFactory, webApiRequestExecutor, userTokenWebApiWrapper);
            M2MgoProjectTranslator projectTranslator = new M2MgoProjectTranslator();
            var gatewayService = new GatewayService(m2MgoGatewayProjectWebApiWrapper, _loggerFactory.GetLoggerFor(typeof(GatewayService)), _serializer, projectTranslator);

            M2mgoGetwayProjectDto gatewayProject = gatewayService.RegisterProject(_configuration, serialId, project);

            M2mgoDeviceWebApiWrapper        apiWrapper          = new M2mgoDeviceWebApiWrapper(_serializer, webApiRequestExecutor, _loggerFactory.GetLoggerFor(typeof(M2mgoDeviceWebApiWrapper)), userTokenWebApiWrapper);
            M2mgoGatewayBlueprintTranslator blueprintTranslator = new M2mgoGatewayBlueprintTranslator(projectTranslator);

            _m2MgoProjectBlueprintTranslator = new M2MgoProjectBlueprintTranslator(project, edms);
            var blueprintService = new BlueprintService(apiWrapper, _loggerFactory.GetLoggerFor(typeof(BlueprintService)), blueprintTranslator, _m2MgoProjectBlueprintTranslator, projectTranslator, m2MgoGatewayProjectWebApiWrapper);

            _applianceBlueprints = blueprintService.SynchronizeWithCloud(_configuration, serialId, project, gatewayProject);

            _projectDataTopic      = new DataTopic(_applianceBlueprints.ProjectBlueprint.Identifier.ID, serialId);
            _projectAttributeTopic = new AttributeTopic(_applianceBlueprints.ProjectBlueprint.Identifier.ID, serialId);
            _gatewayDataTopic      = new DataTopic(_applianceBlueprints.GatewayBlueprint.Identifier.ID, serialId);
        }
Exemplo n.º 11
0
 private void UpdateGatewayAttributes(M2MgoCloudAgentConfiguration config, string serialId, UicProject project, BlueprintDto gatewayBlueprint)
 {
     _apiWrapper.PostAttributes(config, gatewayBlueprint.Identifier.ID, serialId,
                                M2mgoGatewayBlueprintTranslator.AttributeKeySerialId, serialId);
     _apiWrapper.PostAttributes(config, gatewayBlueprint.Identifier.ID, serialId,
                                M2mgoGatewayBlueprintTranslator.AttributeKeyProjectKey, project.ProjectKey);
     _apiWrapper.PostAttributes(config, gatewayBlueprint.Identifier.ID, serialId,
                                M2mgoGatewayBlueprintTranslator.AttributeKeyProjectName, project.Name);
     _apiWrapper.PostAttributes(config, gatewayBlueprint.Identifier.ID, serialId,
                                M2mgoGatewayBlueprintTranslator.AttributeKeyCustomer, project.Owner);
 }
Exemplo n.º 12
0
        private BlueprintDto EnsureProjectBlueprint(M2MgoCloudAgentConfiguration config, UicProject project)
        {
            string blueprintCode = _projectBlueprintTranslator.GetBlueprintCodeFrom(project);

            BlueprintDto[] searchResult = _apiWrapper.SearchBlueprint(config, _projectTranslator.GetProjectDomain(project), blueprintCode);

            if (searchResult.Count() > 1)
            {
                throw new Exception(String.Format("found more than 1 project blueprints {0} in Domain {1}", _projectTranslator.GetProjectDomain(project),
                                                  blueprintCode));
            }
            if (searchResult.Any())
            {
                BlueprintDto blueprint = _projectBlueprintTranslator.UpdateProjectDomain(searchResult.Single());
                string       result    = _apiWrapper.UpdateBlueprint(config, blueprint);
                _logger.Information("Updateing Blueprint: " + result);
                return(blueprint);
            }
            else
            {
                BlueprintDto projectBlueprintDto = _projectBlueprintTranslator.GetProjectBlueprintDto(project, _projectTranslator.GetProjectDomain(project));
                projectBlueprintDto.PrepareMasterForCreation();

                string result = _apiWrapper.CreateBlueprint(config, _projectTranslator.GetProjectDomain(project), projectBlueprintDto);
                _logger.Information("CreateBlueprint Blueprint: " + result);
                return(_apiWrapper.SearchBlueprint(config, _projectTranslator.GetProjectDomain(project), blueprintCode).Single());
            }
        }
Exemplo n.º 13
0
 internal Guid GetProjectDomain(UicProject project)
 {
     return(project.CustomerForeignKey);
 }
Exemplo n.º 14
0
        private GatewayProjectGetModel EnsureProject(M2MgoCloudAgentConfiguration config, UicProject project)
        {
            string result = _apiWrapper.GetGatewayProject(config, project);

            if (result.IsNullOrEmpty())
            {
                var model = new GatewayProjectPutModel(_projectTranslator.GetProjectDomain(project), config.SgetGatewayTypeId, project.Name, project.ProjectKey, "", project.GetType().ToString());
                _apiWrapper.CreateGatewayProject(config, model);
                result = _apiWrapper.GetGatewayProject(config, project);
                if (result.IsNullOrEmpty())
                {
                    throw new Exception("Could not create GatewayProject!");
                }
            }
            _logger.Information(result);
            var gatewayProjectGetModel = _serializer.Deserialize <GatewayProjectGetModel>(result);

            return(gatewayProjectGetModel);
        }
Exemplo n.º 15
0
        internal BlueprintDto GetGatewayBlueprintDefiniton(UicProject project)
        {
            const string name  = "CloudMapper Gateway";
            const string code  = CloudMapperGatewayAnchorBlueprintCode;
            const string label = name;

            var sensors = new List <Sensor>
            {
                new Sensor
                {
                    DataType    = (int)SensorDataType.String,
                    Description = String.Empty,
                    Icon        = String.Empty,
                    Name        = "Debug Channel",
                    SensorKey   = SensorKeyDebug,
                    Units       = String.Empty,
                },
                new Sensor
                {
                    DataType    = (int)SensorDataType.Boolean,
                    Description = String.Empty,
                    Icon        = String.Empty,
                    Name        = "Debug Enabled",
                    SensorKey   = SensorKeyDebugEnabled,
                    Units       = String.Empty,
                },
            };
            var commands = new List <CommandDto>
            {
                new CommandDto
                {
                    Command = "board.debug@on",
                    Name    = CommandKeyDebugOn,
                },
                new CommandDto
                {
                    Command = "board.debug@off",
                    Name    = CommandKeyDebugOff,
                },
            };
            var attributes = new List <Attribute> {
                new Attribute
                {
                    Name = AttributeKeySerialId,
                },
                new Attribute
                {
                    Name = AttributeKeyProjectKey,
                },
                new Attribute
                {
                    Name = AttributeKeyProjectName,
                },
                new Attribute
                {
                    Name = AttributeKeyCustomer,
                },
            };

            return(new BlueprintDto
            {
                Attributes = attributes,
                Commands = commands,
                CreationDate = null,
                Description = null,
                DomainIdentifier = new Identifier
                {
                    ID = _projectTranslator.GetProjectDomain(project)
                },
                IsSelfRegisteringAllowed = true,
                Label = label,
                MaxDevices = 50,
                Code = code,
                Name = name,
                Sensors = sensors,
            });
        }
Exemplo n.º 16
0
        public ApplianceBlueprints SynchronizeWithCloud(M2MgoCloudAgentConfiguration config, string serialId, UicProject project, M2mgoGetwayProjectDto m2MgoGetwayProjectDto)
        {
            BlueprintDto gatewayBlueprint = EnsureGatewayBlueprint(config, project);

            EnsureDevice(config, serialId, gatewayBlueprint, m2MgoGetwayProjectDto.Gateway);
            UpdateGatewayAttributes(config, serialId, project, gatewayBlueprint);

            BlueprintDto projectBlueprint = EnsureProjectBlueprint(config, project);

            EnsureDevice(config, serialId, projectBlueprint, m2MgoGetwayProjectDto.Gateway);
            UpdateProjectDeviceAttributes(config, serialId, projectBlueprint);

            SetRelevantDevicesOfGateway(config, m2MgoGetwayProjectDto.Gateway.Identifier.ID, projectBlueprint, serialId);

            return(new ApplianceBlueprints(gatewayBlueprint, projectBlueprint));
        }
Exemplo n.º 17
0
 private string GetBlueprintNameFrom(UicProject project)
 {
     return(String.Format("{0}: {1} Project", project.Owner, project.Name));
 }
Exemplo n.º 18
0
        public M2MgoProjectBlueprintTranslator(UicProject project, List <EmbeddedDriverModule> edms)
        {
            _project = project;

            edms.ForEach(edm => BuildEdmMap(edm.GetCapability()));
        }
Exemplo n.º 19
0
 internal string GetBlueprintCodeFrom(UicProject project)
 {
     return(String.Format("{0}@{1}@project", project.ProjectKey, project.CustomerForeignKey));
 }
Exemplo n.º 20
0
        public void Startup()
        {
            _uicConfiguartion = uicConfiguartionProvider.GetUicConfiguartion();

            string serialId = "extract serial Id of the embedded device as asset identifier for the cloud applicaiton";

            foreach (EmbeddedDriverModule edm in _uicConfiguartion.EmbeddedDriverModulesToLoad)
            {
                edm.Initialize();
            }

            if (_uicConfiguartion.IsEdmSnychronizationEnabled)
            {
                foreach (EmbeddedDriverModule edm in _uicConfiguartion.EmbeddedDriverModulesToLoad)
                {
                    EdmCapability edmCapability = edm.GetCapability();
                    // Synchronize edm with edm and project cloud
                }
            }

            UicProject project = null;

            if (_uicConfiguartion.IsRemoteProjectLoadingEnabled)
            {
                //Url EdmSnychronizationUrl { get; }
                //Url RemoteProjectConfigurationUrl();

                //var projectConfigurationUrl = _uicConfiguartion.RemoteProjectConfigurationUrl();
                //project = LoadProjectFromRemote(projectConfigurationUrl);
            }
            else
            {
                var serializedProjectFilepath = _uicConfiguartion.AbsoluteProjectConfigurationFilePath;
                project = LoadProjectFromFile(serializedProjectFilepath);
            }

            _communicationAgent.Synchronize(serialId, project);
            _communicationAgent.Connect(CloudAgentCommandHandler);

            // read and publish
            foreach (var attribtueDefinition in project.Attributes)
            {
                EmbeddedDriverModule edm          = GetEdmFor(attribtueDefinition);
                AttributeValue       attibutValue = edm.GetValueFor(attribtueDefinition);
                _communicationAgent.Push(attibutValue);

                //Set Asynchronous EDM Calbbacks if necessary
                edm.SetAttributeCallback(attribtueDefinition, attributeValue => _communicationAgent.Push(attributeValue));
            }

            foreach (ProjectDatapointTask datapointTask in project.DatapointTasks)
            {
                EmbeddedDriverModule edm = GetEdmFor(datapointTask.Definition);

                //start Monitoring the DatapointTasks from the project
                StartDatapointMonitoring(datapointTask.Definition, datapointTask.PollIntervall,
                                         datapointTask.ReportingCondition, edm);

                //Set Asynchronous EDM Calbbacks if necessary
                edm.SetDatapointCallback(datapointTask, datapointValue => _communicationAgent.Push(datapointValue));
            }
        }
Exemplo n.º 21
0
        private BlueprintDto EnsureGatewayBlueprint(M2MgoCloudAgentConfiguration config, UicProject project)
        {
            BlueprintDto[] searchResult = _apiWrapper.SearchBlueprint(config, config.SgetDomainID, M2mgoGatewayBlueprintTranslator.CloudMapperGatewayAnchorBlueprintCode);

            if (searchResult.Count() > 1)
            {
                throw new Exception(String.Format("found more than 1 masterdefinitions {0} in Domain {1}", _projectTranslator.GetProjectDomain(project),
                                                  M2mgoGatewayBlueprintTranslator.CloudMapperGatewayAnchorBlueprintCode));
            }
            if (searchResult.Any())
            {
                _logger.Information("Gateway Blueprint {0} alredy exists.", M2mgoGatewayBlueprintTranslator.CloudMapperGatewayAnchorBlueprintCode);
                return(searchResult.Single());
            }
            BlueprintDto gatewayBlueprintDefiniton = _m2MgoGatewayBlueprintTranslator.GetGatewayBlueprintDefiniton(project);

            gatewayBlueprintDefiniton.PrepareMasterForCreation();

            string result = _apiWrapper.CreateBlueprint(config, _projectTranslator.GetProjectDomain(project), gatewayBlueprintDefiniton);

            _logger.Information("CreateBlueprint Blueprint: " + result);
            return(_apiWrapper.SearchBlueprint(config, _projectTranslator.GetProjectDomain(project), M2mgoGatewayBlueprintTranslator.CloudMapperGatewayAnchorBlueprintCode).Single());
        }
Exemplo n.º 22
0
        public M2mgoGetwayProjectDto RegisterProject(M2MgoCloudAgentConfiguration config, string serialId, UicProject project)
        {
            GatewayProjectGetModel gatewayProject = EnsureProject(config, project);
            GatewayGetModel        gateway        = EnsureGateway(config, serialId, gatewayProject);

            return(new M2mgoGetwayProjectDto(gateway, gatewayProject));
        }