コード例 #1
0
        /// <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));
                }
            }
        }
コード例 #2
0
        public StringBuilder GetResourceDefinition(bool prepairForDeployment, Guid resourceId, StringBuilder contents)
        {
            var serializer = new Dev2JsonSerializer();
            var res        = new ExecuteMessage();

            try
            {
                if (!contents.IsNullOrEmpty())
                {
                    var assembly = Assembly.Load("Dev2.Data");
                    var type     = assembly.GetType("Dev2.Runtime.ServiceModel.Data.Resource");
                    var instance = Activator.CreateInstance(type, contents.ToXElement());

                    var resource = (IResource)instance;
                    if (resource.ResourceType == @"DbSource")
                    {
                        res.Message.Append(contents);
                    }
                    else
                    {
                        DoWorkflowServiceMessage(contents, res);
                    }
                }
            }
            catch (ServiceNotAuthorizedException ex)
            {
                res.Message  = ex.Message.ToStringBuilder();
                res.HasError = true;
                return(serializer.SerializeToBuilder(res));
            }
            catch (Exception e)
            {
                Dev2Logger.Error(string.Format(ErrorResource.ErrorGettingResourceDefinition, resourceId), e, GlobalConstants.WarewolfError);
            }

            if (!res.Message.IsNullOrEmpty())
            {
                var dev2XamlCleaner = new Dev2XamlCleaner();
                res.Message = dev2XamlCleaner.StripNaughtyNamespaces(res.Message);
            }
            if (prepairForDeployment)
            {
                try
                {
                    res.Message = DecryptAllPasswords(res.Message);
                }
                catch (CryptographicException e)
                {
                    Dev2Logger.Error(@"Encryption had issues.", e, GlobalConstants.WarewolfError);
                }
            }


            return(serializer.SerializeToBuilder(res));
        }
コード例 #3
0
        public StringBuilder GetResourceDefinition(IWorkspace theWorkspace, Dev2JsonSerializer serializer, ExecuteMessage res, bool prepairForDeployment, Guid resourceId)
        {
            try
            {
                var result = ResourceCatalog.Instance.GetResourceContents(theWorkspace.ID, resourceId);
                if (!result.IsNullOrEmpty())
                {
                    var tempResource = new Resource(result.ToXElement());
                    var resource     = tempResource;

                    if (resource.ResourceType == @"DbSource")
                    {
                        res.Message.Append(result);
                    }
                    else
                    {
                        DoWorkflowServiceMessage(result, res);
                    }
                }
            }
            catch (ServiceNotAuthorizedException ex)
            {
                res.Message  = ex.Message.ToStringBuilder();
                res.HasError = true;
                return(serializer.SerializeToBuilder(res));
            }
            catch (Exception e)
            {
                Dev2Logger.Error(string.Format(ErrorResource.ErrorGettingResourceDefinition, resourceId), e);
            }

            if (!res.Message.IsNullOrEmpty())
            {
                Dev2XamlCleaner dev2XamlCleaner = new Dev2XamlCleaner();
                res.Message = dev2XamlCleaner.StripNaughtyNamespaces(res.Message);
            }
            if (prepairForDeployment)
            {
                try
                {
                    res.Message = DecryptAllPasswords(res.Message);
                }
                catch (CryptographicException e)
                {
                    Dev2Logger.Error(@"Encryption had issues.", e);
                }
            }


            return(serializer.SerializeToBuilder(res));
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        /// <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(ErrorResource.NoResourceIdInTheIncomingData);
// ReSharper restore NotResolvedInText
                }

                var version = serializer.Deserialize <IVersionInfo>(values["versionInfo"]);
                Dev2Logger.Info("Get Version. " + version);
                StringBuilder tmp;
                Guid          resourceId = Guid.Empty;
                values.TryGetValue("resourceId", out tmp);
                if (tmp != null)
                {
                    resourceId = Guid.Parse(tmp.ToString());
                }
                var resourcePath = ResourceCatalog.GetResourcePath(theWorkspace.ID, resourceId);
                var result       = ServerVersionRepo.GetVersion(version, resourcePath);
                res.Message.Append(result);
                Dev2XamlCleaner dev2XamlCleaner = new Dev2XamlCleaner();
                res.Message = dev2XamlCleaner.StripNaughtyNamespaces(res.Message);


                return(serializer.SerializeToBuilder(res));
            }
            catch (Exception e)
            {
                Dev2Logger.Error(e);
                IExplorerRepositoryResult error = new ExplorerRepositoryResult(ExecStatus.Fail, e.Message);
                return(serializer.SerializeToBuilder(error));
            }
        }
コード例 #6
0
        /// <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

            if (GlobalConstants.RuntimeNamespaceClean)

            {
                xamlDefinition = new Dev2XamlCleaner().CleanServiceDef(xamlDefinition);
            }
            // End Mods


            var generation = 0;

            using (xamlStream = xamlDefinition.EncodeForXmlDocument())
            {
                var settings = new XamlXmlReaderSettings
                {
                    LocalAssembly = System.Reflection.Assembly.GetAssembly(typeof(VirtualizedContainerService))
                };
                using (var reader = new XamlXmlReader(xamlStream, settings))
                {
                    workflowActivity = ActivityXamlServices.Load(reader);
                }

                xamlStream.Seek(0, SeekOrigin.Begin);
                workflowPool.Clear();

                generation++;

                for (int i = 0; i < GlobalConstants._xamlPoolSize; i++)
                {
                    var activity = ActivityXamlServices.Load(xamlStream);
                    xamlStream.Seek(0, SeekOrigin.Begin);
                    workflowPool.Enqueue(new PooledServiceActivity(generation, activity));
                }
            }
        }
コード例 #7
0
        /// <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));
            }
        }
コード例 #8
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            try
            {
                var res = new ExecuteMessage {
                    HasError = false
                };

                string        serviceId            = null;
                bool          prepairForDeployment = false;
                StringBuilder tmp;
                values.TryGetValue("ResourceID", out tmp);

                if (tmp != null)
                {
                    serviceId = tmp.ToString();
                }

                values.TryGetValue("PrepairForDeployment", out tmp);

                if (tmp != null)
                {
                    prepairForDeployment = bool.Parse(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);
                    if (!result.IsNullOrEmpty())
                    {
                        var tempResource = new Resource(result.ToXElement());
                        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 ;)
                if (!res.Message.IsNullOrEmpty())
                {
                    Dev2XamlCleaner dev2XamlCleaner = new Dev2XamlCleaner();
                    res.Message = dev2XamlCleaner.StripNaughtyNamespaces(res.Message);
                }
                if (prepairForDeployment)
                {
                    res.Message = DecryptAllPasswords(res.Message);
                }

                Dev2JsonSerializer serializer = new Dev2JsonSerializer();
                return(serializer.SerializeToBuilder(res));
            }
            catch (Exception err)
            {
                Dev2Logger.Log.Error(err);
                throw;
            }
        }
コード例 #9
0
        /// <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));
            }
        }