Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, MessagesContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }/*
              * app.UseSwaggerUi(typeof(Startup).GetTypeInfo().Assembly, settings =>
              * {
              * settings.GeneratorSettings.DefaultPropertyNameHandling =
              *     PropertyNameHandling.CamelCase;
              * });
              */
            app.UseSwaggerUi3(typeof(Startup).GetTypeInfo().Assembly, swaggerSettings =>
            {
                swaggerSettings.GeneratorSettings.OperationProcessors.Add(new OperationSecurityScopeProcessor("custom-auth"));

                swaggerSettings.GeneratorSettings.DocumentProcessors.Add(
                    new SecurityDefinitionAppender("custom-auth", new SwaggerSecurityScheme
                {
                    Type        = SwaggerSecuritySchemeType.ApiKey,
                    Name        = "Authorization",
                    Description = "Copy 'Bearer ' + valid JWT token into field",
                    In          = SwaggerSecurityApiKeyLocation.Header
                }));
            });

            app.UseAuthentication();
            app.UseMvc();

            // dbContext.Database.EnsureCreated();
            // dbContext.Database.Migrate();
        }
Esempio n. 2
0
 public MessagesRepository()
 {
     _pendingMessages = new List <ChatMessageDto>();
     AutoSaveOptions  = new AutoSaveOptions();
     _streamCheck     = new MessagesContext();
     _syncRoot        = new object();
 }
Esempio n. 3
0
        public static void Initialize(MessagesContext context)
        {
            context.Database.EnsureCreated();
            if (context.Messages.Any())
            {
                return;
            }
            var messages = new Message[]
            {
                new Message {
                    Title = "Sverige vidare i VM", Body = "Enkelt!"
                },
                new Message {
                    Title = "Microsoft köper GitHub", Body = "Hmmmmm"
                },
                new Message {
                    Title = "En elefant promenerade...", Body = "...på en liten liten spindeltråd."
                }
            };

            foreach (Message m in messages)
            {
                context.Messages.Add(m);
            }
            context.SaveChanges();
        }
Esempio n. 4
0
        private static void AddLoginEvent(EventMessage message, MessagesContext dbContext)
        {
            var le = new LoginEvents
            {
                Ip       = message.IP,
                Login    = message.Initiator,
                Browser  = message.Browser,
                Platform = message.Platform,
                Date     = message.Date,
                TenantId = message.TenantId,
                UserId   = message.UserId,
                Page     = message.Page,
                Action   = (int)message.Action
            };

            if (message.Description != null && message.Description.Any())
            {
                le.Description =
                    JsonConvert.SerializeObject(message.Description, new JsonSerializerSettings
                {
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc
                });
            }

            dbContext.LoginEvents.Add(le);
            dbContext.SaveChanges();
        }
Esempio n. 5
0
        private static void AddAuditEvent(EventMessage message, MessagesContext dbContext)
        {
            var ae = new AuditEvent
            {
                Ip        = message.IP,
                Initiator = message.Initiator,
                Browser   = message.Browser,
                Platform  = message.Platform,
                Date      = message.Date,
                TenantId  = message.TenantId,
                UserId    = message.UserId,
                Page      = message.Page,
                Action    = (int)message.Action,
                Target    = message.Target?.ToString()
            };

            if (message.Description != null && message.Description.Any())
            {
                ae.Description =
                    JsonConvert.SerializeObject(GetSafeDescription(message.Description), new JsonSerializerSettings
                {
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc
                });
            }

            dbContext.AuditEvents.Add(ae);
            dbContext.SaveChanges();
        }
Esempio n. 6
0
        public Messages()
        {
            InitializeComponent();

            var message = new MessagesContext();

            message.Message.Load();
            var messages = message.Message.Local.ToObservableCollection();
        }
Esempio n. 7
0
        public DatabaseFixture()
        {
            conn = new SqliteConnection("DataSource=:memory:");
            conn.Open();
            var options = new DbContextOptionsBuilder <MessagesContext>()
                          .UseSqlite(conn)
                          .Options;

            Db = new MessagesContext(options);
            Db.Database.EnsureCreated();
            DbInitializer.Initialize(Db);
        }
Esempio n. 8
0
 public IActionResult Index(MessagesContext dbContext)
 {
     DbController.Db = dbContext;
     if (User.Identity.IsAuthenticated)
     {
         return(View());
     }
     else
     {
         return(Redirect("/Auth/Login"));
     }
 }
Esempio n. 9
0
        public MainWindow()
        {
            InitializeComponent();

            var message = new MessagesContext();

            message.Message.Load();
            var messages = message.Message.Local.ToObservableCollection();

            var contact = new ContactsContext();

            contact.Contact.Load();
            var contacts = contact.Contact.Local.ToObservableCollection();
        }
Esempio n. 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie cookie = new HttpCookie("SecretInformation", "likeOMGMegan");

            HttpContext.Current.Response.Cookies.Add(cookie);

            using (var dbContext = new MessagesContext())
            {
                foreach (var message in dbContext.Messages.OrderByDescending(m => m.CreatedOn))
                {
                    MessagesList.Rows.Add(CreateMessageRow(message));
                }
            }
        }
Esempio n. 11
0
        public ActionResult Index(int id = 0)
        {
            using (var context = new MessagesContext())
            {
                var model = (from m in context.Messages where m.Id == id select m).SingleOrDefault();

                if (model == null)
                {
                    return(new HttpNotFoundResult());
                }

                return(View(model));
            }
        }
Esempio n. 12
0
        public void Send(string who, string message)
        {
            string name        = Context.User.Identity.Name;
            var    store       = new UserStore <ApplicationUser>(new ApplicationDbContext());
            var    manager     = new UserManager <ApplicationUser>(store);
            var    currentUser = manager.FindByEmail(who);
            string receiverId  = currentUser.Id;


            if (who != "")
            {
                Message         messageObj = new Message(message, DateTime.Now, Context.User.Identity.GetUserId(), receiverId);
                MessagesContext db         = new MessagesContext();
                messageObj.AddMessage(db);
                Clients.Group(name).appendNewMessage(name, message, messageObj.GetFormattedDate());
                Clients.Group(who).appendNewMessage(name, message, messageObj.GetFormattedDate());
            }
        }
Esempio n. 13
0
        public async Task CanSaveMessage()
        {
            // Arrange
            var dbContext      = new MessagesContext(options);
            var messageService = new MessagesService(dbContext);

            var message = new Messages
            {
                Id      = 100,
                Message = "TestMessage"
            };

            // Act
            var savedCount = await messageService.SaveMessage(message);

            // Assert
            Assert.AreEqual(1, savedCount);
        }
Esempio n. 14
0
        private void SendMessage(object sender, RoutedEventArgs e)
        {
            string toSend = MBody.Text;

            if (toSend != "")
            {
                ServicesConsume.PostMessages(ContactInfo.userId, toSend);
                Message        tmp  = new Message(ContactInfo.userId, 3, toSend);
                List <Message> List = new List <Message>();
                List.Add(tmp);
                MessagesContext.insertMessages(List);
                MBody.Text = "";
            }
            else
            {
                MessageBox.Show("No puedes enviar un mensaje vacío");
            }
        }
Esempio n. 15
0
        public ActionResult Protected(int id = 0)
        {
            using (var context = new MessagesContext())
            {
                var model = (from m in context.Messages where m.Id == id select m).SingleOrDefault();

                if (model == null)
                {
                    return(new HttpNotFoundResult());
                }

                if (model.To != User.Identity.Name)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }

                return(View("Index", model));
            }
        }
Esempio n. 16
0
        public async Task SaveChangesAsync()
        {
            _saving = true;
            List <ChatMessageDto> temp;

            lock (_syncRoot)
            {
                temp             = _pendingMessages;
                _pendingMessages = new List <ChatMessageDto>();
            }
            var context = new MessagesContext();

            context.Configuration.AutoDetectChangesEnabled = false;
            context.Configuration.ValidateOnSaveEnabled    = false;
            // ReSharper disable once AccessToDisposedClosure
            await Task.Run(() => { context.BulkInsert(temp); });

            context.Dispose();
            SaveCompleted.Invoke(this, DateTime.Now);
            _saving = false;
        }
Esempio n. 17
0
        protected void Post_Click(object sender, EventArgs e)
        {
            using (var dbContext = new MessagesContext())
            {
                int id = 0;
                if (dbContext.Messages.Count != 0)
                {
                    id = dbContext.Messages.OrderByDescending(i => i.Id).First().Id++;
                }

                var message = new Message
                {
                    Id        = id,
                    Title     = MessageTitle.Text,
                    Views     = 0,
                    CreatedOn = DateTime.Now
                };

                dbContext.Messages.Add(message);
                MessagesList.Rows.AddAt(1, CreateMessageRow(message));
            }
        }
Esempio n. 18
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // Database
            var dbContext = new MessagesContext();

            dbContext.Database.EnsureCreated();
            if (!dbContext.Messages.Any())
            {
                dbContext.Messages.Add
                (
                    new Model.Message
                {
                    User    = "******",
                    Content = "Hello!"
                }
                );
            }
            dbContext.SaveChanges();

            // Exceptions in Development
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();
            app.UseHttpsRedirection();
            app.UseRouting();

            // Routes
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
        //No validation yet
        public async void Add(String content)
        {
            try
            {
                //use onConfiguring
                using (var context = new MessagesContext())
                {
                    Messages user = new Messages
                    {
                        Content = content
                    };


                    //Only use AddSync So if you use a value generator that might need to access the DB to get new values to assign to new entries, such as the SequenceHiLo generator, then use AddAsync().
                    context.Messages.Add(user);

                    await context.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 20
0
 public MessangerRepository(MessagesContext context)
 {
     _context = context;
 }
 public MessagesController(MessagesContext context)
 {
     this._context = context;
 }
Esempio n. 22
0
 public DefaultController(MessagesContext messagesContext, IQueueRepository queueRepository)
 {
     this.messagesContext = messagesContext;
     this.queueRepository = queueRepository;
 }
Esempio n. 23
0
 public MessagesService(MessagesContext dbCtxt)
 {
     this.dbContext = dbCtxt;
 }
Esempio n. 24
0
 public MessagesController(MessagesContext dbContext)
 {
     _dbContext = dbContext;
 }
Esempio n. 25
0
 public MessagesRepository(MessagesContext messagecontext, ILogger <MessagesRepository> logger)
 {
     _messageContext = messagecontext;
     _logger         = logger;
 }
Esempio n. 26
0
 public MessageService(MessagesContext messages, UserManager <User> users)
 {
     _messageConverter = new MessageConverter(users);
     _messages         = messages;
 }
Esempio n. 27
0
 public TestingController(IConfiguration configuration, MessagesContext messages)
 {
     _config   = configuration;
     _messages = messages;
 }
Esempio n. 28
0
 private void refresh(object sender, RoutedEventArgs e)
 {
     MessagesContext.insertMessages(ServicesConsume.GetMessages(this.UserId));
 }
Esempio n. 29
0
 public MessageService(MessagesContext messagesContext, IMapper mapper)
 {
     AutoMapper      = mapper;
     MessagesContext = messagesContext;
 }
Esempio n. 30
0
 public MessengerController(MessagesContext messages)
 {
     _testMessages = messages;
 }