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));
        }
        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));
        }
        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");
        }
Exemple #4
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));
            }
        }
Exemple #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("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));
            }
        }
Exemple #6
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;
            }
        }
        /// <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));
            }
        }