Exemple #1
0
        public async Task <Batch> SaveBatch(Batch batch, string userEmail)
        {
            var db = _mongoClient.GetDatabase("BeerDb");
            var mongoCollection = db.GetCollection <BatchCollection>("Batches");
            var query           = Builders <BatchCollection> .Filter.Eq(f => f.UserEmail, userEmail);

            var batchCollections = await mongoCollection.Find(query).ToListAsync();

            BatchCollection usersCollection = null;

            if (batchCollections == null || batchCollections.Count == 0)
            {
                usersCollection = CreateNewBatchCollection(userEmail, mongoCollection);
            }
            else
            {
                //should only be one collection per user
                usersCollection = batchCollections[0];
            }
            var batchToUpdate = usersCollection.Batches.SingleOrDefault(f => f.Id == batch.Id);

            if (batchToUpdate == null)
            {
                batch.Id = Guid.NewGuid();
            }
            else
            {
                usersCollection.Batches.Remove(batchToUpdate);
            }
            usersCollection.Batches.Add(batch);
            var filter = Builders <BatchCollection> .Filter.Eq(f => f.Id, usersCollection.Id);

            mongoCollection.ReplaceOne(filter, usersCollection);
            return(batch);
        }
Exemple #2
0
        public TerrainDebug(TerrainInfo map)
        {
            vertices = new BatchCollection <VertexColor>(6 * 10000);

            vertexBuffer = new Buffer(Display.device, new BufferDescription(vertices.Capacity * VertexColor.SizeInBytes, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));

            map_info = map;
        }
Exemple #3
0
        public async Task <OpResult> DeleteBatch(Batch batch, string userEmail)
        {
            try
            {
                var db = _mongoClient.GetDatabase("BeerDb");
                var mongoCollection = db.GetCollection <BatchCollection>("Batches");
                var query           = Builders <BatchCollection> .Filter.Eq(f => f.UserEmail, userEmail);

                var batchCollections = await mongoCollection.Find(query).ToListAsync();

                BatchCollection usersCollection = null;
                if (batchCollections == null || batchCollections.Count == 0)
                {
                    return(new OpResult
                    {
                        Success = false,
                        Message = "Batch not found"
                    });
                }
                else
                {
                    //should only be one collection per user
                    usersCollection = batchCollections[0];
                }

                var batchToUpdate = usersCollection.Batches.SingleOrDefault(f => f.Id == batch.Id);
                if (batchToUpdate == null)
                {
                    return(new OpResult
                    {
                        Success = false,
                        Message = "Batch not found"
                    });
                }
                else
                {
                    usersCollection.Batches.Remove(batchToUpdate);
                    var filter = Builders <BatchCollection> .Filter.Eq(f => f.Id, usersCollection.Id);

                    mongoCollection.ReplaceOne(filter, usersCollection);
                }
                return(new OpResult
                {
                    Success = true,
                    Message = "ok"
                });
            }
            catch (Exception ex)
            {
                return(new OpResult
                {
                    Success = false,
                    Message = ex.Message
                });
            }
        }
        public void TestRetrieveAll()
        {
            BatchCollection batchCollection = Batch.All();

            Assert.IsNotNull(batchCollection);
            foreach (Batch batch in batchCollection.batches)
            {
                Assert.IsNotNull(batch.id);
                Assert.AreEqual(batch.id.Substring(0, 6), "batch_");
            }
        }
Exemple #5
0
        private BatchCollection CreateNewBatchCollection(string email, IMongoCollection <BatchCollection> collection)
        {
            var col = new BatchCollection
            {
                UserEmail = email,
                Batches   = new List <Batch>()
            };

            collection.InsertOne(col);
            return(col);
        }
Exemple #6
0
        private SqlBatchCollection GetSqlBatchCollection(IQueryProvider queryProvider)
        {
            if (_topBatch is SqlBatchCollection && ReferenceEquals(_topBatch?.ExecutorReference, queryProvider))
            {
                return(_topBatch as SqlBatchCollection);
            }

            _topBatch = new SqlBatchCollection(queryProvider);
            _batches.Add(_topBatch);
            return(_topBatch as SqlBatchCollection);
        }
        public virtual ActionResult ActiveBatches(long?batchId)
        {
            LogI("ActiveBatches, batchId=" + batchId);

            var model = new BatchCollection
            {
                Batches = OrderBatchViewModel.GetAllForTabs(Db, batchId)
            };

            if (model.Batches.Any() && model.Batches.All(b => !b.Selected))
            {
                model.Batches.First().Selected = true;
            }
            return(View(model));
        }
Exemple #8
0
        /// <summary>
        /// Build the EnumSet with the entire list of Enum Members
        /// </summary>
        /// <param name="setId">Set Id</param>
        /// <param name="setDescription">Set Description</param>
        /// <returns>EnumDescCollection</returns>
        private async Task <EnumDescCollection> GetMemberListAsync(string setId, string setDescription)
        {
            var memberList      = new List <EnumMemberBatchCollectionItem>();
            var enumMemberBatch = new BatchCollection <EnumMemberBatchCollectionItem>();
            var nextURL         = $"{_url}/{setId}{_membersEndPoint}?pageSize={_pageSize}";
            var enumDesc        = new EnumDescCollection();

            try
            {
                _stopWatch.Start();
                var setIdInt = 0;
                int.TryParse(setId, out setIdInt);

                while (!string.IsNullOrWhiteSpace(nextURL))
                {
                    enumMemberBatch = await GetCollectionAsync <EnumMemberBatchCollectionItem>($"{ApiRequest.UrlBase}{nextURL}");

                    if (enumMemberBatch != null)
                    {
                        memberList.AddRange(enumMemberBatch.Items);
                        nextURL = enumMemberBatch.Next;
                    }
                    else
                    {
                        nextURL = string.Empty;
                    }
                    _stopWatch.Stop();
                    LoggerService.LogApiRequest(nextURL, memberList.Count, TimeSpan.FromMilliseconds(_stopWatch.Elapsed.TotalMilliseconds).ToString());
                    _stopWatch.Reset();
                }
                foreach (var member in memberList)
                {
                    enumDesc.Add(new EnumDescDataStoreModel {
                        SetId = setIdInt, MemberId = member.Id, SetDesc = setDescription, MemberDesc = member.Description
                    });
                }
            }
            catch (Exception ex)
            {
                _stopWatch.Stop();
                LoggerService.LogException(nextURL, TimeSpan.FromMilliseconds(_stopWatch.Elapsed.TotalMilliseconds).ToString(), ex);
                _stopWatch.Reset();

                throw;
            }

            return(enumDesc);
        }
        /// <summary>
        /// Call the annotations URL
        /// </summary>
        /// <param name="annotationLink">Complete annotations link</param>
        /// <returns>List of AnnotationDataStoreModel items</returns>
        private async Task <List <AnnotationDataStoreModel> > GetAnnotationsAsync(string annotationLink)
        {
            var annotations          = new List <AnnotationBatchCollectionItem>();
            var annotationCollection = new BatchCollection <AnnotationBatchCollectionItem>();
            var annotationDataModels = new List <AnnotationDataStoreModel>();

            var nextLink = annotationLink;

            try
            {
                while (!string.IsNullOrWhiteSpace(nextLink))
                {
                    _stopWatch.Start();
                    annotationCollection = await GetCollectionAsync <AnnotationBatchCollectionItem>($"{ApiRequest.UrlBase}{nextLink}");

                    if (annotationCollection != null)
                    {
                        annotations.AddRange(annotationCollection.Items);
                        nextLink = annotationCollection.Next;
                    }
                    else
                    {
                        nextLink = string.Empty;
                    }
                    _stopWatch.Stop();
                    LoggerService.LogApiRequest(nextLink, annotationCollection.Items.Count, TimeSpan.FromMilliseconds(_stopWatch.Elapsed.TotalMilliseconds).ToString());
                    _stopWatch.Reset();
                }

                annotations.ForEach(a => annotationDataModels.Add(new AnnotationDataStoreModel
                {
                    Text         = a.Text,
                    User         = a.User,
                    CreationTime = a.CreationTime,
                    Action       = a.Action
                }));
            }
            catch (Exception ex)
            {
                _stopWatch.Stop();
                LoggerService.LogException(nextLink, TimeSpan.FromMilliseconds(_stopWatch.Elapsed.TotalMilliseconds).ToString(), ex);
                _stopWatch.Reset();

                throw;
            }

            return(annotationDataModels);
        }
Exemple #10
0
        /// <summary>
        /// Build the EnumSet description collection from the URL
        /// </summary>
        /// <returns>EnumDescCollection</returns>
        private async Task <EnumDescCollection> BuildEnumDescCollectionAsync()
        {
            var enumDescData      = new EnumDescCollection();
            var enumSetCollection = new BatchCollection <EnumSetBatchCollectionItem>();
            var nextURL           = $"{ _url}?pageSize={_pageSize}";

            try
            {
                _stopWatch.Start();
                var enumSetBatch = new List <EnumSetBatchCollectionItem>();
                while (!string.IsNullOrWhiteSpace(nextURL))
                {
                    enumSetCollection = await GetCollectionAsync <EnumSetBatchCollectionItem>($"{ApiRequest.UrlBase}{nextURL}");

                    if (enumSetCollection != null)
                    {
                        enumSetBatch.AddRange(enumSetCollection.Items);
                        nextURL = enumSetCollection.Next;
                    }
                    else
                    {
                        nextURL = string.Empty;
                    }
                    _stopWatch.Stop();
                    LoggerService.LogApiRequest(nextURL, enumSetCollection.Items.Count, TimeSpan.FromMilliseconds(_stopWatch.Elapsed.TotalMilliseconds).ToString());
                    _stopWatch.Reset();
                }
                foreach (var item in enumSetBatch)
                {
                    enumDescData.AddRange(await GetMemberListAsync(item.Id.ToString(), item.Description));
                }
            }
            catch (Exception ex)
            {
                _stopWatch.Stop();
                LoggerService.LogException(nextURL, TimeSpan.FromMilliseconds(_stopWatch.Elapsed.TotalMilliseconds).ToString(), ex);
                _stopWatch.Reset();
                throw;
            }

            return(enumDescData);
        }
        public ucBatchViewer()
        {
            InitializeComponent();

            TreeView.DragDropEnabled  = false;
            TreeView.ExpandButtonType = eExpandButtonType.Triangle;
            TreeView.ExpandButtonSize = new Size(16, 16);

            TreeView.NodeSpacing         = 5;
            TreeView.SelectionFocusAware = false;

            TreeView.Nodes.Clear();

            TreeView.KeyPress        += TreeView_KeyPress;
            TreeView.AfterNodeSelect += TreeView_AfterNodeSelect;;

            ItemDataCollection = new BatchCollection();

            Items = ItemDataCollection.Items;
        }
Exemple #12
0
        public async Task <IEnumerable <Batch> > GetAllBatchesForUser(string userEmail)
        {
            var db    = _mongoClient.GetDatabase("BeerDb");
            var query = Builders <BatchCollection> .Filter.Eq(f => f.UserEmail, userEmail);

            var mongoCollection  = db.GetCollection <BatchCollection>("Batches");
            var batchCollections = await mongoCollection.Find(query).ToListAsync();

            BatchCollection col = null;

            if (batchCollections == null || batchCollections.Count == 0)
            {
                col = CreateNewBatchCollection(userEmail, mongoCollection);
            }
            else
            {
                //should only be one collection per user
                col = batchCollections[0];
            }

            return(col.Batches);
        }
Exemple #13
0
        public static void LoadBatchListOnCombo(ComboTree cb, Action onChangedAction, int batchId = 0)
        {
            var loader = new BatchCollection();

            if (batchId != 0)
            {
                loader.LoadItem(batchId);
            }
            else
            {
                loader.LoadAllItemsFromDb();
            }

            cb.Nodes.Clear();

            foreach (var item in loader.Items)
            {
                var node = new Node()
                {
                    Name = item.Id.ToString(),
                    Text = $@"{item.BatchName} - {item.Semester}",
                    Tag  = item,
                    //Image = Properties.Resources.Address_Book_16
                };
                cb.Nodes.Add(node);
            }

            if (cb.Nodes.Count != 0)
            {
                cb.SelectedNode = cb.Nodes[cb.Nodes.Count - 1];
            }
            if (onChangedAction != null)
            {
                cb.TextChanged += (s, e) => { onChangedAction(); }
            }
            ;
        }
    }
Exemple #14
0
        public static void Initialize()
        {
            vertices         = new BatchCollection <Vertex2D>(8192);
            vertexBufferSize = vertices.Capacity;
            vertexBuffer     = new Buffer(Display.device, new BufferDescription(vertexBufferSize * Vertex2D.SizeInBytes, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));
            vertexBufferBind = new VertexBufferBinding(vertexBuffer, Vertex2D.SizeInBytes, 0);



            short[] shArr = new short[12288];
            for (int i = 0; i < 2048; i++)
            {
                shArr[i * 6]       = (short)(i * 4);
                shArr[(i * 6) + 1] = (short)((i * 4) + 1);
                shArr[(i * 6) + 2] = (short)((i * 4) + 2);
                shArr[(i * 6) + 3] = (short)((i * 4) + 2);
                shArr[(i * 6) + 4] = (short)((i * 4) + 1);
                shArr[(i * 6) + 5] = (short)((i * 4) + 3);
            }


            indexBuffer = new Buffer(Display.device, DataStream.Create(shArr, false, false), new BufferDescription(12288 * sizeof(short), ResourceUsage.Dynamic, BindFlags.IndexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));
        }
Exemple #15
0
        public DotManager()
        {
            vertices = new BatchCollection <VertexColor>(10000);

            vertexBuffer = new Buffer(Display.device, new BufferDescription(vertices.Capacity * VertexColor.SizeInBytes, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0));
        }