Example #1
0
        public void BoxId_CountsMatchesCorrectly(string input, bool twoMatch, bool threeMatch)
        {
            var boxId = new BoxId(input);

            boxId.TwoMatch.Should().Be(twoMatch);
            boxId.ThreeMatch.Should().Be(threeMatch);
        }
        public XElement Serialize()
        {
            var result = new XElement(Constants.XMLNamespaces.EHEALTHBOX_PUBLICATION + "SendMessageRequest",
                                      new XAttribute("xmlns", Constants.XMLNamespaces.EHEALTHBOX_PUBLICATION));

            if (BoxId != null)
            {
                result.Add(BoxId.Serialize());
            }

            foreach (var contextType in DestinationContextLst)
            {
                result.Add(contextType.Serialize());
            }

            result.Add(ContentContext.Serialize());
            foreach (var copyMailTo in CopyMailToLst)
            {
                result.Add(new XElement("CopyMailTo", copyMailTo));
            }

            if (!string.IsNullOrWhiteSpace(PublicationId))
            {
                result.Add(new XAttribute("PublicationId", PublicationId));
            }

            return(result);
        }
Example #3
0
        private static async Task <ContactItem> GetContactItem(ILogger _logger, ISiteMap siteMap, UserService userService,
                                                               BoxId fromBoxId, ChatDbModel chatDbModel = null)
        {
            var contact = new ContactItem();

            if (!string.IsNullOrEmpty(fromBoxId?.Id))
            {
                if (fromBoxId.Type == TypeBox.User)
                {
                    var userDb = await userService.FindApplicationUserByIdAsync(fromBoxId.Id);

                    contact.FullName = userDb.FullName;
                    contact.Id       = fromBoxId.Id;
                    contact.Type     = TypeBox.User;
                }
                else if (fromBoxId.Type == TypeBox.Site)
                {
                    contact.FullName = await siteMap.GetSiteNameAsync(fromBoxId.Id);

                    contact.Id   = fromBoxId.Id;
                    contact.Type = TypeBox.Site;
                }
                else if (fromBoxId.Type == TypeBox.UserNotAuthenticated)
                {
                    InitContactNotAUthenticated(_logger, chatDbModel, contact);
                }
            }
            else
            {
                InitContactNotAUthenticated(_logger, chatDbModel, contact);
            }
            return(contact);
        }
Example #4
0
        public void FindCommonLetters()
        {
            var ids = Input.Day02Parse(Puzzle2Example).Select(x => new BoxId(x)).ToList();

            var common = BoxId.FindCommonLetters(ids);

            common.Should().Be("fgij");
        }
Example #5
0
        public void Puzzle2_FindCommonLetters()
        {
            var ids = Input.Day02Parse(Input.Day02).Select(x => new BoxId(x)).ToList();

            var common = BoxId.FindCommonLetters(ids);

            common.Should().Be("krdmtuqjgwfoevnaboxglzjph");
        }
        public async Task <long> CountUnreadChatAsync(BoxId boxId, BoxId readerBoxId)
        {
            var builder = Builders <ChatDbModel> .Filter;
            var filter  = builder.Eq("To._id._id", boxId.Id) & builder.Eq("To._id.Type", boxId.Type);

            filter = filter & builder.Ne("LastReads._id._id", readerBoxId.Id);

            var count = await _chats.CountAsync(filter);

            return(count);
        }
        public void Case7()
        {
            // Arrange
            var id = "ababab";

            // Act
            var boxId = new BoxId(id);

            // Assert
            Assert.Single(boxId.Multiple);
            Assert.Contains(3, boxId.Multiple);
        }
        public void Case1()
        {
            // Arrange
            var id = "abcdef";

            // Act
            var boxId = new BoxId(id);

            // Assert

            Assert.Empty(boxId.Multiple);
        }
        public void Case5()
        {
            // Arrange
            var id = "aabcdd";

            // Act
            var boxId = new BoxId(id);

            // Assert
            Assert.Single(boxId.Multiple);
            Assert.Contains(2, boxId.Multiple);
        }
        public void Case2()
        {
            // Arrange
            var id = "bababc";

            // Act
            var boxId = new BoxId(id);

            // Assert
            Assert.Equal(2, boxId.Multiple.Count);
            Assert.Contains(2, boxId.Multiple);
            Assert.Contains(3, boxId.Multiple);
        }
Example #11
0
        public XElement Serialize()
        {
            var result = new XElement(Constants.XMLNamespaces.EHEALTHBOX_CONSULTATION + "GetMessagesListRequest",
                                      new XAttribute("xmlns", Constants.XMLNamespaces.EHEALTHBOX_CONSULTATION));

            if (BoxId != null)
            {
                result.Add(BoxId.Serialize());
            }

            result.Add(new XElement("Source", Enum.GetName(typeof(EHealthBoxSources), Source)));
            result.Add(new XElement("StartIndex", StartIndex));
            result.Add(new XElement("EndIndex", EndIndex));
            return(result);
        }
Example #12
0
        public async Task <CreateBoxRequest.Response> Handle(CreateBoxRequest request,
                                                             CancellationToken cancellationToken)
        {
            var boxId   = BoxId.ForBarcode(request.Barcode);
            var command = new CreateBoxCommand(boxId, new Barcode(request.Barcode));
            var result  = await _mediator.Send(command, cancellationToken).ConfigureAwait(false);

            if (result.IsOk)
            {
                return(new CreateBoxRequest.Response(true, null, boxId.Value));
            }

            var failureMessage = string.Join("\r\n", result.FailedWith());

            return(new CreateBoxRequest.Response(false, failureMessage, null));
        }
Example #13
0
        public XElement Serialize()
        {
            var result = new XElement(Constants.XMLNamespaces.EHEALTHBOX_CONSULTATION + "DeleteMessageRequest",
                                      new XAttribute("xmlns", Constants.XMLNamespaces.EHEALTHBOX_CONSULTATION));

            if (BoxId != null)
            {
                result.Add(BoxId.Serialize());
            }

            result.Add(new XElement("Source", Enum.GetName(typeof(EHealthBoxSources), Source)));
            foreach (var messageId in MessageIdLst)
            {
                result.Add(new XElement("MessageId", messageId));
            }

            return(result);
        }
        public async Task <long> CountChatAsync(BoxId boxId, CountChatFilters getChatsFilter)
        {
            var builder = Builders <ChatDbModel> .Filter;
            var filter  = builder.Eq("To._id._id", boxId.Id) & builder.Eq("To._id.Type", boxId.Type);

            if (getChatsFilter.DateGt.HasValue)
            {
                filter = filter & builder.Gt(p => p.UpdateDate, getChatsFilter.DateGt.Value);
            }

            if (getChatsFilter.DateLt.HasValue)
            {
                filter = filter & builder.Lt(p => p.UpdateDate, getChatsFilter.DateLt.Value);
            }
            var count = await _chats.CountAsync(filter);

            return(count);
        }
Example #15
0
        protected override async Task ActionAsync()
        {
            var userBoxId = new BoxId()
            {
                Id = Input.UserId, Type = TypeBox.User
            };
            var siteBoxId = new BoxId()
            {
                Id = Input.Data, Type = TypeBox.Site
            };
            var numberUnreadMessage = await _messageService.CountUnreadChatAsync(userBoxId, userBoxId);

            var numberUnreadSiteMessage = await _messageService.CountUnreadChatAsync(siteBoxId, userBoxId);

            Result.Data = new GetNotificationResult()
            {
                NumberSiteUnreadMessage = numberUnreadSiteMessage,
                NumberUnreadMessage     = numberUnreadMessage
            };
        }
Example #16
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (PlayerId != 0UL)
            {
                hash ^= PlayerId.GetHashCode();
            }
            if (BoxId != 0)
            {
                hash ^= BoxId.GetHashCode();
            }
            if (BoxSource != 0)
            {
                hash ^= BoxSource.GetHashCode();
            }
            if (BoxSourceParam != 0)
            {
                hash ^= BoxSourceParam.GetHashCode();
            }
            return(hash);
        }
        public async Task <IList <ChatDbModel> > GetChatsAsync(BoxId boxId, GetChatsFilter getChatsFilter)
        {
            var builder = Builders <ChatDbModel> .Filter;
            var filter  = builder.Eq("To._id._id", boxId.Id) & builder.Eq("To._id.Type", boxId.Type);

            if (getChatsFilter.DateGt.HasValue)
            {
                filter = filter & builder.Gt(p => p.UpdateDate, getChatsFilter.DateGt.Value);
            }

            if (getChatsFilter.DateLt.HasValue)
            {
                filter = filter & builder.Lt(p => p.UpdateDate, getChatsFilter.DateLt.Value);
            }

            var sort = Builders <ChatDbModel> .Sort.Descending(x => x.UpdateDate);

            var cursor = _chats.Find(filter);

            cursor.Sort(sort);

            cursor.Limit(getChatsFilter.Limit);
            var chats = await cursor.ToListAsync();

            // TODO remove
            foreach (var chatDbModel in chats)
            {
                if (chatDbModel.LastReads == null)
                {
                    chatDbModel.LastReads = new List <Read>();
                    await _chats.ReplaceOneAsync(new BsonDocument("_id", new Guid(chatDbModel.Id)), chatDbModel);
                }
            }

            return(chats);
        }
Example #18
0
        private static async Task FirstTest(ServiceProvider serviceProvider)
        {
            //var sqliteContext = serviceProvider.GetService<Sqlite.StoreContext>();
            //sqliteContext.Database.EnsureCreated();
            //var id1 = Guid.NewGuid();
            //var o11 = new Order(id1, "ZehDog1", 150);
            //sqliteContext.Orders.Add(o11);
            //var o111 = sqliteContext.Orders.Find(o11.Id);
            //sqliteContext.SaveChanges();
            //var exp = sqliteContext.Orders.Where(x => x.Id == o11.Id).AsQueryable().ElementType;
            //var o1 = await sqliteContext.Orders.FirstOrDefaultAsync();

            //if (o1 != null)
            //{
            //    sqliteContext.Orders.Remove(o1);
            //    var o1111 = sqliteContext.Orders.Find(o11.Id);
            //    sqliteContext.SaveChanges();
            //}

            //var mongoClient = serviceProvider.GetService<IMongoClient>();
            //var idM = new BoxId("123");
            //var boxM = new Box(idM, 10);
            //var filterM = Builders<object>.Filter.Eq("_id", idM);
            //Expression<Func<Box, bool>> filterM2 = x => x.Id == idM;

            //var collection = mongoClient.GetDatabase("store104").GetCollection<BsonDocument>(typeof(Box).Name);
            //var collection2 = mongoClient.GetDatabase("store104").GetCollection<Box>(typeof(Box).Name);

            //var result1 = await collection2.FindAsync(filterM2);
            //var entity1 = result1.FirstOrDefault();
            //entity1.Measures = 99;

            //var id1 = typeof(Box).GetProperty("Id").GetValue(entity1, null);
            //var filterM1 = Builders<BsonDocument>.Filter.Eq("_id", (BoxId)id1);

            //var result = await collection.ReplaceOneAsync(
            //                    filterM1,
            //                    entity1.ToBsonDocument(),
            //                    new ReplaceOptions { IsUpsert = false });

            await PerformanceTest(serviceProvider);

            return;

            var mongoContext = serviceProvider.GetService <Mongo.StoreContext>();

            var os = await mongoContext.Orders.ToListAsync();

            for (int i = 0; i < 1; i++)
            {
                var o1 = new Order(Guid.NewGuid(), "fdg", 11);
                mongoContext.Orders.Add(o1);

                //var o2 = new Order(Guid.NewGuid(), "fdg", 11);
                //mongoContext.OrdersBkp.Add(o2);

                var o3 = new OrderFlat(Guid.NewGuid(), "fdg", 11);
                mongoContext.OrdersFlat.Add(o3);

                await mongoContext.SaveChangesAsync();
            }

            //var o2 = new Order(Guid.NewGuid(), "fdg", 11);
            //mongoContext.Orders.Add(o2);
            //await mongoContext.SaveChangesAsync();


            var id1  = new BoxId("555");
            var box1 = new Box(id1, 10);

            box1.Numbers = new List <int>()
            {
                1, 2, 3
            };
            box1.Configurations = new List <Configuration> {
                new Configuration {
                    TenantId = new TenantId {
                        Value = 10000
                    }
                }
            };
            mongoContext.Boxes.Add(box1);

            var id = new BoxId("123");
            Expression <Func <Box, bool> > filter = x => x.Configurations.Any(n => n.TenantId == new TenantId {
                Value = 10000
            });
            //Expression<Func<Box, bool>> filter = x => x.Id == id;
            var box = await mongoContext.Boxes.FirstOrDefaultAsync(filter);

            //var box = await mongoContext.Boxes.FindAsync(id);
            //box.Measures = 234;
            //box.Numbers = new List<int>() { 1, 2, 3 };

            await mongoContext.SaveChangesAsync();

            var x = 1;

            //// var all = await mongoContext.Orders.ToListAsync();

            //var id2 = Guid.Parse("bdcbfe0d-b74b-473c-a069-c06f2c444960"); //Guid.NewGuid();
            ////var o22 = new Order(id2, "ZehDog2", 129);
            ////mongoContext.Orders.Add(o22);
            //var o222 = await mongoContext.Orders.FindAsync(id2);
            ////var o22233 = await mongoContext.Orders.FindAsync(Guid.NewGuid());

            //o222.StoreName = "sdfg";

            //await mongoContext.SaveChangesAsync();

            //var allox2 = await mongoContext.Orders.ToListAsync();

            //var id21 = 3;
            //var o221 = new Item(id21, "ZehDog2", 129);
            //mongoContext.Items.Add(o221);

            //await mongoContext.SaveChangesAsync();

            //var allo2223 = await mongoContext.Items.ToListAsync();

            //var idd = new ItemId(3, "ZehDog2");
            //var o2223 = await mongoContext.Items.FindAsync(idd);

            //var ox2 = await mongoContext.Orders.FirstOrDefaultAsync(x => x.Id == o22.Id);

            //var o2 = await mongoContext.Orders.FirstOrDefaultAsync();
            //if (o2 != null)
            //{
            //    mongoContext.Orders.Remove(o2);
            //    var o2222 = await mongoContext.Orders.FindAsync(o22.Id);
            //    await mongoContext.SaveChangesAsync();
            //}
        }