public override Operation <DisassociateResponse> Disassociate(string entityName, Guid entityId, Relationship relationship, EntityReferenceCollection relatedEntities, ExecuteParams executeParams) { using var service = GetService(); return(((IEnhancedOrgService)service).Disassociate(entityName, entityId, relationship, relatedEntities, executeParams)); }
internal async Task <List <T> > GetAll <T>(ExecuteParams param) where T : MultipleResultBase { Uri uri = new Uri(param.Uri, UriKind.Relative); List <T> resultList = new List <T>(); do { param.SetUri(uri.ToString()); var result = await Get(param); var multipleResultBase = result.ConvertToData <MultipleResultBase>(); resultList.Add(result.ConvertToData <T>()); var tempUri = multipleResultBase?.next?.ToString(); if (tempUri == null) { uri = null; } else { var index = tempUri.IndexOf("/api"); if (index == -1) { break; } uri = new Uri(tempUri.Substring(index), UriKind.Relative); } } while (uri != null); return(resultList); }
public override IEnumerable <TEntityType> RetrieveMultiplePage <TEntityType>(QueryExpression query, int pageSize = 5000, int page = 1, ExecuteParams executeParams = null) { using var service = GetService(); return(((IEnhancedOrgService)service).RetrieveMultiplePage <TEntityType>(query, pageSize, page, executeParams)); }
private async Task <T> Execute <T>(ExecuteParams param) { var callResult = await ExecuteCall(param); if (callResult.Success) { return(JsonConvert.DeserializeObject <T>(callResult.Response)); } return(default(T)); }
public async Task <List <MultipleCategoriesResult> > GetAll(IConnectionCcvShop connection = null, string lan = null) { //todo: add counter, max 150 per minute var uri = "/api/rest/v1/categories/"; var p = new ExecuteParams(connection, lan); p.SetUri(uri); return(await GetAll <MultipleCategoriesResult>(p)); }
public async Task <MultipleWebshopsResult> Get(IConnectionCcvShop connection = null, string lan = null) { //todo: add counter, max 150 per minute var uri = "/api/rest/v1/webshops/"; var p = new ExecuteParams(connection, lan); p.SetUri(uri); return(await Get <MultipleWebshopsResult>(p)); }
public async Task <bool> Verify(IConnectionCcvShop connection = null) { var p = new ExecuteParams(connection) { Uri = $"/api/rest/v1/apps/{AppInformation.Instance.AppId}", Data = new { is_installed = true } }; var result = await Patch(p); return(result.Success); }
public async Task <SettingsResult> GetByWebshopId(IConnectionCcvShop connection, int id, string lan = null) { //todo: add counter, max 150 per minute var p = new ExecuteParams(connection, lan) { Uri = $"/api/rest/v1/webshops/{id}/settings/", }; return(await Get <SettingsResult>(p)); }
public async Task <ProductResult> GetById(IConnectionCcvShop connection, int id, string lan = null) { //todo: add counter, max 150 per minute var p = new ExecuteParams(connection, lan) { Uri = $"/api/rest/v1/products/{id}", }; return(await Get <ProductResult>(p)); }
public async Task <List <MultipleProductsResult> > GetAll(IConnectionCcvShop connection = null, Parameters parameters = null, string lan = null) { //todo: add order by module //todo: add counter, max 150 per minute var uri = "/api/rest/v1/products/"; var p = new ExecuteParams(connection, lan); p.SetUri(uri, parameters); return(await GetAll <MultipleProductsResult>(p)); }
public async Task <bool> Patch(IConnectionCcvShop connection, int id, ProductResult original, string lan = null) { //todo: add counter, max 100 per minute var p = new ExecuteParams(connection, lan) { Uri = $"/api/rest/v1/products/{id}", Data = Core.Compare.GetChanges(original) }; return((await Patch(p)).Success); }
public static void Execute(ExecuteParams executeParams) { var allProjectReferences = Crawler.FindProjectDependencies(executeParams.ProjectName, executeParams.SolutionName); var foundProjects = allProjectReferences as IList<Project> ?? allProjectReferences.ToList(); var projectReferences = foundProjects.Where(project => project.DependencyType == DependencyType.ProjectReference); // var assemblyReferences = allProjectReferences.Where(project => project.DependencyType == DependencyType.AssemblyReference); var references = projectReferences as IList<Project> ?? projectReferences.ToList(); switch (executeParams.Action) { case CommandAction.Enable: const string enableMessage = "Following project dependencies have been found...LINQBridge them? (Recommended)"; PackageConfigurator.EnableProject(executeParams.ProjectOutput, executeParams.AssemblyName, executeParams.SolutionName); var enabledDependencies = new List<string>(); enabledDependencies.Insert(0, executeParams.AssemblyName); if (references.Any(project => PackageConfigurator.IsBridgeDisabled(project.AssemblyName, executeParams.SolutionName))) { var projectDependencies = new ProjectDependencies(references, enableMessage); var dependencies = projectDependencies.ShowDependencies(PackageConfigurator.EnableProject); enabledDependencies.AddRange(dependencies.Select(project => project.AssemblyName)); } MessageBox.Show(string.Format("LINQBridge on {0} has been Enabled...", string.Join(", ", enabledDependencies)), "Success", MessageBoxButtons.OK); break; case CommandAction.Disable: const string disableMessage = "Following project dependencies have been found...Un-LINQBridge them? (Recommended)"; PackageConfigurator.DisableProject(executeParams.ProjectOutput, executeParams.AssemblyName, executeParams.SolutionName); var disableDependencies = new List<string>(); disableDependencies.Insert(0, executeParams.AssemblyName); if (references.Any(project => PackageConfigurator.IsBridgeEnabled(project.AssemblyName, executeParams.SolutionName))) { var projectDependencies = new ProjectDependencies(references, disableMessage); var dependencies = projectDependencies.ShowDependencies(PackageConfigurator.DisableProject); disableDependencies.AddRange(dependencies.Select(project => project.AssemblyName)); } MessageBox.Show(string.Format("LINQBridge on {0} has been Disabled...", string.Join(", ", disableDependencies)), "Success", MessageBoxButtons.OK); break; default: throw new ArgumentOutOfRangeException("action"); } }
private static void SetHeaders(ExecuteParams param, string timeStamp, string hash, HttpClient client) { string publicKey = param.Connection.ApiPublic; if (!string.IsNullOrEmpty(param.TargetLanguage)) { client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Language", param.TargetLanguage); } client.DefaultRequestHeaders.Add("x-date", timeStamp); client.DefaultRequestHeaders.Add("x-hash", hash); client.DefaultRequestHeaders.Add("x-public", publicKey); client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=UTF-8"); }
public static void Execute(ExecuteParams executeParams) { var allProjectReferences = Crawler.FindProjectDependencies(executeParams.ProjectName, executeParams.SolutionName); var foundProjects = allProjectReferences as IList <Project> ?? allProjectReferences.ToList(); var projectReferences = foundProjects.Where(project => project.DependencyType == DependencyType.ProjectReference); // var assemblyReferences = allProjectReferences.Where(project => project.DependencyType == DependencyType.AssemblyReference); var references = projectReferences as IList <Project> ?? projectReferences.ToList(); switch (executeParams.Action) { case CommandAction.Enable: const string enableMessage = "Following project dependencies have been found...LINQBridge them? (Recommended)"; PackageConfigurator.EnableProject(executeParams.ProjectOutput, executeParams.AssemblyName, executeParams.SolutionName); var enabledDependencies = new List <string>(); enabledDependencies.Insert(0, executeParams.AssemblyName); if (references.Any(project => PackageConfigurator.IsBridgeDisabled(project.AssemblyName, executeParams.SolutionName))) { var projectDependencies = new ProjectDependencies(references, enableMessage); var dependencies = projectDependencies.ShowDependencies(PackageConfigurator.EnableProject); enabledDependencies.AddRange(dependencies.Select(project => project.AssemblyName)); } MessageBox.Show(string.Format("LINQBridge on {0} has been Enabled...", string.Join(", ", enabledDependencies)), "Success", MessageBoxButtons.OK); break; case CommandAction.Disable: const string disableMessage = "Following project dependencies have been found...Un-LINQBridge them? (Recommended)"; PackageConfigurator.DisableProject(executeParams.ProjectOutput, executeParams.AssemblyName, executeParams.SolutionName); var disableDependencies = new List <string>(); disableDependencies.Insert(0, executeParams.AssemblyName); if (references.Any(project => PackageConfigurator.IsBridgeEnabled(project.AssemblyName, executeParams.SolutionName))) { var projectDependencies = new ProjectDependencies(references, disableMessage); var dependencies = projectDependencies.ShowDependencies(PackageConfigurator.DisableProject); disableDependencies.AddRange(dependencies.Select(project => project.AssemblyName)); } MessageBox.Show(string.Format("LINQBridge on {0} has been Disabled...", string.Join(", ", disableDependencies)), "Success", MessageBoxButtons.OK); break; default: throw new ArgumentOutOfRangeException("action"); } }
private HttpRequestMessage ConstructRequest(ExecuteParams param, HttpClient client, string timeStamp, string hash) { var httpMethod = new HttpMethod(param.Method); SetHeaders(param, timeStamp, hash, client); var request = new HttpRequestMessage(httpMethod, $"{param.Connection.ApiRoot}{param.Uri}"); if (param.HasData) { request.Content = new StringContent(param.DataJson); } return(request); }
/// <summary> /// Actually calls into Compare Service to perform comparison. Currently it used a hardcoded /// binding wsHttpBinding. After the call has returned successfully, it calls the results /// routine to display the results. /// </summary> /// <param name="sOriginalFile"></param> /// <param name="sModifiedFile"></param> /// <param name="sVirtualPath"></param> private void DoCompare(string sOriginalFile, string sModifiedFile, string sVirtualPath) { ResponseOptions responseOptions = ResponseOptions.Rtf; string password = (string)Session["Passw"]; password = CodePassword(password); // Hardcoded wsHttpBinding. Host info is picked from config file ComparerClient cp = new ComparerClient("CompareWebServiceWCF"); cp.ClientCredentials.Windows.ClientCredential.UserName = UserNameTextBox.Text; cp.ClientCredentials.Windows.ClientCredential.Password = password; cp.ClientCredentials.Windows.ClientCredential.Domain = RealmTextBox.Text; // Authenticate first. if (cp.Authenticate(RealmTextBox.Text, UserNameTextBox.Text, password)) { byte[] original = File.ReadAllBytes(sOriginalFile); byte[] modified = File.ReadAllBytes(sModifiedFile); string sRenderingSet = RenderingSetDropDownList.SelectedValue; string sOptionSet = File.ReadAllText(Request.MapPath(Path.Combine(sRenderSetPath, sRenderingSet))); ExecuteParams executeParams = new ExecuteParams() { CompareOptions = sOptionSet, ResponseOption = responseOptions, Original = original, Modified = modified, OriginalDocumentInfo = new DocumentInfo() { DocumentDescription = Path.GetFileName(sOriginalFile), DocumentSource = Path.GetFileName(sOriginalFile) }, ModifiedDocumentInfo = new DocumentInfo() { DocumentDescription = Path.GetFileName(sModifiedFile), DocumentSource = Path.GetFileName(sModifiedFile) }, }; // Peform comparison CompareResults results = cp.ExecuteEx(executeParams); // Prepare and Display results. HandleResults(results, responseOptions, sOriginalFile, sModifiedFile, sRenderingSet, sVirtualPath); } else { ShowMessage("Authentication failed."); } }
private string GetResponseError(ExecuteParams param, string timeStamp, string hash, string responseContent) { return($@"Sending CCVShop request. This went totaly wrong! <br /> <br /><b>Request:</b> <br />PublicKey: {param.Connection.ApiPublic} <br />Method: {param.Method} <br />Uri: {param.Uri} <br />ApiRoot: {param.Connection.ApiRoot} <br />DataJson: {param.DataJson} <br />TimeStamp: {timeStamp} <br />Hash: {hash} <br /> <br /><b>Response:</b> <br />{responseContent}"); }
protected internal virtual object CustomRetry(Func <IOrganizationService, object> action, Operation operation, ExecuteParams executeParams, Exception ex) { foreach (var fallbackNode in FallbackNodes) { try { return((fallbackNode.Pool.GetService() as EnhancedOrgServiceBase)?.TryRunOperation(action, operation, executeParams)); } catch { // ignored } } return(null); }
private string GenerateHash(ExecuteParams param, string timeStamp) { var secretKey = param.Connection.ApiSecret; var publicKey = param.Connection.ApiPublic; var method = param.Method; var uri = param.Uri; var dataJson = param.DataJson; List <string> aDataToHash = new List <string>(); aDataToHash.Add(publicKey); aDataToHash.Add(method); aDataToHash.Add(uri); aDataToHash.Add(dataJson); aDataToHash.Add(timeStamp); var sStringToHash = string.Join("|", aDataToHash); var sHash = Security.Encryption.ComputeHmacSha512(secretKey, sStringToHash); sHash = sHash.ToLower(); return(sHash); }
public void TestExecute() { int successedCount = 5; int count = 0; var executeParams = new ExecuteParams() { TimeInterval = new TimeSpan(0, 0, 0, 0, 100), AttemptsCount = 3, RequestFunction = async (url, proxy, step) => { await Task.Run(() => { count++; if (count != successedCount) throw new ArgumentException("Не выполнено!"); }); }, ExceptionAction = (url, proxy, step, ex) => { } }; TasksExecuteHelper.Execute(executeParams).Wait(); }
private async Task <ExecuteResult> ExecuteCall(ExecuteParams param) { var connection = param.Connection; var timeStamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss+00:00"); var hash = GenerateHash(param, timeStamp); using (var client = new HttpClient()) { var request = ConstructRequest(param, client, timeStamp, hash); var httpResponse = client.SendAsync(request).Result; var response = await httpResponse.Content.ReadAsStringAsync(); bool success = httpResponse.IsSuccessStatusCode; if (!success) { var errorMessage = GetResponseError(param, timeStamp, hash, response); Error.ErrorLogger.ErrorOccurred(errorMessage); } return(new ExecuteResult(success, response)); } }
public override Operation <RetrieveMultipleResponse> RetrieveMultipleAsOperation(QueryBase query, ExecuteParams executeParams = null) { using var service = GetService(); return(((IEnhancedOrgService)service).RetrieveMultipleAsOperation(query, executeParams)); }
public override Operation ExecuteAsOperation(OrganizationRequest request, ExecuteParams executeParams, Func <IOrganizationService, OrganizationRequest, OrganizationRequest> undoFunction) { using var service = GetService(); return(((IEnhancedOrgService)service).ExecuteAsOperation(request, executeParams, undoFunction)); }
public override Operation <TResponse> ExecuteAsOperation <TResponse, TRequest>(OrganizationRequest request, ExecuteParams executeParams = null, Func <IOrganizationService, TRequest, OrganizationRequest> undoFunction = null) { using var service = GetService(); return(((IEnhancedOrgService)service).ExecuteAsOperation <TResponse, TRequest>(request, executeParams, undoFunction)); }
public override Operation <DeleteResponse> DeleteAsOperation(string entityName, Guid id, ExecuteParams executeParams = null) { using var service = GetService(); return(((IEnhancedOrgService)service).DeleteAsOperation(entityName, id, executeParams)); }
internal async Task <ExecuteResult> Get(ExecuteParams param) { param.Method = Methods.Get; return(await ExecuteCall(param)); }
public override Operation <TResponse> ExecuteAsOperation <TResponse>(OrganizationRequest request, ExecuteParams executeParams = null) { using var service = GetService(); return(((IEnhancedOrgService)service).ExecuteAsOperation <TResponse>(request, executeParams)); }
//TODO: Do something with the rate limit here internal async Task <T> Get <T>(ExecuteParams param) => (await Get(param)).ConvertToData <T>();
public override Operation <RetrieveResponse> RetrieveAsOperation(string entityName, Guid id, ColumnSet columnSet, ExecuteParams executeParams = null) { using var service = GetService(); return(((IEnhancedOrgService)service).RetrieveAsOperation(entityName, id, columnSet, executeParams)); }
internal async Task <T> Patch <T>(ExecuteParams param) => (await Patch(param)).ConvertToData <T>();
internal async Task <ExecuteResult> Patch(ExecuteParams param) { param.Method = Methods.Patch; return(await ExecuteCall(param)); }
public ComparerResult DoComparison(IPrincipal principal, ComparerArguments arguments) { ComparerResult cResult = new ComparerResult(); try { /* Impersonation for connect to WCF using ASP.net Authenticated User */ System.Security.Principal.WindowsImpersonationContext impersonationContext = ((System.Security.Principal.WindowsIdentity)principal.Identity).Impersonate(); ComparerClient cc = GetComparerClient(); /* Uploaded files should be readed by ISS Application Pool User */ impersonationContext.Undo(); byte[] original = System.IO.File.ReadAllBytes(Path.Combine(UploadPath, arguments.OriginalDoc.ServerName)); // string resultPath = System.IO.Directory.GetParent(arguments.OriginalDoc.ServerName).FullName; foreach (ServerFile file in arguments.ModifiedDoc) { ComparisonResult result = new ComparisonResult(); CompareResults cr; try { result.File = file.ClientName; byte[] modified = System.IO.File.ReadAllBytes(Path.Combine(UploadPath, file.ServerName)); string sOptionSet = System.IO.File.ReadAllText(arguments.RenderingSet); Log.Write(TraceEventType.Information, "Comparing {0} and {1} files", arguments.OriginalDoc.ClientName, file.ClientName); var executeParams = new ExecuteParams() { CompareOptions = sOptionSet, Original = original, Modified = modified, ResponseOption = arguments.OutputFormat, OriginalDocumentInfo = CreateDocInfo(arguments.OriginalDoc.ClientName), ModifiedDocumentInfo = CreateDocInfo(file.ClientName) }; cr = cc.ExecuteEx(executeParams); if (cr != null) { string fileName = System.IO.Path.GetFileNameWithoutExtension(result.File); if (cr.Redline != null) { result.Redline = storeFileOnServer(cr.Redline, fileName + ".redline." + getExtension(arguments.OutputFormat)); } if (!string.IsNullOrEmpty(cr.RedlineMl)) { result.RedlineMl = storeFileOnServer(cr.RedlineMl, fileName + ".redlineml.xml"); } if (!string.IsNullOrEmpty(cr.Summary)) { result.Summary = storeFileOnServer(cr.Summary, fileName + ".summary.xml"); } } else { Log.Write(TraceEventType.Error, "Null result"); result.Error = "No results"; } } catch (System.Security.SecurityException ex) { Log.Write(TraceEventType.Error, "{0}", ex); result.Error = "Security Error: " + ex.Message; } catch (FileNotFoundException ex) { Log.Write(TraceEventType.Error, "{0}", ex); result.Error = "File not found on server"; } catch (Exception ex) { Log.Write(TraceEventType.Error, "{0}", ex); result.Error = ex.Message; } cResult.Comperisons.Add(result); } checkTimeOutFiles(); } catch (System.ServiceModel.ServerTooBusyException ex) { cResult.Errors.Add("Server Too Busy"); Log.Write(TraceEventType.Error, "{0}", ex); } catch (TimeoutException ex) { cResult.Errors.Add("Faild to connect to server (Timeout)"); Log.Write(TraceEventType.Error, "{0}", ex); } catch (System.ServiceModel.FaultException ex) { cResult.Errors.Add("FaultException: " + ex.Message); Log.Write(TraceEventType.Error, "{0}", ex); } catch (System.ServiceModel.CommunicationException ex) { if (ex.Message.Contains("request is unauthorized")) { cResult.Errors.Add(@"Unauthorized issue arised, please check User Name and/or Password and/or domain!"); } else { cResult.Errors.Add("CommunicationException: " + ex.Message); } Log.Write(TraceEventType.Error, "{0}", ex); } catch (FileNotFoundException ex) { Log.Write(TraceEventType.Error, "{0}", ex); throw new Exception("Original file not found on server"); } catch (Exception ex) { ComparerResult result = new ComparerResult(); cResult.Errors.Add(ex.Message); Log.Write(TraceEventType.Error, "{0}", ex); } return(cResult); }