// 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(); }
public MessagesRepository() { _pendingMessages = new List <ChatMessageDto>(); AutoSaveOptions = new AutoSaveOptions(); _streamCheck = new MessagesContext(); _syncRoot = new object(); }
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(); }
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(); }
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(); }
public Messages() { InitializeComponent(); var message = new MessagesContext(); message.Message.Load(); var messages = message.Message.Local.ToObservableCollection(); }
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); }
public IActionResult Index(MessagesContext dbContext) { DbController.Db = dbContext; if (User.Identity.IsAuthenticated) { return(View()); } else { return(Redirect("/Auth/Login")); } }
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(); }
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)); } } }
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)); } }
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()); } }
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); }
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"); } }
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)); } }
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; }
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)); } }
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); } }
public MessangerRepository(MessagesContext context) { _context = context; }
public MessagesController(MessagesContext context) { this._context = context; }
public DefaultController(MessagesContext messagesContext, IQueueRepository queueRepository) { this.messagesContext = messagesContext; this.queueRepository = queueRepository; }
public MessagesService(MessagesContext dbCtxt) { this.dbContext = dbCtxt; }
public MessagesController(MessagesContext dbContext) { _dbContext = dbContext; }
public MessagesRepository(MessagesContext messagecontext, ILogger <MessagesRepository> logger) { _messageContext = messagecontext; _logger = logger; }
public MessageService(MessagesContext messages, UserManager <User> users) { _messageConverter = new MessageConverter(users); _messages = messages; }
public TestingController(IConfiguration configuration, MessagesContext messages) { _config = configuration; _messages = messages; }
private void refresh(object sender, RoutedEventArgs e) { MessagesContext.insertMessages(ServicesConsume.GetMessages(this.UserId)); }
public MessageService(MessagesContext messagesContext, IMapper mapper) { AutoMapper = mapper; MessagesContext = messagesContext; }
public MessengerController(MessagesContext messages) { _testMessages = messages; }