Esempio n. 1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            Debug.WriteLine($"{DateTime.Now} - run background task");

            try
            {
                await _dataContextManager.RefreshSettingsDataContext();

                await _dataContextManager.BeginTransaction();

                _actionExecutor.Execute();
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
            }
            finally
            {
                await _dataContextManager.SaveChanges();

                deferral.Complete();
            }
        }
Esempio n. 2
0
        protected override void Arrange()
        {
            DataContextManager = new DataContextManager();
            DataContextManager.RefreshSettingsDataContext().Wait();

            var switchableDevice = new Device {
                Identifier = Guid.NewGuid(), Name = "switchable device", Capability = DeviceCapability.Switchable, Type = DeviceType.Fifthplay
            };
            var unsupportedDevice = new Device {
                Identifier = Guid.NewGuid(), Name = "unsupported device", Capability = DeviceCapability.None, Type = DeviceType.Ifttt
            };

            DataContextManager.SettingsDataContext.IsApplicationEnabled = true;
            DataContextManager.SettingsDataContext.Devices = new List <Device> {
                switchableDevice, unsupportedDevice
            };

            DataContextManager.SettingsDataContext.Actions = new List <Business.Model.Action>
            {
                new Business.Model.Action
                {
                    Identifier               = Guid.NewGuid(),
                    DeviceIdentifier         = switchableDevice.Identifier,
                    ActionTypeIdentifier     = DataContextManager.SettingsDataContext.ActionTypes.First().Identifer,
                    ActionArgumentIdentifier = DataContextManager.SettingsDataContext.ActionTypes.First().ActionArguments.First().Identifer,
                    ActionTrigger            = ActionTrigger.Home
                },
                new Business.Model.Action
                {
                    Identifier               = Guid.NewGuid(),
                    DeviceIdentifier         = unsupportedDevice.Identifier,
                    ActionTypeIdentifier     = DataContextManager.SettingsDataContext.ActionTypes.First().Identifer,
                    ActionArgumentIdentifier = DataContextManager.SettingsDataContext.ActionTypes.First().ActionArguments.ElementAt(1).Identifer,
                    ActionTrigger            = ActionTrigger.Away
                }
            };

            DataContextManager.SettingsDataContext.Logs.Add(new ActionLog {
                Identifier = Guid.NewGuid(), ActionArgumentValue = "on", Type = "Home", ActionTypeName = "switch", DeviceName = "dummy device", Timestamp = DateTimeOffset.UtcNow
            });
            DataContextManager.SettingsDataContext.Logs.Add(new ActionLog {
                Identifier = new Guid("6fd4aa18-e36c-493c-815d-d4e1e8ed675f"), ActionArgumentValue = "on", Type = "Home", ActionTypeName = "switch", DeviceName = "Desk lamp", Timestamp = DateTimeOffset.UtcNow
            });
            DataContextManager.SettingsDataContext.Logs.Add(new FailedActionLog {
                Identifier = Guid.NewGuid(), ActionArgumentValue = "on", Type = "Home", ActionTypeName = "switch", DeviceName = "dummy device", Timestamp = DateTimeOffset.UtcNow, Error = "dummy-error"
            });
            DataContextManager.SettingsDataContext.Logs.Add(new FailedActionLog {
                Identifier = Guid.NewGuid(), ActionArgumentValue = "on", Type = "Home", ActionTypeName = "switch", DeviceName = "dummy device", Timestamp = DateTimeOffset.UtcNow, Error = "dummy-error"
            });
            DataContextManager.SettingsDataContext.Logs.Add(new ExceptionLog {
                Identifier = Guid.NewGuid(), Error = new Exception().ToString(), Timestamp = DateTimeOffset.UtcNow
            });
            DataContextManager.SettingsDataContext.Logs.Add(new ExceptionLog {
                Identifier = Guid.NewGuid(), Error = "dummy-error", Timestamp = DateTimeOffset.UtcNow
            });
        }
        public async Task Load()
        {
            try
            {
                if (IsLoading)
                {
                    return;
                }

                IsLoading = true;

                await _dataContextManager.RefreshSettingsDataContext();

                await LoadViewModel();
            }
            finally
            {
                IsLoading = false;
            }
        }
Esempio n. 4
0
        protected override void Arrange()
        {
            DataContextManager = new DataContextManager();
            DataContextManager.RefreshSettingsDataContext().Wait();

            var switchableDevice = new Device { Identifier = Guid.NewGuid(), Name = "switchable device", Capability = DeviceCapability.Switchable, Type = DeviceType.Fifthplay };
            var unsupportedDevice = new Device { Identifier = Guid.NewGuid(), Name = "unsupported device", Capability = DeviceCapability.None, Type = DeviceType.Ifttt };

            DataContextManager.SettingsDataContext.IsApplicationEnabled = true;
            DataContextManager.SettingsDataContext.Devices = new List<Device> { switchableDevice, unsupportedDevice };

            DataContextManager.SettingsDataContext.Actions = new List<Business.Model.Action>
            {
                new Business.Model.Action
                {
                    Identifier = Guid.NewGuid(),
                    DeviceIdentifier = switchableDevice.Identifier,
                    ActionTypeIdentifier = DataContextManager.SettingsDataContext.ActionTypes.First().Identifer,
                    ActionArgumentIdentifier = DataContextManager.SettingsDataContext.ActionTypes.First().ActionArguments.First().Identifer,
                    ActionTrigger = ActionTrigger.Home
                },
                new Business.Model.Action
                {
                    Identifier = Guid.NewGuid(),
                    DeviceIdentifier = unsupportedDevice.Identifier,
                    ActionTypeIdentifier = DataContextManager.SettingsDataContext.ActionTypes.First().Identifer,
                    ActionArgumentIdentifier = DataContextManager.SettingsDataContext.ActionTypes.First().ActionArguments.ElementAt(1).Identifer,
                    ActionTrigger = ActionTrigger.Away
                }
            };

            DataContextManager.SettingsDataContext.Logs.Add(new ActionLog { Identifier = Guid.NewGuid(), ActionArgumentValue = "on", Type = "Home", ActionTypeName = "switch", DeviceName = "dummy device", Timestamp = DateTimeOffset.UtcNow });
            DataContextManager.SettingsDataContext.Logs.Add(new ActionLog { Identifier = new Guid("6fd4aa18-e36c-493c-815d-d4e1e8ed675f"), ActionArgumentValue = "on", Type = "Home", ActionTypeName = "switch", DeviceName = "Desk lamp", Timestamp = DateTimeOffset.UtcNow });
            DataContextManager.SettingsDataContext.Logs.Add(new FailedActionLog { Identifier = Guid.NewGuid(), ActionArgumentValue = "on", Type = "Home", ActionTypeName = "switch", DeviceName = "dummy device", Timestamp = DateTimeOffset.UtcNow, Error = "dummy-error" });
            DataContextManager.SettingsDataContext.Logs.Add(new FailedActionLog { Identifier = Guid.NewGuid(), ActionArgumentValue = "on", Type = "Home", ActionTypeName = "switch", DeviceName = "dummy device", Timestamp = DateTimeOffset.UtcNow, Error = "dummy-error" });
            DataContextManager.SettingsDataContext.Logs.Add(new ExceptionLog { Identifier = Guid.NewGuid(), Error = new Exception().ToString(), Timestamp = DateTimeOffset.UtcNow });
            DataContextManager.SettingsDataContext.Logs.Add(new ExceptionLog { Identifier = Guid.NewGuid(), Error = "dummy-error", Timestamp = DateTimeOffset.UtcNow });
        }