Esempio n. 1
0
        private void ProcessResults(WaitableTask <Dictionary <int, EncounterBasicStatus> > result, TaskResult <string[]> fileTexts)
        {
            if (!fileTexts.HasValue())
            {
                result.SetResult(new Dictionary <int, EncounterBasicStatus>());
                return;
            }

            var statuses = new Dictionary <int, EncounterBasicStatus>();

            foreach (var fileText in fileTexts.Value)
            {
                var metadata = parser.Deserialize(fileText);
                if (statuses.ContainsKey(metadata.Key))
                {
                    Debug.LogError($"Duplicate saved status for key {metadata.Key}");
                    continue;
                }
                if (metadata.Value != null)
                {
                    statuses.Add(metadata.Key, metadata.Value);
                }
            }

            result.SetResult(statuses);
        }
        protected virtual void ProcessResults(WaitableTask result, TaskResult <string> serverOutput)
        {
            if (serverOutput == null || serverOutput.IsError())
            {
                result.SetError(serverOutput.Exception);
                return;
            }

            var output = serverOutput.Value.Trim();

            if (output.StartsWith("1"))
            {
                result.SetCompleted();
                return;
            }

            string errorStart = "-1|";

            if (output.StartsWith(errorStart, StringComparison.InvariantCultureIgnoreCase))
            {
                var encounterLock = parser.Deserialize(output.Substring(errorStart.Length));
                result.SetError(new EncounterAlreadyLockedException(encounterLock));
                return;
            }

            result.SetError(new Exception("Could not unlock the encounter."));
        }
        public T Deserialize(string text)
        {
            var xmlDoc       = xmlParser.Deserialize(text);
            var deserializer = new XmlDeserializer(xmlDoc);

            return(serializationFactory.Deserialize(deserializer));
        }
 private void ProcessResults(WaitableTask <EncounterImageContent> result, TaskResult <string> fileText)
 {
     if (fileText.IsError())
     {
         result.SetError(fileText.Exception);
     }
     else
     {
         result.SetResult(parser.Deserialize(fileText.Value));
     }
 }
        private void ProcessResults(WaitableTask <List <EncounterMetadata> > result, TaskResult <string> serverOutput)
        {
            if (serverOutput == null || serverOutput.IsError())
            {
                result.SetError(serverOutput.Exception);
                return;
            }

            var metadatas = parser.Deserialize(serverOutput.Value);

            result.SetResult(metadatas);
        }
Esempio n. 6
0
        private void ProcessResults(WaitableTask <EncounterMetadata> result, TaskResult <string> fileText)
        {
            if (fileText.Value == null)
            {
                result.SetError(null);
                return;
            }

            var metadata = parser.Deserialize(fileText.Value);

            result.SetResult(metadata);
        }
Esempio n. 7
0
        public async Task <QueryResponse <T> > PerformQueryAsync <T>(GraphQlHost host, string query)
        {
            var response = await httpClient.PostAsync(host.GetHostUrl(), query);

            if (!response.IsSuccess)
            {
                return(QueryResponse.Failed <T>());
            }

            var deserializedObject = stringDeserializer.Deserialize <T>(response.StringResponse);

            return(QueryResponse.Success(deserializedObject));
        }
        public Task <StorageRetrievalResponse <T> > Get(string key)
        {
            var properties = this.app.Properties;

            T thing = default(T);

            if (properties.TryGetValue(key, out object value))
            {
                thing = deserializer.Deserialize <T>((string)value);
            }

            if (thing != null)
            {
                return(Task.FromResult(StorageRetrievalResponse <T> .CreateSucceeded(thing)));
            }

            return(Task.FromResult(StorageRetrievalResponse <T> .CreateFailed("Failed to retrieve data")));
        }
        private void ProcessResults(WaitableTask <List <EncounterMetadata> > result, TaskResult <string[]> fileTexts)
        {
            if (fileTexts == null)
            {
                result.SetError(null);
                return;
            }

            var metadatas = new List <EncounterMetadata>();

            foreach (var fileText in fileTexts.Value)
            {
                var metadata = parser.Deserialize(fileText);
                if (metadata != null)
                {
                    metadatas.Add(metadata);
                }
            }

            result.SetResult(metadatas);
        }
        protected virtual void ProcessResults(
            WaitableTask <Dictionary <int, EncounterEditLock> > result,
            TaskResult <string> serverOutput)
        {
            if (serverOutput == null || serverOutput.IsError())
            {
                result.SetError(serverOutput.Exception);
                return;
            }

            var locks          = parser.Deserialize(serverOutput.Value);
            var lockDictionary = new Dictionary <int, EncounterEditLock>();

            foreach (var encounterLock in locks)
            {
                if (!lockDictionary.ContainsKey(encounterLock.RecordNumber))
                {
                    lockDictionary.Add(encounterLock.RecordNumber, encounterLock);
                }
            }
            result.SetResult(lockDictionary);
        }
Esempio n. 11
0
        public async Task <TResponse> PostAsync <TBody, TResponse>(string url, TBody body)
        {
            var httpClient    = new HttpClient();
            var authorization = configurationProvider.GetConfigurationValue("authorization");

            httpClient.DefaultRequestHeaders.Add("Authorization", $"bearer {authorization}");

            string bodyAsString = body as string;

            if (bodyAsString == null)
            {
                bodyAsString = stringSerializer.Serialize(body);
            }

            var response = await httpClient.PostAsync(url, new StringContent(bodyAsString));

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

            var responseContent = stringDeserializer.Deserialize <TResponse>(responseBody);

            return(responseContent);
        }
        public async Task <WebRequestResponse <T> > GetResponseFromEndpoint <T>(string url, CancellationToken token)
        {
            if (!networkChecker.HasInternetAccess())
            {
                return(WebRequestFactory.Cancelled <T>());
            }

            try
            {
                var responseString = await GetResponseString(url, token);

                var obj = stringDeserializer.Deserialize <T>(responseString);

                return(WebRequestFactory.Success(obj));
            }
            catch (System.Net.WebException)
            {
                return(WebRequestFactory.Cancelled <T>());
            }
            catch (HttpRequestException)
            {
                return(WebRequestFactory.Errored <T>("Internet connection was disrupted."));
            }
        }
 private void ProcessResults(WaitableTask <EncounterNonImageContent> result, TaskResult <string> serverResult)
 {
     result.SetResult(parser.Deserialize(serverResult.Value));
 }
        private void ProcessResults(WaitableTask <EncounterStatus> result,
                                    TaskResult <string> fileText, EncounterBasicStatus basicStatus)
        {
            EncounterContentStatus detailedStatus = (fileText.IsError()) ? new EncounterContentStatus() : parser.Deserialize(fileText.Value);
            var status = new EncounterStatus(basicStatus, detailedStatus);

            result.SetResult(status);
        }