Пример #1
0
        public override void ConfirmContinueTimer(ContinueTimerIntent intent, Action <ContinueTimerIntentResponse> completion)
        {
            if (togglAPI == null)
            {
                completion(new ContinueTimerIntentResponse(ContinueTimerIntentResponseCode.FailureNoApiToken, null));
                return;
            }

            togglAPI.TimeEntries.GetAll()
            .ToObservable()
            .FirstAsync()
            .Select(timeEntries => timeEntries.First())
            .Subscribe(
                timeEntry =>
            {
                lastEntry        = timeEntry;
                var userActivity = new NSUserActivity(continueTimerActivityType);
                userActivity.SetEntryDescription(timeEntry.Description);
                completion(new ContinueTimerIntentResponse(ContinueTimerIntentResponseCode.Ready, userActivity));
            },
                exception =>
            {
                completion(new ContinueTimerIntentResponse(ContinueTimerIntentResponseCode.Failure, null));
            });
        }
        public override void ConfirmStopTimer(StopTimerIntent intent, Action <StopTimerIntentResponse> completion)
        {
            if (togglAPI == null)
            {
                var userActivity = new NSUserActivity(stopTimerActivityType);
                userActivity.SetResponseText("Log in to use this shortcut.");
                completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.FailureNoApiToken, userActivity));
                return;
            }

            var lastUpdated = SharedStorage.instance.GetLastUpdateDate();

            togglAPI.TimeEntries.GetAll()
            .Select(checkSyncConflicts(lastUpdated))
            .Select(getRunningTimeEntry)
            .Subscribe(
                runningTE =>
            {
                runningEntry     = runningTE;
                var userActivity = new NSUserActivity(stopTimerActivityType);
                userActivity.SetEntryDescription(runningTE.Description);
                completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.Ready, userActivity));
            },
                exception =>
            {
                SharedStorage.instance.AddSiriTrackingEvent(SiriTrackingEvent.Error(exception.Message));
                completion(responseFromException(exception));
            });
        }
        public override void ConfirmStopTimer(StopTimerIntent intent, Action <StopTimerIntentResponse> completion)
        {
            if (togglAPI == null)
            {
                var userActivity = new NSUserActivity(stopTimerActivityType);
                userActivity.SetResponseText(Resources.SiriShortcutLoginToUseShortcut);
                completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.FailureNoApiToken, userActivity));
                return;
            }

            togglAPI.TimeEntries.GetAll()
            .Select(getRunningTimeEntry)
            .Subscribe(
                runningTE =>
            {
                runningEntry     = runningTE;
                var userActivity = new NSUserActivity(stopTimerActivityType);
                userActivity.SetEntryDescription(runningTE.Description);
                completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.Ready, userActivity));
            },
                exception =>
            {
                SharedStorage.instance.AddSiriTrackingEvent(SiriTrackingEvent.Error(exception.Message));
                completion(responseFromException(exception));
            });
        }