public override async Task Init()
        {
            await base.Init();

            SelectedChannel = null;
            SelectedFolder  = null;
            SelectedItem    = null;

            if (Root != null)
            {
                Root = null;
            }

            Root = new ContentItemEx()
            {
                ID   = "",
                Name = "Channels",
            };

            SelectedItem = Root;
            if (!Initialized)
            {
                FacebookToolsService.Instance.LogCustomEvent("ChannelsRootLoaded");
            }

            if (!productsViewModel.Initialized)
            {
                await TaskQueue.EnqueueAsync(async() => await productsViewModel.Init());
            }
        }
        protected override async Task refresh(bool silent)
        {
            if (selectedFolder != null)
            {
                await TaskQueue.EnqueueAsync(async() => await loadChildrenAsync(selectedFolder, silent));
            }

            await base.refresh(silent);
        }
예제 #3
0
        internal async Task <T> SendMessageToServerAsync <T>(
            string guid,
            string method,
            object args,
            bool ignoreNullValues = true,
            JsonSerializerOptions serializerOptions = null,
            bool treatErrorPropertyAsError          = true)
        {
            if (IsClosed)
            {
                throw new PlaywrightSharpException($"Connection closed ({_reason})");
            }

            int id       = Interlocked.Increment(ref _lastId);
            var tcs      = new TaskCompletionSource <JsonElement?>(TaskCreationOptions.RunContinuationsAsynchronously);
            var callback = new ConnectionCallback
            {
                TaskCompletionSource      = tcs,
                TreatErrorPropertyAsError = treatErrorPropertyAsError,
            };

            _callbacks.TryAdd(id, callback);

            await _queue.EnqueueAsync(() =>
            {
                var message = new MessageRequest
                {
                    Id     = id,
                    Guid   = guid,
                    Method = method,
                    Params = args,
                };

                string messageString = JsonSerializer.Serialize(message, serializerOptions ?? GetDefaultJsonSerializerOptions(ignoreNullValues));
                _logger?.LogInformation($"pw:channel:command {messageString}");

                return(_transport.SendAsync(messageString));
            }).ConfigureAwait(false);

            var result = await tcs.Task.ConfigureAwait(false);

            if (typeof(T) == typeof(JsonElement?))
            {
                return((T)(object)result);
            }
            else if (result == null)
            {
                return(default);
        public async Task <bool> PerformChannelLogout(IContentItem item)
        {
            if ((item == null) || !(item is ChannelEx))
            {
                return(false);
            }

            try
            {
                accountViewModel.IsLoading = true;
                var channel = item as ChannelEx;
                if ((channel != null) && (channel.LoginInfo != null))
                {
                    string email = channel.LoginInfo.Username;
                    channel.LoginInfo                      = new ChannelLoginInfo();
                    channel.LoginInfo.Username             = email;
                    channel.LoginInfo.ValidationSuccessful = false;
                    UserStoreService.Instance.StoreRecordInKeychain(getAccountEmail() + "channel-" + item.ID, JsonConvert.SerializeObject(channel.LoginInfo));
                    accountViewModel.RefreshSelectedChannel();
                    if (SelectedChannel == channel)
                    {
                        selectedItem = channel;
                        OnPropertyChanged("SelectedItem");
                        selectedItem.Children = null;
                        SelectedFolder        = selectedItem;
                        updateBreadcrumbs();
                        await TaskQueue.EnqueueAsync(async() => await loadChildrenAsync(selectedItem, false));

                        OnPropertyChanged("SelectedChannel");
                    }

                    return(true);
                }
            }
            finally
            {
                accountViewModel.IsLoading = false;
            }

            return(false);
        }
        public async Task <bool> PerformChannelLogin(IContentItem item)
        {
            var result = false;

            if ((item == null) || !(item is ChannelEx))
            {
                return(result);
            }

            try
            {
                IsLoading = true;
                accountViewModel.IsLoading = true;
                var channel = item as ChannelEx;
                if ((channel != null) && (channel.LoginInfo != null))
                {
                    try
                    {
                        var validation = await SettingsClient.ValidateCredentials(channel.ID, channel.LoginInfo);

                        if (validation != null)
                        {
                            channel.LoginInfo.LoginPerformed       = validation.Success;
                            channel.LoginInfo.ValidationSuccessful = validation.Success;
                            result = validation.Success;
                            if (!validation.Success)
                            {
                                Device.BeginInvokeOnMainThread(() => AlertViewService.Instance.ShowAlert(validation.Message));
                            }

                            if (validation.Success)
                            {
                                UserStoreService.Instance.StoreRecordInKeychain(getAccountEmail() + "channel-" + item.ID, JsonConvert.SerializeObject(channel.LoginInfo));
                            }
                        }
                    }
                    finally
                    {
                        accountViewModel.IsLoading = false;
                    }

                    channel.RefreshIsSearchVisible();
                    accountViewModel.RefreshSelectedChannel();

                    if (channel.LoginInfo.LoginPerformed)
                    {
                        if (SelectedChannel == channel)
                        {
                            selectedItem = channel;
                            OnPropertyChanged("SelectedItem");
                            selectedItem.Children = null;
                            SelectedFolder        = selectedItem;
                            updateBreadcrumbs();
                            await TaskQueue.EnqueueAsync(async() => await loadChildrenAsync(selectedItem, false));

                            OnPropertyChanged("SelectedChannel");
                        }
                    }
                }
            }
            finally
            {
                IsLoading = false;
            }

            return(result);
        }