Beispiel #1
0
        public int SaveOriginalValue(Guid _uid, AbstractXReportItem _reportItem, IStorage _storage, int?_lastId,
                                     DateTime _now, AbstractXServer _abstractXServer)
        {
            var items = ((XReportList)_reportItem).Items;

            foreach (var reportListItem in items)
            {
                switch (reportListItem.State)
                {
                case EReportListItemState.ADDED:
                    m_list.Add(reportListItem.Uid);
                    break;

                case EReportListItemState.REMOVED:
                    m_list.Remove(reportListItem.Uid);
                    _abstractXServer.Delete(_storage, reportListItem.Uid, _reportItem.FieldId.GetHashCode(), _now);
                    break;

                case EReportListItemState.ORIGINAL:
                    if (_abstractXServer.IsShrinking)
                    {
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(-1);
        }
Beispiel #2
0
        public int SaveOriginalValue(Guid _uid, AbstractXReportItem _reportItem, IStorage _storage,
                                     int?_lastId, DateTime _now, AbstractXServer _abstractXServer)
        {
            var item = (XReportItem <T>)_reportItem;

            Value = item.Value;
            return(_storage.InsertValue(_uid, _reportItem.FieldId.GetHashCode(), item.Value, _lastId, _now));
        }
        protected AbstractXServer()
        {
            if (Instance != null)
                throw new Exception("Instance of Server Allready Exist");

            Instance = this;
            XTransportService.InitTransportHost();
        }
 public ServerXObjectContainer(Guid _uid, AbstractXServer.ObjectDescriptor _descriptor)
 {
     m_kind = _descriptor.Kind;
     Uid = _uid;
     ValidFrom = _descriptor.ValidFrom;
     ValidTill = _descriptor.ValidTill;
     Stored = _descriptor.ValidTill.HasValue ? (uint)0 : (uint)1;
 }
Beispiel #5
0
        internal bool Save(SessionId _sessionId, IStorage _storage, DateTime _now, AbstractXServer _abstractXServer)
        {
            List <XReport> reports;

            if (m_changes.TryGetValue(_sessionId, out reports) && m_currentVersion[_sessionId] >= 0)
            {
                var reverseItems = new List <AbstractXReportItem>();

                var changes = reports[m_currentVersion[_sessionId]];
                foreach (var item in changes.Items)
                {
                    IServerXValue xValue;
                    if (!m_xValues.TryGetValue(item.FieldId, out xValue))
                    {
                        xValue = item.CreateXValue();
                        m_xValues.Add(item.FieldId, xValue);
                        reverseItems.Add(item.CreateDefaultReportItem());
                    }
                    else
                    {
                        reverseItems.Add(xValue.CreateReverseReportItem(item));
                    }

                    int oldId;
                    if (m_xValueOldIds.TryGetValue(item.FieldId, out oldId))
                    {
                        m_xValueOldIds[item.FieldId] = xValue.SaveOriginalValue(Uid, item, _storage, oldId, _now, _abstractXServer);
                    }
                    else
                    {
                        m_xValueOldIds[item.FieldId] = xValue.SaveOriginalValue(Uid, item, _storage, null, _now, _abstractXServer);
                    }
                }
                reports.Clear();
                m_currentVersion[_sessionId] = -1;
                ValidFrom = _now;

                foreach (var pair in m_changes)
                {
                    if (pair.Key == _sessionId)
                    {
                        continue;
                    }
                    var reverseReport = new XReport(changes.Uid, reverseItems, changes.Kind, EState.UNDO_ABLE | EState.REVERT_ABLE | (pair.Value.Any()?EState.REDO_ABLE : EState.SINGLE))
                    {
                        ActualFrom = changes.ActualFrom
                    };
                    foreach (var xReport in pair.Value)
                    {
                        xReport.UpdateAccordingNewValues(m_xValues, reverseReport);
                    }
                    pair.Value.Insert(0, reverseReport);
                    m_currentVersion[pair.Key]++;
                }
                return(true);
            }
            return(false);
        }
        protected AbstractXServer()
        {
            if (Instance != null)
            {
                throw new Exception("Instance of Server Allready Exist");
            }

            Instance = this;
            XTransportService.InitTransportHost();
        }
        internal void GetAvailableRedoDate(Guid _uid, SessionId _sessionId, AbstractXServer _server, ref uint _generation,
                                           ref List <Guid> _candidates)
        {
            ServerXObjectContainer xObjectContainer;

            if (m_objects.TryGetValue(_uid, out xObjectContainer))
            {
                xObjectContainer.GetAvailableRedoDate(_sessionId, this, ref _generation, ref _candidates);
            }
        }
Beispiel #8
0
        internal void GetAvailableRedoDate(SessionId _sessionId, AbstractXServer _server,
                                           ref uint _generation, ref List <Guid> _candidates)
        {
            XReport changes = null;
            int     version;

            if (m_currentVersion.TryGetValue(_sessionId, out version))
            {
                if (version < m_changes[_sessionId].Count)
                {
                    if (version < m_changes[_sessionId].Count - 1)
                    {
                        changes = m_changes[_sessionId][version + 1];
                        var result = changes.ActualFrom;
                        if (result < _generation)
                        {
                            _candidates.Clear();
                            _generation = result;
                        }
                        if (result == _generation)
                        {
                            _candidates.Add(Uid);
                        }
                    }
                    else if (version >= 0)
                    {
                        changes = m_changes[_sessionId][version];
                    }
                }
            }
            var uids = new List <Guid>();

            if (changes != null)
            {
                uids.AddRange(
                    changes.Items.OfType <XReportList>().SelectMany(_list => _list.Items).Where(
                        _item => _item.State == EReportListItemState.ADDED).Select(_item => _item.Uid));
            }
            foreach (var pair in m_xValues)
            {
                var list = pair.Value as ServerXList;
                if (list == null)
                {
                    continue;
                }
                uids.AddRange(list.GetGuids());
            }
            foreach (var uid in uids)
            {
                _server.GetAvailableRedoDate(uid, _sessionId, _server, ref _generation, ref _candidates);
            }
        }
Beispiel #9
0
        internal virtual bool SaveChildren(AbstractXServer _server, SessionId _sessionId, IStorage _storage, DateTime _now)
        {
            var saved = false;

            foreach (var pair in m_xValues)
            {
                var list = pair.Value as ServerXList;
                if (list != null)
                {
                    foreach (var childUid in list.GetGuids())
                    {
                        saved = _server.SaveChild(childUid, Uid, _sessionId, _storage, pair.Key, _now) | saved;
                    }
                }
            }
            return(saved);
        }
 internal override bool SaveChildren(AbstractXServer _server, SessionId _sessionId, IStorage _storage, DateTime _now)
 {
     var toSave = new List<Guid>();
     foreach (var pair in XValues)
     {
         var list = pair.Value as ServerXList;
         if (list != null)
         {
             toSave.AddRange(list.GetGuids());
         }
     }
     var saved = false;
     foreach (var uid in toSave.Distinct())
     {
         saved |= _server.SaveInternal(uid, _storage, _now, _sessionId);
     }
     return saved;
 }
        internal override bool SaveChildren(AbstractXServer _server, SessionId _sessionId, IStorage _storage, DateTime _now)
        {
            var toSave = new List <Guid>();

            foreach (var pair in XValues)
            {
                var list = pair.Value as ServerXList;
                if (list != null)
                {
                    toSave.AddRange(list.GetGuids());
                }
            }
            var saved = false;

            foreach (var uid in toSave.Distinct())
            {
                saved |= _server.SaveInternal(uid, _storage, _now, _sessionId);
            }
            return(saved);
        }
 internal virtual bool SaveChildren(AbstractXServer _server, SessionId _sessionId, IStorage _storage, DateTime _now)
 {
     var saved = false;
     foreach (var pair in m_xValues)
     {
         var list = pair.Value as ServerXList;
         if (list != null)
         {
             foreach (var childUid in list.GetGuids())
             {
                 saved = _server.SaveChild(childUid, Uid, _sessionId, _storage, pair.Key, _now) | saved;
             }
         }
     }
     return saved;
 }
Beispiel #13
0
        internal void GetAvailableUndoDate(SessionId _sessionId, AbstractXServer _server,
                                           ref uint _dateTime, ref List <Guid> _candidates)
        {
            XReport changes = null;
            var     result  = Stored;
            int     version;

            if (m_currentVersion.TryGetValue(_sessionId, out version))
            {
                if (version >= 0)
                {
                    changes = m_changes[_sessionId][version];
                    result  = changes.ActualFrom;
                }
                if (result > _dateTime)
                {
                    _candidates.Clear();
                    _dateTime = result;
                }
                if (result == _dateTime)
                {
                    _candidates.Add(Uid);
                }
            }

            var uids = new List <Guid>();

            if (changes != null)
            {
                uids.AddRange(
                    changes.Items.OfType <XReportList>().SelectMany(_list => _list.Items).Where(
                        _item => _item.State == EReportListItemState.ADDED).Select(_item => _item.Uid));
            }

            foreach (var pair in m_xValues)
            {
                var list = pair.Value as ServerXList;
                if (list == null)
                {
                    continue;
                }
                uids.AddRange(list.GetGuids());
                if (changes != null)
                {
                    var pairCopy = pair;
                    var update   = (XReportList)changes.Items.FirstOrDefault(_item => _item.FieldId == pairCopy.Key);
                    if (update != null)
                    {
                        foreach (var item in update.Items)
                        {
                            switch (item.State)
                            {
                            case EReportListItemState.REMOVED:
                                uids.Remove(item.Uid);
                                break;
                            }
                        }
                    }
                }
            }
            foreach (var uid in uids)
            {
                _server.GetAvailableUndoDate(uid, _sessionId, _server, ref _dateTime, ref _candidates);
            }
        }
Beispiel #14
0
        public int SaveOriginalValue(Guid _uid, AbstractXReportItem _reportItem, IStorage _storage, int? _lastId,
            DateTime _now, AbstractXServer _abstractXServer)
        {
            var items = ((XReportList) _reportItem).Items;
            foreach (var reportListItem in items)
            {
                switch (reportListItem.State)
                {
                    case EReportListItemState.ADDED:
                        m_list.Add(reportListItem.Uid);
                        break;
                    case EReportListItemState.REMOVED:
                        m_list.Remove(reportListItem.Uid);
                        _abstractXServer.Delete(_storage, reportListItem.Uid, _reportItem.FieldId.GetHashCode(), _now);
                        break;
                    case EReportListItemState.ORIGINAL:
                        if(_abstractXServer.IsShrinking)
                        {

                        }
                        else
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }
            return -1;
        }
Beispiel #15
0
 internal void GetAvailableUndoDate(Guid _uid, SessionId _sessionId, AbstractXServer _server, ref uint _dateTime,
     ref List<Guid> _candidates)
 {
     ServerXObjectContainer xObjectContainer;
     if (m_objects.TryGetValue(_uid, out xObjectContainer))
     {
         xObjectContainer.GetAvailableUndoDate(_sessionId, this, ref _dateTime, ref _candidates);
     }
 }
 internal void GetAvailableRedoDate(SessionId _sessionId, AbstractXServer _server,
     ref uint _generation, ref List<Guid> _candidates)
 {
     XReport changes = null;
     int version;
     if (m_currentVersion.TryGetValue(_sessionId, out version))
     {
         if (version < m_changes[_sessionId].Count)
         {
             if (version < m_changes[_sessionId].Count - 1)
             {
                 changes = m_changes[_sessionId][version + 1];
                 var result = changes.ActualFrom;
                 if (result < _generation)
                 {
                     _candidates.Clear();
                     _generation = result;
                 }
                 if (result == _generation)
                 {
                     _candidates.Add(Uid);
                 }
             }
             else if (version >= 0)
             {
                 changes = m_changes[_sessionId][version];
             }
         }
     }
     var uids = new List<Guid>();
     if (changes != null)
     {
         uids.AddRange(
             changes.Items.OfType<XReportList>().SelectMany(_list => _list.Items).Where(
                 _item => _item.State == EReportListItemState.ADDED).Select(_item => _item.Uid));
     }
     foreach (var pair in m_xValues)
     {
         var list = pair.Value as ServerXList;
         if (list == null) continue;
         uids.AddRange(list.GetGuids());
     }
     foreach (var uid in uids)
     {
         _server.GetAvailableRedoDate(uid, _sessionId, _server, ref _generation, ref _candidates);
     }
 }
        internal void GetAvailableUndoDate(SessionId _sessionId, AbstractXServer _server,
            ref uint _dateTime, ref List<Guid> _candidates)
        {
            XReport changes = null;
            var result = Stored;
            int version;
            if (m_currentVersion.TryGetValue(_sessionId, out version))
            {
                if (version >= 0)
                {
                    changes = m_changes[_sessionId][version];
                    result = changes.ActualFrom;
                }
                if (result > _dateTime)
                {
                    _candidates.Clear();
                    _dateTime = result;
                }
                if (result == _dateTime)
                {
                    _candidates.Add(Uid);
                }
            }

            var uids = new List<Guid>();
            if (changes != null)
            {
                uids.AddRange(
                    changes.Items.OfType<XReportList>().SelectMany(_list => _list.Items).Where(
                        _item => _item.State == EReportListItemState.ADDED).Select(_item => _item.Uid));
            }

            foreach (var pair in m_xValues)
            {
                var list = pair.Value as ServerXList;
                if (list == null) continue;
                uids.AddRange(list.GetGuids());
                if (changes != null)
                {
                    var pairCopy = pair;
                    var update = (XReportList) changes.Items.FirstOrDefault(_item => _item.FieldId == pairCopy.Key);
                    if (update != null)
                    {
                        foreach (var item in update.Items)
                        {
                            switch (item.State)
                            {
                                case EReportListItemState.REMOVED:
                                    uids.Remove(item.Uid);
                                    break;
                            }
                        }
                    }
                }
            }
            foreach (var uid in uids)
            {
                _server.GetAvailableUndoDate(uid, _sessionId, _server, ref _dateTime, ref _candidates);
            }
        }
        internal bool Save(SessionId _sessionId, IStorage _storage, DateTime _now, AbstractXServer _abstractXServer)
        {
            List<XReport> reports;
            if (m_changes.TryGetValue(_sessionId, out reports) && m_currentVersion[_sessionId] >= 0)
            {
                var reverseItems = new List<AbstractXReportItem>();

                var changes = reports[m_currentVersion[_sessionId]];
                foreach (var item in changes.Items)
                {
                    IServerXValue xValue;
                    if (!m_xValues.TryGetValue(item.FieldId, out xValue))
                    {
                        xValue = item.CreateXValue();
                        m_xValues.Add(item.FieldId, xValue);
                        reverseItems.Add(item.CreateDefaultReportItem());
                    }
                    else
                    {
                        reverseItems.Add(xValue.CreateReverseReportItem(item));
                    }

                    int oldId;
                    if (m_xValueOldIds.TryGetValue(item.FieldId, out oldId))
                    {
                        m_xValueOldIds[item.FieldId] = xValue.SaveOriginalValue(Uid, item, _storage, oldId, _now, _abstractXServer);
                    }
                    else
                    {
                        m_xValueOldIds[item.FieldId] = xValue.SaveOriginalValue(Uid, item, _storage, null, _now, _abstractXServer);
                    }
                }
                reports.Clear();
                m_currentVersion[_sessionId] = -1;
                ValidFrom = _now;

                foreach (var pair in m_changes)
                {
                    if (pair.Key == _sessionId)
                    {
                        continue;
                    }
                    var reverseReport = new XReport(changes.Uid, reverseItems, changes.Kind, EState.UNDO_ABLE | EState.REVERT_ABLE | (pair.Value.Any()?EState.REDO_ABLE : EState.SINGLE)) { ActualFrom = changes.ActualFrom };
                    foreach (var xReport in pair.Value)
                    {
                        xReport.UpdateAccordingNewValues(m_xValues, reverseReport);
                    }
                    pair.Value.Insert(0, reverseReport);
                    m_currentVersion[pair.Key]++;
                }
                return true;
            }
            return false;
        }