public void SaveStartServiceLog() { var addedLog = new StartServiceLog { Device = new DeviceInformationHelper().GetDeviceInformationAsync().RunNotAsync(), Toffset = TimeHelper.CurrentTimeInMilliseconds(), Services = new List <string> { "Service0", "Service1", "Service2" }, Sid = Guid.NewGuid() }; var storage = new Mobile.Storage.Storage(); storage.DeleteLogsAsync(StorageTestChannelName).RunNotAsync(); storage.PutLogAsync(StorageTestChannelName, addedLog).RunNotAsync(); var retrievedLogs = new List <Log>(); storage.GetLogsAsync(StorageTestChannelName, 1, retrievedLogs).RunNotAsync(); var retrievedLog = retrievedLogs[0] as StartServiceLog; foreach (var serviceName in addedLog.Services) { Assert.IsTrue(retrievedLog.Services.Contains(serviceName)); } }
// That method isn't async itself but can return async task from the channel for awaiting log enqueue. private Task SetInstanceEnabled(bool value) { var enabledTerm = value ? "enabled" : "disabled"; if (InstanceEnabled == value) { AppCenterLog.Info(AppCenterLog.LogTag, $"App Center has already been {enabledTerm}."); return(Task.FromResult(default(object))); } // Update channels state. _channelGroup?.SetEnabled(value); // Store state in the application settings. _applicationSettings.SetValue(EnabledKey, value); // Apply change to services. foreach (var service in _services) { service.InstanceEnabled = value; } AppCenterLog.Info(AppCenterLog.LogTag, $"App Center has been {enabledTerm}."); // Send started services. if (_startedServiceNames != null && value) { var startServiceLog = new StartServiceLog { Services = _startedServiceNames }; _startedServiceNames = null; return(_channel.EnqueueAsync(startServiceLog)); } return(Task.FromResult(default(object))); }
public void SaveStartServiceLog() { var addedLog = new StartServiceLog { Device = new DeviceInformationHelper().GetDeviceInformationAsync().RunNotAsync(), Timestamp = DateTime.Now, Services = new List <string> { "Service0", "Service1", "Service2" }, Sid = Guid.NewGuid() }; var storage = new Microsoft.AppCenter.Storage.Storage(); storage.DeleteLogs(StorageTestChannelName); storage.PutLog(StorageTestChannelName, addedLog); var retrievedLogs = new List <Log>(); storage.GetLogsAsync(StorageTestChannelName, 1, retrievedLogs).RunNotAsync(); var retrievedLog = retrievedLogs[0] as StartServiceLog; foreach (var serviceName in addedLog.Services) { Assert.IsTrue(retrievedLog.Services.Contains(serviceName)); } }
public void CheckInitialValues() { var log = new StartServiceLog(); Assert.IsNull(log.Device); Assert.AreEqual(0, log.Services.Count); Assert.IsNull(log.Sid); Assert.AreEqual(null, log.Timestamp); }
public void ValidateStartServiceLog() { var log = new StartServiceLog { Services = null, Device = new DeviceInformationHelper().GetDeviceInformationAsync().RunNotAsync(), Toffset = TimeHelper.CurrentTimeInMilliseconds() }; Assert.ThrowsException <Rest.ValidationException>((Action)log.Validate); }
public void ValidateStartServiceLog() { var log = new StartServiceLog { Services = null, Device = new DeviceInformationHelper().GetDeviceInformationAsync().RunNotAsync(), Timestamp = DateTime.Now }; Assert.ThrowsException <ValidationException>((Action)log.Validate); }
public void CheckInitialValuesWithServices() { var servicesNames = new List <string> { "Service0", "Service1", "Service2" }; var log = new StartServiceLog(0, null, servicesNames); Assert.IsNotNull(log.Services); foreach (var serviceName in log.Services) { Assert.IsTrue(servicesNames.Contains(serviceName)); } }
internal void StartInstance(params Type[] services) { if (services == null) { throw new MobileCenterException("Services array is null."); } if (!_instanceConfigured) { throw new MobileCenterException("Mobile Center has not been configured."); } var startServiceLog = new StartServiceLog(); foreach (var serviceType in services) { if (serviceType == null) { MobileCenterLog.Warn(MobileCenterLog.LogTag, "Skipping null service. Please check that you did not pass a null argument."); continue; } try { // We don't support distribute in UWP, not even a custom start. if (IsDistributeService(serviceType)) { MobileCenterLog.Warn(MobileCenterLog.LogTag, "Distribute service is not yet supported on UWP."); } else { var serviceInstance = serviceType.GetRuntimeProperty("Instance")?.GetValue(null) as IMobileCenterService; if (serviceInstance == null) { throw new MobileCenterException("Service type does not contain static 'Instance' property of type IMobileCenterService"); } StartService(serviceInstance); startServiceLog.Services.Add(serviceInstance.ServiceName); } } catch (MobileCenterException ex) { MobileCenterLog.Warn(MobileCenterLog.LogTag, $"Failed to start service '{serviceType.Name}'; skipping it.", ex); } } // Enqueue a log indicating which services have been initialized if (startServiceLog.Services.Count > 0) { _channel.Enqueue(startServiceLog); } }
public void SaveStartServiceLog() { Constants.AppCenterDatabasePath = "temp.db"; if (System.IO.File.Exists(Constants.AppCenterDatabasePath)) { try { System.IO.File.Delete(Constants.AppCenterDatabasePath); } catch { // ignored } } var addedLog = new StartServiceLog { Device = new DeviceInformationHelper().GetDeviceInformationAsync().RunNotAsync(), Timestamp = DateTime.Now, Services = new List <string> { "Service0", "Service1", "Service2" }, Sid = Guid.NewGuid() }; var storage = new Microsoft.AppCenter.Storage.Storage(); storage.DeleteLogs(StorageTestChannelName); storage.PutLog(StorageTestChannelName, addedLog); var retrievedLogs = new List <Log>(); storage.GetLogsAsync(StorageTestChannelName, 1, retrievedLogs).RunNotAsync(); var retrievedLog = retrievedLogs[0] as StartServiceLog; foreach (var serviceName in addedLog.Services) { Assert.IsTrue(retrievedLog.Services.Contains(serviceName)); } }