public WebService()
 {
     ResourceID = Guid.Empty;
     ResourceType = ResourceType.WebService;
     Source = new WebSource();
     Recordsets = new RecordsetList();
     Method = new ServiceMethod();
 }
示例#2
0
 public PluginService()
 {
     ResourceID = Guid.Empty;
     ResourceType = ResourceType.PluginService;
     Source = new PluginSource();
     Recordsets = new RecordsetList();
     Method = new ServiceMethod();
 }
示例#3
0
 public WebService()
 {
     ResourceID = Guid.Empty;
     ResourceType = Common.Interfaces.Data.ResourceType.WebService;
     Source = new WebSource();
     Recordsets = new RecordsetList();
     Method = new ServiceMethod();
 }
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            ExecuteMessage     msg        = new ExecuteMessage();
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();

            try
            {
                Dev2Logger.Info("Save Plugin Service");
                StringBuilder resourceDefinition;


                values.TryGetValue("PluginService", out resourceDefinition);

                IPluginService serviceDef = serializer.Deserialize <IPluginService>(resourceDefinition);
                // ReSharper disable MaximumChainedReferences
                // ReSharper restore MaximumChainedReferences
                var source = ResourceCatalogue.GetResource <PluginSource>(GlobalConstants.ServerWorkspaceID, serviceDef.Source.Id);
                var output = new List <MethodOutput>(serviceDef.OutputMappings.Select(a => new MethodOutput(a.MappedFrom, a.MappedTo, "", false, a.RecordSetName, false, "", false, "", false)));
                var recset = new RecordsetList();
                var rec    = new Recordset();
                rec.Fields.AddRange(new List <RecordsetField>(serviceDef.OutputMappings.Select(a => new RecordsetField {
                    Name = a.MappedFrom, Alias = a.MappedTo, RecordsetAlias = a.RecordSetName, Path = new DataTablePath(a.RecordSetName, a.MappedFrom)
                })));
                recset.Add(rec);
                var parameters = serviceDef.Inputs?.Select(a => new MethodParameter {
                    EmptyToNull = a.EmptyIsNull, IsRequired = a.RequiredField, Name = a.Name, Value = a.Value, TypeName = a.TypeName
                }).ToList() ?? new List <MethodParameter>();
                var constructorParams = serviceDef.Constructor.Inputs.Select(input => new ConstructorParameter()
                {
                    Name = input.Name, Value = input.Value, TypeName = input.TypeName, EmptyToNull = input.EmptyToNull, IsRequired = input.IsRequired, ShortTypeName = Type.GetType(input.TypeName)?.FullName
                });
                var res = new PluginService
                {
                    Constructor  = new ServiceConstructor(serviceDef.Constructor.ConstructorName, constructorParams, null),
                    Method       = new ServiceMethod(serviceDef.Name, serviceDef.Name, parameters, null, output, serviceDef.Action.Method),
                    ResourceName = serviceDef.Name,
                    ResourceID   = serviceDef.Id,
                    Source       = source,
                    Recordsets   = recset,
                    Namespace    = serviceDef.Action.FullName
                };

                ResourceCatalog.Instance.SaveResource(GlobalConstants.ServerWorkspaceID, res, serviceDef.Path);
                ServerExplorerRepo.UpdateItem(res);

                msg.HasError = false;
            }

            catch (Exception err)
            {
                msg.HasError = true;
                msg.Message  = new StringBuilder(err.Message);
                Dev2Logger.Error(err);
            }

            return(serializer.SerializeToBuilder(msg));
        }
        public void ThenTheMappingShouldContainThePrimitiveArray()
        {
            var           webService    = ScenarioContext.Current.Get <ServiceModel.Data.WebService>("WebService");
            RecordsetList recordsetList = webService.Recordsets;

            Assert.IsNotNull(recordsetList);
            var departmentsRecordSet = recordsetList.Find(recordset => recordset.Name == "Departments");

            Assert.IsNotNull(departmentsRecordSet);
            List <RecordsetField> departmentFields = departmentsRecordSet.Fields;

            Assert.AreEqual(2, departmentFields.Count);
            RecordsetField departmentNameField = departmentFields.Find(field => field.Name == "Name");

            Assert.IsNotNull(departmentNameField);
            RecordsetField departmentAreasField = departmentFields.Find(field => field.Name == "Areas");

            Assert.IsNotNull(departmentAreasField);
        }
示例#6
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            var msg        = new ExecuteMessage();
            var serializer = new Dev2JsonSerializer();

            try
            {
                Dev2Logger.Info("Save Resource Service", GlobalConstants.WarewolfInfo);


                values.TryGetValue("Webservice", out StringBuilder resourceDefinition);

                var src = serializer.Deserialize <IWebService>(resourceDefinition);

                var parameters = src.Inputs?.Select(a => new MethodParameter()
                {
                    EmptyToNull = a.EmptyIsNull, IsRequired = a.RequiredField, Name = a.Name, Value = a.Value
                }).ToList() ?? new List <MethodParameter>();

                var source = ResourceCatalog.Instance.GetResource <WebSource>(GlobalConstants.ServerWorkspaceID, src.Source.Id);
                var output = new List <MethodOutput>(src.OutputMappings.Select(a => new MethodOutput(a.MappedFrom, a.MappedTo, "", false, a.RecordSetName, false, "", false, "", false)));
                var recset = new Recordset();
                recset.Fields.AddRange(new List <RecordsetField>(src.OutputMappings.Select(a => new RecordsetField {
                    Name = a.MappedFrom, Alias = a.MappedTo, RecordsetAlias = a.RecordSetName
                })));
                var serviceOutputMapping = src.OutputMappings.FirstOrDefault(mapping => !string.IsNullOrEmpty(mapping.RecordSetName));
                if (serviceOutputMapping != null)
                {
                    recset.Name = serviceOutputMapping.RecordSetName;
                }
                var recordsetList = new RecordsetList {
                    recset
                };
                var res = new WebService
                {
                    Method          = new ServiceMethod(),
                    RequestUrl      = string.Concat(src.SourceUrl, src.RequestUrl),
                    ResourceName    = src.Name,
                    ResourceID      = src.Id,
                    RequestBody     = src.PostData,
                    Recordsets      = recordsetList,
                    Source          = source,
                    Headers         = src.Headers,
                    RequestMethod   = src.Method,
                    RequestResponse = src.Response
                };
                res.Method.Name              = src.Name;
                res.Method.Parameters        = parameters;
                res.Method.Outputs           = output;
                res.Method.OutputDescription = res.GetOutputDescription();
                ResourceCatalog.Instance.SaveResource(GlobalConstants.ServerWorkspaceID, res, src.Path);
                ServerExplorerRepo.UpdateItem(res);

                msg.HasError = false;
            }

            catch (Exception err)
            {
                msg.HasError = true;
                msg.Message  = new StringBuilder(err.Message);
                Dev2Logger.Error(err, GlobalConstants.WarewolfError);
            }

            return(serializer.SerializeToBuilder(msg));
        }
        public static RecordsetList ToRecordsetList(this IOutputDescription outputDescription, RecordsetList currentList = null, string defaultFieldName = "")
        {
            if(outputDescription == null || outputDescription.DataSourceShapes == null || outputDescription.DataSourceShapes.Count == 0)
            {
                throw new Exception("Error retrieving shape from service output.");
            }

            var result = currentList ?? new RecordsetList();
            var currentFields = new List<RecordsetField>();

            #region Create a copy of the current list's fields so that we don't lose the user-defined aliases.

            foreach(var rs in result)
            {
                currentFields.AddRange(rs.Fields);
                rs.Fields.Clear();
            }

            #endregion

            var paths = outputDescription.DataSourceShapes[0].Paths;

            foreach(var path in paths)
            {
                var names = SplitRecordsetAndFieldNames(path);
                var rsName = names.Item1;
                var rsAlias = rsName;
                var fieldName = names.Item2;
                if(string.IsNullOrEmpty(fieldName) && string.IsNullOrEmpty(defaultFieldName))
                {
                    continue;
                }

                if(string.IsNullOrEmpty(fieldName) && !string.IsNullOrEmpty(defaultFieldName))
                {
                    fieldName = defaultFieldName;
                }

                // Bug 10532 - Amend to remove : from the alias ;)
                var fieldAlias = fieldName.Replace(":", "");

                var pathLoop = path;
                var rsField = currentFields.FirstOrDefault(f => f.Path == pathLoop) ?? new RecordsetField { Path = path, Alias = fieldAlias, RecordsetAlias = rsAlias };
                rsField.Name = fieldName;

                var rs = result.FirstOrDefault(r => r.Name == rsName);
                if(rs == null)
                {
                    rs = new Recordset { Name = rsName };
                    result.Add(rs);
                }
                var fieldIndex = rs.Fields.Count;
                rs.Fields.Add(rsField);

                var data = path.SampleData.Split(',');
                for(var recordIndex = 0; recordIndex < data.Length; recordIndex++)
                {
                    rs.SetValue(recordIndex, fieldIndex, data[recordIndex]);
                }
            }
            return result;
        }
示例#8
0
        public void ExecuteTest()
        {
            ViewErrors           = new List <IActionableErrorInfo>();
            Errors               = new List <string>();
            OutputArea.IsEnabled = true;
            TestResults          = null;
            IsTesting            = true;

            try
            {
                var testResult      = _serverModel.TestService(Model);
                var serializer      = new Dev2JsonSerializer();
                var responseService = serializer.Deserialize <RecordsetListWrapper>(testResult);
                if (responseService != null)
                {
                    if (responseService.RecordsetList.Any(recordset => recordset.HasErrors))
                    {
                        var errorMessage = string.Join(Environment.NewLine, responseService.RecordsetList.Select(recordset => recordset.ErrorMessage));
                        throw new Exception(errorMessage);
                    }
                    TestResults    = responseService.SerializedResult;
                    _recordsetList = responseService.RecordsetList;
                    if (_recordsetList.Any(recordset => recordset.HasErrors))
                    {
                        var errorMessage = string.Join(Environment.NewLine, _recordsetList.Select(recordset => recordset.ErrorMessage));
                        throw new Exception(errorMessage);
                    }
                    Description = responseService.Description;

                    var outputMapping = _recordsetList.SelectMany(recordset => recordset.Fields, (recordset, recordsetField) =>
                    {
                        var serviceOutputMapping = new ServiceOutputMapping(recordsetField.Name, recordsetField.Alias, recordset.Name)
                        {
                            Path = recordsetField.Path
                        };
                        return(serviceOutputMapping);
                    }).Cast <IServiceOutputMapping>().ToList();

                    _generateOutputArea.IsEnabled = true;
                    _generateOutputArea.Outputs   = outputMapping;
                }
                if (TestResults != null)
                {
                    TestResultsAvailable = TestResults != null;
                    IsTesting            = false;
                    TestPassed           = true;
                    TestFailed           = false;
                }
            }
            catch (JsonSerializationException)
            {
                OutputArea.Outputs = new List <IServiceOutputMapping> {
                    new ServiceOutputMapping("Result", "[[Result]]", "")
                };
            }
            catch (Exception e)
            {
                Errors.Add(e.Message);
                IsTesting  = false;
                TestPassed = false;
                TestFailed = true;
                _generateOutputArea.IsEnabled = false;
                _generateOutputArea.Outputs   = new List <IServiceOutputMapping>();
                _viewmodel.ErrorMessage(e, true);
            }
        }
        public void ExecuteTest()
        {
            ViewErrors           = new List <IActionableErrorInfo>();
            Errors               = new List <string>();
            OutputArea.IsEnabled = true;
            TestResults          = null;
            IsTesting            = true;

            try
            {
                var testResult = _serverModel.TestService(Model);
                var serializer = new Dev2JsonSerializer();
                using (var responseService = serializer.Deserialize <WebService>(testResult))
                {
                    TestResults    = responseService.RequestResponse;
                    _recordsetList = responseService.Recordsets;
                    if (_recordsetList.Any(recordset => recordset.HasErrors))
                    {
                        var errorMessage = string.Join(Environment.NewLine, _recordsetList.Select(recordset => recordset.ErrorMessage));
                        throw new Exception(errorMessage);
                    }

                    Description = responseService.GetOutputDescription();
                }
                // ReSharper disable MaximumChainedReferences
                var outputMapping = _recordsetList.SelectMany(recordset => recordset.Fields, (recordset, recordsetField) =>
                {
                    var serviceOutputMapping = new ServiceOutputMapping(recordsetField.Name, recordsetField.Alias, recordset.Name)
                    {
                        Path = recordsetField.Path
                    };
                    return(serviceOutputMapping);
                }).Cast <IServiceOutputMapping>().ToList();
                // ReSharper restore MaximumChainedReferences
                _generateOutputArea.IsEnabled = true;
                _generateOutputArea.Outputs   = outputMapping;


                if (TestResults != null)
                {
                    TestResultsAvailable     = TestResults != null;
                    IsTesting                = false;
                    TestPassed               = true;
                    TestFailed               = false;
                    OutputCountExpandAllowed = true;
                }
            }
            catch (JsonSerializationException)
            {
                OutputArea.Outputs = new List <IServiceOutputMapping> {
                    new ServiceOutputMapping("Result", "[[Result]]", "")
                };
            }
            catch (Exception e)
            {
                Errors.Add(e.Message);
                IsTesting  = false;
                TestPassed = false;
                TestFailed = true;
                _generateOutputArea.IsEnabled = false;
                _generateOutputArea.Outputs   = new List <IServiceOutputMapping>();
                _viewmodel.ErrorMessage(e, true);
            }
            PasteResponseVisible = false;
        }