예제 #1
0
        //    private readonly IIoTHubResourceDto _ioTHubResourceDto;



        //public IoTHubResourceBus(IIoTHubResourceDto ioTHubResourceDto)
        //{
        //    this._ioTHubResourceDto = ioTHubResourceDto;

//        }
        public async Task <string> GetBySubId(string email, string subid)
        {
            string access_token = _tokenDto.GetTokenString(email, _tokenResource.Value.manage);

            //var accountModel= this._configuration.GetSection("appsettings").Value;
            //SubId = this._accountModel.subscriptionId;
            //subId = "6273fbea-8a11-498b-8218-02b6f4398e12";

            Model.ResponseModel.IoTHubResourceModel objs = null;
            //IoTHubResourceDto ioTHubResourceDto = new IoTHubResourceDto();
            objs = await this._ioTHubResourceDto.ListBySubId(subid, access_token);

            List <Model.IoTHubResourceViewModel> listBySubIdResponse = new List <Model.IoTHubResourceViewModel>();

            foreach (var ob in objs.value)
            {
                Model.IoTHubResourceViewModel ioTHubResource = new Model.IoTHubResourceViewModel();
                ioTHubResource.name           = ob.name;
                ioTHubResource.location       = ob.location;
                ioTHubResource.resourcegroup  = ob.resourcegroup;
                ioTHubResource.type           = ob.type;
                ioTHubResource.subscriptionid = ob.subscriptionid;
                listBySubIdResponse.Add(ioTHubResource);
            }
            string result = JsonConvert.SerializeObject(listBySubIdResponse);

            return(result);
        }
예제 #2
0
        public async Task <IoTHubResourceModel> ListBySubId(string SubId, string access_token)

        {
            //List<KeyValuePair<string, string>> vals = new List<KeyValuePair<string, string>>();

            //vals.Add(new KeyValuePair<string, string>("subscriptionId", SubId));
            string url = string.Format("https://management.chinacloudapi.cn/subscriptions/{0}" +
                                       "/providers/Microsoft.Devices/IotHubs?api-version=2018-04-01", SubId);

            Model.ResponseModel.IoTHubResourceModel objs = null;
            using (HttpClient httpClient = new HttpClient())
            {
                //httpClient.DefaultRequestHeaders.Add("Cache-Control", "no-cache");
                //HttpContent content = new FormUrlEncodedContent(vals);
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token);
                HttpResponseMessage hrm = httpClient.GetAsync(url).Result;
                if (hrm.IsSuccessStatusCode)
                {
                    string data = await hrm.Content.ReadAsStringAsync();

                    objs = JsonConvert.DeserializeObject <IoTHubResourceModel>(data);
                    //await DataOperations(authenticationResponse);
                }
                else
                {
                    Console.WriteLine("Error." + hrm.ReasonPhrase);
                }
            }
            return(objs);
        }
예제 #3
0
        //    private readonly IIoTHubResourceDto _ioTHubResourceDto;



        //public IoTHubResourceBus(IIoTHubResourceDto ioTHubResourceDto)
        //{
        //    this._ioTHubResourceDto = ioTHubResourceDto;

//        }
        public async Task <string> GetBySubId(string SubId)
        {
            //SubId = this._configuration["accountsetting:subscriptionId"];
            SubId = "6273fbea-8a11-498b-8218-02b6f4398e12";
            TokenModel Token = this._tokenDto.GetToken().Result;

            Model.ResponseModel.IoTHubResourceModel objs = null;
            //IoTHubResourceDto ioTHubResourceDto = new IoTHubResourceDto();
            objs = await this._ioTHubResourceDto.ListBySubId(SubId, Token.access_token);

            List <Model.IoTHubResourceViewModel> listBySubIdResponse = new List <Model.IoTHubResourceViewModel>();

            foreach (var ob in objs.value)
            {
                Model.IoTHubResourceViewModel ioTHubResource = new Model.IoTHubResourceViewModel();
                ioTHubResource.name           = ob.name;
                ioTHubResource.location       = ob.location;
                ioTHubResource.resourcegroup  = ob.resourcegroup;
                ioTHubResource.type           = ob.type;
                ioTHubResource.subscriptionid = ob.subscriptionid;
                listBySubIdResponse.Add(ioTHubResource);
            }
            string result = JsonConvert.SerializeObject(listBySubIdResponse);

            return(result);
        }