//To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code BM5M4CEHJ to authenticate.
        public LoginModel GetLoginModel()
        {
            //Login with Az Login
            AzHelper.AzLoginWithDeviceCode();

            //Wait for 20 Seconds
            int    countDownTimer  = 30;
            string deviceCode      = String.Empty;
            string deviceCodeToken = String.Empty;

            while (countDownTimer != 0)
            {
                deviceCode = AzHelper.azError.ToString();
                if (deviceCode.Length != 0 && deviceCode.Contains("enter the code"))
                {
                    break;
                }
                Thread.Sleep(1000 * 1);
                countDownTimer--;
            }

            deviceCode = AzHelper.azError.ToString();

            string urlKey = "https://microsoft.com/devicelogin";

            Match codeMatch = Regex.Match(deviceCode, @"enter the code ([A-Z0-9]+) to authenticate", RegexOptions.IgnoreCase);

            if (!codeMatch.Success)
            {
                return(null);
            }
            string codeKey = codeMatch.Groups[1].Value;

            Console.WriteLine(codeKey);

            if (String.IsNullOrWhiteSpace(urlKey))
            {
                return(null);
            }
            if (String.IsNullOrWhiteSpace(codeKey))
            {
                return(null);
            }

            try
            {
                LoginModel model = new LoginModel(urlKey, codeKey);
                return(model);
            }
            catch (Exception exc)
            {
                return(null);
            }
        }
        public bool SelectSubscription(string subscriptionId)
        {
            AzHelper.AzSetSubscription(subscriptionId);
            return(true);
            //string error = AzHelper.azError.ToString();
            //error = error.Replace("\r\n", "");

            //if (String.IsNullOrWhiteSpace(error)) //No Error Here
            //    return true;

            //return false;
        }
示例#3
0
        public IActionResult SelectPost(string iotEdgeName)
        {
            Console.WriteLine("hello!");
            // var accessToken = accessTokenRepository.GetAccessTokenModel();

            /*IList<SelectListItem> selectListItems = new List<SelectListItem>();
             * var iotHubViewModel = new IoTHubViewModel() { IoTHubName = iotHubName, IoTHubs = selectListItems };*/
            //AzHelper.AzAddCAPDevice(iotHubName, deviceId);
            AzHelper.AzGetConnectionString(IoTEdgeController.iotHubName, iotEdgeName);
            Console.WriteLine(AzHelper.azOutput);

            string header           = "ConnectionString-------------------------------------------------------------------------------------------------------------------------------------";
            int    headerLen        = header.Length;
            string connectionString = AzHelper.azOutput.Remove(0, headerLen).ToString();

            // iotHubName = "phuong";

            return(RedirectToAction("Index", "Configuration", new { connectionString = connectionString }));
        }
        public IList <IoTEdgeModel> GetIoTEdgeModels(string iotHubName)
        {
            AzHelper.AzGetDevices(iotHubName);

            string output = AzHelper.azOutput.ToString();

            output = output.Replace("\r\n", "");
            if (String.IsNullOrWhiteSpace(output))
            {
                return(null);
            }

            try
            {
                IList <IoTEdgeModel> ioTEdgeModels = JsonConvert.DeserializeObject <IList <IoTEdgeModel> >(output);

                return(ioTEdgeModels);
            }
            catch (Exception exc)
            {
                return(null);
            }
        }
        public AccessTokenModel GetAccessTokenModel()
        {
            AzHelper.AzAccountGetAccessToken();

            string output = AzHelper.azOutput.ToString();

            output = output.Replace("\r\n", "");

            if (String.IsNullOrWhiteSpace(output))
            {
                return(null);
            }

            try
            {
                AccessTokenModel account = JsonConvert.DeserializeObject <AccessTokenModel>(output);
                return(account);
            }
            catch (Exception exc)
            {
                return(null);
            }
        }
        public IList <ResourceGroupModel> GetResourceGroupModels()
        {
            AzHelper.AzListResourceGroup();

            string output = AzHelper.azOutput.ToString();

            output = output.Replace("\r\n", "");

            if (String.IsNullOrWhiteSpace(output))
            {
                return(null);
            }

            try
            {
                IList <ResourceGroupModel> resourceGroups = JsonConvert.DeserializeObject <IList <ResourceGroupModel> >(output);
                return(resourceGroups);
            }
            catch (Exception exc)
            {
                return(null);
            }
        }
        public SubscriptionModel GetSubscription()
        {
            AzHelper.AzGetSubscription();

            string output = AzHelper.azOutput.ToString();

            output = output.Replace("\r\n", "");

            if (String.IsNullOrWhiteSpace(output))
            {
                return(null);
            }

            try
            {
                SubscriptionModel subscription = JsonConvert.DeserializeObject <SubscriptionModel>(output);
                return(subscription);
            }
            catch (Exception exc)
            {
                return(null);
            }
        }