private async Task HandleFilterActivatedAsync(object args)
        {
            // walk...
            SearchFilter selected = null;

            foreach (var filter in this.Filters)
            {
                if (filter == args)
                {
                    filter.Active = true;
                    selected      = filter;
                }
                else
                {
                    filter.Active = false;
                }
            }

            // update...
            this.ApplyFilter();

            // save...
            if (selected != null)
            {
                await SettingItem.SetValueAsync(LastFilterKey, selected.Keyword);
            }
            else
            {
                await SettingItem.SetValueAsync(LastFilterKey, null);
            }
        }
Esempio n. 2
0
        public static async Task SetupNotificationChannelAsync()
        {
            // get the notification channel...
            var manager = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            Debug.WriteLine("Channel: " + manager.Uri);

            // if either the URI we sent or the username we sent has changed, resend it...
            var lastUri = await SettingItem.GetValueAsync("NotificationUri");

            var lastToken = await SettingItem.GetValueAsync("NotificationToken");

            if (lastUri != manager.Uri || lastToken != LogonToken)
            {
                // send it...
                Debug.WriteLine("*** This is where you asynchronously send it! ***");

                // store it...
                await SettingItem.SetValueAsync("NotificationUri", manager.Uri);

                await SettingItem.SetValueAsync("NotificationToken", LogonToken);
            }
            else
            {
                Debug.WriteLine("URI not changed.");
            }
        }
Esempio n. 3
0
        private async Task <bool> CanRunAsync()
        {
            // do we have connectivity?
            if (!(StreetFooRuntime.HasConnectivity))
            {
                this.Logger.Info("No connectivity - skipping...");

                // clear the expiration period...
                await SettingItem.SetValueAsync(SyncExpirationKey, string.Empty);

                // return...
                return(false);
            }

            // skip the check if we're debugging... (otherwise it's hard to see what's
            // going on...)
            if (!(Debugger.IsAttached))
            {
                // check the expiration...
                var asString = await SettingItem.GetValueAsync(SyncExpirationKey);

                if (!(string.IsNullOrEmpty(asString)))
                {
                    this.Logger.Info("Expiration time: {0}", asString);

                    // parse...
                    var expiration = DateTime.ParseExact(asString, "o", CultureInfo.InvariantCulture).ToUniversalTime();

                    // if the expiration time is in the future - do nothing...
                    if (expiration > DateTime.UtcNow)
                    {
                        this.Logger.Info("Not expired (expiration is '{0}') - skipping...", expiration);
                        return(false);
                    }
                }
                else
                {
                    this.Logger.Info("No expiration time available.");
                }
            }

            // we're ok - set the new expiration period...
            var newExpiration = DateTime.UtcNow.AddMinutes(5);
            await SettingItem.SetValueAsync(SyncExpirationKey, newExpiration.ToString("o"));

            // try and log the user in...
            var model = new LogonPageViewModel();

            model.Initialize(new NullViewModelHost());
            return(await model.RestorePersistentLogonAsync());
        }
        private async void DoRegistration(CommandExecutionContext context)
        {
            // if we don't have a context, create one...
            if (context == null)
            {
                context = new CommandExecutionContext();
            }

            // validate...
            ErrorBucket errors = new ErrorBucket();

            Validate(errors);

            // ok?
            if (!(errors.HasErrors))
            {
                // get a handler...
                var proxy = TinyIoCContainer.Current.Resolve <IRegisterServiceProxy>();

                // call...
                using (this.EnterBusy())
                {
                    var result = await proxy.RegisterAsync(this.Username, this.Email, this.Password, this.Confirm);

                    // ok?
                    if (!(result.HasErrors))
                    {
                        // show a message to say that a user has been created... (this isn't a helpful message,
                        // included for illustration...)
                        await this.Host.ShowAlertAsync(string.Format("The new user has been created.\r\n\r\nUser ID: {0}", result.UserId));

                        // save the username as the last used...
                        await SettingItem.SetValueAsync(LogonPageViewModel.LastUsernameKey, this.Username);

                        // show the reports page...
                        this.Host.ShowView(typeof(ILogonPageViewModel));
                    }
                    else
                    {
                        errors.CopyFrom(result);
                    }
                }
            }

            // errors?
            if (errors.HasErrors)
            {
                await this.Host.ShowAlertAsync(errors);
            }
        }
        private async void DoLogon(CommandExecutionContext context)
        {
            // validate...
            ErrorBucket errors = new ErrorBucket();

            Validate(errors);

            // ok?
            if (!(errors.HasErrors))
            {
                // get a handler...
                var proxy = TinyIoCContainer.Current.Resolve <ILogonServiceProxy>();

                // call...
                using (this.EnterBusy())
                {
                    var result = await proxy.LogonAsync(this.Username, this.Password);

                    if (!(result.HasErrors))
                    {
                        // logon... pass through the username as each user gets their own database...
                        await StreetFooRuntime.LogonAsync(this.Username, result.Token);

                        // while we're here - store a setting containing the logon name of the user...
                        await SettingItem.SetValueAsync(LastUsernameKey, this.Username);

                        // remember the user?
                        if (this.RememberMe)
                        {
                            await SettingItem.SetValueAsync(LogonTokenKey, result.Token);
                        }

                        // show the reports page...
                        this.Host.ShowView(typeof(IReportsPageViewModel));
                    }
                    else
                    {
                        errors.CopyFrom(result);
                    }
                }
            }

            // errors?
            if (errors.HasErrors)
            {
                await this.Host.ShowAlertAsync(errors);
            }
        }
        private async Task SearchAsync(string queryText)
        {
            // flag...
            this.SearchDone = true;

            // set...
            this.QueryText = queryText;

            // set the narrative...
            if (string.IsNullOrEmpty(queryText))
            {
                this.QueryNarrative = string.Empty;
            }
            else
            {
                this.QueryNarrative = string.Format("Results for '{0}'", queryText);
            }

            // load...
            var reports = await ReportItem.SearchCacheAsync(queryText);

            this.MasterItems.Clear();
            foreach (var report in reports)
            {
                this.MasterItems.Add(new ReportViewItem(report));
            }

            // what was our selected filter?
            var current = this.ActiveFilter;

            if (current != null)
            {
                var builder = new ToastNotificationBuilder(current.Description);
                builder.Update();
            }

            // do we have anything?
            this.Filters.Clear();
            if (this.MasterItems.Any())
            {
                // all filter...
                var allFilter = new SearchFilter("all", this.MasterItems.Count, null, false);
                allFilter.SelectionCommand = new DelegateCommand(async(args) => await HandleFilterActivatedAsync(allFilter));
                this.Filters.Add(allFilter);

                // build up a list of nouns...
                var nouns = new Dictionary <string, int>();
                var regex = new Regex(@"\b\w+$", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                foreach (var report in reports)
                {
                    var match = regex.Match(report.Title);

                    // word...
                    string noun = match.Value.ToLower();
                    if (!(nouns.ContainsKey(noun)))
                    {
                        nouns[noun] = 0;
                    }
                    nouns[noun]++;
                }

                // add the filters...
                foreach (var noun in nouns.Keys)
                {
                    var filter = new SearchFilter(noun, nouns[noun], noun);
                    filter.SelectionCommand = new DelegateCommand(async(args) => await HandleFilterActivatedAsync(filter));
                    this.Filters.Add(filter);
                }

                // update...
                var manager = new ReportImageCacheManager();
                foreach (var report in this.MasterItems)
                {
                    await report.InitializeAsync(manager);
                }
            }

            // do we need to select the filter?
            var lastQuery = await SettingItem.GetValueAsync(LastQueryKey);

            if (lastQuery == queryText)
            {
                // select the filter...
                var lastFilterName = await SettingItem.GetValueAsync(LastFilterKey);

                if (!(string.IsNullOrEmpty(lastFilterName)))
                {
                    ActivateFilter(lastFilterName);
                }
            }
            else
            {
                // update...
                await SettingItem.SetValueAsync(LastQueryKey, queryText);
            }

            // apply the filter...
            this.ApplyFilter();
        }