Beispiel #1
0
        /// <summary>
        /// Clones the specified type of.
        /// </summary>
        /// <param name="depth">The depth.</param>
        /// <param name="errorResult">The error result.</param>
        /// <param name="onlySystemTags">if set to <c>true</c> [only system tags].</param>
        /// <returns></returns>
        public IBinaryDataList Clone(enTranslationDepth depth, out ErrorResultTO errorResult, bool onlySystemTags)
        {
            // set parent child reference
            BinaryDataList result = new BinaryDataList {
                ParentUID = ParentUID
            };

            errorResult = new ErrorResultTO();

            // clone the dictionary
            foreach (string e in _templateDict.Keys)
            {
                if ((onlySystemTags && e.IndexOf(GlobalConstants.SystemTagNamespaceSearch, StringComparison.Ordinal) >= 0) || !onlySystemTags)
                {
                    string error;
                    // fetch this instance via clone, fetch toClone instance and merge the data
                    IBinaryDataListEntry cloned = _templateDict[e].Clone(depth, UID, out error);
                    // Copy over the intellisesne parts ;)
                    result._intellisenseParts = _intellisenseParts;
                    errorResult.AddError(error);
                    if (error == string.Empty)
                    {
                        // safe to add
                        result._templateDict[e] = cloned;
                    }
                }
            }

            // if only system tags, clean the intellisense parts out ;)
            if (onlySystemTags)
            {
                var parts =
                    result._intellisenseParts.Where(
                        c => c.Name.IndexOf(GlobalConstants.SystemTagNamespaceSearch, StringComparison.Ordinal) >= 0);
                result._intellisenseParts = parts.ToList();
            }


            return(result);
        }
        /// <summary>
        /// Clones the specified type of.
        /// </summary>
        /// <param name="depth">The depth.</param>
        /// <param name="errorResult">The error result.</param>
        /// <param name="onlySystemTags">if set to <c>true</c> [only system tags].</param>
        /// <returns></returns>
        public IBinaryDataList Clone(enTranslationDepth depth, out ErrorResultTO errorResult, bool onlySystemTags)
        {
            // set parent child reference
            BinaryDataList result = new BinaryDataList { ParentUID = ParentUID };

            errorResult = new ErrorResultTO();

            // clone the dictionary
            foreach(string e in _templateDict.Keys)
            {

                if((onlySystemTags && e.IndexOf(GlobalConstants.SystemTagNamespaceSearch, StringComparison.Ordinal) >= 0) || !onlySystemTags)
                {
                    string error;
                    // fetch this instance via clone, fetch toClone instance and merge the data
                    IBinaryDataListEntry cloned = _templateDict[e].Clone(depth, UID, out error);
                    // Copy over the intellisesne parts ;)
                    result._intellisenseParts = _intellisenseParts;
                    errorResult.AddError(error);
                    if(error == string.Empty)
                    {
                        // safe to add
                        result._templateDict[e] = cloned;
                    }
                }
            }

            // if only system tags, clean the intellisense parts out ;)
            if(onlySystemTags)
            {
                var parts =
                    result._intellisenseParts.Where(
                        c => c.Name.IndexOf(GlobalConstants.SystemTagNamespaceSearch, StringComparison.Ordinal) >= 0);
                result._intellisenseParts = parts.ToList();
            }


            return result;
        }
Beispiel #3
0
        /// <summary>
        /// Merges the into instance.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="typeOf">The type of.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="errorResult">The error result.</param>
        private void MergeIntoInstance(IBinaryDataList obj, enDataListMergeTypes typeOf, enTranslationDepth depth, out ErrorResultTO errorResult)
        {
            errorResult = new ErrorResultTO();
            BinaryDataList toClone = (BinaryDataList)obj;

            if (obj.ParentUID != UID)
            {
                ParentUID = toClone.ParentUID;
            }
            IList <string> lamdaErrors  = new List <string>();
            IList <string> errorList    = new List <string>();
            IList <string> unionKeyHits = new List <string>();

            // clone the dictionary
            IList <string> tmp = _templateDict.Keys.ToList();  // must be this way since we modify the collection...

            foreach (string e in tmp)
            {
                string error;
                IBinaryDataListEntry cloned;

                if (typeOf == enDataListMergeTypes.Union)
                {
                    // fetch this instance via clone, fetch toClone instance and merge the data
                    IBinaryDataListEntry fetchTmp;
                    if (toClone._templateDict.TryGetValue(e, out fetchTmp))
                    {
                        unionKeyHits.Add(e);
                        cloned = fetchTmp.Clone(depth, UID, out error);
                        if (error != string.Empty)
                        {
                            lamdaErrors.Add(error);
                        }
                        else
                        {
                            DepthMerge(depth, cloned, e, out lamdaErrors);
                        }

                        // We need to ensure that the intellisense dictionary is populated with this key ;)
                    }
                }
                else if (typeOf == enDataListMergeTypes.Intersection)
                {
                    IBinaryDataListEntry toFetch;
                    if (toClone.TryGetEntry(e, out toFetch, out error))
                    {
                        cloned = toClone._templateDict[e].Clone(depth, UID, out error);
                        if (error != string.Empty)
                        {
                            lamdaErrors.Add(error);
                        }
                        else
                        {
                            DepthMerge(depth, cloned, e, out lamdaErrors);
                        }
                    }
                    else
                    {
                        lamdaErrors.Add("Missing DataList item [ " + e + " ] ");
                    }
                }

                // compile error list ?!
                foreach (string err in lamdaErrors)
                {
                    errorList.Add(err);
                }
                lamdaErrors.Clear();
            }


            // now process key misses for union
            if (typeOf == enDataListMergeTypes.Union)
            {
                //toClone._templateDict.Keys
                foreach (string k in (toClone._templateDict.Keys.ToArray().Except(unionKeyHits)))
                {
                    string error;
                    IBinaryDataListEntry cloned = toClone._templateDict[k].Clone(depth, UID, out error);
                    if (error != string.Empty)
                    {
                        lamdaErrors.Add(error);
                    }
                    else
                    {
                        DepthMerge(depth, cloned, k, out lamdaErrors);
                    }
                }
            }

            // now build the silly composite object since lamba is an daft construct
            // how about proper exception handling MS?!
            foreach (string err in errorList)
            {
                errorResult.AddError(err);
            }
        }
        // internal to impl api methods
        private IBinaryDataList ConvertTo(byte[] input, StringBuilder targetShape, out ErrorResultTO errors, bool onlyMapInputs)
        {
            errors = new ErrorResultTO();
            string payload = Encoding.UTF8.GetString(input);

            IBinaryDataList result = new BinaryDataList();
            TranslatorUtils tu = new TranslatorUtils();

            // build shape
            if(targetShape == null)
            {
                errors.AddError("Null payload or shape");
            }
            else
            {
                ErrorResultTO invokeErrors;
                result = tu.TranslateShapeToObject(targetShape, true, out invokeErrors);
                errors.MergeErrors(invokeErrors);

                // populate the shape 
                if(payload != string.Empty)
                {
                    try
                    {
                        string toLoad = DataListUtil.StripCrap(payload); // clean up the rubish ;)
                        XmlDocument xDoc = new XmlDocument();

                        // BUG 9626 - 2013.06.11 - TWR: ensure our DocumentElement
                        toLoad = string.Format("<Tmp{0}>{1}</Tmp{0}>", Guid.NewGuid().ToString("N"), toLoad);
                        xDoc.LoadXml(toLoad);

                        if(xDoc.DocumentElement != null)
                        {
                            XmlNodeList children = xDoc.DocumentElement.ChildNodes;

                            IDictionary<string, int> indexCache = new Dictionary<string, int>();

                            // BUG 9626 - 2013.06.11 - TWR: refactored for recursion
                            TryConvert(children, result, indexCache, errors, onlyMapInputs);
                        }

                        // Transfer System Tags
                        for(int i = 0; i < TranslationConstants.systemTags.Length; i++)
                        {
                            string key = TranslationConstants.systemTags.GetValue(i).ToString();
                            string query = String.Concat("//", key);
                            XmlNode n = xDoc.SelectSingleNode(query);

                            // try system namespace tags ;)
                            if(n == null)
                            {
                                var values = "//" + DataListUtil.BuildSystemTagForDataList(key, false);
                                query = values;
                                n = xDoc.SelectSingleNode(query);
                            }

                            if(n != null && !string.IsNullOrEmpty(n.InnerXml))
                            {
                                string bkey = DataListUtil.BuildSystemTagForDataList(key, false);
                                string error;
                                IBinaryDataListEntry sysEntry;
                                if(result.TryGetEntry(bkey, out sysEntry, out error))
                                {
                                    sysEntry.TryPutScalar(Dev2BinaryDataListFactory.CreateBinaryItem(n.InnerXml, bkey), out error);
                                }
                            }
                        }
                    }
                    catch(Exception e)
                    {
                        // if use passed in empty input they only wanted the shape ;)
                        if(input.Length > 0)
                        {
                            errors.AddError(e.Message);
                        }
                    }
                }
            }
            return result;
        }