public StripNaughtyNamespaces ( |
||
def | The def. | |
Résultat |
/// <summary> /// Executes the service /// </summary> /// <param name="values">The values.</param> /// <param name="theWorkspace">The workspace.</param> /// <returns></returns> public StringBuilder Execute(Dictionary<string, StringBuilder> values, IWorkspace theWorkspace) { var serializer = new Dev2JsonSerializer(); try { var res = new ExecuteMessage { HasError = false }; if (values == null) { throw new ArgumentNullException("values"); } if (!values.ContainsKey("versionInfo")) { // ReSharper disable NotResolvedInText throw new ArgumentNullException("No resourceId was found in the incoming data"); // ReSharper restore NotResolvedInText } var version = serializer.Deserialize<IVersionInfo>(values["versionInfo"]); Dev2Logger.Log.Info("Get Version. " + version); var result = ServerVersionRepo.GetVersion(version); res.Message.Append(result); Dev2XamlCleaner dev2XamlCleaner = new Dev2XamlCleaner(); res.Message = dev2XamlCleaner.StripNaughtyNamespaces(res.Message); return serializer.SerializeToBuilder(res); } catch (Exception e) { Dev2Logger.Log.Error(e); IExplorerRepositoryResult error = new ExplorerRepositoryResult(ExecStatus.Fail, e.Message); return serializer.SerializeToBuilder(error); } }
public void Dev2XamlCleaner_StripNaughtyNamespaces_WhenContainsBadNamespace_ExpectNamespaceRemoved() { //------------Setup for test-------------------------- var dev2XamlCleaner = new Dev2XamlCleaner(); var data = new StringBuilder(ParserStrings.XamlLoaderBadNamespace); //------------Execute Test--------------------------- var result = dev2XamlCleaner.StripNaughtyNamespaces(data); //------------Assert Results------------------------- int indexOf = result.ToString().IndexOf("clr-namespace:clr-namespace:Unlimited.Framework;assembly=Dev2.Core", StringComparison.Ordinal); int indexOf2 = result.ToString().IndexOf(@"<Variable x:TypeArguments=""uf:UnlimitedObject"" Name=""d"" />", StringComparison.Ordinal); Assert.IsTrue(indexOf < 0, "Dev2.Core Namespace was left behind"); Assert.IsTrue(indexOf2 < 0, "UnlimitedObject d was left behind"); }
/// <summary> /// Executes the service /// </summary> /// <param name="values">The values.</param> /// <param name="theWorkspace">The workspace.</param> /// <returns></returns> public StringBuilder Execute(Dictionary<string, StringBuilder> values, IWorkspace theWorkspace) { var serializer = new Dev2JsonSerializer(); try { var res = new ExecuteMessage { HasError = false }; if (values == null) { throw new ArgumentNullException("values"); } if (!values.ContainsKey("versionInfo")) { // ReSharper disable NotResolvedInText throw new ArgumentNullException("No resourceId was found in the incoming data"); // ReSharper restore NotResolvedInText } var version = serializer.Deserialize<IVersionInfo>(values["versionInfo"]); Dev2Logger.Log.Info("Get Version. " + version); var result = ServerVersionRepo.GetVersion(version); var resource = Resources.GetResource(theWorkspace.ID, version.ResourceId); if (resource != null && resource.ResourceType == ResourceType.DbSource) { res.Message.Append(result); } else { var startIdx = result.IndexOf(PayloadStart, 0, false); if (startIdx >= 0) { // remove beginning junk startIdx += PayloadStart.Length; result = result.Remove(0, startIdx); startIdx = result.IndexOf(PayloadEnd, 0, false); if (startIdx > 0) { var len = result.Length - startIdx; result = result.Remove(startIdx, len); res.Message.Append(result.Unescape()); } } else { // handle services ;) startIdx = result.IndexOf(AltPayloadStart, 0, false); if (startIdx >= 0) { // remove begging junk startIdx += AltPayloadStart.Length; result = result.Remove(0, startIdx); startIdx = result.IndexOf(AltPayloadEnd, 0, false); if (startIdx > 0) { var len = result.Length - startIdx; result = result.Remove(startIdx, len); res.Message.Append(result.Unescape()); } } else { // send the entire thing ;) res.Message.Append(result); } } } Dev2XamlCleaner dev2XamlCleaner = new Dev2XamlCleaner(); res.Message = dev2XamlCleaner.StripNaughtyNamespaces(res.Message); return serializer.SerializeToBuilder(res); } catch (Exception e) { Dev2Logger.Log.Error(e); IExplorerRepositoryResult error = new ExplorerRepositoryResult(ExecStatus.Fail, e.Message); return serializer.SerializeToBuilder(error); } }
public StringBuilder Execute(Dictionary<string, StringBuilder> values, IWorkspace theWorkspace) { try { var res = new ExecuteMessage { HasError = false }; string serviceId = null; StringBuilder tmp; values.TryGetValue("ResourceID", out tmp); if (tmp != null) { serviceId = tmp.ToString(); } Guid resourceId; Guid.TryParse(serviceId, out resourceId); Dev2Logger.Log.Info("Fetch Resource definition. ResourceId:" + resourceId); try { var result = ResourceCatalog.Instance.GetResourceContents(theWorkspace.ID, resourceId); var tempResource = new Resource(result.ToXElement()); //var resource = ResourceCatalog.Instance.GetResource(theWorkspace.ID, resourceId); var resource = tempResource; if (resource.ResourceType == ResourceType.DbSource) { res.Message.Append(result); } else { var startIdx = result.IndexOf(PayloadStart, 0, false); if (startIdx >= 0) { // remove beginning junk startIdx += PayloadStart.Length; result = result.Remove(0, startIdx); startIdx = result.IndexOf(PayloadEnd, 0, false); if (startIdx > 0) { var len = result.Length - startIdx; result = result.Remove(startIdx, len); res.Message.Append(result.Unescape()); } } else { // handle services ;) startIdx = result.IndexOf(AltPayloadStart, 0, false); if (startIdx >= 0) { // remove begging junk startIdx += AltPayloadStart.Length; result = result.Remove(0, startIdx); startIdx = result.IndexOf(AltPayloadEnd, 0, false); if (startIdx > 0) { var len = result.Length - startIdx; result = result.Remove(startIdx, len); res.Message.Append(result.Unescape()); } } else { // send the entire thing ;) res.Message.Append(result); } } } } catch (Exception e) { Dev2Logger.Log.Error(string.Format("Error getting resource definition for: {0}", resourceId), e); } // Finally, clean the definition as per execution hydration rules ;) Dev2XamlCleaner dev2XamlCleaner = new Dev2XamlCleaner(); res.Message = dev2XamlCleaner.StripNaughtyNamespaces(res.Message); Dev2JsonSerializer serializer = new Dev2JsonSerializer(); return serializer.SerializeToBuilder(res); } catch (Exception err) { Dev2Logger.Log.Error(err); throw; } }