Esempio n. 1
0
 private void Init()
 {
     if (_initialized)
     {
         return;
     }
     lock (Locker)
     {
         if (_initialized)
         {
             return;
         }
         _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitingEvent(this));
         _dicByCode.Clear();
         _dicById.Clear();
         _dicByCode.Add(CatalogState.VirtualRoot.Code, CatalogState.VirtualRoot);
         _dicById.Add(CatalogState.VirtualRoot.Id, CatalogState.VirtualRoot);
         var allCatalogs = _acDomain.RetrieveRequiredService <IOriginalHostStateReader>().GetCatalogs().OrderBy(a => a.ParentCode);
         foreach (var catalog in allCatalogs)
         {
             CatalogState orgState = CatalogState.Create(_acDomain, catalog);
             if (!_dicByCode.ContainsKey(catalog.Code))
             {
                 _dicByCode.Add(catalog.Code, orgState);
             }
             if (!_dicById.ContainsKey(catalog.Id))
             {
                 _dicById.Add(catalog.Id, orgState);
             }
         }
         _initialized = true;
         _acDomain.MessageDispatcher.DispatchMessage(new MemorySetInitializedEvent(this));
     }
 }
Esempio n. 2
0
        private void changeState(CatalogState state)
        {
            switch (state)
            {
            case CatalogState.Homepage:
                homePageController.Show();
                shopController.Hide();
                headerController.ShowStatsButton();
                statsController.Hide();
                subnavController.Hide();
                break;

            case CatalogState.ItemsView:
                homePageController.Show();
                homePageController.SetChallengeVisiblity(isActive: false);
                shopController.Show();
                headerController.ShowBackButton();
                statsController.Hide();
                subnavController.Show();
                break;

            case CatalogState.StatsView:
                homePageController.Hide();
                shopController.Hide();
                headerController.ShowBackButton();
                statsController.Show();
                subnavController.Hide();
                break;
            }
        }
Esempio n. 3
0
        public void CatalogState_ToString_1()
        {
            CatalogState state = new CatalogState();

            Assert.AreEqual("(null) 0001-01-01 00:00:00 0", state.ToString());

            state = _GetState();
            Assert.AreEqual("IBIS 2017-12-08 22:42:00 123", state.ToString());
        }
Esempio n. 4
0
        public void CatalogState_ToJson_1()
        {
            CatalogState state = new CatalogState();

            Assert.AreEqual("{}", JsonUtility.SerializeShort(state));

            state = _GetState();
            Assert.AreEqual("{'date':'2017-12-08T22:42:00','database':'IBIS','maxMfn':123,'records':[{'mfn':1,'status':1,'version':3},{'mfn':2,'status':1,'version':2},{'mfn':3,'status':1,'version':1},{'mfn':4,'status':32,'version':2}],'logicallyDeleted':[1,2,3]}", JsonUtility.SerializeShort(state));
        }
Esempio n. 5
0
        public void SetupProducts()
        {
            var catalogState = new CatalogState();
            this.Queries = catalogState;
            this.Changes = catalogState;
            this.a_fake_ProductIdGenerator = new FakeProductIdGenerator();

            this.Catalog = new Catalog(catalogState, catalogState, a_fake_ProductIdGenerator);
        }
Esempio n. 6
0
        public void CatalogState_Serialization_1()
        {
            CatalogState state = new CatalogState();

            _TestSerialization(state);

            state = _GetState();
            _TestSerialization(state);
        }
Esempio n. 7
0
        public void CatalogState_ToXml_1()
        {
            CatalogState state = new CatalogState();

            Assert.AreEqual("<database />", XmlUtility.SerializeShort(state));

            state = _GetState();
            Assert.AreEqual("<database date=\"2017-12-08T22:42:00\" database=\"IBIS\" maxMfn=\"123\"><records><record mfn=\"1\" status=\"LogicallyDeleted\" version=\"3\" /><record mfn=\"2\" status=\"LogicallyDeleted\" version=\"2\" /><record mfn=\"3\" status=\"LogicallyDeleted\" version=\"1\" /><record mfn=\"4\" status=\"Last\" version=\"2\" /></records><logicallyDeleted><mfn>1</mfn><mfn>2</mfn><mfn>3</mfn></logicallyDeleted></database>", XmlUtility.SerializeShort(state));
        }
Esempio n. 8
0
        public bool TryGetCatalog(string catalogCode, out CatalogState catalog)
        {
            if (!_initialized)
            {
                Init();
            }
            Debug.Assert(!string.IsNullOrEmpty(catalogCode), "catalogCode不能为空,编码为空的目录对应的可能是Catalog.Empty目录,请在应用层做判断。");

            return(_dicByCode.TryGetValue(catalogCode, out catalog));
        }
Esempio n. 9
0
        public bool TryGetCatalog(Guid catalogId, out CatalogState oragnization)
        {
            if (!_initialized)
            {
                Init();
            }
            Debug.Assert(catalogId != Guid.Empty, "传入的catalogId值不应该是Guid.Empty");

            return(_dicById.TryGetValue(catalogId, out oragnization));
        }
Esempio n. 10
0
        public void CatalogState_Construction_1()
        {
            CatalogState state = new CatalogState();

            Assert.AreEqual(0, state.Id);
            Assert.AreEqual(DateTime.MinValue, state.Date);
            Assert.IsNull(state.Database);
            Assert.AreEqual(0, state.MaxMfn);
            Assert.IsNull(state.Records);
            Assert.IsNull(state.LogicallyDeleted);
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                return;
            }

            try
            {
                string connectionString = args[0];
                using (IrbisConnection connection
                           = new IrbisConnection(connectionString))
                {
                    ConnectedClient provider
                        = new ConnectedClient(connection);

                    CatalogState first;
                    if (File.Exists("first.state"))
                    {
                        first = SerializationUtility
                                .RestoreObjectFromFile <CatalogState>
                                (
                            "first.state"
                                );
                        Console.WriteLine("Previous state restored from first.state");
                    }
                    else
                    {
                        first = provider.GetCatalogState("ISTU");
                        first.SaveToFile("first.state");
                        Console.WriteLine("Initial state saved to first.state");

                        return;
                    }

                    CatalogState second = provider.GetCatalogState("ISTU");
                    second.SaveToFile("second.state");
                    Console.WriteLine("New state saved to second.state");

                    CatalogDelta delta = CatalogDelta.Create
                                         (
                        first,
                        second
                                         );
                    delta.SaveToFile("state.delta");
                    Console.WriteLine("Difference saved to state.delta");
                    Console.WriteLine(delta);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 12
0
 public static CatalogTr Create(CatalogState catalog)
 {
     return(new CatalogTr
     {
         CategoryCode = catalog.CategoryCode,
         Code = catalog.Code,
         CreateOn = catalog.CreateOn,
         Id = catalog.Id,
         IsEnabled = catalog.IsEnabled,
         Name = catalog.Name,
         ParentCode = catalog.ParentCode,
         ParentName = catalog.Parent.Name,
         SortCode = catalog.SortCode
     });
 }
Esempio n. 13
0
            private void Update(CatalogState state)
            {
                var dicByCode = _set._dicByCode;
                var dicById   = _set._dicById;
                var oldKey    = dicById[state.Id].Code;
                var newKey    = state.Code;

                dicById[state.Id] = state;
                if (!dicByCode.ContainsKey(newKey))
                {
                    dicByCode.Add(newKey, state);
                    dicByCode.Remove(oldKey);
                }
                else
                {
                    dicByCode[newKey] = state;
                }
            }
Esempio n. 14
0
        private void _TestSerialization
        (
            [NotNull] CatalogState first
        )
        {
            byte[]       bytes  = first.SaveToMemory();
            CatalogState second = bytes.RestoreObjectFromMemory <CatalogState>();

            Assert.AreEqual(first.Id, second.Id);
            Assert.AreEqual(first.Date, second.Date);
            Assert.AreEqual(first.Database, second.Database);
            Assert.AreEqual(first.MaxMfn, second.MaxMfn);
            if (ReferenceEquals(first.Records, null))
            {
                Assert.IsNull(second.Records, null);
            }
            else
            {
                Assert.IsNotNull(second.Records);
                Assert.AreEqual(first.Records.Length, second.Records.Length);
                for (int i = 0; i < first.Records.Length; i++)
                {
                    Assert.AreEqual(first.Records[i].Id, second.Records[i].Id);
                    Assert.AreEqual(first.Records[i].Mfn, second.Records[i].Mfn);
                    Assert.AreEqual(first.Records[i].Status, second.Records[i].Status);
                    Assert.AreEqual(first.Records[i].Version, second.Records[i].Version);
                }
            }
            if (ReferenceEquals(first.LogicallyDeleted, null))
            {
                Assert.IsNull(second.LogicallyDeleted);
            }
            else
            {
                Assert.IsNotNull(second.LogicallyDeleted);
                Assert.AreEqual(first.LogicallyDeleted.Length, second.LogicallyDeleted.Length);
                for (int i = 0; i < first.LogicallyDeleted.Length; i++)
                {
                    Assert.AreEqual(first.LogicallyDeleted[i], second.LogicallyDeleted[i]);
                }
            }
        }
Esempio n. 15
0
        private ProcessResult ValidCatalogCode(out CatalogState org)
        {
            if (string.IsNullOrEmpty(this.CatalogCode))
            {
                org = CatalogState.Empty;
                return(new ProcessResult(false, Status.InvalidCatalog, "目录码为空"));
            }
            if (!_acDomain.CatalogSet.TryGetCatalog(this.CatalogCode, out org))
            {
                return(new ProcessResult(false, Status.InvalidCatalog, string.Format("非法的目录码{0}", this.CatalogCode)));
            }
            OntologyCatalogState oorg;

            if (!this.Ontology.Catalogs.TryGetValue(org, out oorg))
            {
                return(new ProcessResult(false, Status.InvalidCatalog, string.Format("对于{0}来说{1}是非法的目录码", this.Ontology.Ontology.Name, org.Code)));
            }
            var orgCode = org.Code;

            return(_acDomain.CatalogSet.Any(o => orgCode.Equals(o.ParentCode, StringComparison.OrdinalIgnoreCase)) ? new ProcessResult(false, Status.InvalidCatalog, string.Format("{0}不是叶节点,不能容纳" + this.Ontology.Ontology.Name, org.Name)) : ProcessResult.Ok);
        }
Esempio n. 16
0
 public bool TryGetFunction(CatalogState resourceType, string functionCode, out FunctionState function)
 {
     if (!_initialized)
     {
         Init();
     }
     if (resourceType == null)
     {
         throw new ArgumentNullException("resourceType");
     }
     if (string.IsNullOrEmpty(functionCode))
     {
         throw new ArgumentNullException("functionCode");
     }
     if (_dicByCode.ContainsKey(resourceType))
     {
         return(_dicByCode[resourceType].TryGetValue(functionCode, out function));
     }
     function = FunctionState.Empty;
     return(false);
 }
Esempio n. 17
0
            private void Handle(IAcSession acSession, ICatalogCreateIo input, bool isCommand)
            {
                var acDomain          = _set._acDomain;
                var dicByCode         = _set._dicByCode;
                var dicById           = _set._dicById;
                var catalogRepository = acDomain.RetrieveRequiredService <IRepository <Catalog> >();

                if (!input.Id.HasValue)
                {
                    throw new ValidationException("标识是必须的");
                }
                if (string.IsNullOrEmpty(input.Code))
                {
                    throw new ValidationException("编码不能为空");
                }
                if (string.IsNullOrEmpty(input.Name))
                {
                    throw new ValidationException("名称是必须的");
                }
                Catalog entity;

                lock (MessageLocker)
                {
                    CatalogState catalog;
                    if (acDomain.CatalogSet.TryGetCatalog(input.Id.Value, out catalog))
                    {
                        throw new ValidationException("给定标识的目录已经存在");
                    }
                    if (acDomain.CatalogSet.TryGetCatalog(input.Code, out catalog))
                    {
                        throw new ValidationException("重复的目录码");
                    }
                    if (!string.IsNullOrEmpty(input.ParentCode))
                    {
                        CatalogState parentOragnization;
                        if (!acDomain.CatalogSet.TryGetCatalog(input.ParentCode, out parentOragnization))
                        {
                            throw new ValidationException("标识为" + input.ParentCode + "的父目录不存在");
                        }
                        if (string.Equals(input.Code, input.ParentCode) || !input.Code.StartsWith(parentOragnization.Code, StringComparison.OrdinalIgnoreCase))
                        {
                            throw new ValidationException("子级目录的编码必须以父级目录编码为前缀");
                        }
                        if (acDomain.CatalogSet.Any(a => string.Equals(a.ParentCode, input.ParentCode) && string.Equals(a.Name, input.Name, StringComparison.OrdinalIgnoreCase)))
                        {
                            throw new ValidationException("兄弟目录间不能重名");
                        }
                    }
                    else
                    {
                        if (acDomain.CatalogSet.Any(a => string.IsNullOrEmpty(a.ParentCode) && string.Equals(a.Name, input.Name, StringComparison.OrdinalIgnoreCase)))
                        {
                            throw new ValidationException("重复的目录名");
                        }
                    }

                    entity = Catalog.Create(input);
                    var state = CatalogState.Create(acDomain, entity);
                    if (!dicByCode.ContainsKey(entity.Code))
                    {
                        dicByCode.Add(entity.Code, state);
                    }
                    if (!dicById.ContainsKey(entity.Id))
                    {
                        dicById.Add(entity.Id, state);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            catalogRepository.Add(entity);
                            catalogRepository.Context.Commit();
                        }
                        catch
                        {
                            if (dicByCode.ContainsKey(entity.Code))
                            {
                                dicByCode.Remove(entity.Code);
                            }
                            if (dicById.ContainsKey(entity.Id))
                            {
                                dicById.Remove(entity.Id);
                            }
                            catalogRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new CatalogAddedEvent(acSession, entity, input, isPrivate: true));
                }
            }
        private bool ValidCatalogCode(OntologyDescriptor ontology, string catalogCode, out CatalogState org, out ProcessResult result)
        {
            if (string.IsNullOrEmpty(catalogCode))
            {
                org    = CatalogState.Empty;
                result = ProcessResult.Ok;
                return(false);
            }
            if (!ontology.Host.CatalogSet.TryGetCatalog(catalogCode.Trim(), out org))
            {
                result = new ProcessResult(false, Status.InvalidCatalog, string.Format("非法的目录码{0}", catalogCode));
                return(false);
            }
            OntologyCatalogState oorg;

            if (!ontology.Catalogs.TryGetValue(org, out oorg))
            {
                result = new ProcessResult(false, Status.InvalidCatalog, string.Format("对于{0}来说{1}是非法的目录码", ontology.Ontology.Name, org.Code));
                return(false);
            }
            var orgCode = org.Code;

            if (ontology.Host.CatalogSet.Any(o => orgCode.Equals(o.ParentCode, StringComparison.OrdinalIgnoreCase)))
            {
                result = new ProcessResult(false, Status.InvalidCatalog, string.Format("{0}不是叶节点,不能容纳" + ontology.Ontology.Name, org.Name));
                return(false);
            }
            result = ProcessResult.Ok;
            return(true);
        }
Esempio n. 19
0
 private bool ValidCatalogCode(OntologyDescriptor ontology, string catalogCode, out CatalogState org, out ProcessResult result)
 {
     if (string.IsNullOrEmpty(catalogCode))
     {
         org = CatalogState.Empty;
         result = ProcessResult.Ok;
         return false;
     }
     if (!ontology.Host.CatalogSet.TryGetCatalog(catalogCode.Trim(), out org))
     {
         result = new ProcessResult(false, Status.InvalidCatalog, string.Format("非法的目录码{0}", catalogCode));
         return false;
     }
     OntologyCatalogState oorg;
     if (!ontology.Catalogs.TryGetValue(org, out oorg))
     {
         result = new ProcessResult(false, Status.InvalidCatalog, string.Format("对于{0}来说{1}是非法的目录码", ontology.Ontology.Name, org.Code));
         return false;
     }
     var orgCode = org.Code;
     if (ontology.Host.CatalogSet.Any(o => orgCode.Equals(o.ParentCode, StringComparison.OrdinalIgnoreCase)))
     {
         result = new ProcessResult(false, Status.InvalidCatalog, string.Format("{0}不是叶节点,不能容纳" + ontology.Ontology.Name, org.Name));
         return false;
     }
     result = ProcessResult.Ok;
     return true;
 }
Esempio n. 20
0
 public static CatalogTr Create(CatalogState catalog)
 {
     return new CatalogTr
     {
         CategoryCode = catalog.CategoryCode,
         Code = catalog.Code,
         CreateOn = catalog.CreateOn,
         Id = catalog.Id,
         IsEnabled = catalog.IsEnabled,
         Name = catalog.Name,
         ParentCode = catalog.ParentCode,
         ParentName = catalog.Parent.Name,
         SortCode = catalog.SortCode
     };
 }
Esempio n. 21
0
            private void Handle(IAcSession acSession, ICatalogUpdateIo input, bool isCommand)
            {
                var acDomain          = _set._acDomain;
                var catalogRepository = acDomain.RetrieveRequiredService <IRepository <Catalog> >();

                if (string.IsNullOrEmpty(input.Code))
                {
                    throw new ValidationException("编码不能为空");
                }
                CatalogState bkState;

                if (!acDomain.CatalogSet.TryGetCatalog(input.Id, out bkState))
                {
                    throw new ValidationException("给定标识的目录不存在" + input.Id);
                }
                Catalog entity;
                var     stateChanged = false;

                lock (MessageLocker)
                {
                    CatalogState oragnization;
                    if (acDomain.CatalogSet.TryGetCatalog(input.Code, out oragnization) && oragnization.Id != input.Id)
                    {
                        throw new ValidationException("重复的目录码" + input.Code);
                    }
                    if (!string.IsNullOrEmpty(input.ParentCode))
                    {
                        CatalogState parentOragnization;
                        if (!acDomain.CatalogSet.TryGetCatalog(input.ParentCode, out parentOragnization))
                        {
                            throw new ValidationException("标识为" + input.ParentCode + "的父目录不存在");
                        }
                        if (input.ParentCode.Equals(input.Code, StringComparison.OrdinalIgnoreCase))
                        {
                            throw new AnycmdException("目录的父目录不能是自己");
                        }
                        if (!input.Code.StartsWith(parentOragnization.Code, StringComparison.OrdinalIgnoreCase))
                        {
                            throw new ValidationException("子级目录的编码必须以父级目录编码为前缀");
                        }
                        if (input.ParentCode.StartsWith(input.Code, StringComparison.OrdinalIgnoreCase))
                        {
                            throw new AnycmdException("目录的父目录不能是自己的子孙级目录");
                        }
                    }
                    entity = catalogRepository.GetByKey(input.Id);
                    if (entity == null)
                    {
                        throw new NotExistException();
                    }

                    entity.Update(input);

                    var newState = CatalogState.Create(acDomain, entity);
                    stateChanged = newState != bkState;
                    if (stateChanged)
                    {
                        Update(newState);
                    }
                    if (isCommand)
                    {
                        try
                        {
                            catalogRepository.Update(entity);
                            catalogRepository.Context.Commit();
                        }
                        catch
                        {
                            if (stateChanged)
                            {
                                Update(bkState);
                            }
                            catalogRepository.Context.Rollback();
                            throw;
                        }
                    }
                }
                if (isCommand && stateChanged)
                {
                    acDomain.MessageDispatcher.DispatchMessage(new CatalogUpdatedEvent(acSession, entity, input, isPrivate: true));
                }
            }
Esempio n. 22
0
        public void CatalogDelta_Create_1()
        {
            CatalogState firstState = new CatalogState
            {
                Id               = 1,
                Date             = new DateTime(2017, 12, 8, 22, 42, 0),
                Database         = "IBIS",
                MaxMfn           = 4,
                LogicallyDeleted = new[] { 1, 2 },
                Records          = new[]
                {
                    new RecordState
                    {
                        Id      = 2,
                        Mfn     = 1,
                        Status  = RecordStatus.LogicallyDeleted,
                        Version = 3
                    },
                    new RecordState
                    {
                        Id      = 3,
                        Mfn     = 2,
                        Status  = RecordStatus.LogicallyDeleted,
                        Version = 2
                    },
                    new RecordState
                    {
                        Id      = 4,
                        Mfn     = 3,
                        Status  = RecordStatus.Last,
                        Version = 1
                    },
                    new RecordState
                    {
                        Id      = 5,
                        Mfn     = 4,
                        Status  = RecordStatus.Last,
                        Version = 2
                    }
                }
            };

            CatalogState secondState = new CatalogState
            {
                Id               = 2,
                Date             = new DateTime(2017, 12, 9, 22, 42, 0),
                Database         = "IBIS",
                MaxMfn           = 6,
                LogicallyDeleted = new[] { 1, 2, 3 },
                Records          = new[]
                {
                    new RecordState
                    {
                        Id      = 2,
                        Mfn     = 1,
                        Status  = RecordStatus.LogicallyDeleted,
                        Version = 3
                    },
                    new RecordState
                    {
                        Id      = 3,
                        Mfn     = 2,
                        Status  = RecordStatus.LogicallyDeleted,
                        Version = 2
                    },
                    new RecordState
                    {
                        Id      = 4,
                        Mfn     = 3,
                        Status  = RecordStatus.LogicallyDeleted,
                        Version = 2
                    },
                    new RecordState
                    {
                        Id      = 5,
                        Mfn     = 4,
                        Status  = RecordStatus.Last,
                        Version = 4
                    },
                    new RecordState
                    {
                        Id      = 6,
                        Mfn     = 5,
                        Status  = RecordStatus.Last,
                        Version = 1
                    },
                    new RecordState
                    {
                        Id      = 7,
                        Mfn     = 6,
                        Status  = RecordStatus.Last,
                        Version = 1
                    }
                }
            };

            CatalogDelta delta = CatalogDelta.Create
                                 (
                firstState,
                secondState
                                 );

            Assert.AreEqual(0, delta.Id);
            Assert.AreEqual(new DateTime(2017, 12, 8, 22, 42, 0, 0), delta.FirstDate);
            Assert.AreEqual(new DateTime(2017, 12, 9, 22, 42, 0, 0), delta.SecondDate);
            Assert.AreEqual("IBIS", delta.Database);
            Assert.IsNotNull(delta.NewRecords);
            Assert.AreEqual(2, delta.NewRecords.Length);
            Assert.AreEqual(5, delta.NewRecords[0]);
            Assert.AreEqual(6, delta.NewRecords[1]);
            Assert.IsNotNull(delta.DeletedRecords);
            Assert.AreEqual(1, delta.DeletedRecords.Length);
            Assert.AreEqual(3, delta.DeletedRecords[0]);
            Assert.IsNotNull(delta.AlteredRecords);
            Assert.AreEqual(1, delta.AlteredRecords.Length);
            Assert.AreEqual(4, delta.AlteredRecords[0]);
        }
 public CatalogStateChanged(CatalogState state)
 {
     State = state;
 }
 public CatalogModel(CatalogState state)
 {
     this.state = state;
 }
Esempio n. 25
0
 private ProcessResult ValidCatalogCode(out CatalogState org)
 {
     if (string.IsNullOrEmpty(this.CatalogCode))
     {
         org = CatalogState.Empty;
         return new ProcessResult(false, Status.InvalidCatalog, "目录码为空");
     }
     if (!_acDomain.CatalogSet.TryGetCatalog(this.CatalogCode, out org))
     {
         return new ProcessResult(false, Status.InvalidCatalog, string.Format("非法的目录码{0}", this.CatalogCode));
     }
     OntologyCatalogState oorg;
     if (!this.Ontology.Catalogs.TryGetValue(org, out oorg))
     {
         return new ProcessResult(false, Status.InvalidCatalog, string.Format("对于{0}来说{1}是非法的目录码", this.Ontology.Ontology.Name, org.Code));
     }
     var orgCode = org.Code;
     return _acDomain.CatalogSet.Any(o => orgCode.Equals(o.ParentCode, StringComparison.OrdinalIgnoreCase)) ? new ProcessResult(false, Status.InvalidCatalog, string.Format("{0}不是叶节点,不能容纳" + this.Ontology.Ontology.Name, org.Name)) : ProcessResult.Ok;
 }