Example #1
0
        public static bool LoadData(CollectionNames collectionName = CollectionNames.All)
        {
            bool flag = true;

            if (collectionName == CollectionNames.Employees || collectionName == CollectionNames.All)
            {
                var path = SourceLocationEmployees;
                Employees = LoadObj <List <Employee> >(path);
            }
            if (collectionName == CollectionNames.Specializations || collectionName == CollectionNames.All)
            {
                var path = SourceLocationSpecializations;
                Specializations = LoadObj <List <Specialization> >(path);
            }
            if (collectionName == CollectionNames.Employers || collectionName == CollectionNames.All)
            {
                var path = SourceLocationEmployers;
                Employers = LoadObj <List <Employer> >(path);
            }
            if (collectionName == CollectionNames.Contracts || collectionName == CollectionNames.All)
            {
                var path = SourceLocationContracts;
                Contracts = LoadObj <List <Contract> >(path);
            }

            return(flag);
        }
Example #2
0
        public List <Entity> getListByCollectionName(CollectionNames collectionNmaes)
        {
            List <Entity> list = null;

            switch (collectionNmaes)
            {
            case CollectionNames.Employees:
                list = DataSource.Employees.ToList <Entity>();
                break;

            case CollectionNames.Employers:
                list = DataSource.Employers.ToList <Entity>();
                break;

            case CollectionNames.Contracts:
                list = DataSource.Contracts.ToList <Entity>();
                break;

            case CollectionNames.Specializations:
                list = DataSource.Specializations.ToList <Entity>();
                break;

            case CollectionNames.Null:
                list = null;
                break;
            }
            return(list);
        }
        public async static Task <DocumentCollection> CreateCollection(CollectionNames collectionName)
        {
            //Set throughput and partition key
            int    reservedRUs  = 9000; //Will have to sleep when we do bulk updates...
            string partitionKey = "/partitionKey";

            PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition();

            partitionKeyDefinition.Paths.Add(partitionKey); //Weird.  Cannot have more than one partition key...

            RequestOptions requestOptions = new RequestOptions {
                OfferThroughput = reservedRUs
            };
            ResourceResponse <DocumentCollection> response = await BhProvidersDatabaseDa.DocumentClient.CreateDocumentCollectionIfNotExistsAsync(
                DatabaseUri,
                new DocumentCollection
            {
                Id           = collectionName.ToString(),
                PartitionKey = partitionKeyDefinition
            },
                requestOptions
                );

            DocumentCollection collection = response.Resource;

            return(collection);
        }
Example #4
0
 public TestExpression(CollectionNames collectionName, string propertyAccessorName, Operators op, object operand = null)
 {
     Collection           = collectionName;
     PropertyAccessorName = propertyAccessorName;
     Operator             = op;
     Operand = operand;
 }
Example #5
0
        public static bool SaveData(CollectionNames collectionName = CollectionNames.All)
        {
            var flag = true;

            if (collectionName == CollectionNames.Employees || collectionName == CollectionNames.All)
            {
                var path = SourceLocationEmployees;
                SaveObj <List <Employee> >(Employees, path);
            }
            if (collectionName == CollectionNames.Specializations || collectionName == CollectionNames.All)
            {
                var path = SourceLocationSpecializations;
                SaveObj <List <Specialization> >(Specializations, path);
            }
            if (collectionName == CollectionNames.Employers || collectionName == CollectionNames.All)
            {
                var path = SourceLocationEmployers;
                SaveObj <List <Employer> >(Employers, path);
            }
            if (collectionName == CollectionNames.Contracts || collectionName == CollectionNames.All)
            {
                var path = SourceLocationContracts;
                SaveObj <List <Contract> >(Contracts, path);
            }

            return(flag);
        }
Example #6
0
        public bool IsExiste(CollectionNames collectionNmae, int id)
        {
            var list = getListByCollectionName(collectionNmae);

            return(!(list.FirstOrDefault(
                         x =>
                         x.ID == id
                         ) == null));
        }
Example #7
0
        public void addEmployer(Employer newEmployer)
        {
            Employer LocalEmployer = CopyEmployer(newEmployer);

            ExceptionsOfEmployer(LocalEmployer);
            DataSource.Employers.Add(newEmployer);
            CollectionNames collectionName = CollectionNames.Employers;

            DataSource.SaveData(collectionName);
        }
Example #8
0
        public void addEmployee(Employee newEmployee)
        {
            Employee LocalEmployee = CopyEmployee(newEmployee);

            ExceptionsOfEmployee(LocalEmployee);
            DataSource.Employees.Add(LocalEmployee);
            CollectionNames collectionName = CollectionNames.Employees;

            DataSource.SaveData(collectionName);
        }
        public IMongoStorage <TModel, TKey> GetCollection <TModel, TKey>() where TModel : class, IReadModelEx <TKey>
        {
            string collectionName = CollectionNames.GetCollectionName <TModel>();
            var    cache          = _rebuildContext.GetCollection <TModel, TKey>(collectionName);

            return(new CachedMongoStorage <TModel, TKey>(
                       _db.GetCollection <TModel>(collectionName),
                       cache
                       ));
        }
        public async Task Verify_basic_get_for_readmodel_when_signature_change()
        {
            SimpleTestAtomicReadModel.FakeSignature = 1;
            var rm = new SimpleTestAtomicReadModel(new SampleAggregateId(2));
            await _collectionWrapper.UpsertAsync(rm).ConfigureAwait(false);

            var sut  = CreateSut();
            var name = CollectionNames.GetCollectionName(typeof(SimpleTestAtomicReadModel));

            Assert.That(sut.CountReadModelToUpdateByName(name, 2), Is.EqualTo(1));
        }
Example #11
0
        public T GetItem <T>(int id, CollectionNames collectionName) where T : Entity
        {
            var list = getListByCollectionName(collectionName);
            var item = (T)list.FirstOrDefault(X => X.ID == id);

            if (item != null)
            {
                return(CopyItem <T>(item, collectionName));
            }
            return(item);
        }
Example #12
0
        public void addContract(Contract newContract)
        {
            Contract Localcontact = CopyContract(newContract);

            ExceptionsOfContract(Localcontact);
            CollectionNames collectionName = CollectionNames.Contracts;
            var             list           = DataSource.Contracts;

            Localcontact.ID = getID(collectionName);
            list.Add(Localcontact);
            DataSource.SaveData(collectionName);
        }
Example #13
0
 public QuerySection(CollectionNames collection, Type baseType, MemberInfo baseMember, bool includePhi, GetCountsResult counts, QuerySection parentSection = null)
 {
     Collection    = collection;
     ParentSection = parentSection;
     Title         = baseType.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName ?? baseType.Name;
     if (baseMember != null)
     {
         PropertyPath = parentSection.PropertyPath + "." + baseMember.Name;
         JPath        = parentSection.JPath + "." + baseMember.GetSerializedPropertyName();
     }
     baseType.MemberWalk <QuerySection>(
         BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
         (parent, t, mi) => this,
         (ctx, t, mi) =>
     {
         var pi = (PropertyInfo)mi;
         if (ShouldIgnore(pi))
         {
             return;
         }
         if (t.GetTypeInfo().IsClass&& t.Namespace.StartsWith("Traffk."))
         {
             var s = new QuerySection(collection, t, mi, includePhi, counts, this);
             if (s.Children.Count > 0)
             {
                 Children.Add(s);
             }
         }
         else
         {
             var qf = new QueryField(this, pi, counts);
             Children.Add(qf);
         }
     },
         (ctx, t, mi) =>
     {
         if (t.IsA(typeof(IEnumerable)))
         {
             return(false);
         }
         if (!t.Namespace.StartsWith("Traffk."))
         {
             return(false);
         }
         if (ShouldIgnore((PropertyInfo)mi))
         {
             return(false);
         }
         return(true);
     }
         );
 }
Example #14
0
        public void addSpecialization(Specialization newSpecialization)
        {
            Specialization LocalSpecialization = CopySpecialization(newSpecialization);

            ExceptionsOfSpecialization(LocalSpecialization);
            CollectionNames collectionName = CollectionNames.Specializations;
            var             list           = DataSource.Specializations;

            //Inventor number that does not exist in
            LocalSpecialization.ID = getID(collectionName);
            list.Add(LocalSpecialization);
            DataSource.SaveData(collectionName);
        }
        protected void Init()
        {
            var url    = new MongoUrl(ConfigurationManager.ConnectionStrings["readmodel"].ConnectionString);
            var client = new MongoClient(url);

            _db         = client.GetDatabase(url.DatabaseName);
            _collection = _db.GetCollection <SimpleTestAtomicReadModel>(
                CollectionNames.GetCollectionName <SimpleTestAtomicReadModel>());
            _persistence = new InMemoryPersistence();
            _db.Drop();

            _identityManager     = new IdentityManager(new CounterService(_db));
            _mongoBsonCollection = _db.GetCollection <BsonDocument>(CollectionNames.GetCollectionName <SimpleTestAtomicReadModel>());
        }
Example #16
0
        public int getID(CollectionNames collectionName = CollectionNames.Null)
        {
            DataSource.Code++;
            DataSource.SaveCode();
            return(DataSource.Code);

            /* int id;
             * var list = getListByCollectionName(collectionName);
             * do
             * {
             *   id =  r.Next(10000000, 99999999);
             * } while (list != null && IsExiste(collectionName, id));
             * return id;*/
        }
        public ListViewModel(CollectionNames collectionName)
        {
            Bl                  = BL.FactoryBL.GetBL();
            RemoveCommand       = new RelayCommand <int>(Remove);
            EditCommand         = new RelayCommand <int>(Edit);
            ViewCommand         = new RelayCommand <int>(View);
            AddCommand          = new RelayCommand(Add);
            SearchCommand       = new RelayCommand <string>(Search);
            CloseCommand        = new RelayCommand(Close);
            SaveCommand         = new RelayCommand(Save);
            UpdateCommand       = new RelayCommand(Update);
            this.collectionName = collectionName;

            Mode = ViewMode.Edit;
            GetCollection();
        }
        public void OneTimeSetup()
        {
            var url    = new MongoUrl(ConfigurationManager.ConnectionStrings["readmodel"].ConnectionString);
            var client = new MongoClient(url);

            _db = client.GetDatabase(url.DatabaseName);
            _db.Drop();

            _collection = _db.GetCollection <SimpleTestAtomicReadModel>(
                CollectionNames.GetCollectionName <SimpleTestAtomicReadModel>());

            _persistence       = new InMemoryPersistence();
            _collectionWrapper = new AtomicMongoCollectionWrapper <SimpleTestAtomicReadModel>(
                _db,
                new AtomicReadModelFactory(),
                new LiveAtomicReadModelProcessor(new AtomicReadModelFactory(), new CommitEnhancer(), _persistence));
        }
Example #19
0
        public void addEmployeeIfNotExist(Employee newEmployee)
        {
            CollectionNames collectionName = CollectionNames.Employees;
            var             list           = DataSource.Employees;
            int             id             = newEmployee.ID;

            if (id == 0)
            {
                newEmployee.ID = getID(collectionName);
            }
            else if (IsExiste(collectionName, id))
            {
                throw new Exception("this employee already exist");
            }

            list.Add(newEmployee);
        }
 public void Start()
 {
     Metric.Gauge("checkpoint-behind-AtomicReadModels", CheckAllAtomicsValue(), Unit.Items);
     HealthChecks.RegisterHealthCheck("Slot-All-AtomicReadmodels", CheckSlotHealth());
     foreach (var readModelType in _atomicProjectionCheckpointManager.GetAllRegisteredAtomicReadModels())
     {
         var name = CollectionNames.GetCollectionName(readModelType);
         //try to create an instance to grab the version
         try
         {
             var readmodelVersion = _readModelFactory.GetReamdodelVersion(readModelType);
             Metric.Gauge("versions-behind-" + name, () => _versionLoader.CountReadModelToUpdateByName(name, readmodelVersion), Unit.Items);
         }
         catch (Exception ex)
         {
             Logger.ErrorFormat(ex, "Unable to setup metric for atomic readmodel {0}", readModelType.FullName);
         }
     }
 }
Example #21
0
        public bool RemoveItem <T>(int id, CollectionNames collectionName)
        {
            switch (collectionName)
            {
            case CollectionNames.Employees:
                return(removeEmployee(id));

            case CollectionNames.Employers:
                return(removeEmployer(id));

            case CollectionNames.Contracts:
                return(removeContract(id));

            case CollectionNames.Specializations:
                return(removeSpecialization(id));

            default:
                throw new Exception();
            }
        }
Example #22
0
        public T CopyItem <T>(T value, CollectionNames collectionName) where T : Entity
        {
            switch (collectionName)
            {
            case CollectionNames.Employees:
                return(CopyEmployee(value as Employee) as T);

            case CollectionNames.Employers:
                return(CopyEmployer(value as Employer) as T);

            case CollectionNames.Contracts:
                return(CopyContract(value as Contract) as T);

            case CollectionNames.Specializations:
                return(CopySpecialization(value as Specialization) as T);

            default:
                throw new Exception();
            }
        }
Example #23
0
        public IEnumerable <T> SearchItem <T>(string query, CollectionNames collectionName) where T : Entity
        {
            switch (collectionName)
            {
            case CollectionNames.Employees:
                return(searchEmployees(query).Cast <T>());

            case CollectionNames.Employers:
                return(searchEmployers(query).Cast <T>());

            case CollectionNames.Contracts:
                return(searchContracts(query).Cast <T>());

            case CollectionNames.Specializations:
                return(searchSpecializations(query).Cast <T>());

            default:
                throw new Exception();
            }
        }
Example #24
0
        public IEnumerable <T> getListByCollectionName <T>(CollectionNames collectionName) where T : Entity
        {
            switch (collectionName)
            {
            case CollectionNames.Employees:
                return(GetAllEmployees().Cast <T>());

            case CollectionNames.Employers:
                return(GetAllEmployers().Cast <T>());

            case CollectionNames.Contracts:
                return(GetAllContracts().Cast <T>());

            case CollectionNames.Specializations:
                return(GetAllSpecializations().Cast <T>());

            default:
                throw new Exception();
            }
        }
        public AtomicMongoCollectionWrapper(
            IMongoDatabase readmodelDb,
            IAtomicReadModelFactory atomicReadModelFactory,
            ILiveAtomicReadModelProcessor liveAtomicReadModelProcessor)
        {
            _liveAtomicReadModelProcessor = liveAtomicReadModelProcessor;

            var collectionName = CollectionNames.GetCollectionName <TModel>();

            _collection = readmodelDb.GetCollection <TModel>(collectionName);

            Logger = NullLogger.Instance;

            //Auto create the basic index you need
            _collection.Indexes.CreateOne(
                new CreateIndexModel <TModel>(
                    Builders <TModel> .IndexKeys
                    .Ascending(_ => _.ProjectedPosition),
                    new CreateIndexOptions()
            {
                Name       = "ProjectedPosition",
                Background = false
            }
                    )
                );

            _collection.Indexes.CreateOne(
                new CreateIndexModel <TModel>(
                    Builders <TModel> .IndexKeys
                    .Ascending(_ => _.ReadModelVersion),
                    new CreateIndexOptions()
            {
                Name       = "ReadModelVersion",
                Background = false
            }
                    )
                );

            _actualVersion = atomicReadModelFactory.GetReamdodelVersion(typeof(TModel));
        }
Example #26
0
        public void UpdateItem <T>(T value, CollectionNames collectionName) where T : Entity
        {
            switch (collectionName)
            {
            case CollectionNames.Employees:
                updatinEmployee(value as Employee);
                break;

            case CollectionNames.Employers:
                updatinEmployer(value as Employer);
                break;

            case CollectionNames.Contracts:
                updatinContract(value as Contract);
                break;

            case CollectionNames.Specializations:
                updatinSpecialization(value as Specialization);
                break;

            default:
                throw new Exception();
            }
        }
Example #27
0
 public FifoLifoList(int collectionNames)
 {
     first = null;
     last  = null;
     this.collectionNames = (CollectionNames)collectionNames;
 }
Example #28
0
 protected IMongoCollection <T> GetCollection <T>()
     where T : IAtomicReadModel
 {
     return(_db.GetCollection <T>(CollectionNames.GetCollectionName <T>()));
 }
Example #29
0
        public static bool InitData(CollectionNames collectionName = CollectionNames.All)
        {
            // init code for ids
            initCode();
            // load bank branchs data
            var ele = LoadXmlElement(BabkBranchsDataLocation);

            BankData = new BankData(ele);
            bool flag = true;

            if (collectionName == CollectionNames.Employees || collectionName == CollectionNames.All)
            {
                var path = SourceLocationEmployees;
                if (File.Exists(path))
                {
                    Employees = LoadObj <List <Employee> >(path);
                }
                else
                {
                    SaveObj <List <Employee> >(Employees, path);
                }
            }
            if (collectionName == CollectionNames.Specializations || collectionName == CollectionNames.All)
            {
                var path = SourceLocationSpecializations;
                if (File.Exists(path))
                {
                    Specializations = LoadObj <List <Specialization> >(path);
                }
                else
                {
                    SaveObj <List <Specialization> >(Specializations, path);
                }
            }
            if (collectionName == CollectionNames.Employers || collectionName == CollectionNames.All)
            {
                var path = SourceLocationEmployers;
                if (File.Exists(path))
                {
                    Employers = LoadObj <List <Employer> >(path);
                }
                else
                {
                    SaveObj <List <Employer> >(Employers, path);
                }
            }
            if (collectionName == CollectionNames.Contracts || collectionName == CollectionNames.All)
            {
                var path = SourceLocationContracts;
                if (File.Exists(path))
                {
                    Contracts = LoadObj <List <Contract> >(path);
                }
                else
                {
                    SaveObj <List <Contract> >(Contracts, path);
                }
            }

            return(flag);
        }
Example #30
0
 public DocumentWriter(IMongoDatabase readModelDb)
 {
     _collection = readModelDb.GetCollection <DocumentReadModel>(CollectionNames.GetCollectionName <DocumentReadModel>());
 }