Пример #1
1
        public ApiContext GetAuthorizedContext(PelicanContext pelicanContext,
                                               Guid companyFileId)
        {
            var keyService = new OAuthKeyService(this);

            var configuration = new ApiConfiguration(pelicanContext.ClientKey,
                                                     pelicanContext.ClientSecret,
                                                     pelicanContext.RedirectUrl);

            // get companyfiles
            var cfService = new CompanyFileService(configuration,
                                                   null,
                                                   keyService);
            var companyFiles = cfService.GetRange();

            // select
            var companyFile = companyFiles.FirstOrDefault(_ => _.Id == companyFileId);

            // fetch accounts
            var credentials = new CompanyFileCredentials("Administrator",
                                                         "");

            return new ApiContext
                   {
                       ApiConfiguration = configuration,
                       CompanyFileCredentials = credentials,
                       KeyService = keyService,
                       CompanyFile = companyFile,
                   };
        }
 public void SetUp()
 {
     _configuration = Substitute.For<IApiConfiguration>();
     _webFactory = new TestWebRequestFactory();
     _service = new CompanyFileService(_configuration, _webFactory);
     _configuration.ApiBaseUrl.Returns(ApiRequestHandler.ApiRequestUri.AbsoluteUri);
 }
        public JsonResult Search(string search, SortDescription sort, string webApiUrl, bool isCloud)
        {
            if (isCloud)
            {
                APIConfiguration = new ApiConfiguration(OAuthInformation.Key, OAuthInformation.Secret, OAuthInformation.RedirectUri);
            }
            else
            {
                APIConfiguration = new ApiConfiguration(webApiUrl);
            }

            var searchCriteria = new List<SearchCriteria>();
            if (!string.IsNullOrEmpty(search))
                searchCriteria = new[]{
                    new SearchCriteria
                    {
                        Field = "Name",
                        SearchText = search,
                        FieldType = typeof(string)
                    },
                    new SearchCriteria
                    {
                        Field = "ProductVersion",
                        SearchText = search,
                        FieldType = typeof(string)
                    },
                    new SearchCriteria
                    {
                        Field = "LibraryPath",
                        SearchText = search,
                        FieldType = typeof(string)
                    }}.ToList();

            var query = QueryStringHelper.CombineQuery(searchCriteria, LogicalOperator.or, new[]{sort}, null);
            var service = new CompanyFileService(APIConfiguration, null, KeyService);
            var model = service.GetRange(query).ToList() ;
            return Json(model);
        }
        internal CompanyFileWithResources Login(CompanyFile companyFile, string userId, string password)
        {
            var _login = new LoginContext { Username = userId, Password = password };

            var _service = new CompanyFileService(APIConfiguration, null, KeyService);
            CompanyFileResource = _service.Get(companyFile, _login);
            CompanyCredential = new CompanyFileCredentials(userId, password);
            return CompanyFileResource;
        }
 public void FetchCompanyFies(Action<Exception> onError)
 {
     CompanyFiles.Clear();
     IsLoading = true;
     ShowBrowser = false;
     var config = new ApiConfiguration();
     var service = new CompanyFileService(config, new WebRequestFactory(config), _keyService);
     service.GetRangeAsync()
            .ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        onError(t.Exception);
                        ShowBrowser = true;
                        IsLoading = false;
                    }
                    else
                    {
                        CompanyFiles.Clear();
                        foreach (var companyFile in t.Result)
                        {
                            CompanyFiles.Add(new CompanyFileViewModel {CompanyFile = companyFile});
                        }
                        IsLoading = false;
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
 }
        /// <summary>
        /// Event that is called when the form loads
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks></remarks>
        private void CompanyFilesLoad(object sender, EventArgs e)
        {
            try
            {
                ShowSpinner();

                //If developer key  enable (see above) and set useCVloud to true the following section manages OAuth token and accessing cloud service
                if (UseCloud)
                {
                    _configurationCloud = new ApiConfiguration(DeveloperKey, DeveloperSecret, "http://desktop");
                    _oAuthKeyService = new OAuthKeyService();

                    //Get tokens if not stored
                    if (_oAuthKeyService.OAuthResponse == null)
                    {
                        var oauthService = new OAuthService(_configurationCloud);
                        _oAuthKeyService.OAuthResponse =
                            oauthService.GetTokens(OAuthLogin.GetAuthorizationCode(_configurationCloud));
                    }

                    // Load all files from cloud and local simultaneously
                    var cfsCloud = new CompanyFileService(_configurationCloud, null, _oAuthKeyService);
                    cfsCloud.GetRange(OnComplete, OnError);
                }

                _configurationLocal = new ApiConfiguration(LocalApiUrl);
                var cfsLocal = new CompanyFileService(_configurationLocal);
                cfsLocal.GetRange(OnComplete, OnError);

                //' The following two lines can be called to run synchronously rather than async
                //_companyFiles = cfs.GetRange()
                //dgvCompanyFiles.DataSource = _companyFiles
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }