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 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); }
/// <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); } }