Dev2.Runtime.ServiceModel.Data.RecordsetListHelper.SplitRecordsetAndFieldNames C# (CSharp) Method

SplitRecordsetAndFieldNames() public static method

public static SplitRecordsetAndFieldNames ( IPath path ) : string>.Tuple
path IPath
return string>.Tuple
        public static Tuple<string, string> SplitRecordsetAndFieldNames(IPath path)
        {
            var rsName = string.Empty;
            var fieldName = path.ActualPath.Replace(".", "");

            var indexOf = path.ActualPath.LastIndexOf("()", StringComparison.InvariantCultureIgnoreCase);
            if(indexOf != -1)
            {
                int length = path.ActualPath.Length;
                if(indexOf + 2 == length) // This means we have a primitive array as property
                {
                    var upperRecsetName = path.ActualPath.LastIndexOf(".", StringComparison.InvariantCultureIgnoreCase);
                    if(upperRecsetName == -1)
                    {
                        rsName = path.ActualPath.Substring(0, indexOf + 2).Replace("()", "").Replace(".", "_");
                    }
                    else
                    {
                        rsName = path.ActualPath.Substring(0, upperRecsetName).Replace("()", "").Replace(".", "_");
                        fieldName = path.ActualPath.Substring(upperRecsetName).Replace(".", "").Replace("()", "");
                    }
                }
                else
                {
                    rsName = path.ActualPath.Substring(0, indexOf + 2).Replace("()", "").Replace(".", "_");
                    fieldName = path.ActualPath.Substring(indexOf + 2).Replace(".", "");
                }
            }
            return new Tuple<string, string>(rsName, fieldName);
        }

Usage Example

Example #1
0
        // BUG 9626 - 2013.06.11 - TWR : refactored
        protected RecordsetList CreateOutputsRecordsetList(XElement action)
        {
            var result = new RecordsetList();

            var outputDescriptionStr = action.ElementSafe("OutputDescription");
            var paths = new List <IPath>();

            if (!string.IsNullOrEmpty(outputDescriptionStr))
            {
                var outputDescriptionSerializationService = OutputDescriptionSerializationServiceFactory.CreateOutputDescriptionSerializationService();
                var description = outputDescriptionSerializationService.Deserialize(outputDescriptionStr);

                if (description == null)
                {
                    // we need to handle old plugins ;)
                    outputDescriptionStr =
                        outputDescriptionStr.Replace("<JSON />", "")
                        .Replace("</Dev2XMLResult>", "")
                        .Replace("</InterrogationResult>", "")
                        .Replace("<InterrogationResult>", "")
                        .Replace("<Dev2XMLResult>", "");

                    description = outputDescriptionSerializationService.Deserialize(outputDescriptionStr);
                }

                // TODO : Get Result Coming Back ;)

                OutputDescription = description;

                if (description != null && description.DataSourceShapes.Count > 0)
                {
                    paths = description.DataSourceShapes[0].Paths;
                }
            }
            var xElement = action.Element("Outputs");

            if (xElement != null)
            {
                OutputSpecification = xElement.ToString();
            }
            foreach (var output in action.Descendants("Output"))
            {
                var rsName     = output.AttributeSafe("RecordsetName");
                var rsAlias    = output.AttributeSafe("Recordset"); // legacy - should be RecordsetAlias
                var fieldName  = output.AttributeSafe("OriginalName");
                var fieldAlias = output.AttributeSafe("MapsTo");

                var path = paths.FirstOrDefault(p => output.AttributeSafe("Value").Equals(p.OutputExpression, StringComparison.InvariantCultureIgnoreCase));
                if (path != null)
                {
                    var names = RecordsetListHelper.SplitRecordsetAndFieldNames(path);
                    if (string.IsNullOrEmpty(rsName))
                    {
                        rsName = names.Item1;
                    }
                    if (string.IsNullOrEmpty(fieldName))
                    {
                        fieldName = names.Item2;
                    }
                }

                var recordset = result.FirstOrDefault(r => r.Name == rsName);
                if (recordset == null)
                {
                    recordset = new Recordset {
                        Name = rsName
                    };
                    result.Add(recordset);
                }

                recordset.Fields.Add(new RecordsetField
                {
                    Name           = fieldName,
                    Alias          = fieldAlias,
                    RecordsetAlias = rsAlias,
                    Path           = path
                });
            }

            return(result);
        }