Beispiel #1
0
        //IoTDevice
        public void RegisterIoTDevice(int companyId, int iotDeviceId, Format_Base parseData)
        {
            CDSShareLib.ServiceBus.Model.IoTDeviceRegisterModel message = new CDSShareLib.ServiceBus.Model.IoTDeviceRegisterModel();
            message.content = new CDSShareLib.ServiceBus.Model.IoTDeviceRegisterModel.ContentFormat();

            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                IoTDevice iotDevice = dbEntity.IoTDevice.Find(iotDeviceId);
                if (iotDevice == null)
                {
                    throw new CDSException(10902);
                }

                //ServiceBus - Content
                message.content.iothubDeviceId         = iotDevice.IoTHubDeviceID;
                message.content.authenticationType     = iotDevice.AuthenticationType;
                message.content.iothubConnectionString = (iotDevice.IoTHub == null ? "" : iotDevice.IoTHub.IoTHubConnectionString);
                switch (message.content.authenticationType.ToLower())
                {
                case "key":
                    message.content.iothubDeviceKey       = iotDevice.IoTHubDeviceKey;
                    message.content.certificateThumbprint = null;
                    break;

                case "certificate":
                    message.content.iothubDeviceKey       = null;
                    message.content.certificateThumbprint = (iotDevice.DeviceCertificate == null ? "" : iotDevice.DeviceCertificate.Thumbprint);
                    break;
                }
            }

            //ServiceBus - Base parameter
            message.entityId       = iotDeviceId;
            message.requester      = parseData.Requester;
            message.requesterEmail = parseData.requesterEmail;

            //Operation task
            OperationTaskModel.Format_Create operationTaskData = new OperationTaskModel.Format_Create();
            operationTaskData.Entity      = message.entity;
            operationTaskData.Name        = message.task;
            operationTaskData.EntityId    = message.entityId.ToString();
            operationTaskData.TaskContent = JsonConvert.SerializeObject(message);

            OperationTaskModel operationTaskModel = new OperationTaskModel();

            message.taskId = operationTaskModel.Create(companyId, operationTaskData);

            Global.ServiceBus.Helper.SendToQueue(Global.ServiceBus.Queue.Provision, JsonConvert.SerializeObject(message));
        }
Beispiel #2
0
        //Company's CosmosDBCollection
        public void CreateCompanyCosmosDBCollection(int companyId, Format_Base parseData)
        {
            CDSShareLib.ServiceBus.Model.CosmosDBCollectionCreateModel message = new CDSShareLib.ServiceBus.Model.CosmosDBCollectionCreateModel();
            message.content = new CDSShareLib.ServiceBus.Model.CosmosDBCollectionCreateModel.ContentFormat();

            //ServiceBus - Content
            message.content.companyId    = companyId;
            message.content.partitionKey = "/messageContent/equipmentId"; //temporarily fixed
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                //Find company's unexpired and latest subscription
                var subscription = (from c in dbEntity.CompanyInSubscriptionPlan.AsNoTracking()
                                    where c.CompanyID == companyId && c.ExpiredDate > DateTime.UtcNow
                                    orderby c.ExpiredDate descending
                                    select c).FirstOrDefault();
                if (subscription == null)
                {
                    throw new CDSException(10201);
                }

                message.content.collectionRU  = subscription.CosmosDBCollectionReservedUnits.ToString();
                message.content.collectionTTL = subscription.CosmosDBCollectionTTL.ToString();

                //ServiceBus - Flexible parameter
                message.cosmosDBConnectionString = subscription.CosmosDBConnectionString;
            }

            //ServiceBus - Base parameter
            message.entityId       = companyId;
            message.requester      = parseData.Requester;
            message.requesterEmail = parseData.requesterEmail;

            //Operation task
            OperationTaskModel.Format_Create operationTaskData = new OperationTaskModel.Format_Create();
            operationTaskData.Entity      = message.entity;
            operationTaskData.Name        = message.task;
            operationTaskData.EntityId    = message.entityId.ToString();
            operationTaskData.TaskContent = JsonConvert.SerializeObject(message);

            OperationTaskModel operationTaskModel = new OperationTaskModel();

            message.taskId = operationTaskModel.Create(companyId, operationTaskData);

            Global.ServiceBus.Helper.SendToQueue(Global.ServiceBus.Queue.Provision, JsonConvert.SerializeObject(message));
        }
Beispiel #3
0
        public void DeleteIoTDevice(int companyId, int iotDeviceId, Format_Base parseData)
        {
            CDSShareLib.ServiceBus.Model.IoTDeviceDeleteModel message = new CDSShareLib.ServiceBus.Model.IoTDeviceDeleteModel();
            message.content = new CDSShareLib.ServiceBus.Model.IoTDeviceDeleteModel.ContentFormat();

            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                IoTDevice iotDevice = dbEntity.IoTDevice.Find(iotDeviceId);
                if (iotDevice == null)
                {
                    throw new CDSException(10902);
                }

                //ServiceBus - Content
                message.content.iothubDeviceId         = iotDevice.IoTHubDeviceID;
                message.content.iothubConnectionString = (iotDevice.IoTHub == null ? "" : iotDevice.IoTHub.IoTHubConnectionString);
            }

            //ServiceBus - Base parameter
            message.entityId       = iotDeviceId;
            message.requester      = parseData.Requester;
            message.requesterEmail = parseData.requesterEmail;

            //Operation task
            OperationTaskModel.Format_Create operationTaskData = new OperationTaskModel.Format_Create();
            operationTaskData.Entity      = message.entity;
            operationTaskData.Name        = message.task;
            operationTaskData.EntityId    = message.entityId.ToString();
            operationTaskData.TaskContent = JsonConvert.SerializeObject(message);

            OperationTaskModel operationTaskModel = new OperationTaskModel();

            message.taskId = operationTaskModel.Create(companyId, operationTaskData);

            Global.ServiceBus.Helper.SendToQueue(Global.ServiceBus.Queue.Provision, JsonConvert.SerializeObject(message));
        }