Example #1
0
 public int MaxIndex() => IndexList.GetMaxIndex();
Example #2
0
 /// <summary>
 /// Maximums the index.
 /// </summary>
 /// <returns></returns>
 public int MaxIndex()
 {
     return(IndexList.GetMaxIndex());
 }
        public IList <IBinaryDataListItem> this[int key, bool removeFromGaps = true]
        {
            get
            {
                if (key >= 0)
                {
                    ScrubInternalTo();

                    // Generate entry 1 key, generate entry 2 key.
                    var fetchKeys = GenerateFederatedKey(key);

                    short colCnt = 1;
                    if (Columns != null)
                    {
                        colCnt = (short)Columns.Count;
                    }

                    // I am going to look up all the different pieces then, push them together?!
                    foreach (var fedKey in fetchKeys.FetchAsList())
                    {
                        BinaryDataListRow theRow;
                        _itemStorage.TryGetValue(fedKey.TheKey, colCnt, out theRow);

                        if (theRow != null)
                        {
                            var myCols = fedKey.ImpactedColumns;

                            if (myCols != null)
                            {
                                foreach (var col in myCols)
                                {
                                    // Fetch index value
                                    var internalIdx = InternalFetchColumnIndex(col);

                                    // adjust if there is a mapping ;)
                                    // The datalist in the studio used to sort
                                    // hence we always had the correct ordering in the inner and outer xml shape
                                    // Now that this is not happening we need to account for swapped shapes
                                    // This code resolves an issue for certain cases but causes others to fail.
                                    // Need to find a better solution for the case it is trying to solve.


                                    // FOR : Bug_10247_Outter
                                    // if -1 skip and try next key ;)
                                    if (internalIdx != -1)
                                    {
                                        IBinaryDataListItem tmp = _internalReturnValue[internalIdx];

                                        //                                        if(keyAlias != null)
                                        //                                        {
                                        //                                            tmp.UpdateField(col);
                                        //                                        }

                                        // normal object build
                                        tmp.UpdateValue(theRow.FetchValue(internalIdx, colCnt));
                                        tmp.UpdateIndex(key);
                                    }
                                }
                            }
                            else
                            {
                                // we have a scalar value we are dealing with ;)
                                IBinaryDataListItem tmp = _internalReturnValue[0];
                                tmp.UpdateValue(theRow.FetchValue(0, 1));
                            }
                        }
                    }

                    return(_internalReturnValue);
                }

                return(null);
            }

            set
            {
                if (key >= 0)
                {
                    // we need to fetch federated parts if possible ;)
                    short colCnt = 1;
                    if (Columns != null)
                    {
                        colCnt = (short)Columns.Count;
                    }

                    var fetchKeys = GenerateFederatedKey(key);

                    BinaryDataListRow parentRow = null; // Master location
                    BinaryDataListRow childRow;         // Child location

                    // Fetch master location
                    if (fetchKeys.HasParentKey())
                    {
                        if (!_itemStorage.TryGetValue(fetchKeys.ParentKey.TheKey, colCnt, out parentRow))
                        {
                            throw new Exception("Fatal Internal DataList Storage Error");
                        }
                    }

                    // fetch child location
                    if (!_itemStorage.TryGetValue(fetchKeys.ChildKey.TheKey, colCnt, out childRow))
                    {
                        throw new Exception("Fatal Internal DataList Storage Error");
                    }

                    // we got the row object, now update it ;)
                    foreach (IBinaryDataListItem itm in value)
                    {
                        if (!string.IsNullOrEmpty(itm.FieldName))
                        {
                            int idx = InternalFetchColumnIndex(itm.FieldName); // Fetch correct index
                            BinaryDataListAlias keyAlias;

                            // adjust if there is a mapping ;)
                            if (_keyToAliasMap.TryGetValue(itm.FieldName, out keyAlias))
                            {
                                var parentColumns = keyAlias.MasterEntry.Columns;
                                var parentColumn  = keyAlias.MasterColumn;

                                idx = InternalParentFetchColumnIndex(parentColumn, parentColumns);

                                colCnt = (short)parentColumns.Count;
                            }

                            if (idx == -1 && !IsRecordset)
                            {
                                idx = 0; // adjust for scalar
                            }

                            if (idx >= 0)
                            {
                                // it is an alias mapping ;)
                                if (keyAlias != null)
                                {
                                    // alias update, use row 1
                                    if (parentRow != null)
                                    {
                                        try
                                        {
                                            parentRow.UpdateValue(itm.TheValue, idx, colCnt);
                                        }
                                        catch (Exception)
                                        {
                                            parentRow.UpdateValue(null, idx, colCnt);
                                        }
                                    }
                                }
                                else
                                {
                                    // normal update ;)
                                    try
                                    {
                                        childRow.UpdateValue(itm.TheValue, idx, colCnt);
                                    }
                                    catch (Exception)
                                    {
                                        childRow.UpdateValue(null, idx, colCnt);
                                    }
                                }
                            }
                        }
                    }

                    // adjust correctly ;)
                    if ((parentRow != null && !parentRow.IsEmpty) || (!childRow.IsEmpty))
                    {
                        _myKeys.SetMaxValue(key, IsEmtpy);
                    }
                    else
                    {
                        //we removed it?!
                        _myKeys.AddGap(key);
                    }

                    // update federated values ;)
                    if (parentRow != null)
                    {
                        // TODO : Make Faster, AND Adjust for when my view is different to the row's view!

                        // we need to signal master entry to update its view ;)
                        var me = fetchKeys.MasterEntry;
                        if (me != null)
                        {
                            me.AdjustIndexView(_myKeys.Gaps, _myKeys.GetMinIndex(), _myKeys.GetMaxIndex());
                        }

                        _itemStorage.TrySetValue(fetchKeys.ParentKey.TheKey, colCnt, parentRow);
                    }

                    if (childRow != null)
                    {
                        _itemStorage.TrySetValue(fetchKeys.ChildKey.TheKey, colCnt, childRow);
                    }
                }
            }
        }