コード例 #1
0
        public DataListTranslatedPayloadTO ConvertFrom(IBinaryDataList payload, out ErrorResultTO errors)
        {
            if(payload == null)
            {
                throw new ArgumentNullException("payload");
            }

            TranslatorUtils tu = new TranslatorUtils();

            StringBuilder result = new StringBuilder("<" + RootTag + ">");
            errors = new ErrorResultTO();

            IList<string> itemKeys = payload.FetchAllUserKeys();

            foreach(string key in itemKeys)
            {
                IBinaryDataListEntry entry;
                string error;
                if(payload.TryGetEntry(key, out entry, out error))
                {

                    if(entry.IsRecordset && !entry.IsEmpty())
                    {

                        var idxItr = entry.FetchRecordsetIndexes();

                        while(idxItr.HasMore())
                        {
                            var i = idxItr.FetchNextIndex();
                            IList<IBinaryDataListItem> rowData = entry.FetchRecordAt(i, out error);
                            errors.AddError(error);

                            result.Append("<");
                            result.Append(entry.Namespace);
                            result.Append(">");

                            foreach(IBinaryDataListItem col in rowData)
                            {
                                string fName = col.FieldName;

                                result.Append("<");
                                result.Append(fName);
                                result.Append(">");
                                try
                                {
                                    result.Append(tu.FullCleanForEmit(col.TheValue));
                                }
                                // ReSharper disable EmptyGeneralCatchClause
                                catch(Exception)
                                // ReSharper restore EmptyGeneralCatchClause
                                {
                                }
                                result.Append("</");
                                result.Append(fName);
                                result.Append(">");
                            }

                            result.Append("</");
                            result.Append(entry.Namespace);
                            result.Append(">");
                        }

                    }
                    else if(!entry.IsRecordset)
                    {
                        string fName = entry.Namespace;
                        IBinaryDataListItem val = entry.FetchScalar();
                        if(val != null)
                        {
                            result.Append("<");
                            result.Append(fName);
                            result.Append(">");
                            try
                            {
                                result.Append(tu.FullCleanForEmit(val.TheValue));
                            }
                            // ReSharper disable EmptyGeneralCatchClause
                            catch(Exception)
                            // ReSharper restore EmptyGeneralCatchClause
                            {
                            }
                            result.Append("</");
                            result.Append(fName);
                            result.Append(">");
                        }
                    }
                }

            }

            result.Append("</" + RootTag + ">");

            DataListTranslatedPayloadTO tmp = new DataListTranslatedPayloadTO(result.ToString());

            return tmp;
        }
        public DataListTranslatedPayloadTO ConvertFrom(IBinaryDataList payload, out ErrorResultTO errors)
        {
            if(payload == null)
            {
                throw new ArgumentNullException("payload");
            }

            TranslatorUtils tu = new TranslatorUtils();

            StringBuilder result = new StringBuilder("<" + RootTag + ">");
            errors = new ErrorResultTO();

            IList<string> itemKeys = payload.FetchAllUserKeys();

            foreach(string key in itemKeys)
            {
                IBinaryDataListEntry entry;
                string error;
                if(payload.TryGetEntry(key, out entry, out error))
                {

                    if(entry.IsRecordset && !entry.IsEmpty())
                    {

                        var idxItr = entry.FetchRecordsetIndexes();

                        while(idxItr.HasMore())
                        {
                            var i = idxItr.FetchNextIndex();
                            IList<IBinaryDataListItem> rowData = entry.FetchRecordAt(i, out error);
                            errors.AddError(error);

                            result.Append("<");
                            result.Append(entry.Namespace);
                            result.Append(">");

                            foreach(IBinaryDataListItem col in rowData)
                            {
                                string fName = col.FieldName;

                                result.Append("<");
                                result.Append(fName);
                                result.Append(">");
                                try
                                {
                                    result.Append(tu.FullCleanForEmit(col.TheValue));
                                }
                                // ReSharper disable EmptyGeneralCatchClause
                                catch(Exception)
                                // ReSharper restore EmptyGeneralCatchClause
                                {
                                }
                                result.Append("</");
                                result.Append(fName);
                                result.Append(">");
                            }

                            result.Append("</");
                            result.Append(entry.Namespace);
                            result.Append(">");
                        }

                    }
                    else if(!entry.IsRecordset)
                    {
                        string fName = entry.Namespace;
                        IBinaryDataListItem val = entry.FetchScalar();
                        if(val != null)
                        {
                            result.Append("<");
                            result.Append(fName);
                            result.Append(">");
                            try
                            {
                                result.Append(tu.FullCleanForEmit(val.TheValue));
                            }
                            // ReSharper disable EmptyGeneralCatchClause
                            catch(Exception)
                            // ReSharper restore EmptyGeneralCatchClause
                            {
                            }
                            result.Append("</");
                            result.Append(fName);
                            result.Append(">");
                        }
                    }
                }

            }

            result.Append("</" + RootTag + ">");

            DataListTranslatedPayloadTO tmp = new DataListTranslatedPayloadTO(result.ToString());

            return tmp;
        }
コード例 #3
0
        public StringBuilder ConvertAndFilter(IBinaryDataList payload, StringBuilder filterShape, out ErrorResultTO errors)
        {
            if(payload == null)
            {
                throw new ArgumentNullException("payload");
            }

            StringBuilder result = new StringBuilder("<" + RootTag + ">");
            errors = new ErrorResultTO();

            ErrorResultTO invokeErrors;
            TranslatorUtils tu = new TranslatorUtils();

            IBinaryDataList targetDl = _tu.TranslateShapeToObject(filterShape, false, out invokeErrors);
            errors.MergeErrors(invokeErrors);

            IList<string> itemKeys = targetDl.FetchAllKeys();

            foreach(string key in itemKeys)
            {
                IBinaryDataListEntry entry;
                IBinaryDataListEntry tmpEntry;
                string error;
                if(payload.TryGetEntry(key, out entry, out error) && targetDl.TryGetEntry(key, out tmpEntry, out error))
                {

                    if(entry.IsRecordset)
                    {
                        var idxItr = entry.FetchRecordsetIndexes();

                        while(idxItr.HasMore())
                        {
                            var i = idxItr.FetchNextIndex();

                            IList<IBinaryDataListItem> rowData = entry.FetchRecordAt(i, out error);
                            if(error != string.Empty)
                            {
                                errors.AddError(error);
                            }

                            result.Append("<");
                            result.Append(entry.Namespace);
                            result.Append(" ");
                            result.Append(GlobalConstants.RowAnnotation);
                            result.Append("=");
                            result.Append("\"" + i + "\"");
                            result.Append(">");

                            foreach(IBinaryDataListItem col in rowData)
                            {
                                IBinaryDataListItem col1 = col;
                                if(tmpEntry.Columns.Any((c => c.ColumnName == col1.FieldName)))
                                {
                                    string fName = col.FieldName;

                                    result.Append("<");
                                    result.Append(fName);
                                    result.Append(">");
                                    try
                                    {
                                        result.Append(tu.FullCleanForEmit(col.TheValue));
                                    }
                                    // ReSharper disable EmptyGeneralCatchClause
                                    catch(Exception)
                                    // ReSharper restore EmptyGeneralCatchClause
                                    {
                                    }
                                    result.Append("</");
                                    result.Append(fName);
                                    result.Append(">");
                                }
                            }

                            result.Append("</");
                            result.Append(entry.Namespace);
                            result.Append(">");
                        }
                    }
                    else
                    {
                        string fName = entry.Namespace;
                        IBinaryDataListItem val = entry.FetchScalar();

                        if(val != null)
                        {
                            result.Append("<");
                            result.Append(fName);
                            result.Append(">");
                            try
                            {
                                result.Append(entry.Namespace != GlobalConstants.ManagementServicePayload ? tu.FullCleanForEmit(val.TheValue) : val.TheValue);
                            }
                            // ReSharper disable EmptyGeneralCatchClause
                            catch
                            // ReSharper restore EmptyGeneralCatchClause
                            {
                            }
                            result.Append("</");
                            result.Append(fName);
                            result.Append(">");
                        }
                    }
                }

            }

            result.Append("</" + RootTag + ">");

            return result;
        }
        public StringBuilder ConvertAndFilter(IBinaryDataList payload, StringBuilder filterShape, out ErrorResultTO errors)
        {
            if(payload == null)
            {
                throw new ArgumentNullException("payload");
            }

            StringBuilder result = new StringBuilder("<" + RootTag + ">");
            errors = new ErrorResultTO();

            ErrorResultTO invokeErrors;
            TranslatorUtils tu = new TranslatorUtils();

            IBinaryDataList targetDl = _tu.TranslateShapeToObject(filterShape, false, out invokeErrors);
            errors.MergeErrors(invokeErrors);

            IList<string> itemKeys = targetDl.FetchAllKeys();

            foreach(string key in itemKeys)
            {
                IBinaryDataListEntry entry;
                IBinaryDataListEntry tmpEntry;
                string error;
                if(payload.TryGetEntry(key, out entry, out error) && targetDl.TryGetEntry(key, out tmpEntry, out error))
                {

                    if(entry.IsRecordset)
                    {
                        var idxItr = entry.FetchRecordsetIndexes();

                        while(idxItr.HasMore())
                        {
                            var i = idxItr.FetchNextIndex();

                            IList<IBinaryDataListItem> rowData = entry.FetchRecordAt(i, out error);
                            if(error != string.Empty)
                            {
                                errors.AddError(error);
                            }

                            result.Append("<");
                            result.Append(entry.Namespace);
                            result.Append(" ");
                            result.Append(GlobalConstants.RowAnnotation);
                            result.Append("=");
                            result.Append("\"" + i + "\"");
                            result.Append(">");

                            foreach(IBinaryDataListItem col in rowData)
                            {
                                IBinaryDataListItem col1 = col;
                                if(tmpEntry.Columns.Any((c => c.ColumnName == col1.FieldName)))
                                {
                                    string fName = col.FieldName;

                                    result.Append("<");
                                    result.Append(fName);
                                    result.Append(">");
                                    try
                                    {
                                        result.Append(tu.FullCleanForEmit(col.TheValue));
                                    }
                                    // ReSharper disable EmptyGeneralCatchClause
                                    catch(Exception)
                                    // ReSharper restore EmptyGeneralCatchClause
                                    {
                                    }
                                    result.Append("</");
                                    result.Append(fName);
                                    result.Append(">");
                                }
                            }

                            result.Append("</");
                            result.Append(entry.Namespace);
                            result.Append(">");
                        }
                    }
                    else
                    {
                        string fName = entry.Namespace;
                        IBinaryDataListItem val = entry.FetchScalar();

                        if(val != null)
                        {
                            result.Append("<");
                            result.Append(fName);
                            result.Append(">");
                            try
                            {
                                result.Append(entry.Namespace != GlobalConstants.ManagementServicePayload ? tu.FullCleanForEmit(val.TheValue) : val.TheValue);
                            }
                            // ReSharper disable EmptyGeneralCatchClause
                            catch
                            // ReSharper restore EmptyGeneralCatchClause
                            {
                            }
                            result.Append("</");
                            result.Append(fName);
                            result.Append(">");
                        }
                    }
                }

            }

            result.Append("</" + RootTag + ">");

            return result;
        }