Beispiel #1
0
        public async Task <ResultSingle <Trader> > QueryUserAsync(string email, bool throwIfError = true)
        {
            Trader seed = new Trader();

            seed.Email = email;

            ResultSingle <Trader> result = await ResultSingleUI <Trader> .WaitForObjectAsync(
                throwIfError, seed, new CachedHttpRequest <Trader, ResultSingle <Trader> >(
                    Backend.QueryAsync), false);

            return(result);
        }
Beispiel #2
0
        async public Task <ResultSingle <App> > QueryStatusAsync()
        {
            ResultSingle <App> result = await QueryAppAsync();

            if (result.Code == 0)
            {
                await DeploymentViewModel.InitAsync();
            }

            OnPropertyChanged("EditApp");

            return(result);
        }
Beispiel #3
0
        public async Task <ResultSingle <Permit <UserT> > > RevokeTokenAsync(
            bool throwIfError = true)
        {
            ResultSingle <Permit <UserT> > result = await
                                                    Backend.RevokeAccessAsync();

            if (result.Code < 0 && throwIfError)
            {
                MessageHandler.ThrowMessage(result);
            }

            return(result);
        }
Beispiel #4
0
        public async Task <ResultSingle <Devkit> > QueryDevkitAsync(Devkit devkit,
                                                                    bool doCache = false, bool throwIfError = true)
        {
            ResultSingle <Devkit> result = await ResultSingleUI <Devkit> .WaitForObjectAsync(
                throwIfError, devkit, new CachedHttpRequest <Devkit, ResultSingle <Devkit> >(
                    Backend.QueryAsync), doCache);

            if (result.Code >= 0)
            {
                result.Data.Payload.CopyTo(devkit);
            }

            return(result);
        }
Beispiel #5
0
        public static async Task <ResultSingle <PayloadT> > WaitForObjectAsync(bool throwIfError,
                                                                               PayloadT seed, CachedHttpRequest <PayloadT, ResultSingle <PayloadT> > request,
                                                                               bool doCache = true, IDictionary <string, object> data = null, string subPath = null)
        {
            ResultSingle <PayloadT> result = await
                                             request(seed, data, subPath, doCache);

            if (result.Code < 0 && throwIfError)
            {
                MessageHandler.ThrowMessage(result);
            }

            return(result);
        }
Beispiel #6
0
        public async Task <ResultSingle <Permit <UserT> > > RevokeAccessAsync(
            Dictionary <string, object> data = null)
        {
            Notifier?.BeginQuery();

            ResultSingle <Permit <UserT> > result = await
                                                    Send <Permit <UserT>, ResultSingle <Permit <UserT> >, Permit <UserT> >(
                new HttpRequest <Permit <UserT>, ResultSingle <Permit <UserT> > >(DeleteAsync),
                Permit, true, data, null, false);

            Notifier?.EndQuery();

            return(result);
        }
        public async Task <ResultSingle <Share> > UpdateShareAsync(
            bool doCache = true, bool throwIfError = true)
        {
            ResultSingle <Share> result = await ResultSingleUI <Share> .WaitForObjectAsync(
                throwIfError, _selectedShare, new CachedHttpRequest <Share, ResultSingle <Share> >(
                    Backend.UpdateAsync), doCache);

            if (result.Code >= 0)
            {
                result.Data.Payload.CopyTo(SelectedShare);
            }

            return(result);
        }
Beispiel #8
0
        public async Task <ResultSingle <ObjectT> > RemoveAsync <ObjectT>(
            ObjectT seed, IDictionary <string, object> data = null,
            string subPath = null, bool doCache = false)
            where ObjectT : ICloudObject, new()
        {
            Notifier?.BeginQuery();

            ResultSingle <ObjectT> result = await TrySend <ObjectT, ResultSingle <ObjectT>, ObjectT>(
                new HttpRequest <ObjectT, ResultSingle <ObjectT> >(DeleteAsync),
                seed, true, data, subPath, doCache);

            Notifier?.EndQuery();

            return(result);
        }
        public async Task <ResultSingle <Credit> > QueryCreditAsync(Credit credit = null,
                                                                    bool dCache   = false, bool throwIfError = true)
        {
            Credit theCredit = credit == null ? EditCredit : credit;

            ResultSingle <Credit> result = await ResultSingleUI <Credit> .WaitForObjectAsync(
                throwIfError, theCredit, new CachedHttpRequest <Credit, ResultSingle <Credit> >(
                    Backend.QueryAsync), dCache, null, null);

            if (result.Code >= 0)
            {
                EditCredit = result.Data.Payload;
            }

            return(result);
        }
        public async Task <ResultSingle <PaymentMethod> > CreatePaymentMethodAsync(
            bool doCache = false, bool throwIfError = true)
        {
            EditPaymentMethod.OwnedBy = Backend.Permit.User;

            ResultSingle <PaymentMethod> result = await ResultSingleUI <PaymentMethod> .WaitForObjectAsync(
                throwIfError, EditPaymentMethod, new CachedHttpRequest <PaymentMethod, ResultSingle <PaymentMethod> >(
                    Backend.CreateAsync), doCache);

            if (result.Code >= 0)
            {
                EditPaymentMethod = result.Data.Payload;
            }

            return(result);
        }
Beispiel #11
0
        public async Task <ResultSingle <Inkton.Nest.Model.Nest> > UpdateNestAsync(Inkton.Nest.Model.Nest nest = null,
                                                                                   bool doCache = false, bool throwIfError = true)
        {
            Inkton.Nest.Model.Nest theNest = nest == null ? _editNest : nest;

            ResultSingle <Inkton.Nest.Model.Nest> result = await ResultSingleUI <Inkton.Nest.Model.Nest> .WaitForObjectAsync(
                throwIfError, theNest, new CachedHttpRequest <Inkton.Nest.Model.Nest, ResultSingle <Inkton.Nest.Model.Nest> >(
                    Backend.UpdateAsync), doCache);

            if (result.Code >= 0)
            {
                _editNest = result.Data.Payload;
            }

            return(result);
        }
        public async Task <ResultSingle <Share> > QueryShareAsync(
            bool doCache = true, bool throwIfError = true)
        {
            SelectedShare.OwnedBy = _selectedIndustry;

            ResultSingle <Share> result = await ResultSingleUI <Share> .WaitForObjectAsync(
                throwIfError, SelectedShare, new CachedHttpRequest <Share, ResultSingle <Share> >(
                    Backend.QueryAsync), doCache);

            if (result.Code >= 0)
            {
                result.Data.Payload.CopyTo(SelectedShare);
            }

            return(result);
        }
Beispiel #13
0
        public async Task <ResultSingle <Permit <UserT> > > SignupAsync(
            Dictionary <string, object> data = null)
        {
            Notifier?.BeginQuery();

            ResultSingle <Permit <UserT> > result = await
                                                    Send <Permit <UserT>, ResultSingle <Permit <UserT> >, Permit <UserT> >(
                new HttpRequest <Permit <UserT>, ResultSingle <Permit <UserT> > >(PostAsync),
                Permit, false, data, null, false);

            UpdatePermit(result);

            Notifier?.EndQuery();

            return(result);
        }
        public async Task<ResultSingle<AppDomainCertificate>> UpdateDomainCertificateAsync(AppDomainCertificate cert = null,
            bool doCache = false, bool throwIfError = true)
        {
            AppDomainCertificate theCert = cert == null ? _editDomain.Certificate : cert;

            ResultSingle<AppDomainCertificate> result = await ResultSingleUI<AppDomainCertificate>.WaitForObjectAsync(
                throwIfError, theCert, new CachedHttpRequest<AppDomainCertificate, ResultSingle<AppDomainCertificate>>(
                    Backend.UpdateAsync), doCache);

            if (result.Code >= 0)
            {
                _editDomain.Certificate = result.Data.Payload;
            }

            return result;
        }
Beispiel #15
0
        public async Task <ResultSingle <App> > UpdateAppAsync(App app      = null,
                                                               bool doCache = false, bool throwIfError = true)
        {
            App theApp = app == null ? _editApp : app;

            ResultSingle <App> result = await ResultSingleUI <App> .WaitForObjectAsync(
                throwIfError, theApp, new CachedHttpRequest <App, ResultSingle <App> >(
                    Backend.UpdateAsync), doCache);

            if (result.Code == 0)
            {
                EditApp = result.Data.Payload;
            }

            return(result);
        }
Beispiel #16
0
        public static ResultSingle <PayloadT> ConvertObject(string json, PayloadT seed)
        {
            ResultSingle <PayloadT> result = JsonConvert.DeserializeObject <ResultSingle <PayloadT> >(json,
                                                                                                      new SingleDataContainerConverter <PayloadT>());

            if (result.Code == 0 && result.Data != null)
            {
                /* make a complete object by setting null
                 * values in the received object by the seed
                 * object
                 */
                FillNullsFrom(seed, result.Data.Payload);
            }

            return(result);
        }
        public async Task <ResultSingle <Collaboration> > QueryContactCollaborateAccountAsync(Collaboration collaboration = null,
                                                                                              bool doCache = false, bool throwIfError = true)
        {
            Collaboration theCollaboration = collaboration == null ? _collaboration : collaboration;

            theCollaboration.AccountId = "0";

            ResultSingle <Collaboration> result = await ResultSingleUI <Collaboration> .WaitForObjectAsync(
                throwIfError, theCollaboration, new CachedHttpRequest <Collaboration, ResultSingle <Collaboration> >(
                    Backend.QueryAsync), doCache, null, null);

            if (result.Code >= 0)
            {
                _collaboration = result.Data.Payload;
            }

            return(result);
        }
Beispiel #18
0
        public async Task <ResultSingle <Permit <UserT> > > SignupAsync(
            string password, bool throwIfError = true)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(Backend.Permit.User.Email));

            Dictionary <string, object> data = new Dictionary <string, object>();

            data["password"] = password;

            ResultSingle <Permit <UserT> > result =
                await Backend.SignupAsync(data);

            if (result.Code < 0 && throwIfError)
            {
                MessageHandler.ThrowMessage(result);
            }

            return(result);
        }
Beispiel #19
0
        public async Task <ResultSingle <Permit <UserT> > > RequestEmailConfirmationAsync(
            bool throwIfError = true)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(Backend.Permit.User.Email));

            Dictionary <string, object> data = new Dictionary <string, object>();

            data["action"] = PermitAction.RequestEmailConfirmation.ToString();

            ResultSingle <Permit <UserT> > result =
                await Backend.SetupPermitAsync(data);

            if (result.Code < 0 && throwIfError)
            {
                MessageHandler.ThrowMessage(result);
            }

            return(result);
        }
        public async Task <ResultSingle <Contact> > RemoveContactAsync(Contact contact = null,
                                                                       bool doCache    = false, bool throwIfError = true)
        {
            Contact theContact = contact == null ? _editContact : contact;

            ResultSingle <Contact> result = await ResultSingleUI <Contact> .WaitForObjectAsync(
                throwIfError, theContact, new CachedHttpRequest <Contact, ResultSingle <Contact> >(
                    Backend.RemoveAsync), doCache);

            if (result.Code >= 0)
            {
                if (contact != null)
                {
                    _contacts.Remove(contact);
                    OnPropertyChanged("Contacts");
                }
            }

            return(result);
        }
Beispiel #21
0
        public async Task <ResultSingle <Inkton.Nest.Model.Nest> > RemoveNestAsync(Inkton.Nest.Model.Nest nest = null,
                                                                                   bool doCache = false, bool throwIfError = true)
        {
            Inkton.Nest.Model.Nest theNest = nest == null ? _editNest : nest;

            ResultSingle <Inkton.Nest.Model.Nest> result = await ResultSingleUI <Inkton.Nest.Model.Nest> .WaitForObjectAsync(
                throwIfError, theNest, new CachedHttpRequest <Inkton.Nest.Model.Nest, ResultSingle <Inkton.Nest.Model.Nest> >(
                    Backend.RemoveAsync), doCache);

            if (result.Code >= 0)
            {
                if (nest != null)
                {
                    _nests.Remove(nest);
                    OnPropertyChanged("Nests");
                }
            }

            return(result);
        }
Beispiel #22
0
        public async Task <ResultSingle <Deployment> > RemoveDeploymentAsync(Deployment deployment = null,
                                                                             bool doCache          = false, bool throwIfError = true)
        {
            Deployment theDeployment = deployment == null ? _editApp.Deployment : deployment;

            ResultSingle <Deployment> result = await ResultSingleUI <Deployment> .WaitForObjectAsync(
                throwIfError, theDeployment, new CachedHttpRequest <Deployment, ResultSingle <Deployment> >(
                    Backend.RemoveAsync), doCache);

            if (result.Code == 0)
            {
                if (deployment == null)
                {
                    _deployments.Remove(deployment);
                    OnPropertyChanged("Deployments");
                }
            }

            return(result);
        }
        public async Task<ResultSingle<AppDomain>> UpdateDomainAsync(AppDomain domain = null,
            bool doCache = false, bool throwIfError = true)
        {
            AppDomain theDomain = domain == null ? _editDomain : domain;

            ResultSingle<AppDomain> result = await ResultSingleUI<AppDomain>.WaitForObjectAsync(
                throwIfError, theDomain, new CachedHttpRequest<AppDomain, ResultSingle<AppDomain>>(
                    Backend.UpdateAsync), doCache);

            if (result.Code >= 0)
            {
                _editDomain = result.Data.Payload;

                /* updates to the domain invalidates attached
                 * certificates.
                */
                _editDomain.Certificate = null;
            }

            return result;
        }
Beispiel #24
0
        public async Task <ResultSingle <Deployment> > UpdateDeploymentAsync(string activity,
                                                                             Deployment deployment = null, bool doCache = true, bool throwIfError = true)
        {
            Deployment theDeployment = deployment == null ? _editApp.Deployment : deployment;

            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("activity", activity);

            ResultSingle <Deployment> result = await ResultSingleUI <Deployment> .WaitForObjectAsync(
                throwIfError, theDeployment, new CachedHttpRequest <Deployment, ResultSingle <Deployment> >(
                    Backend.UpdateAsync), doCache, data);

            if (result.Code >= 0)
            {
                _editDeployment     = result.Data.Payload;
                _editApp.Deployment = _editDeployment;
            }

            return(result);
        }
Beispiel #25
0
        public async Task <ResultSingle <Permit <UserT> > > ChangePasswordAsync(
            string securityCode, string password, bool throwIfError = true)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(Backend.Permit.User.Email));

            Dictionary <string, object> data = new Dictionary <string, object>();

            data["action"]       = PermitAction.ChangePassword.ToString();
            data["securityCode"] = securityCode;
            data["password"]     = password;

            ResultSingle <Permit <UserT> > result =
                await Backend.SetupPermitAsync(data);

            if (result.Code < 0 && throwIfError)
            {
                MessageHandler.ThrowMessage(result);
            }

            return(result);
        }
Beispiel #26
0
        async private void OnLoginButtonClickedAsync(object sender, EventArgs e)
        {
            IsServiceActive = true;

            try
            {
                ResultSingle <Permit> result = await BaseViewModels
                                               .AuthViewModel.QueryTokenAsync(false);

                if (result.Code == Cloud.ServerStatus.NEST_RESULT_ERROR_AUTH_SECCODE)
                {
                    // the user can be hanging in inactive state
                    // if he/she did not confirm the security code
                    // in the second stage after registration.
                    // this result suggests the credentials were
                    // sound but need to confirm the security code.
                    // a new sec code would have been sent too.

                    await PushUserUpdateAsync();
                }
                else if (result.Code == Cloud.ServerStatus.NEST_RESULT_SUCCESS)
                {
                    await BaseViewModels.PaymentViewModel.InitAsync();

                    await BaseViewModels.AppCollectionViewModel.LoadApps();

                    await MainView.GoHomeAsync();
                }
                else
                {
                    new ResultHandler <Permit>(result).Throw();
                }
            }
            catch (Exception ex)
            {
                await ErrorHandler.ExceptionAsync(this, ex);
            }

            IsServiceActive = false;
        }
        private async void ButtonDoDiscount_ClickedAsync(object sender, EventArgs e)
        {
            IsServiceActive = true;

            try
            {
                AppViewModel.ServicesViewModel.CreateServicesTables();
                AppViewModel.DeploymentViewModel.ApplyCredit = null;

                if (CreditCode.Text.Length > 0)
                {
                    Credit credit = BaseViewModels.PaymentViewModel.EditCredit;
                    credit.Code = CreditCode.Text.Trim();

                    ResultSingle <Credit> result = await BaseViewModels
                                                   .PaymentViewModel.QueryCreditAsync();

                    if (result.Code == 0)
                    {
                        credit = BaseViewModels.PaymentViewModel.EditCredit;
                        DisplayTotals(credit);
                        AppViewModel
                        .DeploymentViewModel
                        .ApplyCredit = credit;
                    }
                }
                else
                {
                    DisplayTotals();
                }

                await PricesGrid.ScrollToAsync(0, PricesGrid.Content.Height, true);
            }
            catch (Exception ex)
            {
                await ErrorHandler.ExceptionAsync(this, ex);
            }

            IsServiceActive = false;
        }
        public async Task<ResultSingle<AppDomain>> RemoveDomainAsync(AppDomain domain = null,
             bool doCache = false, bool throwIfError = true)
         {
            AppDomain theDomain = domain == null ? _editDomain : domain;

            ResultSingle<AppDomain> result = await ResultSingleUI<AppDomain>.WaitForObjectAsync(
                throwIfError, theDomain, new CachedHttpRequest<AppDomain, ResultSingle<AppDomain>>(
                    Backend.RemoveAsync), doCache);

            if (result.Code >= 0)
            {
                if (domain != null)
                {
                    // any cert that belong to the domain
                    // are automatically removed in the server
                    _domains.Remove(domain);
                    OnPropertyChanged("Domains");
                }
            }

            return result;
        }
        public async Task<ResultSingle<AppDomain>> QueryDomainAsync(AppDomain domain = null, 
            bool doCache = false, bool throwIfError = true)
        {
            AppDomain theDomain = domain == null ? _editDomain : domain;

            ResultSingle<AppDomain> result = await ResultSingleUI<AppDomain>.WaitForObjectAsync(
                throwIfError, theDomain, new CachedHttpRequest<AppDomain, ResultSingle<AppDomain>>(
                    Backend.QueryAsync), doCache, null, null);

            if (result.Code >= 0)
            {
                _editDomain = result.Data.Payload;

                AppDomainCertificate seedCert = new AppDomainCertificate();
                seedCert.OwnedBy = _editDomain;

                ResultMultiple<AppDomainCertificate> certResult = await ResultMultipleUI<AppDomainCertificate>.WaitForObjectsAsync(
                    true, seedCert, new CachedHttpRequest<AppDomainCertificate, ResultMultiple<AppDomainCertificate>>(
                        Backend.QueryAsyncListAsync), true);

                if (certResult.Code >= 0)
                {
                    ObservableCollection<AppDomainCertificate> list = certResult.Data.Payload;

                    if (list.Any())
                    {
                        theDomain.Certificate = list.First();
                        theDomain.Certificate.OwnedBy = theDomain;
                    }
                }

                if (domain != null)
                {
                    _editDomain.CopyTo(domain);
                }
            }

            return result;
        }
Beispiel #30
0
        public void TestSearch()
        {
            // Arrange
            var mockRuntime = new Mock <Runtime>(
                QueueMode.Server | QueueMode.Client,
                180, Enviorenment.Development
                )
            {
                CallBase = true
            };

            mockRuntime.Setup(x => x.ReceiveSingle <SearchResult>())
            .Returns(ResultSingle <SearchResult> .ConvertObject(
                         GetInput("test-input-a"), new SearchResult()));
            mockRuntime.Setup(x => x.ReceiveSingle <SearchResult>())
            .Returns(ResultSingle <SearchResult> .ConvertObject(
                         GetInput("test-input-b"), new SearchResult()));

            var serviceProvider = new ServiceCollection()
                                  .AddLogging()
                                  .BuildServiceProvider();

            var factory = serviceProvider.GetService <ILoggerFactory>();

            var logger = factory.CreateLogger <SearchController>();

            var controller = new SearchController(
                logger, mockRuntime.Object);

            // Act
            var result = controller.Get("docker");

            // Assert
            var okResult = result as JsonResult;

            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
            Assert.IsType <Result <List <SearchResult> > >(okResult.Value);
        }