private static void DoMigrations(IJabbrConfiguration config) { if (String.IsNullOrEmpty(config.SqlConnectionString.ProviderName) || !config.SqlConnectionString.ProviderName.Equals(SqlClient, StringComparison.OrdinalIgnoreCase)) { return; } Database.SetInitializer<JabbrContext>(null); // Only run migrations for SQL server (Sql ce not supported as yet) var settings = new MigrationsConfiguration(); var migrator = new DbMigrator(settings); migrator.Update(); }
private static void DoMigrations(IJabbrConfiguration config) { if (String.IsNullOrEmpty(config.SqlConnectionString.ProviderName) || !config.SqlConnectionString.ProviderName.Equals(SqlClient, StringComparison.OrdinalIgnoreCase)) { return; } Database.SetInitializer <JabbrContext>(null); // Only run migrations for SQL server (Sql ce not supported as yet) var settings = new MigrationsConfiguration(); var migrator = new DbMigrator(settings); migrator.Update(); }
private static void SetupSignalR(IJabbrConfiguration jabbrConfig, IKernel kernel, IAppBuilder app) { var resolver = new NinjectSignalRDependencyResolver(kernel); var connectionManager = resolver.Resolve <IConnectionManager>(); var heartbeat = resolver.Resolve <ITransportHeartbeat>(); var hubPipeline = resolver.Resolve <IHubPipeline>(); var configuration = resolver.Resolve <IConfigurationManager>(); // Enable service bus scale out if (!String.IsNullOrEmpty(jabbrConfig.ServiceBusConnectionString) && !String.IsNullOrEmpty(jabbrConfig.ServiceBusTopicPrefix)) { var sbConfig = new ServiceBusScaleoutConfiguration(jabbrConfig.ServiceBusConnectionString, jabbrConfig.ServiceBusTopicPrefix) { TopicCount = 5 }; resolver.UseServiceBus(sbConfig); } if (jabbrConfig.ScaleOutSqlServer) { resolver.UseSqlServer(ConfigurationManager.ConnectionStrings["Jabbr"].ConnectionString); } kernel.Bind <IConnectionManager>() .ToConstant(connectionManager); // We need to extend this since the inital connect might take a while configuration.TransportConnectTimeout = TimeSpan.FromSeconds(30); var config = new HubConfiguration { Resolver = resolver }; hubPipeline.AddModule(kernel.Get <LoggingHubPipelineModule>()); app.MapSignalR(config); var monitor = new PresenceMonitor(kernel, connectionManager, heartbeat); monitor.Start(); }
public HomeModule(ApplicationSettings settings, IJabbrConfiguration configuration, IConnectionManager connectionManager, IJabbrRepository jabbrRepository) { Get["/"] = _ => { if (IsAuthenticated) { var viewModel = new SettingsViewModel { GoogleAnalytics = settings.GoogleAnalytics, Sha = configuration.DeploymentSha, Branch = configuration.DeploymentBranch, Time = configuration.DeploymentTime, DebugMode = (bool)Context.Items["_debugMode"], Version = Constants.JabbRVersion, IsAdmin = Principal.HasClaim(JabbRClaimTypes.Admin), ClientLanguageResources = BuildClientResources(), MaxMessageLength = settings.MaxMessageLength }; return(View["index", viewModel]); } if (Principal != null && Principal.HasPartialIdentity()) { // If the user is partially authenticated then take them to the register page return(Response.AsRedirect("~/account/register")); } return(HttpStatusCode.Unauthorized); }; Get["/monitor"] = _ => { ClaimsPrincipal principal = Principal; if (principal == null || !principal.HasClaim(JabbRClaimTypes.Admin)) { return(HttpStatusCode.Forbidden); } return(View["monitor"]); }; Get["/status", runAsync : true] = async(_, token) => { var model = new StatusViewModel(); // Try to send a message via SignalR // NOTE: Ideally we'd like to actually receive a message that we send, but right now // that would require a full client instance. SignalR 2.1.0 plans to add a feature to // easily support this on the server. var signalrStatus = new SystemStatus { SystemName = "SignalR messaging" }; model.Systems.Add(signalrStatus); try { var hubContext = connectionManager.GetHubContext <Chat>(); await(Task) hubContext.Clients.Client("doesn't exist").noMethodCalledThis(); signalrStatus.SetOK(); } catch (Exception ex) { signalrStatus.SetException(ex.GetBaseException()); } // Try to talk to database var dbStatus = new SystemStatus { SystemName = "Database" }; model.Systems.Add(dbStatus); try { var roomCount = jabbrRepository.Rooms.Count(); dbStatus.SetOK(); } catch (Exception ex) { dbStatus.SetException(ex.GetBaseException()); } // Try to talk to azure storage var azureStorageStatus = new SystemStatus { SystemName = "Azure Upload storage" }; model.Systems.Add(azureStorageStatus); try { if (!String.IsNullOrEmpty(settings.AzureblobStorageConnectionString)) { var azure = new AzureBlobStorageHandler(settings); UploadResult result; using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("test"))) { result = await azure.UploadFile("statusCheck.txt", "text/plain", stream); } azureStorageStatus.SetOK(); } else { azureStorageStatus.StatusMessage = "Not configured"; } } catch (Exception ex) { azureStorageStatus.SetException(ex.GetBaseException()); } //try to talk to local storage var localStorageStatus = new SystemStatus { SystemName = "Local Upload storage" }; model.Systems.Add(localStorageStatus); try { if (!String.IsNullOrEmpty(settings.LocalFileSystemStoragePath) && !String.IsNullOrEmpty(settings.LocalFileSystemStorageUriPrefix)) { var local = new LocalFileSystemStorageHandler(settings); UploadResult localResult; using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("test"))) { localResult = await local.UploadFile("statusCheck.txt", "text/plain", stream); } localStorageStatus.SetOK(); } else { localStorageStatus.StatusMessage = "Not configured"; } } catch (Exception ex) { localStorageStatus.SetException(ex.GetBaseException()); } // Force failure if (Context.Request.Query.fail) { var failedSystem = new SystemStatus { SystemName = "Forced failure" }; failedSystem.SetException(new ApplicationException("Forced failure for test purposes")); model.Systems.Add(failedSystem); } var view = View["status", model]; if (!model.AllOK) { return(view.WithStatusCode(HttpStatusCode.InternalServerError)); } return(view); }; }
public HomeModule(ApplicationSettings settings, IJabbrConfiguration configuration, UploadCallbackHandler uploadHandler, IConnectionManager connectionManager, IJabbrRepository jabbrRepository) { Get["/"] = _ => { if (IsAuthenticated) { var viewModel = new SettingsViewModel { GoogleAnalytics = settings.GoogleAnalytics, Sha = configuration.DeploymentSha, Branch = configuration.DeploymentBranch, Time = configuration.DeploymentTime, DebugMode = (bool)Context.Items["_debugMode"], Version = Constants.JabbRVersion, IsAdmin = Principal.HasClaim(JabbRClaimTypes.Admin), ClientLanguageResources = BuildClientResources() }; return View["index", viewModel]; } if (Principal != null && Principal.HasPartialIdentity()) { // If the user is partially authenticated then take them to the register page return Response.AsRedirect("~/account/register"); } return HttpStatusCode.Unauthorized; }; Get["/monitor"] = _ => { ClaimsPrincipal principal = Principal; if (principal == null || !principal.HasClaim(JabbRClaimTypes.Admin)) { return HttpStatusCode.Forbidden; } return View["monitor"]; }; Get["/status"] = _ => { var model = new StatusViewModel(); // Try to send a message via SignalR // NOTE: Ideally we'd like to actually receive a message that we send, but right now // that would require a full client instance. SignalR 2.1.0 plans to add a feature to // easily support this on the server. var signalrStatus = new SystemStatus { SystemName = "SignalR messaging" }; model.Systems.Add(signalrStatus); try { var hubContext = connectionManager.GetHubContext<Chat>(); var sendTask = (Task)hubContext.Clients.Client("doesn't exist").noMethodCalledThis(); sendTask.Wait(); signalrStatus.SetOK(); } catch (Exception ex) { signalrStatus.SetException(ex.GetBaseException()); } // Try to talk to database var dbStatus = new SystemStatus { SystemName = "Database" }; model.Systems.Add(dbStatus); try { var roomCount = jabbrRepository.Rooms.Count(); dbStatus.SetOK(); } catch (Exception ex) { dbStatus.SetException(ex.GetBaseException()); } // Try to talk to storage var azureStorageStatus = new SystemStatus { SystemName = "Upload storage" }; model.Systems.Add(azureStorageStatus); try { if (!String.IsNullOrEmpty(settings.AzureblobStorageConnectionString)) { var azure = new AzureBlobStorageHandler(settings); UploadResult result; using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("test"))) { result = azure.UploadFile("statusCheck.txt", "text/plain", stream) .Result; } azureStorageStatus.SetOK(); } else { azureStorageStatus.StatusMessage = "Not configured"; } } catch (Exception ex) { azureStorageStatus.SetException(ex.GetBaseException()); } // Force failure if (Context.Request.Query.fail) { var failedSystem = new SystemStatus { SystemName = "Forced failure" }; failedSystem.SetException(new ApplicationException("Forced failure for test purposes")); model.Systems.Add(failedSystem); } var view = View["status", model]; if (!model.AllOK) { return view.WithStatusCode(HttpStatusCode.InternalServerError); } return view; }; Post["/upload-file"] = _ => { if (!IsAuthenticated) { return 403; } string roomName = Request.Form.room; string connectionId = Request.Form.connectionId; string file = Request.Form.file; //string fileName = "clipboard_" + Guid.NewGuid().ToString("N"); string fileName = Request.Form.filename; string contentType = Request.Form.type; byte[] binData = null; var info = Regex.Match(file, @"data:(?:(?<unkown>.+?)/(?<type>.+?))?;base64,(?<data>.+)"); binData = Convert.FromBase64String(info.Groups["data"].Value); contentType = info.Groups["type"].Value; if (String.IsNullOrWhiteSpace(contentType)) { contentType = "application/octet-stream"; } UploadFile( uploadHandler, Principal.GetUserId(), connectionId, roomName, fileName, contentType, new MemoryStream(binData)).Wait(); return 200; }; }
private static void SetupSignalR(IJabbrConfiguration jabbrConfig, IKernel kernel, IAppBuilder app) { var resolver = new NinjectSignalRDependencyResolver(kernel); var connectionManager = resolver.Resolve<IConnectionManager>(); var heartbeat = resolver.Resolve<ITransportHeartbeat>(); var hubPipeline = resolver.Resolve<IHubPipeline>(); var configuration = resolver.Resolve<IConfigurationManager>(); // Enable service bus scale out if (!String.IsNullOrEmpty(jabbrConfig.ServiceBusConnectionString) && !String.IsNullOrEmpty(jabbrConfig.ServiceBusTopicPrefix)) { var sbConfig = new ServiceBusScaleoutConfiguration(jabbrConfig.ServiceBusConnectionString, jabbrConfig.ServiceBusTopicPrefix) { TopicCount = 5 }; resolver.UseServiceBus(sbConfig); } if (jabbrConfig.ScaleOutSqlServer) { resolver.UseSqlServer(ConfigurationManager.ConnectionStrings["Jabbr"].ConnectionString); } kernel.Bind<IConnectionManager>() .ToConstant(connectionManager); // We need to extend this since the inital connect might take a while configuration.TransportConnectTimeout = TimeSpan.FromSeconds(30); var config = new HubConfiguration { Resolver = resolver }; hubPipeline.AddModule(kernel.Get<LoggingHubPipelineModule>()); app.MapSignalR(config); var monitor = new PresenceMonitor(kernel, connectionManager, heartbeat); monitor.Start(); }
public HomeModule(ApplicationSettings settings, IJabbrConfiguration configuration, UploadCallbackHandler uploadHandler, IConnectionManager connectionManager, IJabbrRepository jabbrRepository) { Get["/"] = _ => { if (IsAuthenticated) { var viewModel = new SettingsViewModel { GoogleAnalytics = settings.GoogleAnalytics, Sha = configuration.DeploymentSha, Branch = configuration.DeploymentBranch, Time = configuration.DeploymentTime, DebugMode = (bool)Context.Items["_debugMode"], Version = Constants.JabbRVersion, IsAdmin = Principal.HasClaim(JabbRClaimTypes.Admin), ClientLanguageResources = BuildClientResources() }; return(View["index", viewModel]); } if (Principal != null && Principal.HasPartialIdentity()) { // If the user is partially authenticated then take them to the register page return(Response.AsRedirect("~/account/register")); } return(HttpStatusCode.Unauthorized); }; Get["/monitor"] = _ => { ClaimsPrincipal principal = Principal; if (principal == null || !principal.HasClaim(JabbRClaimTypes.Admin)) { return(HttpStatusCode.Forbidden); } return(View["monitor"]); }; Get["/status"] = _ => { var model = new StatusViewModel(); // Try to send a message via SignalR // NOTE: Ideally we'd like to actually receive a message that we send, but right now // that would require a full client instance. SignalR 2.1.0 plans to add a feature to // easily support this on the server. var signalrStatus = new SystemStatus { SystemName = "SignalR messaging" }; model.Systems.Add(signalrStatus); try { var hubContext = connectionManager.GetHubContext <Chat>(); var sendTask = (Task)hubContext.Clients.Client("doesn't exist").noMethodCalledThis(); sendTask.Wait(); signalrStatus.SetOK(); } catch (Exception ex) { signalrStatus.SetException(ex.GetBaseException()); } // Try to talk to database var dbStatus = new SystemStatus { SystemName = "Database" }; model.Systems.Add(dbStatus); try { var roomCount = jabbrRepository.Rooms.Count(); dbStatus.SetOK(); } catch (Exception ex) { dbStatus.SetException(ex.GetBaseException()); } // Try to talk to storage var azureStorageStatus = new SystemStatus { SystemName = "Upload storage" }; model.Systems.Add(azureStorageStatus); try { if (!String.IsNullOrEmpty(settings.AzureblobStorageConnectionString)) { var azure = new AzureBlobStorageHandler(settings); UploadResult result; using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("test"))) { result = azure.UploadFile("statusCheck.txt", "text/plain", stream) .Result; } azureStorageStatus.SetOK(); } else { azureStorageStatus.StatusMessage = "Not configured"; } } catch (Exception ex) { azureStorageStatus.SetException(ex.GetBaseException()); } // Force failure if (Context.Request.Query.fail) { var failedSystem = new SystemStatus { SystemName = "Forced failure" }; failedSystem.SetException(new ApplicationException("Forced failure for test purposes")); model.Systems.Add(failedSystem); } var view = View["status", model]; if (!model.AllOK) { return(view.WithStatusCode(HttpStatusCode.InternalServerError)); } return(view); }; Post["/upload-file"] = _ => { if (!IsAuthenticated) { return(403); } string roomName = Request.Form.room; string connectionId = Request.Form.connectionId; string file = Request.Form.file; //string fileName = "clipboard_" + Guid.NewGuid().ToString("N"); string fileName = Request.Form.filename; string contentType = Request.Form.type; byte[] binData = null; var info = Regex.Match(file, @"data:(?:(?<unkown>.+?)/(?<type>.+?))?;base64,(?<data>.+)"); binData = Convert.FromBase64String(info.Groups["data"].Value); contentType = info.Groups["type"].Value; if (String.IsNullOrWhiteSpace(contentType)) { contentType = "application/octet-stream"; } UploadFile( uploadHandler, Principal.GetUserId(), connectionId, roomName, fileName, contentType, new MemoryStream(binData)).Wait(); return(200); }; }
private static KernelBase SetupNinject(IJabbrConfiguration configuration) { var kernel = new StandardKernel(new[] { new FactoryModule() }); kernel.Bind <JabbrContext>() .To <JabbrContext>(); kernel.Bind <IRecentMessageCache>() .To <NoopCache>() .InSingletonScope(); kernel.Bind <IJabbrRepository>() .To <PersistedRepository>(); kernel.Bind <IChatService>() .To <ChatService>(); kernel.Bind <IDataProtector>() .To <JabbRDataProtection>(); kernel.Bind <ICookieAuthenticationProvider>() .To <JabbRFormsAuthenticationProvider>(); kernel.Bind <ILogger>() .To <RealtimeLogger>(); kernel.Bind <IUserIdProvider>() .To <JabbrUserIdProvider>(); kernel.Bind <IJabbrConfiguration>() .ToConstant(configuration); // We're doing this manually since we want the chat repository to be shared // between the chat service and the chat hub itself kernel.Bind <Chat>() .ToMethod(context => { var resourceProcessor = context.Kernel.Get <ContentProviderProcessor>(); var recentMessageCache = context.Kernel.Get <IRecentMessageCache>(); var repository = context.Kernel.Get <IJabbrRepository>(); var cache = context.Kernel.Get <ICache>(); var logger = context.Kernel.Get <ILogger>(); var settings = context.Kernel.Get <ApplicationSettings>(); var service = new ChatService(cache, recentMessageCache, repository, settings); return(new Chat(resourceProcessor, service, recentMessageCache, repository, cache, logger, settings)); }); kernel.Bind <ICryptoService>() .To <CryptoService>(); kernel.Bind <IJavaScriptMinifier>() .To <AjaxMinMinifier>() .InSingletonScope(); kernel.Bind <IMembershipService>() .To <MembershipService>(); kernel.Bind <ApplicationSettings>() .ToMethod(context => { return(context.Kernel.Get <ISettingsManager>().Load()); }); kernel.Bind <ISettingsManager>() .To <SettingsManager>(); kernel.Bind <IUserAuthenticator>() .To <DefaultUserAuthenticator>(); kernel.Bind <IAuthenticationService>() .To <AuthenticationService>(); kernel.Bind <IAuthenticationCallbackProvider>() .To <JabbRAuthenticationCallbackProvider>(); kernel.Bind <ICache>() .To <DefaultCache>() .InSingletonScope(); kernel.Bind <IChatNotificationService>() .To <ChatNotificationService>(); kernel.Bind <IKeyProvider>() .To <SettingsKeyProvider>(); kernel.Bind <IResourceProcessor>() .To <ResourceProcessor>(); RegisterContentProviders(kernel); var serializer = JsonSerializer.Create(new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.IsoDateFormat }); kernel.Bind <JsonSerializer>() .ToConstant(serializer); kernel.Bind <UploadCallbackHandler>() .ToSelf() .InSingletonScope(); kernel.Bind <UploadProcessor>() .ToConstant(new UploadProcessor(kernel)); kernel.Bind <ContentProviderProcessor>() .ToConstant(new ContentProviderProcessor(kernel)); kernel.Bind <IEmailTemplateContentReader>() .To <RazorEmailTemplateContentReader>(); kernel.Bind <IEmailTemplateEngine>() .To <RazorEmailTemplateEngine>(); kernel.Bind <IEmailSender>() .To <SmtpClientEmailSender>(); kernel.Bind <IEmailService>() .To <EmailService>(); return(kernel); }
private static KernelBase SetupNinject(IJabbrConfiguration configuration) { var kernel = new StandardKernel(new[] { new FactoryModule() }); kernel.Bind<JabbrContext>() .To<JabbrContext>(); kernel.Bind<IRecentMessageCache>() .To<NoopCache>() .InSingletonScope(); kernel.Bind<IJabbrRepository>() .To<PersistedRepository>(); kernel.Bind<IChatService>() .To<ChatService>(); kernel.Bind<IDataProtector>() .To<JabbRDataProtection>(); kernel.Bind<ICookieAuthenticationProvider>() .To<JabbRFormsAuthenticationProvider>(); kernel.Bind<ILogger>() .To<RealtimeLogger>(); kernel.Bind<IUserIdProvider>() .To<JabbrUserIdProvider>(); kernel.Bind<IJabbrConfiguration>() .ToConstant(configuration); // We're doing this manually since we want the chat repository to be shared // between the chat service and the chat hub itself kernel.Bind<Chat>() .ToMethod(context => { var resourceProcessor = context.Kernel.Get<ContentProviderProcessor>(); var pushNotification = context.Kernel.Get<PushNotificationService>(); var recentMessageCache = context.Kernel.Get<IRecentMessageCache>(); var repository = context.Kernel.Get<IJabbrRepository>(); var cache = context.Kernel.Get<ICache>(); var logger = context.Kernel.Get<ILogger>(); var settings = context.Kernel.Get<ApplicationSettings>(); var service = new ChatService(cache, recentMessageCache, repository, settings); return new Chat(resourceProcessor, pushNotification, service, recentMessageCache, repository, cache, logger, settings); }); kernel.Bind<ICryptoService>() .To<CryptoService>(); kernel.Bind<PushNotificationService>() .To<PushNotificationService>(); kernel.Bind<IResourceProcessor>() .ToConstant(new ResourceProcessor(kernel)); kernel.Bind<IJavaScriptMinifier>() .To<AjaxMinMinifier>() .InSingletonScope(); kernel.Bind<IMembershipService>() .To<MembershipService>(); kernel.Bind<ApplicationSettings>() .ToMethod(context => { return context.Kernel.Get<ISettingsManager>().Load(); }); kernel.Bind<ISettingsManager>() .To<SettingsManager>(); kernel.Bind<IUserAuthenticator>() .To<DefaultUserAuthenticator>(); kernel.Bind<IAuthenticationService>() .To<AuthenticationService>(); kernel.Bind<IAuthenticationCallbackProvider>() .To<JabbRAuthenticationCallbackProvider>(); kernel.Bind<ICache>() .To<DefaultCache>() .InSingletonScope(); kernel.Bind<IChatNotificationService>() .To<ChatNotificationService>(); kernel.Bind<IKeyProvider>() .To<SettingsKeyProvider>(); var serializer = JsonSerializer.Create(new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.IsoDateFormat }); kernel.Bind<JsonSerializer>() .ToConstant(serializer); kernel.Bind<UploadCallbackHandler>() .ToSelf() .InSingletonScope(); kernel.Bind<UploadProcessor>() .ToConstant(new UploadProcessor(kernel)); kernel.Bind<ContentProviderProcessor>() .ToConstant(new ContentProviderProcessor(kernel)); kernel.Bind<IEmailTemplateContentReader>() .To<RazorEmailTemplateContentReader>(); kernel.Bind<IEmailTemplateEngine>() .To<RazorEmailTemplateEngine>(); kernel.Bind<IEmailSender>() .To<SmtpClientEmailSender>(); kernel.Bind<IEmailService>() .To<EmailService>(); return kernel; }
public ImgurContentProvider(IJabbrConfiguration config) { _config = config; }
public HomeModule(ApplicationSettings settings, IJabbrConfiguration configuration, UploadCallbackHandler uploadHandler) { Get["/"] = _ => { if (IsAuthenticated) { var viewModel = new SettingsViewModel { GoogleAnalytics = settings.GoogleAnalytics, Sha = configuration.DeploymentSha, Branch = configuration.DeploymentBranch, Time = configuration.DeploymentTime, DebugMode = (bool)Context.Items["_debugMode"], Version = Constants.JabbRVersion, IsAdmin = Principal.HasClaim(JabbRClaimTypes.Admin) }; return(View["index", viewModel]); } if (Principal.HasPartialIdentity()) { // If the user is partially authenticated then take them to the register page return(Response.AsRedirect("~/account/register")); } return(HttpStatusCode.Unauthorized); }; Get["/monitor"] = _ => { ClaimsPrincipal principal = Principal; if (principal == null || !principal.HasClaim(JabbRClaimTypes.Admin)) { return(403); } return(View["monitor"]); }; Post["/upload"] = _ => { if (!IsAuthenticated) { return(403); } string roomName = Request.Form.room; string connectionId = Request.Form.connectionId; HttpFile file = Request.Files.First(); // This blocks since we're not using nancy's async support yet UploadFile( uploadHandler, Principal.GetUserId(), connectionId, roomName, file.Name, file.ContentType, file.Value).Wait(); return(200); }; Post["/upload-clipboard"] = _ => { if (!IsAuthenticated) { return(403); } string roomName = Request.Form.room; string connectionId = Request.Form.connectionId; string file = Request.Form.file; string fileName = "clipboard_" + Guid.NewGuid().ToString("N"); string contentType = "image/jpeg"; var info = Regex.Match(file, @"data:image/(?<type>.+?);base64,(?<data>.+)"); var binData = Convert.FromBase64String(info.Groups["data"].Value); contentType = info.Groups["type"].Value; fileName = fileName + "." + contentType.Substring(contentType.IndexOf("/") + 1); UploadFile( uploadHandler, Principal.GetUserId(), connectionId, roomName, fileName, contentType, new MemoryStream(binData)).Wait(); return(200); }; }
public ImgurContentProvider(IJabbrConfiguration config) { _config = config; }
public HomeModule(ApplicationSettings settings, IJabbrConfiguration configuration, IConnectionManager connectionManager, IJabbrRepository jabbrRepository) { Get["/"] = _ => { if (IsAuthenticated) { var viewModel = new SettingsViewModel { GoogleAnalytics = settings.GoogleAnalytics, Sha = configuration.DeploymentSha, Branch = configuration.DeploymentBranch, Time = configuration.DeploymentTime, DebugMode = (bool)Context.Items["_debugMode"], Version = Constants.JabbRVersion, IsAdmin = Principal.HasClaim(JabbRClaimTypes.Admin), ClientLanguageResources = BuildClientResources(), MaxMessageLength = settings.MaxMessageLength }; return View["index", viewModel]; } if (Principal != null && Principal.HasPartialIdentity()) { // If the user is partially authenticated then take them to the register page return Response.AsRedirect("~/account/register"); } return HttpStatusCode.Unauthorized; }; Get["/monitor"] = _ => { ClaimsPrincipal principal = Principal; if (principal == null || !principal.HasClaim(JabbRClaimTypes.Admin)) { return HttpStatusCode.Forbidden; } return View["monitor"]; }; Get["/status", runAsync: true] = async (_, token) => { var model = new StatusViewModel(); // Try to send a message via SignalR // NOTE: Ideally we'd like to actually receive a message that we send, but right now // that would require a full client instance. SignalR 2.1.0 plans to add a feature to // easily support this on the server. var signalrStatus = new SystemStatus { SystemName = "SignalR messaging" }; model.Systems.Add(signalrStatus); try { var hubContext = connectionManager.GetHubContext<Chat>(); await (Task)hubContext.Clients.Client("doesn't exist").noMethodCalledThis(); signalrStatus.SetOK(); } catch (Exception ex) { signalrStatus.SetException(ex.GetBaseException()); } // Try to talk to database var dbStatus = new SystemStatus { SystemName = "Database" }; model.Systems.Add(dbStatus); try { var roomCount = jabbrRepository.Rooms.Count(); dbStatus.SetOK(); } catch (Exception ex) { dbStatus.SetException(ex.GetBaseException()); } // Try to talk to azure storage var azureStorageStatus = new SystemStatus { SystemName = "Azure Upload storage" }; model.Systems.Add(azureStorageStatus); try { if (!String.IsNullOrEmpty(settings.AzureblobStorageConnectionString)) { var azure = new AzureBlobStorageHandler(settings); UploadResult result; using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("test"))) { result = await azure.UploadFile("statusCheck.txt", "text/plain", stream); } azureStorageStatus.SetOK(); } else { azureStorageStatus.StatusMessage = "Not configured"; } } catch (Exception ex) { azureStorageStatus.SetException(ex.GetBaseException()); } //try to talk to local storage var localStorageStatus = new SystemStatus { SystemName = "Local Upload storage" }; model.Systems.Add(localStorageStatus); try { if (!String.IsNullOrEmpty(settings.LocalFileSystemStoragePath) && !String.IsNullOrEmpty(settings.LocalFileSystemStorageUriPrefix)) { var local = new LocalFileSystemStorageHandler(settings); UploadResult localResult; using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("test"))) { localResult = await local.UploadFile("statusCheck.txt", "text/plain", stream); } localStorageStatus.SetOK(); } else { localStorageStatus.StatusMessage = "Not configured"; } } catch (Exception ex) { localStorageStatus.SetException(ex.GetBaseException()); } // Force failure if (Context.Request.Query.fail) { var failedSystem = new SystemStatus { SystemName = "Forced failure" }; failedSystem.SetException(new ApplicationException("Forced failure for test purposes")); model.Systems.Add(failedSystem); } var view = View["status", model]; if (!model.AllOK) { return view.WithStatusCode(HttpStatusCode.InternalServerError); } return view; }; }
public HomeModule(ApplicationSettings settings, IJabbrConfiguration configuration, UploadCallbackHandler uploadHandler) { Get["/"] = _ => { if (IsAuthenticated) { var viewModel = new SettingsViewModel { GoogleAnalytics = settings.GoogleAnalytics, Sha = configuration.DeploymentSha, Branch = configuration.DeploymentBranch, Time = configuration.DeploymentTime, DebugMode = (bool)Context.Items["_debugMode"], Version = Constants.JabbRVersion, IsAdmin = Principal.HasClaim(JabbRClaimTypes.Admin), ClientLanguageResources = BuildClientResources() }; return(View["index", viewModel]); } if (Principal.HasPartialIdentity()) { // If the user is partially authenticated then take them to the register page return(Response.AsRedirect("~/account/register")); } return(HttpStatusCode.Unauthorized); }; Get["/monitor"] = _ => { ClaimsPrincipal principal = Principal; if (principal == null || !principal.HasClaim(JabbRClaimTypes.Admin)) { return(403); } return(View["monitor"]); }; Post["/upload-file"] = _ => { if (!IsAuthenticated) { return(403); } string roomName = Request.Form.room; string connectionId = Request.Form.connectionId; string file = Request.Form.file; //string fileName = "clipboard_" + Guid.NewGuid().ToString("N"); string fileName = Request.Form.filename; string contentType = Request.Form.type; byte[] binData = null; var info = Regex.Match(file, @"data:(?:(?<unkown>.+?)/(?<type>.+?))?;base64,(?<data>.+)"); binData = Convert.FromBase64String(info.Groups["data"].Value); contentType = info.Groups["type"].Value; if (String.IsNullOrWhiteSpace(contentType)) { contentType = "application/octet-stream"; } UploadFile( uploadHandler, Principal.GetUserId(), connectionId, roomName, fileName, contentType, new MemoryStream(binData)).Wait(); return(200); }; }
public ImageContentProvider(IKernel kernel) { _kernel = kernel; _configuration = kernel.Get<IJabbrConfiguration>(); }
public HomeModule(ApplicationSettings settings, IJabbrConfiguration configuration, UploadCallbackHandler uploadHandler) { Get["/"] = _ => { if (IsAuthenticated) { var viewModel = new SettingsViewModel { GoogleAnalytics = settings.GoogleAnalytics, Sha = configuration.DeploymentSha, Branch = configuration.DeploymentBranch, Time = configuration.DeploymentTime, DebugMode = (bool)Context.Items["_debugMode"], Version = Constants.JabbRVersion, IsAdmin = Principal.HasClaim(JabbRClaimTypes.Admin) }; return View["index", viewModel]; } if (Principal.HasPartialIdentity()) { // If the user is partially authenticated then take them to the register page return Response.AsRedirect("~/account/register"); } return HttpStatusCode.Unauthorized; }; Get["/monitor"] = _ => { ClaimsPrincipal principal = Principal; if (principal == null || !principal.HasClaim(JabbRClaimTypes.Admin)) { return 403; } return View["monitor"]; }; Post["/upload"] = _ => { if (!IsAuthenticated) { return 403; } string roomName = Request.Form.room; string connectionId = Request.Form.connectionId; HttpFile file = Request.Files.First(); // This blocks since we're not using nancy's async support yet UploadFile( uploadHandler, Principal.GetUserId(), connectionId, roomName, file.Name, file.ContentType, file.Value).Wait(); return 200; }; Post["/upload-clipboard"] = _ => { if (!IsAuthenticated) { return 403; } string roomName = Request.Form.room; string connectionId = Request.Form.connectionId; string file = Request.Form.file; string fileName = "clipboard_" + Guid.NewGuid().ToString("N"); string contentType = "image/jpeg"; var info = Regex.Match(file, @"data:image/(?<type>.+?);base64,(?<data>.+)"); var binData = Convert.FromBase64String(info.Groups["data"].Value); contentType = info.Groups["type"].Value; fileName = fileName + "." + contentType.Substring(contentType.IndexOf("/") + 1); UploadFile( uploadHandler, Principal.GetUserId(), connectionId, roomName, fileName, contentType, new MemoryStream(binData)).Wait(); return 200; }; }
public ImageContentProvider(IKernel kernel, ApplicationSettings settings) { _kernel = kernel; _settings = settings; _configuration = kernel.Get<IJabbrConfiguration>(); }
public HomeModule(ApplicationSettings settings, IJabbrConfiguration configuration, UploadCallbackHandler uploadHandler) { Get["/"] = _ => { if (IsAuthenticated) { var viewModel = new SettingsViewModel { GoogleAnalytics = settings.GoogleAnalytics, Sha = configuration.DeploymentSha, Branch = configuration.DeploymentBranch, Time = configuration.DeploymentTime, DebugMode = (bool)Context.Items["_debugMode"], Version = Constants.JabbRVersion, IsAdmin = Principal.HasClaim(JabbRClaimTypes.Admin), ClientLanguageResources = BuildClientResources() }; return View["index", viewModel]; } if (Principal.HasPartialIdentity()) { // If the user is partially authenticated then take them to the register page return Response.AsRedirect("~/account/register"); } return HttpStatusCode.Unauthorized; }; Get["/monitor"] = _ => { ClaimsPrincipal principal = Principal; if (principal == null || !principal.HasClaim(JabbRClaimTypes.Admin)) { return 403; } return View["monitor"]; }; Post["/upload-file"] = _ => { if (!IsAuthenticated) { return 403; } string roomName = Request.Form.room; string connectionId = Request.Form.connectionId; string file = Request.Form.file; //string fileName = "clipboard_" + Guid.NewGuid().ToString("N"); string fileName = Request.Form.filename; string contentType = Request.Form.type; byte[] binData = null; var info = Regex.Match(file, @"data:(?:(?<unkown>.+?)/(?<type>.+?))?;base64,(?<data>.+)"); binData = Convert.FromBase64String(info.Groups["data"].Value); contentType = info.Groups["type"].Value; if (String.IsNullOrWhiteSpace(contentType)) { contentType = "application/octet-stream"; } UploadFile( uploadHandler, Principal.GetUserId(), connectionId, roomName, fileName, contentType, new MemoryStream(binData)).Wait(); return 200; }; }
public VideoContentProvider(IKernel kernel) { _kernel = kernel; _configuration = kernel.Get <IJabbrConfiguration>(); }
public ImageContentProvider(IKernel kernel, ApplicationSettings settings) { _kernel = kernel; _settings = settings; _configuration = kernel.Get <IJabbrConfiguration>(); }