예제 #1
0
        /// <summary>
        /// Remove from the sequence all items that satisfy the given predicate.
        /// Returns the number of removed items in an out param, guaranteed to
        /// equal actual number of removed items even if the condition lambda throws.
        /// </summary>
        public void RemoveAll(Func <T, bool> condition, out int removed)
        {
            Shield.AssertInTransaction();
            var        curr     = _head;
            var        tail     = _tail.Value;
            ItemKeeper previous = null;

            removed = 0;
            while (curr.Value != null)
            {
                if (condition(curr.Value.Value))
                {
                    removed++;
                    if (tail == curr.Value)
                    {
                        _tail.Value = previous;
                        if (previous == null)
                        {
                            _head.Value = null;
                            break;
                        }
                    }
                    Skip(curr);
                }
                else
                {
                    previous = curr;
                    curr     = curr.Value.Next;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initialize a new sequence with the given initial contents.
        /// </summary>
        /// <param name="items">Initial items.</param>
        /// <param name="owner">If this is given, then in WhenCommitting subscriptions
        /// this shielded will report its owner instead of itself.</param>
        public ShieldedSeqNc(T[] items = null, object owner = null)
        {
            _owner = owner ?? this;
            if (items == null)
            {
                _head = CreateRef();
                _tail = CreateRef();
                return;
            }

            ItemKeeper item = null;

            for (int i = items.Length - 1; i >= 0; i--)
            {
                item = new ItemKeeper(items[i], item, _owner);
                if (_tail == null)
                {
                    _tail = CreateRef(item);
                }
            }
            _head = CreateRef(item);
            // if this is true, there were no items.
            if (_tail == null)
            {
                _tail = CreateRef();
            }
        }
예제 #3
0
        /// <summary>
        /// Remove the specified item from the sequence.
        /// </summary>
        public bool Remove(T item, IEqualityComparer <T> comp = null)
        {
            Shield.AssertInTransaction();
            if (comp == null)
            {
                comp = EqualityComparer <T> .Default;
            }

            var        curr     = _head;
            ItemKeeper previous = null;

            while (curr.Value != null)
            {
                if (comp.Equals(item, curr.Value.Value))
                {
                    if (curr.Value.Next.Value == null)
                    {
                        _tail.Value = previous;
                    }
                    Skip(curr);
                    return(true);
                }
                else
                {
                    previous = curr;
                    curr     = curr.Value.Next;
                }
            }
            return(false);
        }
예제 #4
0
    public void ExChange(ItemKeeper targetItemKeeper)
    {
        Item tempItem   = targetItemKeeper.Item;
        int  tempAmount = targetItemKeeper.Amount;

        targetItemKeeper.SetItemKeeper(Item, Amount);
        SetItemKeeper(tempItem, tempAmount);
    }
예제 #5
0
        /// <summary>
        /// Prepend an item, i.e. insert at index 0.
        /// </summary>
        public void Prepend(T val)
        {
            var keeper = new ItemKeeper(val, _head, _owner);

            if (_head.Value == null)
            {
                _tail.Value = keeper;
            }
            _head.Value = keeper;
        }
예제 #6
0
    private void StoreItemNewKeeper(Item item, int amount = 1)
    {
        GameObject itemGameobject = Instantiate(itemPrefab);

        itemGameobject.transform.SetParent(this.transform);
        itemGameobject.transform.localPosition = Vector3.zero;
        itemKeeper = itemGameobject.GetComponent <ItemKeeper>();
        itemGameobject.transform.localScale = Vector3.one;
        (itemGameobject.transform as RectTransform).sizeDelta = (gameObject.transform as RectTransform).sizeDelta;
        itemKeeper.SetItemKeeper(item, amount);
    }
예제 #7
0
 /// <summary>
 /// Insert an item at the specified index.
 /// </summary>
 public void Insert(int index, T item)
 {
     RefToIndex(index, plusOne: true).Modify((ref ItemKeeper r) => {
         var newItem = new ItemKeeper(item, r, _owner);
         if (r == null)
         {
             _tail.Value = newItem;
         }
         r = newItem;
     });
 }
예제 #8
0
        private void CoffeePointsFrm_Load(object sender, EventArgs e)
        {
            ItemKeeper <CoffeePoint> coffeePointsDataSource = ItemKeeper <CoffeePoint> .getInstance(CoffeePointsApp.mainDataRoom);

            dfc = new DataFormComponent(coffeePointsDataSource, this, Lib.FrmCrudModeEnum.GridAndFieldsOnTheFly);

            //маппинг контролов
            //грид

            RIFDC_DataGridView grd0 = new RIFDC_DataGridView(
                dgCoffeePoints,
                coffeePointsDataSource,
                CoffeePoint.MyControlFormats.ShortCoffeePointGridFormat.getMyInstance(coffeePointsDataSource.sampleObject),
                DataGridEditabilityMode.NotEditableAtAll);

            dfc.addGridBasedControlMapping(grd0);

            //поля
            dfc.addRecordBasedControlMapping(new RIFDC_TextBox(tbId), "id");
            dfc.addRecordBasedControlMapping(new RIFDC_TextBox(tbCoffeePointName), "name");
            dfc.addRecordBasedControlMapping(new RIFDC_MaskedTextBox(tbLastVisitDate), "lastVisitDate");
            dfc.addRecordBasedControlMapping(new RIFDC_TextBox(tbBigLattePrice), "bigLattePrice");
            dfc.addRecordBasedControlMapping(new RIFDC_TextBox(tbComment), "description");
            dfc.addRecordBasedControlMapping(new RIFDC_TextBox(tbAlias), "alias");

            dfc.addRecordBasedControlMapping(new RIFDC_MaskedTextBox(tbLastVisitDate2), "lastVisitDate2");
            dfc.addRecordBasedControlMapping(new RIFDC_TextBox(tbBigLattePrice2), "bigLattePrice2");
            dfc.addRecordBasedControlMapping(new RIFDC_TextBox(tbComment2), "description2");

            dfc.searchControl = new DFCSearchControl(dfc, Lib.FiltrationTypeEnum.Local, tbSearch, btnSearch, btnCancelSearch);

            //кнопки
            dfc.addButtonMapping(new RIFDC_Button(btnAddNewRecord, FormBtnTypeEnum.btnAddNew));
            dfc.addButtonMapping(new RIFDC_Button(btnDelete, FormBtnTypeEnum.btnDelete));
            dfc.addButtonMapping(new RIFDC_Button(btnSave, FormBtnTypeEnum.btnSelectAll));
            dfc.addButtonMapping(new RIFDC_Button(btnPrevious, FormBtnTypeEnum.btnRecordMovePrevRecord));
            dfc.addButtonMapping(new RIFDC_Button(btnNext, FormBtnTypeEnum.btnRecordMoveNextRecord));
            dfc.addButtonMapping(new RIFDC_Button(btnReload, FormBtnTypeEnum.btnReloadDataFormComponent));

            //dfc.addButtonMapping(new RIFDC_Button(btnGroupOperations, FormBtnTypeEnum.btnOpenGroupOperationsForm));
            dfc.addButtonMapping(new RIFDC_Button(btnHistory, FormBtnTypeEnum.btnOpenHistoryForm));

            dfc.crudOperator.addButtonMapping(new RIFDC_Button(btnToggleSpecLineMultiSelect, FormBtnTypeEnum.btnToggleMultiSelectionMode));
            dfc.crudOperator.addButtonMapping(new RIFDC_Button(btnSpecLineSelectAll, FormBtnTypeEnum.btnSelectAll));
            dfc.crudOperator.addButtonMapping(new RIFDC_Button(btnSpecLineSelectNone, FormBtnTypeEnum.btnSelectNone));


            //запуск
            dfc.readItems();
            dfc.fillTheForm();
        }
예제 #9
0
        void IShielded.TrimCopies(long smallestOpenTransactionId)
        {
            // NB the "smallest transaction" and others can freely read while
            // we're doing this.
            Tuple <long, List <TKey> > item;

            while (_copies.TryPeek(out item) && item.Item1 <= smallestOpenTransactionId)
            {
                _copies.TryDequeue(out item);
                foreach (var key in item.Item2)
                {
                    ItemKeeper point;
                    if (!_dict.TryGetValue(key, out point))
                    {
                        continue;
                    }
                    ItemKeeper pointNewer = null;
                    while (point != null && point.Version > smallestOpenTransactionId)
                    {
                        pointNewer = point;
                        point      = point.Older;
                    }
                    if (point != null)
                    {
                        // point is the last accessible - his Older is not needed.
                        point.Older = null;
                        if (point.Empty)
                        {
                            if (pointNewer != null)
                            {
                                pointNewer.Older = null;
                            }
                            else
                            {
                                //((ICollection<KeyValuePair<TKey, ItemKeeper>>)_dict)
                                //    .Remove(new KeyValuePair<TKey, ItemKeeper>(key, point));
                                lock (_dict)
                                {
                                    ItemKeeper k;
                                    if (_dict.TryGetValue(key, out k) && k == point)
                                    {
                                        _dict.TryRemove(key, out k);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #10
0
        void IShielded.Commit()
        {
            var locals = _localDict.Value;

            if (locals.HasChanges)
            {
                long?version  = null;
                var  copyList = new List <TKey>();
                foreach (var kvp in _localDict.Value.Items)
                {
                    if (kvp.Value == null)
                    {
                        continue;
                    }
                    if (version == null)
                    {
                        version = _writeStamps[kvp.Key].Version;
                    }

                    ItemKeeper v = null;
                    if (_dict.TryGetValue(kvp.Key, out v))
                    {
                        copyList.Add(kvp.Key);
                    }

                    var newCurrent = kvp.Value;
                    // look at this negated - if the new value is empty, and the old value is null, then we
                    // need not add anything to the underlying dict.
                    if (!newCurrent.Empty || v != null)
                    {
                        newCurrent.Version = (long)version;
                        newCurrent.Older   = v;
                        lock (_dict)
                            _dict[kvp.Key] = newCurrent;
                    }

                    WriteStamp ws;
                    _writeStamps.TryRemove(kvp.Key, out ws);
                }
                if (copyList.Count > 0)
                {
                    _copies.Enqueue(Tuple.Create((long)version, copyList));
                }
            }
            _localDict.Release();
        }
예제 #11
0
        /// <summary>
        /// Gets or sets the value under the specified key.
        /// </summary>
        public TItem this [TKey key]
        {
            get
            {
                ItemKeeper v;
                if (!Shield.IsInTransaction)
                {
                    if (!_dict.TryGetValue(key, out v) || v.Empty)
                    {
                        throw new KeyNotFoundException();
                    }
                    return(v.Value);
                }

                v = Read(key);
                if (v == null || v.Empty)
                {
                    throw new KeyNotFoundException();
                }
                return(v.Value);
            }
            set
            {
                ItemKeeper local = PrepareWrite(key);
                ItemKeeper curr;
                if (!Shield.CommitCheckDone && _dict.TryGetValue(key, out curr) && curr.Version > Shield.ReadStamp)
                {
                    throw new TransException("Write collision.");
                }

                if (local == null)
                {
                    var locals = _localDict.Value;
                    locals.Items[key] = new ItemKeeper()
                    {
                        Value = value
                    };
                    locals.HasChanges = true;
                }
                else
                {
                    local.Empty = false;
                    local.Value = value;
                }
            }
        }
예제 #12
0
        public IKeeper getMyHistoryIKeeperObject(IKeepable t)
        {
            IKeeper myHistoryIKeeperObject = ItemKeeper <HistorySaver.HistorySaverUnit> .getInstance(dataRoom);

            Lib.Filter myFilter = new Lib.Filter();

            myFilter.addNewFilteringRule(
                myHistoryIKeeperObject.sampleObject.getFieldInfoByFieldClassName("objectId"),
                Lib.RIFDC_DataCompareOperatorEnum.equal,
                t.id, Lib.Filter.FilteringRuleTypeEnum.ParentFormFilteringRule);

            myHistoryIKeeperObject.filtration.applyGlobalFilter(myFilter);

            myHistoryIKeeperObject.readItems();

            return(myHistoryIKeeperObject);
        }
예제 #13
0
파일: Program.cs 프로젝트: FM102DX/RIFDC
        public static void init()
        {
            cls_mysql.connectionData.server = "37.140.192.97";
            //cls_mysql.connectionData.port = "3306";
            cls_mysql.connectionData.dbName     = "u1325524_rifdcdemo";
            cls_mysql.connectionData.dbUser     = "******";
            cls_mysql.connectionData.dbPassword = "******";

            RIFDC_App.mainDataRoom  = mainDataRoom;
            RIFDC_App.currentUserId = "user01";

            #region localCnn

            /*
             *          cls_mysql.connectionData.server = "127.0.0.1";
             *          //cls_mysql.connectionData.port = "3306";
             *          cls_mysql.connectionData.dbName = "coffeepoints2";
             *          cls_mysql.connectionData.dbUser = "******";
             *          cls_mysql.connectionData.dbPassword = "";
             */

            #endregion


            mainDataRoom.actualCluster = cls_mysql;

            Lib.DbOperationResult or = mainDataRoom.connect();

            if (!or.success)
            {
                fn.mb_info("Ошибка подключения, программа остановлена");
                return;
            }

            //сохраняем Ikeeper этого типа, поскольку тут дженерики ItemKeeper<Class> в рантайме не создашь
            RIFDC_App.iKeeperSampleHolder.registerIKeeper(ItemKeeper <CoffeePoint> .getInstance());

            MainAppFrm frm = new MainAppFrm();
            frm.WindowState = FormWindowState.Maximized;
            frm.ShowDialog();

            mainDataRoom.disconnect();
        }
예제 #14
0
        /// <summary>
        /// Append the specified value, commutatively - if you don't / haven't touched the
        /// sequence in this transaction (using other methods/properties), this will not cause
        /// conflicts! Effectively, the value is simply appended to whatever the sequence
        /// is at commit time. Multiple calls to Append made in one transaction will
        /// append the items in that order - they commute with other transactions only.
        /// </summary>
        public void Append(T val)
        {
            var newItem = new ItemKeeper(val, null, _owner);

            Shield.EnlistCommute(() => {
                if (_head.Value == null)
                {
                    _head.Value = newItem;
                    _tail.Value = newItem;
                }
                else
                {
                    _tail.Modify((ref ItemKeeper t) => {
                        t.Next.Value = newItem;
                        t            = newItem;
                    });
                }
            }, _head, _tail); // the commute degenerates if you read from the seq..
        }
예제 #15
0
 /// <summary>
 /// Get or set the item at the specified index. This iterates through the internal
 /// linked list, so it is not efficient for large sequences.
 /// </summary>
 public T this [int index]
 {
     get
     {
         return(RefToIndex(index).Value.Value);
     }
     set
     {
         RefToIndex(index).Modify((ref ItemKeeper r) => {
             var newItem = new ItemKeeper(value, r.Next, _owner);
             if (r.Next.Value == null)
             {
                 _tail.Value = newItem;
             }
             r.ClearNext();
             r = newItem;
         });
     }
 }
예제 #16
0
        void IShielded.Commit()
        {
            var locals = _localDict.Value;

            if (locals.HasChanges)
            {
                long?version  = null;
                var  copyList = new List <TKey>();
                foreach (var kvp in _localDict.Value.Items)
                {
                    if (kvp.Value == null)
                    {
                        continue;
                    }
                    if (version == null)
                    {
                        version = _writeStamps[kvp.Key].Version;
                    }

                    ItemKeeper v = null;
                    if (_dict.TryGetValue(kvp.Key, out v))
                    {
                        copyList.Add(kvp.Key);
                    }

                    var newCurrent = kvp.Value;
                    newCurrent.Version = (long)version;
                    newCurrent.Older   = v;
                    lock (_dict)
                        _dict[kvp.Key] = newCurrent;

                    WriteStamp ws;
                    _writeStamps.TryRemove(kvp.Key, out ws);
                }
                if (version.HasValue)
                {
                    _copies.Enqueue(Tuple.Create((long)version, copyList));
                }
            }
            _localDict.Release();
        }
예제 #17
0
        public Lib.ObjectOperationResult doDeleteHistory(IKeepable t)
        {
            // полностью удалить историю по объекту
            if (t == null)
            {
                return(Lib.ObjectOperationResult.sayNo("Object is null"));
            }
            if (t.id == "")
            {
                return(Lib.ObjectOperationResult.sayNo("Object has no id"));
            }

            IKeeper HistoryManagerDataSource = ItemKeeper <HistorySaver.HistorySaverUnit> .getInstance(RIFDC_App.mainDataRoom);

            Lib.Filter myFilter = new Lib.Filter();

            myFilter.addNewFilteringRule(
                HistoryManagerDataSource.sampleObject.getFieldInfoByFieldClassName("objectId"),
                Lib.RIFDC_DataCompareOperatorEnum.equal,
                t.id, Lib.Filter.FilteringRuleTypeEnum.NotSpecified);

            return(HistoryManagerDataSource.deleteFiteredPackege(myFilter));
        }
예제 #18
0
 private HistorySaver(IDataRoom _dataRoom, IKeepable _sampleObject = null)
 {
     dataRoom = _dataRoom;
     items    = ItemKeeper <HistorySaverUnit> .getInstance(dataRoom);
 }
예제 #19
0
 public ItemKeeper(T val, ItemKeeper next, object owner)
 {
     Value = val;
     Next  = new Shielded <ItemKeeper>(next, owner);
 }
예제 #20
0
 private Shielded <ItemKeeper> CreateRef(ItemKeeper item = null)
 {
     return(new Shielded <ItemKeeper>(item, _owner));
 }