private PluginExecutionFakeContext(Type pluginType, Guid?userId) { this.userId = userId; this.pluginMethodCache = new Kipon.Fake.Xrm.Reflection.PluginMethod.Cache(pluginType.Assembly); this.orgServiceFactory = new Services.OrganizationServiceFactory(this); var pt = this.orgServiceFactory as Microsoft.Xrm.Sdk.IProxyTypesAssemblyProvider; if (pt != null) { pt.ProxyTypesAssembly = pluginType.Assembly; } this.traceService = new Services.TracingService(); var key = $"{pluginType.FullName}:null:null"; if (plugins.ContainsKey(key)) { this.plugin = plugins[key]; } else { this.plugin = (Microsoft.Xrm.Sdk.IPlugin)System.Activator.CreateInstance(pluginType); plugins[key] = this.plugin; Kipon.Fake.Xrm.Reflection.Types.Instance.SetAssembly(this.plugin.GetType().Assembly); } }
public bool IsValidMinLength(string input, int minLength, Microsoft.Xrm.Sdk.ITracingService trace) { try { bool isValid = false; if (input.Length >= minLength) { isValid = true; } return(isValid); } catch (Exception ex) { this.LogPluginFeedback(new LogClass { Exception = ex.ToString(), Level = "error", ClassName = this.GetType().ToString(), MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name, Message = $"Error validando el min length", ProcessId = "" }, trace); //trace.Trace($"MethodName: {new System.Diagnostics.StackTrace(ex).GetFrame(0).GetMethod().Name}|--|Exception: " + ex.ToString()); throw; } }
public void LogPluginFeedback(LogClass log, Microsoft.Xrm.Sdk.ITracingService trace) { try { WebRequestData wrData = new WebRequestData(); MemoryStream memoryStream = new MemoryStream(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(LogClass)); serializer.WriteObject(memoryStream, log); var jsonObject = Encoding.Default.GetString(memoryStream.ToArray()); memoryStream.Dispose(); wrData.InputData = jsonObject; wrData.ContentType = "application/json"; wrData.Authorization = "Bearer " + Configuration.TokenForWebAPI; wrData.Url = AboxServices.CrmWebAPILog; try { using (WebClient client = new WebClient()) { var webClient = new WebClient(); if (wrData.ContentType != "") { webClient.Headers[HttpRequestHeader.ContentType] = wrData.ContentType; } if (wrData.Authorization != "") { webClient.Headers[HttpRequestHeader.Authorization] = wrData.Authorization; } // var code = "key"; string serviceUrl = wrData.Url; webClient.UploadString(serviceUrl, wrData.InputData); trace.Trace("Url:" + wrData.Url + " | Data:" + wrData.InputData); } } catch (WebException wex) { string error = ""; string statusCode = ""; if (wex.Response != null) { using (var errorResponse = (HttpWebResponse)wex.Response) { using (var reader = new StreamReader(errorResponse.GetResponseStream())) { error = reader.ReadToEnd(); } } } } } catch (Exception ex) { trace.Trace($"MethodName: {new System.Diagnostics.StackTrace(ex).GetFrame(0).GetMethod().Name}|--|Exception: " + ex.ToString()); throw; } }
public ServiceProvider(Microsoft.Xrm.Sdk.IPluginExecutionContext context, Repository.PluginExecutionFakeContext entityContext, System.Reflection.Assembly proxyType) { this.context = context; this.orgServiceFactory = new OrganizationServiceFactory(entityContext); var pp = this.orgServiceFactory as Microsoft.Xrm.Sdk.IProxyTypesAssemblyProvider; if (pp != null) { pp.ProxyTypesAssembly = proxyType; } this.traceService = new TracingService(); }
public bool IsValidPassword(string input, Microsoft.Xrm.Sdk.ITracingService trace) { try { string pattern = Constants.RegexPassword; Match m = Regex.Match(@input, pattern); return(m.Success); } catch (Exception ex) { this.LogPluginFeedback(new LogClass { Exception = ex.ToString(), Level = "error", ClassName = this.GetType().ToString(), MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name, Message = $"Error validando el formato de contraseña", ProcessId = "" }, trace); //trace.Trace($"MethodName: {new System.Diagnostics.StackTrace(ex).GetFrame(0).GetMethod().Name}|--|Exception: " + ex.ToString()); throw; } }
public WebRequestResponse DoGetRequest(WebRequestData requestData, Microsoft.Xrm.Sdk.ITracingService trace) { try { #region debug log this.LogPluginFeedback(new LogClass { Exception = "", Level = "debug", ClassName = this.GetType().ToString(), MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name, Message = $"GETing Url:{requestData.Url}", ProcessId = "" }, trace); #endregion debug log } catch (Exception exc) { } WebRequestResponse wrResponse = new WebRequestResponse(); try { try { using (WebClient client = new WebClient()) { var webClient = new WebClient(); if (requestData.ContentType != "") { webClient.Headers[HttpRequestHeader.ContentType] = requestData.ContentType; } if (requestData.Authorization != "") { webClient.Headers[HttpRequestHeader.Authorization] = requestData.Authorization; } // var code = "key"; string serviceUrl = requestData.Url; wrResponse.Data = webClient.DownloadString(serviceUrl); if (wrResponse.Data != "") { wrResponse.IsSuccessful = true; //TODO:ELiminar para Produccion try { this.LogPluginFeedback(new LogClass { Exception = "", Level = "debug", ClassName = this.GetType().ToString(), MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name, Message = $"Url:{requestData.Url} ResponseFromRequest:{wrResponse.Data}", ProcessId = "" }, trace); } catch (Exception e) { } } } } catch (WebException wex) { string error = ""; string statusCode = ""; if (wex.Response != null) { using (var errorResponse = (HttpWebResponse)wex.Response) { using (var reader = new StreamReader(errorResponse.GetResponseStream())) { error = reader.ReadToEnd(); } } } #region error log this.LogPluginFeedback(new LogClass { Exception = wex.ToString(), Level = "error", ClassName = this.GetType().ToString(), MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name, Message = $"{error}", ProcessId = "" }, trace); #endregion error log wrResponse.Data = null; wrResponse.ErrorMessage = wex.ToString(); wrResponse.IsSuccessful = false; } } catch (Exception ex) { this.LogPluginFeedback(new LogClass { Exception = ex.ToString(), Level = "error", ClassName = this.GetType().ToString(), MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name, Message = $"Excepción realizando el POST request", ProcessId = "" }, trace); trace.Trace($"MethodName: {new System.Diagnostics.StackTrace(ex).GetFrame(0).GetMethod().Name}|--|Exception: " + ex.ToString()); wrResponse.Data = null; wrResponse.IsSuccessful = false; wrResponse.ErrorMessage = ex.ToString(); } return(wrResponse); }