示例#1
0
        /// <summary>
        /// Fetches the next row data.
        /// If scalar repeat
        /// If RS append notation repeat
        /// </summary>
        /// <returns></returns>
        public IList <IBinaryDataListItem> FetchNextRowData()
        {
            IList <IBinaryDataListItem> result = new List <IBinaryDataListItem>();

            if (_entry.IsRecordset)
            {
                string error;
                if (_idxItr.HasMore())
                {
                    var idx = _idxItr.FetchNextIndex();
                    result = _entry.FetchRecordAt(idx, out error);
                }
                else
                {
                    result = _entry.FetchRecordAt(_idxItr.MaxIndex(), out error);
                }
            }
            else
            {
                try
                {
                    result = new List <IBinaryDataListItem> {
                        _entry.FetchScalar()
                    };
                }
                catch (Exception ex)
                {
                    Dev2Logger.Log.Error(ex);
                    // We trap because we want the result if successful else default to empty list
                }
                _iterIdx++;
            }

            return(result);
        }
示例#2
0
 public void Merge(IBinaryDataListEntry toMerge, out string error)
 {
     error = string.Empty;
     if (IsRecordset && toMerge.IsRecordset)
     {
         IIndexIterator ii = toMerge.FetchRecordsetIndexes();
         while (ii.HasMore())
         {
             int next = ii.FetchNextIndex();
             // merge toMerge into this
             foreach (IBinaryDataListItem item in toMerge.FetchRecordAt(next, out error))
             {
                 TryAppendRecordItem(item, out error);
             }
         }
     }
     else if (!IsRecordset && !toMerge.IsRecordset)
     {
         TryPutScalar(toMerge.FetchScalar(), out error); // over write this with toMerge
     }
     else
     {
         error = "Type mis-match, one side is Recordset while the other is a scalar";
     }
 }
        void GetValues(IBinaryDataListEntry dlEntry, string value, int iterCnt, IIndexIterator idxItr, enRecordsetIndexType indexType, IList <IDebugItemResult> results, string initExpression, string labelText, string fieldName = null)
        {
            string error;
            int    index = idxItr.FetchNextIndex();

            if (string.IsNullOrEmpty(fieldName))
            {
                IList <IBinaryDataListItem> record = dlEntry.FetchRecordAt(index, out error);
                // ReSharper disable LoopCanBeConvertedToQuery
                foreach (IBinaryDataListItem recordField in record)
                // ReSharper restore LoopCanBeConvertedToQuery
                {
                    GetValue(dlEntry, value, iterCnt, fieldName, indexType, results, initExpression, recordField, index, false, labelText);
                }
            }
            else
            {
                IBinaryDataListItem recordField = dlEntry.TryFetchRecordsetColumnAtIndex(fieldName, index, out error);
                bool ignoreCompare = false;

                if (recordField == null)
                {
                    if (dlEntry.Columns.Count == 1)
                    {
                        recordField   = dlEntry.TryFetchIndexedRecordsetUpsertPayload(index, out error);
                        ignoreCompare = true;
                    }
                }

                GetValue(dlEntry, value, iterCnt, fieldName, indexType, results, initExpression, recordField, index, ignoreCompare, labelText);
            }
        }
        public void UpsertWhereListStringExpectUpsertCorrectlyMultipleRecordset()
        {
            //------------Setup for test--------------------------
            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();
            IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder();

            toUpsert.Add("[[rec().f1]]", new List <string> {
                "test11", "test12"
            });
            toUpsert.Add("[[rec().f2]]", new List <string> {
                "test21", "test22"
            });
            IBinaryDataList dataList = Dev2BinaryDataListFactory.CreateDataList();
            string          creationError;

            dataList.TryCreateRecordsetTemplate("rec", "recset", new List <Dev2Column> {
                DataListFactory.CreateDev2Column("f1", "f1"), DataListFactory.CreateDev2Column("f2", "f2")
            }, true, out creationError);
            ErrorResultTO localErrors;

            compiler.PushBinaryDataList(dataList.UID, dataList, out localErrors);
            //------------Execute Test---------------------------
            compiler.Upsert(dataList.UID, toUpsert, out _errors);
            //------------Assert Results-------------------------
            IList <IBinaryDataListEntry> binaryDataListEntries = dataList.FetchRecordsetEntries();
            IBinaryDataListEntry         binaryDataListEntry   = binaryDataListEntries[0];
            string errString;
            IList <IBinaryDataListItem> binaryDataListItems = binaryDataListEntry.FetchRecordAt(1, out errString);
            IBinaryDataListItem         binaryDataListItem  = binaryDataListItems[0];
            IBinaryDataListItem         binaryDataListItem2 = binaryDataListItems[1];
            string theValue = binaryDataListItem.TheValue;

            Assert.AreEqual("test11", theValue);
            theValue = binaryDataListItem2.TheValue;
            Assert.AreEqual("test21", theValue);
            binaryDataListItems = binaryDataListEntry.FetchRecordAt(2, out errString);
            binaryDataListItem  = binaryDataListItems[0];
            binaryDataListItem2 = binaryDataListItems[1];
            theValue            = binaryDataListItem.TheValue;
            Assert.AreEqual("test12", theValue);
            theValue = binaryDataListItem2.TheValue;

            Assert.AreEqual("test22", theValue);
        }
        /// <summary>
        /// Processes the record set.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        private string ProcessRecordSet(IBinaryDataListEntry entry, out string error)
        {
            StringBuilder result = new StringBuilder();

            error = string.Empty;

            // MAKE RS START ;)
            result.Append("\"");
            result.Append(entry.Namespace);
            result.Append("\" : [");

            IIndexIterator idxItr = entry.FetchRecordsetIndexes();

            int rsCnt = 0;

            while (idxItr.HasMore() && !entry.IsEmpty())
            {
                int idx = idxItr.FetchNextIndex();

                IList <IBinaryDataListItem> rowData = entry.FetchRecordAt(idx, out error);
                result.Append("{");

                int colIdx = 0;
                foreach (IBinaryDataListItem col in rowData)
                {
                    result.Append("\"");
                    result.Append(col.FieldName);
                    result.Append("\":\"");
                    result.Append(col.TheValue);
                    result.Append("\"");

                    // add , if need be ;)
                    colIdx++;
                    if (colIdx < rowData.Count)
                    {
                        result.Append(",");
                    }
                }

                result.Append("}");

                // append , for row data ;)
                rsCnt++;
                if (rsCnt < idxItr.Count)
                {
                    result.Append(", ");
                }
            }

            // END RS ;)
            result.Append("]");


            return(result.ToString());
        }
        internal static void DoRecordSetAppending(ErrorResultTO errors, IBinaryDataListEntry entry, StringBuilder result)
        {
            var cnt = entry.FetchLastRecordsetIndex();
            var cols = entry.Columns;
            if(!cols.Any(c => c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input))
            {
                return;
            }
            for(var i = 1; i <= cnt; i++)
            {
                string error;
                var rowData = entry.FetchRecordAt(i, out error);
                errors.AddError(error);

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

                foreach(var col in rowData)
                {

                    var fName = col.FieldName;

                    if(cols.Any(c => c.ColumnName == fName &&
                        (c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input)))
                    {

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

                result.Append("</");
                result.Append(entry.Namespace);
                result.Append(">");
            }
        }
示例#7
0
        internal static void DoRecordSetAppending(ErrorResultTO errors, IBinaryDataListEntry entry, StringBuilder result)
        {
            var cnt  = entry.FetchLastRecordsetIndex();
            var cols = entry.Columns;

            if (!cols.Any(c => c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input))
            {
                return;
            }
            for (var i = 1; i <= cnt; i++)
            {
                string error;
                var    rowData = entry.FetchRecordAt(i, out error);
                errors.AddError(error);

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

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

                    if (cols.Any(c => c.ColumnName == fName &&
                                 (c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input)))
                    {
                        result.Append("<");
                        result.Append(fName);
                        result.Append(">");
                        try
                        {
                            result.Append(col.TheValue);
                        }
                        // ReSharper disable EmptyGeneralCatchClause
                        catch (Exception)
                        {
                        }
                        result.Append("</");
                        result.Append(fName);
                        result.Append(">");
                    }
                }

                result.Append("</");
                result.Append(entry.Namespace);
                result.Append(">");
            }
        }
        IList <IDataListItem> ConvertIBinaryDataListEntryToIDataListItem(IBinaryDataListEntry dataListEntry)
        {
            IList <IDataListItem> result = new List <IDataListItem>();

            if (dataListEntry.IsRecordset)
            {
                var sizeOfCollection = dataListEntry.ItemCollectionSize();
                if (sizeOfCollection == 0)
                {
                    sizeOfCollection++;
                }
                var count = 0;

                var fields = dataListEntry.Columns.Where(c => c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input).ToList();

                while (count < sizeOfCollection)
                {
                    string error;
                    var    items = dataListEntry.FetchRecordAt(count + 1, out error);
                    foreach (var item in items)
                    {
                        // check field mapping ;)
                        if (fields.Any(f => f.ColumnName == item.FieldName))
                        {
                            IDataListItem singleRes = new DataListItem();
                            singleRes.IsRecordset    = true;
                            singleRes.Recordset      = item.Namespace;
                            singleRes.Field          = item.FieldName;
                            singleRes.RecordsetIndex = (count + 1).ToString(CultureInfo.InvariantCulture);
                            try
                            {
                                singleRes.Value = item.TheValue;
                            }
                            catch (Exception)
                            {
                                singleRes.Value = null;
                            }

                            singleRes.DisplayValue = item.DisplayValue;
                            var desc = dataListEntry.Columns.FirstOrDefault(c => c.ColumnName == item.FieldName);
                            singleRes.Description = desc == null ? null : desc.ColumnDescription;
                            result.Add(singleRes);
                        }
                    }
                    count++;
                }
            }
            else
            {
                var item = dataListEntry.FetchScalar();
                if (item != null)
                {
                    IDataListItem singleRes = new DataListItem();
                    singleRes.IsRecordset  = false;
                    singleRes.Field        = item.FieldName;
                    singleRes.DisplayValue = item.FieldName;
                    try
                    {
                        singleRes.Value = item.TheValue;
                    }
                    catch (Exception)
                    {
                        singleRes.Value = null;
                    }
                    var desc = dataListEntry.Description;
                    singleRes.Description = string.IsNullOrWhiteSpace(desc) ? null : desc;
                    result.Add(singleRes);
                }
            }
            return(result);
        }
        IList<IDataListItem> ConvertIBinaryDataListEntryToIDataListItem(IBinaryDataListEntry dataListEntry)
        {
            IList<IDataListItem> result = new List<IDataListItem>();
            if(dataListEntry.IsRecordset)
            {
                var sizeOfCollection = dataListEntry.ItemCollectionSize();
                if(sizeOfCollection == 0) { sizeOfCollection++; }
                var count = 0;

                var fields = dataListEntry.Columns.Where(c => c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input).ToList();

                while(count < sizeOfCollection)
                {
                    string error;
                    var items = dataListEntry.FetchRecordAt(count + 1, out error);
                    foreach(var item in items)
                    {
                        // check field mapping ;)
                        if(fields.Any(f => f.ColumnName == item.FieldName))
                        {
                            IDataListItem singleRes = new DataListItem();
                            singleRes.IsRecordset = true;
                            singleRes.Recordset = item.Namespace;
                            singleRes.Field = item.FieldName;
                            singleRes.RecordsetIndex = (count + 1).ToString(CultureInfo.InvariantCulture);
                            try
                            {
                                singleRes.Value = item.TheValue;
                            }
                            catch(Exception)
                            {
                                singleRes.Value = null;
                            }

                            singleRes.DisplayValue = item.DisplayValue;
                            var desc = dataListEntry.Columns.FirstOrDefault(c => c.ColumnName == item.FieldName);
                            singleRes.Description = desc == null ? null : desc.ColumnDescription;
                            result.Add(singleRes);
                        }
                    }
                    count++;
                }
            }
            else
            {
                var item = dataListEntry.FetchScalar();
                if(item != null)
                {
                    IDataListItem singleRes = new DataListItem();
                    singleRes.IsRecordset = false;
                    singleRes.Field = item.FieldName;
                    singleRes.DisplayValue = item.FieldName;
                    try
                    {
                        singleRes.Value = item.TheValue;
                    }
                    catch(Exception)
                    {
                        singleRes.Value = null;
                    }
                    var desc = dataListEntry.Description;
                    singleRes.Description = string.IsNullOrWhiteSpace(desc) ? null : desc;
                    result.Add(singleRes);
                }
            }
            return result;
        }
        /// <summary>
        /// Depths the merge.
        /// </summary>
        /// <param name="depth">The depth.</param>
        /// <param name="cloned">The cloned.</param>
        /// <param name="key"></param>
        /// <param name="errors">The errors.</param>
        private void DepthMerge(enTranslationDepth depth, IBinaryDataListEntry cloned, string key, out IList<string> errors)
        {
            errors = new List<string>();

            if(key != null)
            {

                if(depth == enTranslationDepth.Data || depth == enTranslationDepth.Data_With_Blank_OverWrite)
                {

                    // safe to add
                    if(cloned.IsRecordset)
                    {

                        // Inject into the intellisense options...
                        CreateIntelliseneResult(key, cloned.Columns);

                        //Massimo.Guerrera - 21-01-2013 - Added for the DeleteRecordOperation, it need to over write the data with blank values.
                        if(depth == enTranslationDepth.Data_With_Blank_OverWrite)
                        {
                            _templateDict[key] = cloned;
                        }
                        else
                        {
                            // merge all the cloned rows into this reference

#pragma warning disable 219
                            // ReSharper disable NotAccessedVariable
                            int insertIdx = 1; // always default to start of recordset
                            // ReSharper restore NotAccessedVariable
#pragma warning restore 219
                            // fetch last row id and build from there
                            IBinaryDataListEntry tmpRec;
                            bool isFound = _templateDict.TryGetValue(key, out tmpRec);
                            // verify that the key exist first ;)

                            IIndexIterator ii = cloned.FetchRecordsetIndexes();
                            while(ii.HasMore())
                            {
                                int next = ii.FetchNextIndex();
                                string error;
                                IList<IBinaryDataListItem> cols = cloned.FetchRecordAt(next, out error);
                                if(error != string.Empty)
                                {
                                    errors.Add(error);
                                }

                                if(!isFound)
                                {
                                    // we need to boot strap the recordset ;)
                                    // intellisense takecare of with template method ;)
                                    TryCreateRecordsetTemplate(cloned.Namespace, cloned.Description, cloned.Columns, true, out error);
                                    if(error != string.Empty)
                                    {
                                        errors.Add(error);
                                    }
                                    isFound = true;
                                }

                                foreach(IBinaryDataListItem itm in cols)
                                {
                                    _templateDict[key].TryPutRecordItemAtIndex(itm, next, out error);
                                    if(error != string.Empty)
                                    {
                                        errors.Add(error);
                                    }
                                }
                                insertIdx++;
                            }

                        }
                    }
                    else
                    {
                        IBinaryDataListEntry thisTmp;
                        // we have an entry, better check clone for empty
                        if(_templateDict.TryGetValue(key, out thisTmp))
                        {
                            string theValue = null;
                            try
                            {
                                theValue = cloned.FetchScalar().TheValue;
                            }
                            catch(Exception e)
                            {
                                Dev2Logger.Log.Error(e);
                            }
                            if(theValue != string.Empty && depth == enTranslationDepth.Data)
                            {
                                // The clone has data, over write it on the merge ;)
                                _templateDict[key] = cloned;
                                // Inject into the intellisense options...
                                CreateIntelliseneResult(key);
                            }
                            else if(depth == enTranslationDepth.Data_With_Blank_OverWrite)
                            {
                                // The user wants to over-write Blank data on the right with existing data on the left ;)
                                _templateDict[key] = cloned;
                                // Inject into the intellisense options...
                                CreateIntelliseneResult(key);
                            }
                        }
                        else
                        {
                            // no entry, just place it there as there is no harm ;)
                            _templateDict[key] = cloned;
                            // Inject into the intellisense options...
                            CreateIntelliseneResult(key);
                        }
                    }
                }
                else if(depth == enTranslationDepth.Shape)
                {
                    _templateDict[key] = cloned; // set blank data ;)
                    // Inject into the intellisense options...
                    CreateIntelliseneResult(key);
                }
            }
        }
示例#11
0
        /// <summary>
        /// Depths the merge.
        /// </summary>
        /// <param name="depth">The depth.</param>
        /// <param name="cloned">The cloned.</param>
        /// <param name="key"></param>
        /// <param name="errors">The errors.</param>
        private void DepthMerge(enTranslationDepth depth, IBinaryDataListEntry cloned, string key, out IList <string> errors)
        {
            errors = new List <string>();

            if (key != null)
            {
                if (depth == enTranslationDepth.Data || depth == enTranslationDepth.Data_With_Blank_OverWrite)
                {
                    // safe to add
                    if (cloned.IsRecordset)
                    {
                        // Inject into the intellisense options...
                        CreateIntelliseneResult(key, cloned.Columns);

                        //Massimo.Guerrera - 21-01-2013 - Added for the DeleteRecordOperation, it need to over write the data with blank values.
                        if (depth == enTranslationDepth.Data_With_Blank_OverWrite)
                        {
                            _templateDict[key] = cloned;
                        }
                        else
                        {
                            // merge all the cloned rows into this reference

#pragma warning disable 219
                            int insertIdx = 1; // always default to start of recordset
#pragma warning restore 219
                            // fetch last row id and build from there
                            IBinaryDataListEntry tmpRec;
                            bool isFound = _templateDict.TryGetValue(key, out tmpRec);
                            // verify that the key exist first ;)

                            IIndexIterator ii = cloned.FetchRecordsetIndexes();
                            while (ii.HasMore())
                            {
                                int    next = ii.FetchNextIndex();
                                string error;
                                IList <IBinaryDataListItem> cols = cloned.FetchRecordAt(next, out error);
                                if (error != string.Empty)
                                {
                                    errors.Add(error);
                                }

                                if (!isFound)
                                {
                                    // we need to boot strap the recordset ;)
                                    // intellisense takecare of with template method ;)
                                    TryCreateRecordsetTemplate(cloned.Namespace, cloned.Description, cloned.Columns, true, out error);
                                    if (error != string.Empty)
                                    {
                                        errors.Add(error);
                                    }
                                    isFound = true;
                                }

                                foreach (IBinaryDataListItem itm in cols)
                                {
                                    _templateDict[key].TryPutRecordItemAtIndex(itm, next, out error);
                                    if (error != string.Empty)
                                    {
                                        errors.Add(error);
                                    }
                                }
                                insertIdx++;
                            }
                        }
                    }
                    else
                    {
                        IBinaryDataListEntry thisTmp;
                        // we have an entry, better check clone for empty
                        if (_templateDict.TryGetValue(key, out thisTmp))
                        {
                            string theValue = null;
                            try
                            {
                                theValue = cloned.FetchScalar().TheValue;
                            }
                            catch (Exception e)
                            {
                                Dev2Logger.Log.Error(e);
                            }
                            if (theValue != string.Empty && depth == enTranslationDepth.Data)
                            {
                                // The clone has data, over write it on the merge ;)
                                _templateDict[key] = cloned;
                                // Inject into the intellisense options...
                                CreateIntelliseneResult(key);
                            }
                            else if (depth == enTranslationDepth.Data_With_Blank_OverWrite)
                            {
                                // The user wants to over-write Blank data on the right with existing data on the left ;)
                                _templateDict[key] = cloned;
                                // Inject into the intellisense options...
                                CreateIntelliseneResult(key);
                            }
                        }
                        else
                        {
                            // no entry, just place it there as there is no harm ;)
                            _templateDict[key] = cloned;
                            // Inject into the intellisense options...
                            CreateIntelliseneResult(key);
                        }
                    }
                }
                else if (depth == enTranslationDepth.Shape)
                {
                    _templateDict[key] = cloned; // set blank data ;)
                    // Inject into the intellisense options...
                    CreateIntelliseneResult(key);
                }
            }
        }
        void GetValues(IBinaryDataListEntry dlEntry, string value, int iterCnt, IIndexIterator idxItr, enRecordsetIndexType indexType, IList<IDebugItemResult> results, string initExpression, string labelText, string fieldName = null)
        {
            string error;
            int index = idxItr.FetchNextIndex();
            if(string.IsNullOrEmpty(fieldName))
            {
                IList<IBinaryDataListItem> record = dlEntry.FetchRecordAt(index, out error);
                // ReSharper disable LoopCanBeConvertedToQuery
                foreach(IBinaryDataListItem recordField in record)
                // ReSharper restore LoopCanBeConvertedToQuery
                {
                    GetValue(dlEntry, value, iterCnt, fieldName, indexType, results, initExpression, recordField, index, false, labelText);
                }
            }
            else
            {
                IBinaryDataListItem recordField = dlEntry.TryFetchRecordsetColumnAtIndex(fieldName, index, out error);
                bool ignoreCompare = false;

                if(recordField == null)
                {
                    if(dlEntry.Columns.Count == 1)
                    {
                        recordField = dlEntry.TryFetchIndexedRecordsetUpsertPayload(index, out error);
                        ignoreCompare = true;
                    }
                }

                GetValue(dlEntry, value, iterCnt, fieldName, indexType, results, initExpression, recordField, index, ignoreCompare, labelText);
            }
        }
        /// <summary>
        /// Processes the record set.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        private string ProcessRecordSet(IBinaryDataListEntry entry, out string error)
        {
            StringBuilder result = new StringBuilder();
            error = string.Empty;

            // MAKE RS START ;)
            result.Append("\"");
            result.Append(entry.Namespace);
            result.Append("\" : [");

            IIndexIterator idxItr = entry.FetchRecordsetIndexes();

            int rsCnt = 0;

            while(idxItr.HasMore() && !entry.IsEmpty())
            {
                int idx = idxItr.FetchNextIndex();

                IList<IBinaryDataListItem> rowData = entry.FetchRecordAt(idx, out error);
                result.Append("{");

                int colIdx = 0;
                foreach(IBinaryDataListItem col in rowData)
                {
                    result.Append("\"");
                    result.Append(col.FieldName);
                    result.Append("\":\"");
                    result.Append(col.TheValue);
                    result.Append("\"");

                    // add , if need be ;)
                    colIdx++;
                    if(colIdx < rowData.Count)
                    {
                        result.Append(",");
                    }
                }

                result.Append("}");

                // append , for row data ;)
                rsCnt++;
                if(rsCnt < idxItr.Count)
                {
                    result.Append(", ");
                }
            }

            // END RS ;)
            result.Append("]");


            return result.ToString();
        }