/// <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> /// Loads the specified xaml definition. /// </summary> /// <param name="xamlDefinition">The xaml definition.</param> /// <param name="xamlStream">The xaml stream.</param> /// <param name="workflowPool">The workflow pool.</param> /// <param name="workflowActivity">The workflow activity.</param> /// <exception cref="System.ArgumentNullException">xamlDefinition</exception> public void Load(StringBuilder xamlDefinition, ref Stream xamlStream, ref Queue<PooledServiceActivity> workflowPool, ref Activity workflowActivity) { if (xamlDefinition == null || xamlDefinition.Length == 0) { throw new ArgumentNullException("xamlDefinition"); } // Travis.Frisinger : 13.11.2012 - Remove bad namespaces // ReSharper disable ConditionIsAlwaysTrueOrFalse if (GlobalConstants.runtimeNamespaceClean) // ReSharper restore ConditionIsAlwaysTrueOrFalse { xamlDefinition = new Dev2XamlCleaner().CleanServiceDef(xamlDefinition); } // End Mods int generation = 0; using (xamlStream = xamlDefinition.EncodeForXmlDocument()) { workflowActivity = ActivityXamlServices.Load(xamlStream); xamlStream.Seek(0, SeekOrigin.Begin); workflowPool.Clear(); generation++; for (int i = 0; i < GlobalConstants._xamlPoolSize; i++) { Activity activity = ActivityXamlServices.Load(xamlStream); xamlStream.Seek(0, SeekOrigin.Begin); workflowPool.Enqueue(new PooledServiceActivity(generation, activity)); } } }
/// <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; } }