public void Setup() { CMApplication app = new CMApplication(appID, apiKey); IRestWrapper api = new PCLRestWrapper(); appObjSrvc = new CMAppObjectService(app, api); }
public void Setup() { CMApplication app = new CMApplication(appID, apiKey); IRestWrapper api = new PCLRestWrapper(); userService = new CMUserService(app, api); }
public AvailableAppsControl(CMApplication app, DateTime?nextServiceTime) { InitializeComponent(); _availableAppsSettings = Globals.Settings.AvailableAppsSettings; _app = app; DataContext = _app; SetStatus(_app); TpPicker.MaximumDate = DateTime.Now.AddYears(1); TpPicker.MinimumDate = RoundUp(DateTime.Now); TpPicker.SelectedDate = RoundUp(DateTime.Now); BtInstall.IsEnabled = !_app.InstallState.Equals("Installed"); BtUninstall.IsEnabled = _app.InstallState.Equals("Installed"); BtRepair.IsEnabled = _app.InstallState.Equals("Installed") && _app.AllowedActions.Contains("Repair"); if (!string.IsNullOrEmpty(_app.Icon.Trim())) { Icon.Source = Utils.ToBitmapImage(_app.Icon.Trim()); } if (!string.IsNullOrEmpty(_app.Description)) { LoadMessage(_app.Description); } Globals.CcmWmiEventListener.OnStatusChange += CcmWmiEventListener_OnStatusChange; SetupTimer(); }
public void SetUp() { CMApplication app = new CMApplication(appID, apiKey); IRestWrapper api = new PCLRestWrapper(); pushService = new CMPushNotificationService(app, api); userService = new CMUserService(app, api); }
public RequiredAppsControl(CMApplication app, DateTime enforcementTime, long id, DateTime?nextServiceTime) { InitializeComponent(); _requiredAppsSettings = Globals.Settings.RequiredAppsSettings; _nextServiceTime = nextServiceTime; _app = app; DataContext = _app; _isReschedule = true; _enforcementTime = enforcementTime; _scheduleId = id; TpPicker.SelectedDate = _enforcementTime; TpPicker.MaximumDate = _nextServiceTime != null ? ((DateTime)_nextServiceTime).DropSeconds() : _app.Deadline.DropSeconds(); TpPicker.MinimumDate = RoundUp(DateTime.Now); if (!string.IsNullOrEmpty(_app.Icon)) { var bmp = Utils.ToBitmapImage(_app.Icon); if (bmp != null) { Icon.Source = Utils.ToBitmapImage(_app.Icon); } } if (!string.IsNullOrEmpty(_app.Description)) { LoadMessage(_app.Description); } Globals.CcmWmiEventListener.OnStatusChange += CcmWmiEventListener_OnStatusChange; SetupTimer(); if (_nextServiceTime != null && !_app.InstallState.Equals("Installed")) { if (_enforcementTime > _nextServiceTime) { if (nextServiceTime <= RoundUp(DateTime.Now).AddMinutes(5)) { TpPicker.MinimumDate = ((DateTime)_nextServiceTime).AddMinutes(-10); TimeGrid.IsEnabled = false; ButtonGrid.IsEnabled = false; _timer.Stop(); } TpPicker.MaximumDate = (DateTime)_nextServiceTime; TpPicker.SelectedDate = (DateTime)_nextServiceTime; StatusGreen.Visibility = Visibility.Visible; StatusText.Text = Globals.Settings.RequiredAppsSettings.CoveredByServiceCycleText.Replace("%TIME%", _nextServiceTime.ToString()); return; } } SetStatus(_app); }
protected TodoService() { string appID = ""; string apiKey = ""; app = new CMApplication(appID, apiKey); restWrapper = new PCLRestWrapper(); appObjectService = new CMAppObjectService(app, restWrapper); }
public RequiredAppsControl(CMApplication app, DateTime?nextServiceTime) { InitializeComponent(); _requiredAppsSettings = Globals.Settings.RequiredAppsSettings; _nextServiceTime = nextServiceTime; _app = app; DataContext = _app; TpPicker.MaximumDate = _app.InstallState.Equals("Installed") && _app.AllowedActions.Contains("Repair") ? DateTime.Now.AddYears(1) : _app.Deadline.DropSeconds(); TpPicker.MinimumDate = RoundUp(DateTime.Now); TpPicker.SelectedDate = RoundUp(DateTime.Now); BtInstall.IsEnabled = !_app.InstallState.Equals("Installed"); BtRepair.IsEnabled = _app.InstallState.Equals("Installed") && _app.AllowedActions.Contains("Repair"); if (!string.IsNullOrEmpty(_app.Icon.Trim())) { Icon.Source = Utils.ToBitmapImage(_app.Icon.Trim()); } if (!string.IsNullOrEmpty(_app.Description)) { LoadMessage(_app.Description); } Globals.CcmWmiEventListener.OnStatusChange += CcmWmiEventListener_OnStatusChange; SetupTimer(); if (_nextServiceTime != null && !_app.InstallState.Equals("Installed")) { if (_nextServiceTime < _app.Deadline) { if (_nextServiceTime <= RoundUp(DateTime.Now).AddMinutes(5)) { TpPicker.MinimumDate = ((DateTime)_nextServiceTime).AddMinutes(-5); TimeGrid.IsEnabled = false; ButtonGrid.IsEnabled = false; _timer.Stop(); } TpPicker.MaximumDate = (DateTime)_nextServiceTime; TpPicker.SelectedDate = (DateTime)_nextServiceTime; StatusGreen.Visibility = Visibility.Visible; StatusText.Text = Globals.Settings.RequiredAppsSettings.CoveredByServiceCycleText.Replace("%TIME%", _nextServiceTime.ToString()); return; } } SetStatus(_app); }
private void InstallIpuApplication(CMApplication cmApp) { if (_ipuRunning) { return; } _ipuRunning = true; Task.Run(() => { _runningIpuApp = CcmUtils.GetSpecificApp(new ScheduledObject { ObjectId = cmApp.Id, Revision = cmApp.Revision }); if (_runningIpuApp == null) { Globals.Log.Error($"Failed to get specific application, Id '{cmApp.Id}' Revision: '{cmApp.Revision}'"); _ipuRunning = false; RegistryMethods.RemoveIpuIsRunning(); return; } var contentInfo = SqlCe.GetContentStatus(_runningIpuApp.DeploymentTypeId, _runningIpuApp.DeploymentTypeRevision); if (contentInfo != null) { if (contentInfo.IsDownloaded && contentInfo.InstallTime < DateTime.Now.AddMinutes(-30)) { Globals.Log.Information($"Detected request for upgrade, IpuApplication at '{contentInfo.Location}' - attempting upgrade."); RegistryMethods.SetIpuIsRunning(); CcmUtils.InstallApplication(_runningIpuApp); } else { Globals.Log.Information($"Detected request for upgrade, IpuApplication at '{contentInfo.Location}' - content not yet downloaded or already installed, skipping."); _ipuRunning = false; RegistryMethods.RemoveIpuIsRunning(); } } else { Globals.Log.Information($"Detected request for upgrade, IpuApplication DT Id '{_runningIpuApp.DeploymentTypeId}' Revision '{_runningIpuApp.DeploymentTypeRevision}' - content status returned Null, skipping."); _ipuRunning = false; RegistryMethods.RemoveIpuIsRunning(); } }); }
public static void NotifyAppInstallationStart(CMApplication app) { // Construct the visuals of the toast var toastContent = new ToastContent() { // Arguments when the user taps body of toast Launch = new QueryString() { { "action", "ok" }, { "appidrevision", $"close" }, }.ToString(), Visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = _settings.ToastNotifyAppInstallationStartSettings.Title, }, new AdaptiveText() { Text = app.Name, }, }, }, }, Scenario = (ToastScenario)_settings.ToastNotifyAppInstallationStartSettings.ToastScenario, }; var doc = new XmlDocument(); doc.LoadXml(toastContent.GetContent()); // And create the toast notification var toast = new ToastNotification(doc) { ExpirationTime = DateTimeOffset.Now.AddSeconds(_settings.ToastNotifyAppInstallationStartSettings.Duration) }; // And then show it DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); }
private async Task EvaluateApplication() { BtInstall.IsEnabled = false; BtUninstall.IsEnabled = false; BtRepair.IsEnabled = false; BtSchedule.IsEnabled = false; //TpPicker.Expanded = false; TpPicker.IsEnabled = false; ProgressbarEnforcement.Visibility = Visibility.Visible; CMApplication tmpApp = null; await Task.Run(() => { try { tmpApp = CcmUtils.GetSpecificApp(new ScheduledObject { ObjectId = _app.Id, Revision = _app.Revision }, false); SetStatus(tmpApp); do { System.Threading.Thread.Sleep(2500); tmpApp = CcmUtils.GetSpecificApp(new ScheduledObject { ObjectId = _app.Id, Revision = _app.Revision }, false); SetStatus(tmpApp); }while (!(tmpApp.EvaluationState == 1 || tmpApp.EvaluationState == 3 || tmpApp.EvaluationState == 4 || tmpApp.EvaluationState == 16 || tmpApp.EvaluationState == 24 || tmpApp.EvaluationState == 25)); } catch { Globals.MainWnd.SpAvailableApps.Children.Remove(this); } }); ProgressbarEnforcement.Visibility = Visibility.Hidden; BtInstall.IsEnabled = !tmpApp.InstallState.Equals("Installed"); BtUninstall.IsEnabled = tmpApp.InstallState.Equals("Installed"); BtRepair.IsEnabled = tmpApp.InstallState.Equals("Installed") && _app.AllowedActions.Contains("Repair"); TpPicker.IsEnabled = true; BtSchedule.IsEnabled = true; _app = CcmUtils.GetSpecificApp(new ScheduledObject { ObjectId = _app.Id, Revision = _app.Revision }); }
public CMUserService(CMApplication application, IRestWrapper apiService) { Application = application; APIService = apiService; }
public CMPushNotificationService(CMApplication application, IRestWrapper apiService) { Application = application; APIService = apiService; }
private void SetStatus(CMApplication app) { Dispatcher.Invoke(() => { StatusRed.Visibility = Visibility.Hidden; StatusGreen.Visibility = Visibility.Hidden; StatusOrange.Visibility = Visibility.Hidden; StatusBlue.Visibility = Visibility.Hidden; StatusRed.ToolTip = app.EvaluationStateText; StatusGreen.ToolTip = app.EvaluationStateText; StatusOrange.ToolTip = app.EvaluationStateText; StatusBlue.ToolTip = app.EvaluationStateText; if (app.InstallState.Equals("Installed") && app.EvaluationState == 1 && !_isReschedule) { StatusGreen.Visibility = Visibility.Visible; StatusText.Text = _availableAppsSettings.AppIsInstalledStatusText; return; } switch (app.EvaluationState) { case 1: case 3: if (_isReschedule) { StatusGreen.Visibility = Visibility.Visible; StatusText.Text = _availableAppsSettings.InstallationHasBeenScheduledStatusText; } else { StatusBlue.Visibility = Visibility.Visible; StatusText.Text = _availableAppsSettings.AppCanBeInstalledStatusText; } break; case 4: case 16: case 24: case 25: StatusRed.Visibility = Visibility.Visible; StatusText.Text = _availableAppsSettings.AppIsInErrorStateStatusText; break; default: StatusOrange.Visibility = Visibility.Visible; StatusText.Text = app.EvaluationState == 13 ? "Reboot pending." : _availableAppsSettings.AppIsBeingEnforcedStatusText; ProgressbarEnforcement.Visibility = Visibility.Visible; TpPicker.IsEnabled = false; BtInstall.IsEnabled = false; BtRepair.IsEnabled = false; BtSchedule.IsEnabled = false; if (_isReschedule) { if (SqlCe.IsAppScheduled(app.Id, app.Revision, out var id)) { SqlCe.SetEnforcedFlag(id); } _isReschedule = false; } break; } }); }
/// <summary> /// Request the specified app, action, method, content and options. /// </summary> /// <param name="app">An instance of application ID and API key.</param> /// <param name="action">URL action which the platform should execute ("user/binary/", "user/search")</param> /// <param name="method">HTTP method type which the action uses (PUT, POST, GET, DELETE)</param> /// <param name="content">Content stream to be sent in the body. Also can be passed through on options</param> /// <param name="options">CMRequestOptions which contains the necessary values for query parameters and headers.</param> /// <typeparam name="T">CMResponse type derivative which wraps the return shape in the task response.</typeparam> public async Task <T> Request <T>(CMApplication app, string action, HttpMethod method, Stream content, CMRequestOptions options) where T : CMResponse, new() { HttpClientHandler clientHandler = new HttpClientHandler() { AllowAutoRedirect = true }; using (HttpClient httpClient = new HttpClient(clientHandler)) { CMRequestOptions opts = options ?? new CMRequestOptions(); // Set various query options. List <string> query = GetCloudMineQuery(opts); Uri uri = GetCloudmineUri(options.BaseURL ?? "api.cloudmine.io", app.APIVersion, app.ApplicationID, action, query); httpClient.BaseAddress = uri; if (opts.Credentials != null) { if (!string.IsNullOrEmpty(opts.Credentials.Username)) { var authData = string.Format("{0}:{1}", opts.Credentials.Username, opts.Credentials.Password); var authHeaderValue = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(authData)); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue); } } // push needs a platform but in the default case lets give our metrics something to chew on. if (!httpClient.DefaultRequestHeaders.Contains("device_type")) { httpClient.DefaultRequestHeaders.Add("device_type", "csharp"); } httpClient.DefaultRequestHeaders.Add("X-CloudMine-ApiKey", app.APIKey); httpClient.DefaultRequestHeaders.Add("sdk_type", "csharp"); httpClient.DefaultRequestHeaders.Add("X-Unique-Id", Guid.NewGuid().ToString()); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(opts.ContentType)); foreach (string headerKey in opts.Headers.Keys) { httpClient.DefaultRequestHeaders.Add(headerKey, opts.Headers[headerKey]); } if (method == HttpMethod.Post) { // Login requests post no body if (content != null || opts.Data != null) { StreamContent contentData = content != null ? new StreamContent(content) : new StreamContent(opts.Data); StringContent stringContent = new StringContent(await contentData.ReadAsStringAsync(), System.Text.Encoding.UTF8, "application/json"); using (HttpResponseMessage responseMsg = await httpClient.PostAsync(uri, stringContent)) return(await GenerateCMResponseObject <T> (responseMsg)); } else { using (HttpResponseMessage responseMsg = await httpClient.PostAsync(uri, new StringContent(string.Empty))) return(await GenerateCMResponseObject <T> (responseMsg)); } } else if (method == HttpMethod.Put) { StreamContent contentData = content != null ? new StreamContent(content) : new StreamContent(opts.Data); StringContent stringContent = new StringContent(await contentData.ReadAsStringAsync(), System.Text.Encoding.UTF8, "application/json"); using (HttpResponseMessage responseMsg = await httpClient.PutAsync(uri, stringContent)) return(await GenerateCMResponseObject <T>(responseMsg)); } else if (method == HttpMethod.Get) { using (HttpResponseMessage responseMsg = await httpClient.GetAsync(uri)) return(await GenerateCMResponseObject <T>(responseMsg)); } else if (method == HttpMethod.Delete) { using (HttpResponseMessage responseMsg = await httpClient.DeleteAsync(uri)) return(await GenerateCMResponseObject <T>(responseMsg)); } else { throw new InvalidOperationException(string.Format("{0} is not a CloudMine API supported HttpMethod.", method.Method)); } } }
/// <summary> /// Request the specified app, action, method, content and options. /// </summary> /// <param name="app">An instance of application ID and API key.</param> /// <param name="action">URL action which the platform should execute ("user/binary/", "user/search")</param> /// <param name="method">HTTP method type which the action uses (PUT, POST, GET, DELETE)</param> /// <param name="content">Content stream to be sent in the body. Also can be passed through on options</param> /// <param name="options">CMRequestOptions which contains the necessary values for query parameters and headers.</param> public Task <CMResponse> Request(CMApplication app, string action, HttpMethod method, Stream content, CMRequestOptions options) { return(Request <CMResponse>(app, action, method, content, options)); }
public AccessListService(CMApplication application, IRestWrapper apiService) { Application = application; APIService = apiService; }