/// <summary>
        /// Determines if the target application is running on the target device.
        /// </summary>
        /// <param name="packageName"></param>
        /// <param name="targetDevice"></param>
        /// <param name="appInfo">Optional cached <see cref="ApplicationInfo"/>.</param>
        /// <returns>True, if the application is running.</returns>
        public static async Task <bool> IsAppRunningAsync(string packageName, DeviceInfo targetDevice, ApplicationInfo appInfo = null)
        {
            Debug.Assert(!string.IsNullOrEmpty(packageName));

            if (appInfo == null)
            {
                appInfo = await GetApplicationInfoAsync(packageName, targetDevice);
            }

            if (appInfo == null)
            {
                Debug.LogError($"{packageName} not installed.");
                return(false);
            }

            var response = await Rest.GetAsync(string.Format(ProcessQuery, FinalizeUrl(targetDevice.IP)), targetDevice.Authorization);

            if (response.Successful)
            {
                var processList = JsonUtility.FromJson <ProcessList>(response.ResponseBody);
                for (int i = 0; i < processList.Processes.Length; ++i)
                {
                    if (processList.Processes[i].ImageName.Contains(appInfo.Name))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            if (response.ResponseCode == 403 && await RefreshCsrfTokenAsync(targetDevice))
            {
                return(await IsAppRunningAsync(packageName, targetDevice, appInfo));
            }

            Debug.LogError($"{response.ResponseBody}");
            return(false);
        }
        /// <summary>
        /// Gets the <see cref="Microsoft.MixedReality.Toolkit.WindowsDevicePortal.PowerStateInfo"/> of the target device.
        /// </summary>
        /// <returns><see cref="Microsoft.MixedReality.Toolkit.WindowsDevicePortal.PowerStateInfo"/></returns>
        public static async Task <PowerStateInfo> GetPowerStateAsync(DeviceInfo targetDevice)
        {
            var isAuth = await EnsureAuthenticationAsync(targetDevice);

            if (!isAuth)
            {
                return(null);
            }

            string query    = string.Format(GetPowerStateQuery, FinalizeUrl(targetDevice.IP));
            var    response = await Rest.GetAsync(query, targetDevice.Authorization);

            if (!response.Successful)
            {
                if (response.ResponseCode == 403 && await RefreshCsrfTokenAsync(targetDevice))
                {
                    await GetPowerStateAsync(targetDevice);
                }
                return(null);
            }

            return(JsonUtility.FromJson <PowerStateInfo>(response.ResponseBody));
        }
Exemple #3
0
        public static async Task <Activity[]> GetActivities(int limit = 10, int before = -1, int after = -1)
        {
            string url = baseUrl;

            url += "?before=" + before.ToString();
            url += "&after=" + after.ToString();
            url += "&limit=" + limit.ToString();
            url += "&fillChildElements=false";

            Response response = await Rest.GetAsync(url);

            if (!response.Successful)
            {
                Debug.LogError(response.ResponseCode + ": " + response.ResponseBody);
                return(null);
            }
            else
            {
                string     json       = JsonHelper.EncapsulateInWrapper(response.ResponseBody);
                Activity[] activities = JsonHelper.FromJson <Activity>(json);
                return(activities);
            }
        }
Exemple #4
0
        public static Task <DistanceMatrixResponse> GetDistanceAsync(string apiKey, List <string> originAddresses,
                                                                     List <string> destinationAddresses,
                                                                     GeoUnit geoUnit = GeoUnit.Metric, RequestOutputFormat outputFormat = RequestOutputFormat.Json)
        {
            if (apiKey.IsNotNullOrEmpty() && originAddresses?.Count > 0 &&
                destinationAddresses?.Count() > 0)
            {
                var path = $"{(outputFormat == RequestOutputFormat.Json ? "json" : "xml")}?key={apiKey}";
                if (geoUnit != GeoUnit.Metric)
                {
                    path += "&units=imperial";
                }
                var origins      = string.Join("|", originAddresses.Select(item => item.Trim()));
                var destinations = string.Join("|", destinationAddresses.Select(item => item.Trim()));

                path += $"&origins={origins}&destinations={destinations}";
                using (var rest = new Rest(new Uri(RequestUrl)))
                {
                    return(rest.GetAsync <DistanceMatrixResponse>(path));
                }
            }

            return(Task.FromResult(default(DistanceMatrixResponse)));
        }
        private async void Start()
        {
            Response response = new Response();

            try
            {
                response = await Rest.GetAsync(uri);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }

            if (!response.Successful)
            {
                Debug.LogError($"Failed to get glb model from {uri}");
                return;
            }

            var gltfObject = GltfUtility.GetGltfObjectFromGlb(response.ResponseData);

            try
            {
                await gltfObject.ConstructAsync();
            }
            catch (Exception e)
            {
                Debug.LogError($"{e.Message}\n{e.StackTrace}");
                return;
            }

            if (gltfObject != null)
            {
                Debug.Log("Import successful");
            }
        }
        public static async Task <InstalledApps> GetAllInstalledAppsAsync(DeviceInfo targetDevice)
        {
            var isAuth = await EnsureAuthenticationAsync(targetDevice);

            if (!isAuth)
            {
                return(null);
            }

            var response = await Rest.GetAsync(string.Format(PackagesQuery, FinalizeUrl(targetDevice.IP)), targetDevice.Authorization);

            if (!response.Successful)
            {
                if (response.ResponseCode == 403 && await RefreshCsrfTokenAsync(targetDevice))
                {
                    return(await GetAllInstalledAppsAsync(targetDevice));
                }

                Debug.LogError(response.ResponseBody);
                return(null);
            }

            return(JsonUtility.FromJson <InstalledApps>(response.ResponseBody));
        }
 private async Task GetBanks()
 {
     await UIHelper.ToggleProgressBar(true, res.GetString("Loading"));
     KeyValuePair<HttpStatusCode,JObject> MyResult = await Rest.GetAsync("banks", "");
     HttpStatusCode statuscode = MyResult.Key;
     JObject output = MyResult.Value;
     
     if (statuscode == HttpStatusCode.OK)
     {
         string status = (string)output["status"];
         if (status != "error")
         {
             JArray banksArray = (JArray)output["data"];
             List<string> lstbank = banksArray.Select(c => (string)c).ToList();
             bankslist = new List<string>();
             Bankslist = new List<string>();
             foreach (var item in lstbank)
             {
                 Bankslist.Add(item);
                 bankslist.Add(item);
             }
         }
         else
         {
             await UIHelper.ShowAlert((string)output["error"]["message"][0]);
         }
     }
     else if (statuscode == HttpStatusCode.Unauthorized)
     {               
     }
     else
     {
         await UIHelper.ShowAlert((string)output["error"]["message"][0]);
     }
     await UIHelper.ToggleProgressBar(false);
 }
        /// <summary>
        /// Converts a text id to the corresponding string
        /// </summary>
        /// <param name="id">The id which identifies the text segment</param>
        /// <returns>The text segment of the id</returns>
        public static async Task <string> GetString(short id)
        {
            if (id == -1)
            {
                return("");
            }

            Response resp = await Rest.GetAsync(
                ConnectionManager.Instance.BackendAPIBaseURL + serviceEndpoint + "/" + id,
                null,
                -1,
                null,
                true);

            if (resp.Successful)
            {
                return(resp.ResponseBody);
            }
            else
            {
                Debug.LogError(resp.ResponseBody);
                return("");
            }
        }
Exemple #9
0
        public static async Task <TwilioMessage> GetMessage(
            RestCredentialInfo restCredentialInfo,
            string messageId)
        {
            var restCredential = new Rest(
                restCredentialInfo.AccountId,
                restCredentialInfo.SecretKey);
            var url = string.Format(
                SmsGetUrl,
                restCredentialInfo.AccountId,
                messageId);
            var response = await restCredential.GetAsync(
                url);

            var responseContent = await response.Content.ReadAsStringAsync();

            var twilioMessage = new TwilioMessage();
            var xmlDoc        = new XmlDocument();

            xmlDoc.LoadXml(
                responseContent);

            if (response.IsSuccessStatusCode)
            {
                try
                {
                    twilioMessage.ReturnSid = xmlDoc.SelectSingleNode(
                        "TwilioResponse/Message/Sid").InnerText;
                    twilioMessage.Created = Convert.ToDateTime(
                        xmlDoc.SelectSingleNode(
                            "TwilioResponse/Message/DateCreated")
                        .InnerText);
                    twilioMessage.Updated = Convert.ToDateTime(
                        xmlDoc.SelectSingleNode(
                            "TwilioResponse/Message/DateUpdated")
                        .InnerText);
                    twilioMessage.Sent = Convert.ToDateTime(
                        xmlDoc.SelectSingleNode(
                            "TwilioResponse/Message/DateSent")
                        .InnerText);
                    twilioMessage.From = xmlDoc.SelectSingleNode(
                        "TwilioResponse/Message/From").InnerText;
                    twilioMessage.To = xmlDoc.SelectSingleNode(
                        "TwilioResponse/Message/To").InnerText;
                    twilioMessage.Message = xmlDoc.SelectSingleNode(
                        "TwilioResponse/Message/Body").InnerText;
                    twilioMessage.NumberOfSms = Convert.ToInt32(xmlDoc.SelectSingleNode(
                                                                    "TwilioResponse/Message/NumSegments").InnerText);
                    twilioMessage.Status = xmlDoc.SelectSingleNode(
                        "TwilioResponse/Message/Status").InnerText;
                    twilioMessage.Direction = xmlDoc.SelectSingleNode(
                        "TwilioResponse/Message/Direction").InnerText;
                    var errorCode = xmlDoc.SelectSingleNode(
                        "TwilioResponse/Message/ErrorCode");
                    if (errorCode != null)
                    {
                        var twilioException = new TwilioException()
                        {
                            Code    = Convert.ToInt32(errorCode.InnerText),
                            Message = xmlDoc.SelectSingleNode(
                                "TwilioResponse/Message/ErrorMessage").InnerText
                        };
                        twilioMessage.RestException = twilioException;
                    }
                }
                catch
                {
                }
            }
            return(twilioMessage);
        }
        /// <summary>
        /// Loads content using MRTK's Web access classes
        /// </summary>
        /// <param name="uri">The uri which should be loaded</param>
        /// <returns>Returns a WebResponse with the content of the web request</returns>
        public async Task <WebResponse <string> > LoadAsync(string uri)
        {
            Response resp = await Rest.GetAsync(uri);

            return(FromResponse(resp));
        }