/// <summary> /// Return appropriate migrator instance depending upon type of WSE Module /// </summary> public static IMigrator GetMigrator(XModule wseModule) { if (wseModule.Search("=>SELF[ScanTag==\"Communicate with Web service (REST/JSON)\"]").Any()) { return(new CommunicateWithWebServiceJsonArtifactMigrator(wseModule)); } if (wseModule.Search("=>SELF[ScanTag==\"Communicate with Web service\"]").Any()) { return(new CommunicateWithWebServiceXmlArtifactMigrator(wseModule)); } return(new ScannedWebserviceArtifactMigrator(wseModule)); }
/// <summary> /// Get Endpoint, Resource and Query Params from WSE Module /// </summary> /// <param name="wseModule"></param> /// <returns>AddressParserResult object which contains Endpoint, Resource and Query Params</returns> public AddressParserResult Parse(XModule wseModule) { var addressParserResult = new AddressParserResult(); try { TCObject addressValueTql = wseModule.Search(AddOnConstants.AddressValueTql).FirstOrDefault(); if (addressValueTql == null) { return(addressParserResult); } XModuleAttribute addressValue = addressValueTql as XModuleAttribute; if (string.IsNullOrEmpty(addressValue?.DefaultValue)) { return(addressParserResult); } ParseAddressInternal(addressParserResult, addressValue.DefaultValue); } catch (Exception ex) { FileLogger.Instance.Error(ex); } return(addressParserResult); }
/// <summary> /// Parses WSE Module to get payload in string format /// </summary> /// <param name="wseModule">WSE Module</param> /// <param name="tql"> Not used</param> /// <returns>payload in string format</returns> public string Parse(XModule wseModule, string tql = "") { try { if (wseModule == null) { return(string.Empty); } XModuleAttribute jsonObject = wseModule .Search("=>SUBPARTS:XModuleAttribute").Cast <XModuleAttribute>() .FirstOrDefault(x => x.BusinessType == "JsonObject" || x.BusinessType == "JsonArray"); if (jsonObject != null) { JArray arrayObject = new JArray(); JObject plainObject = CommonUtilities.ConstructJsonStructure(jsonObject, new JObject()); if (jsonObject.BusinessType == "JsonObject") { return(Convert.ToString(plainObject)); } arrayObject.Add(plainObject.Values()); return(Convert.ToString(arrayObject)); } } catch (Exception e) { FileLogger.Instance.Error( $"Failed to create Json payload for request :{wseModule?.Name}", e); } return(string.Empty); }
private static int GetHashCode(XModule xModule) { var stringBuilder = new StringBuilder(); var treeObjects = xModule.Search("=>SUBPARTS:XModuleAttribute[Name==\"Request\"]=>SubAttributes"); foreach (var t in treeObjects) { stringBuilder.Append(t.DisplayedName); } return(stringBuilder.ToString().GetHashCode()); }
/// <summary> /// Gets payload from Wse Module /// </summary> /// <param name="wseModule">WSE Module</param> /// <param name="tql"> Tql to get root xml element from WSE Module Request or Response XModuleAttribute </param> /// <returns></returns> public string Parse(XModule wseModule, string tql = "") { if (wseModule == null) { return(string.Empty); } try { var rootAttribute = wseModule.Search(tql).Cast <XModuleAttribute>().FirstOrDefault(); return(Parse(rootAttribute)); } catch (Exception) { // do nothing as this could happen possibly, just move on with the other attributes } return(string.Empty); }
/// <summary> /// Extracts method from WSE Module /// </summary> /// <param name="xModule">WSE Module</param> /// <returns>HTTP Method</returns> public string Parse(XModule xModule) { try { XModuleAttribute method = (XModuleAttribute) xModule.Search(AddOnConstants.MethodTql).FirstOrDefault(); if (method == null) { return(string.Empty); } return(method.DefaultValue); } catch (Exception ex) { FileLogger.Instance.Error(ex); } return(string.Empty); }
/// <summary> /// Gets Response Status Code from WSE Module /// </summary> /// <param name="xModule">WSE Module</param> /// <returns>Status code</returns> public string ParseResponseStatus(XModule xModule) { try { TCObject statusCodeModuleAttribute = xModule.Search(AddOnConstants.ResponseStatusTql) .FirstOrDefault(); if (statusCodeModuleAttribute == null) { return(string.Empty); } XModuleAttribute statusCodeXModuleAttribute = statusCodeModuleAttribute as XModuleAttribute; return(statusCodeXModuleAttribute?.DefaultValue); } catch (Exception ex) { FileLogger.Instance.Error("Failed to retrieve response Status Code :", ex); } return(string.Empty); }
/// <summary> /// Gets headers from WSE Module /// </summary> /// <param name="wseModule">WSE Module</param> /// <param name="tql">tql to get Header XModuleAttribute from WSE Module</param> /// <returns>All headers as a dictionary</returns> public Dictionary <string, string> Parse(XModule wseModule, string tql) { var headersDict = new Dictionary <string, string>(); try { List <TCObject> headers = wseModule.Search(tql); foreach (TCObject header in headers) { XModuleAttribute headerAttribute = (XModuleAttribute)header; if (string.IsNullOrEmpty(headerAttribute.DefaultValue)) { continue; } headersDict.Add(headerAttribute.Name, CommonUtilities.RemoveExtraDoubleQuotes(headerAttribute.DefaultValue)); } } catch (Exception) { // do nothing as this could happen possibly, just move on with the other attributes } return(headersDict); }