private Task <ParseCommand> PrepareCommand(ParseCommand command) { ParseCommand newCommand = new ParseCommand(command); Task <ParseCommand> installationIdTask = installationIdController.GetAsync().ContinueWith(t => { newCommand.Headers.Add(new KeyValuePair <string, string>("X-Parse-Installation-Id", t.Result.ToString())); return(newCommand); }); // TODO (richardross): Inject configuration instead of using shared static here. ParseClient.Configuration configuration = ParseClient.CurrentConfiguration; newCommand.Headers.Add(new KeyValuePair <string, string>("X-Parse-Application-Id", configuration.ApplicationId)); newCommand.Headers.Add(new KeyValuePair <string, string>("X-Parse-Client-Version", ParseClient.VersionString)); if (configuration.AdditionalHTTPHeaders != null) { foreach (var header in configuration.AdditionalHTTPHeaders) { newCommand.Headers.Add(header); } } if (!string.IsNullOrEmpty(configuration.VersionInfo.BuildVersion)) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-Parse-App-Build-Version", configuration.VersionInfo.BuildVersion)); } if (!string.IsNullOrEmpty(configuration.VersionInfo.DisplayVersion)) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-Parse-App-Display-Version", configuration.VersionInfo.DisplayVersion)); } if (!string.IsNullOrEmpty(configuration.VersionInfo.OSVersion)) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-Parse-OS-Version", configuration.VersionInfo.OSVersion)); } // TODO (richardross): I hate the idea of having this super tightly coupled static variable in here. // Lets eventually get rid of it. if (!string.IsNullOrEmpty(ParseClient.MasterKey)) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-Parse-Master-Key", ParseClient.MasterKey)); } else { newCommand.Headers.Add(new KeyValuePair <string, string>("X-Parse-Windows-Key", configuration.WindowsKey)); } // TODO (richardross): Inject this instead of using static here. if (ParseUser.IsRevocableSessionEnabled) { newCommand.Headers.Add(new KeyValuePair <string, string>("X-Parse-Revocable-Session", revocableSessionTokentrueValue)); } return(installationIdTask); }
public Task <ParseInstallation> GetAsync(CancellationToken cancellationToken) { ParseInstallation cachedCurrent; cachedCurrent = CurrentInstallation; if (cachedCurrent != null) { return(Task <ParseInstallation> .FromResult(cachedCurrent)); } return(taskQueue.Enqueue(toAwait => { return toAwait.ContinueWith(_ => { return storageController.LoadAsync().OnSuccess(stroage => { Task fetchTask; object temp; stroage.Result.TryGetValue(ParseInstallationKey, out temp); var installationDataString = temp as string; ParseInstallation installation = null; if (installationDataString != null) { var installationData = Json.Parse(installationDataString) as IDictionary <string, object>; installation = installationCoder.Decode(installationData); fetchTask = Task.FromResult <object>(null); } else { installation = ParseObject.Create <ParseInstallation>(); fetchTask = installationIdController.GetAsync().ContinueWith(t => { installation.SetIfDifferent("installationId", t.Result.ToString()); }, Parse.ParseClient.DefaultTaskContinuationOptions); } CurrentInstallation = installation; return fetchTask.ContinueWith(t => { return installation; }, Parse.ParseClient.DefaultTaskContinuationOptions); }); }, Parse.ParseClient.DefaultTaskContinuationOptions).Unwrap().Unwrap(); }, cancellationToken)); }