internal static bool BootstrapLibrary() { if (String.IsNullOrWhiteSpace(SecretKey)) { return(true); } BroadcastManager.Init(); ChatManager.Init(); PlaylistManager.Init(); QueueManager.Init(); SettingsManager.Init(); UserManager.Init(); SuggestionManager.Init(); StatisticsManager.Init(); // ModuleManager should always load last. ModuleManager.Init(); using (var s_Db = Database.GetConnection()) if (s_Db.SingleById <CoreSetting>("gsun") == null || s_Db.SingleById <CoreSetting>("gspw") == null) { return(false); } UserManager.Authenticate(); return(true); }
public void BroadcastManagerMethodSend() { // creating net pipe repository var mockNetNamedPipeRepository = new Mock <INetNamedPipeRepository>(); mockNetNamedPipeRepository.Setup(x => x.RegisterService(It.IsAny <string>(), It.IsAny <string>())); mockNetNamedPipeRepository.Setup(x => x.SendBroadcastToListener( It.IsAny <string>(), It.IsAny <object>(), It.IsAny <EndpointAddress>())); // add mock repositories to the container ServiceLocator.Container.RegisterInstance <INetNamedPipeRepository>( mockNetNamedPipeRepository.Object); var netNamedPipeRepository = ServiceLocator.Resolve <INetNamedPipeRepository>(); netNamedPipeRepository.MessageReceived += this.MessageReceivedHandler; BroadcastManager settingsManager = new BroadcastManager(); settingsManager.RegisterService("net.pipe://localhost", "Host3"); EndpointAddress endpoint = new EndpointAddress("net.pipe://localhost/Host3"); settingsManager.SendBroadcastToListener( new Dictionary <string, dynamic>() { { "settingName", "HostServer" }, { "settingValue", "message HostServer" }, { "endPoint", endpoint } }); Assert.IsTrue(true); }
private void PrinterConnectionDiscoveryTabPanel_Load(object sender, EventArgs e) { try { if (this.ManualIPAddress != null) { ConnectionManager.AtumFirmwareResults += PrinterFirmwareResults; var bwSendManualIP = new BackgroundWorker(); bwSendManualIP.DoWork += bwSendManualIP_DoWork; bwSendManualIP.RunWorkerAsync(); } else { BroadcastManager.SendAsBroadcast(BroadcastManager.typeBroadcastAction.GetPrinter, (new byte[0])); } } catch { } this._currentTick = 0; this._timerProgressBar.Interval = 1000; this._timerProgressBar.Tick += new EventHandler(_timerProgressBar_Tick); this._timerProgressBar.Start(); if (PrinterManager.AvailablePrinters == null) { PrinterManager.AvailablePrinters = new BindingList <DAL.Hardware.AtumPrinter>(); } PrinterManager.AvailablePrinters.ListChanged += new ListChangedEventHandler(AvailablePrinters_ListChanged); this.UpdateAvailablePrinters(); }
public override void DoAction() { broadcastController = FindObjectOfType <BroadcastManager>(); if (broadcastController.currentCamera != null) { broadcastController.currentCamera.enabled = false; } if (GameObject.Find(newCamera).GetComponent <Camera>() != null) { GameObject.Find(newCamera).GetComponent <Camera>().enabled = true; } }
public void CachedSettingManagerCachedSettingsManagerPropertyGetForHost() { var mockNetNamedPipeRepository = new Moq.Mock <INetNamedPipeRepository>(); mockNetNamedPipeRepository.Setup(x => x.RegisterService(It.IsAny <string>(), It.IsAny <string>())); // add mock repositories to the container ServiceLocator.Container.RegisterInstance <INetNamedPipeRepository>( mockNetNamedPipeRepository.Object); BroadcastManager settingsManager = new BroadcastManager(); ServiceHost host = settingsManager.Host; Assert.IsNull(host); }
private async Task <ICorrelationId> BroadcastMessage(PeerId broadcaster) { var gossipMessageHandler = new BroadcastManager( _peers, _peerSettings, _cache, Substitute.For <IPeerClient>(), _keySigner, Substitute.For <ILogger>()); var innerMessage = TransactionHelper.GetPublicTransaction() .ToProtocolMessage(broadcaster); await gossipMessageHandler.BroadcastAsync(innerMessage); return(innerMessage.CorrelationId.ToCorrelationId()); }
private void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame frame = e.OpenSkeletonFrame()) { if (frame == null) { return; } frame.GetSkeletons(ref skeletons); if (skeletons.All(s => s.TrackingState == SkeletonTrackingState.NotTracked)) { return; } foreach (var skeleton in skeletons) { if (skeleton.TrackingState != SkeletonTrackingState.Tracked) { continue; } foreach (Joint joint in skeleton.Joints) { if (joint.TrackingState != JointTrackingState.Tracked) { continue; } if (joint.JointType == JointType.HandRight) { MouseControllerAction action = MouseController.Current.SetHandPosition(kinectSensor, joint, skeleton); BroadcastManager.GetBroadcastEngine().ScheduleForBroadcasting(action); } } } } }
public void BroadcastManagerMethodStartHost() { // creating net pipe repository var mockNetNamedPipeRepository = new Mock <INetNamedPipeRepository>(); mockNetNamedPipeRepository.Setup(x => x.RegisterService(It.IsAny <string>(), It.IsAny <string>())); // add mock repositories to the container ServiceLocator.Container.RegisterInstance <INetNamedPipeRepository>( mockNetNamedPipeRepository.Object); var netNamedPipeRepository = ServiceLocator.Resolve <INetNamedPipeRepository>(); netNamedPipeRepository.MessageReceived += this.MessageReceivedHandler; BroadcastManager settingsManager = new BroadcastManager(); settingsManager.RegisterService( "net.pipe://localhost", "Host"); Assert.IsNotNull(mockNetNamedPipeRepository.Object); }
public async Task Can_Increase_Received_Count_When_Broadcast_Message_Is_Received(int receivedCount) { PopulatePeers(100); var peerId = PeerIdHelper.GetPeerId("1"); var senderIdentifier = PeerIdHelper.GetPeerId("sender"); IBroadcastManager broadcastMessageHandler = new BroadcastManager( _peers, _peerSettings, _cache, Substitute.For <IPeerClient>(), _keySigner, Substitute.For <ILogger>()); var messageDto = new MessageDto( TransactionHelper.GetPublicTransaction().ToProtocolMessage(senderIdentifier), peerId ); var gossipDto = messageDto.Content .ToProtocolMessage(senderIdentifier, messageDto.CorrelationId); await broadcastMessageHandler.ReceiveAsync(gossipDto); _cache.TryGetValue(messageDto.CorrelationId.Id, out BroadcastMessage value); value.ReceivedCount.Should().Be(1); for (var i = 0; i < receivedCount; i++) { await broadcastMessageHandler.ReceiveAsync(gossipDto); } _cache.TryGetValue(messageDto.CorrelationId.Id, out value); value.ReceivedCount.Should().Be(receivedCount + 1); }
public SettingsModule() { this.RequiresAuthentication(); Get["/settings"] = p_Parameters => { if (!Context.CurrentUser.Claims.Contains("super")) { return(new RedirectResponse("/")); } return(View["CoreSettings", new { SuperUser = Context.CurrentUser.Claims.Contains("super"), History = SettingsManager.MaxHistorySongs(), Threshold = SettingsManager.SongVoteThreshold(), Title = BroadcastManager.GetBroadcastName(), Description = BroadcastManager.GetBroadcastDescription(), CommandPrefix = SettingsManager.CommandPrefix().ToString(), WithoutGuest = SettingsManager.CanCommandWithoutGuest() }]); }; Post["/settings"] = p_Parameters => { if (!Context.CurrentUser.Claims.Contains("super")) { return(new RedirectResponse("/")); } var s_Request = this.Bind <SaveSettingsRequest>(); SettingsManager.MaxHistorySongs(s_Request.History); SettingsManager.SongVoteThreshold(s_Request.Threshold); SettingsManager.CommandPrefix(s_Request.Prefix[0]); SettingsManager.CanCommandWithoutGuest(s_Request.Guest); using (var s_Db = Database.GetConnection()) { if (s_Request.Title.Trim().Length > 3) { s_Db.Update(new CoreSetting() { Key = "bcname", Value = s_Request.Title.Trim() }); Application.Library.Broadcast.UpdateBroadcastName(s_Request.Title.Trim()); } if (s_Request.Description.Trim().Length > 3) { s_Db.Update(new CoreSetting() { Key = "bcdesc", Value = s_Request.Description.Trim() }); Application.Library.Broadcast.UpdateBroadcastDescription(s_Request.Description.Trim()); } } return(View["CoreSettings", new { SuperUser = Context.CurrentUser.Claims.Contains("super"), History = SettingsManager.MaxHistorySongs(), Threshold = SettingsManager.SongVoteThreshold(), Title = BroadcastManager.GetBroadcastName(), Description = BroadcastManager.GetBroadcastDescription(), CommandPrefix = SettingsManager.CommandPrefix().ToString(), WithoutGuest = SettingsManager.CanCommandWithoutGuest() }]); }; Get["/settings/reset"] = p_Parameters => { if (!Context.CurrentUser.Claims.Contains("super")) { return(new RedirectResponse("/")); } using (var s_Db = Database.GetConnection()) { // Delete all settings. s_Db.DeleteByIds <CoreSetting>(new List <String> { "gsun", "gspw", "gssess", "bcmobile", "bcname", "bcdesc", "bctag", "cmdprefix", "cmdguest", "votethreshold", "history" }); // Stop the broadcast. Application.Library.Broadcast.DestroyBroadcast(); // Re-initialize SharpShark. Application.Library.Chat.Disconnect(); Application.Library = new SharpShark(Application.SecretKey); Application.BootstrapLibrary(); return(new RedirectResponse("/setup")); } }; }
public static void ViewerThreadStart(List <string> inputFiles, bool standalone) { Trace.WriteLine("ViewerThreadStart starting"); Application.EnableVisualStyles(); Application.DoEvents(); Process p = Process.GetCurrentProcess(); SetProcessWorkingSetSize(p.Handle, -1, -1); #if WEBSERVER // Create the web service Web.WebService web_server = new Web.WebService(null, "9090"); #endif #if DEBUG && LOGGING LoggingService logger = new LoggingService(); #endif Trace.WriteLine("Make PresenterModel"); PresenterModel model = new PresenterModel(); Trace.WriteLine("Make DeckMarshalService"); using (DeckMarshalService loader = new DefaultDeckMarshalService()) { Trace.WriteLine("Construct ViewerForm"); ViewerForm viewer = new ViewerForm(loader, model); ConnectionManager rtp = null; #if RTP_BUILD Trace.WriteLine("Make RTPConnectionManager"); rtp = new RTPConnectionManager(model); #endif ConnectionManager tcp = new TCPConnectionManager(model); #if RTP_BUILD Trace.WriteLine("Make BroadcastManager"); BroadcastManager bm = new BroadcastManager(model, (TCPConnectionManager)tcp, (RTPConnectionManager)rtp); #else BroadcastManager bm = new BroadcastManager(model, (TCPConnectionManager)tcp); #endif using (rtp) { using (tcp) { using (bm) { Trace.WriteLine("Make ViewerStateService"); using (ViewerStateService viewerState = new ViewerStateService(model.ViewerState)) { using (RegistryService registry = new RegistryService(model.ViewerState)) { using (RegistryService penreg = new RegistryService(model.PenState)) { #if DEBUG && LOGGING // Attach the logger to the model logger.AttachToModel(model.ViewerState); #endif #if STUDENT_CLIENT_ONLY using (Synchronizer.Lock(model.ViewerState.SyncRoot)){ model.ViewerState.iRole = 1; } #endif // Start the printing service PrintingService printing = new PrintingService(model.ViewerState); using (WorkspaceUndoService undo = new WorkspaceUndoService(viewer.m_EventQueue, model)) { using (Synchronizer.Lock(model.Network.SyncRoot)) { model.Network.Protocols.Add(tcp.Protocol); #if RTP_BUILD model.Network.Protocols.Add(rtp.Protocol); #endif } using (NetworkAssociationService association = new NetworkAssociationService(viewer.m_EventQueue, model)) { using (DeckMatcherService deckMatcher = new DeckMatcherService(viewer.m_EventQueue, model)) { // Set the Initial Deck to Load if we are Loading from an Icon viewer.OpenInputFiles = inputFiles; viewer.StandAlone = standalone; Trace.WriteLine("Ready to run viewer"); Application.Run(viewer); } } } penreg.SaveAllProperties(); } registry.SaveAllProperties(); } } } } } } #if WEBSERVER // Dispose of the web server web_server.Dispose(); #endif }
public SongsModule() { this.RequiresAuthentication(); Get["/songs"] = p_Parameters => { return(View["Songs", new { SuperUser = Context.CurrentUser.Claims.Contains("super") }]); }; Get["/songs/all.json"] = p_Parameters => { using (var s_Db = Database.GetConnection()) { var s_Serialized = JsonConvert.SerializeObject(s_Db.Select <SongEntry>()); var s_Encoded = Encoding.UTF8.GetBytes(s_Serialized); return(new Response() { ContentType = "application/json", Contents = p_Writer => p_Writer.Write(s_Encoded, 0, s_Encoded.Length) }); } }; Get["/songs/add"] = p_Parameters => { return(View["AddSong", new { SuperUser = Context.CurrentUser.Claims.Contains("super"), Error = "" }]); }; Get["/songs/autocomplete/{query}.json"] = p_Parameters => { String s_Query = p_Parameters.query; var s_Results = Application.Library.Search.GetAutocomplete(s_Query, "song"); if (s_Results.ContainsKey("song")) { return(s_Results["song"]); } return(new List <ResultData>()); }; Post["/songs/add"] = p_Parameters => { var s_Request = this.Bind <AddSongRequest>(); if (s_Request.SongID <= 0 || s_Request.AlbumID <= 0 || s_Request.ArtistID <= 0 || String.IsNullOrWhiteSpace(s_Request.Song) || String.IsNullOrWhiteSpace(s_Request.Album) || String.IsNullOrWhiteSpace(s_Request.Artist)) { return(View["AddSong", new { SuperUser = Context.CurrentUser.Claims.Contains("super"), Error = "Please fill in all the required fields." }]); } var s_PreviousSongCount = QueueManager.CollectionSongs.Count; using (var s_Db = Database.GetConnection()) { var s_Song = s_Db.SingleById <SongEntry>(s_Request.SongID); if (s_Song != null) { return(View["AddSong", new { SuperUser = Context.CurrentUser.Claims.Contains("super"), Error = "The specified song already exists in your collection." }]); } s_Song = new SongEntry() { AlbumName = s_Request.Album, AlbumID = s_Request.AlbumID, ArtistID = s_Request.ArtistID, ArtistName = s_Request.Artist, SongID = s_Request.SongID, SongName = s_Request.Song }; s_Db.Insert(s_Song); QueueManager.CollectionSongs.Add(s_Song.SongID); } if (s_PreviousSongCount < 2 && QueueManager.CollectionSongs.Count >= 2) { BroadcastManager.CreateBroadcast(); } return(new RedirectResponse("/songs")); }; Get["/songs/delete/{song:long}"] = p_Parameters => { Int64 s_SongID = p_Parameters.song; // Don't allow the user to delete the last two songs. if (QueueManager.CollectionSongs.Count <= 2) { return(new RedirectResponse("/songs")); } using (var s_Db = Database.GetConnection()) { var s_Song = s_Db.SingleById <SongEntry>(s_SongID); if (s_Song == null) { return(new RedirectResponse("/songs")); } QueueManager.CollectionSongs.Remove(s_SongID); s_Db.Delete <PlaylistEntry>(p_Entry => p_Entry.SongID == s_Song.SongID); s_Db.Delete(s_Song); } return(new RedirectResponse("/songs")); }; Get["/songs/import"] = p_Parameters => { return(View["ImportSongs", new { SuperUser = Context.CurrentUser.Claims.Contains("super"), User = Application.Library.User.Data.UserID }]); }; Get["/songs/import/autocomplete/{query}.json"] = p_Parameters => { String s_Query = p_Parameters.query; var s_Results = Application.Library.Search.GetAutocomplete(s_Query, "user"); if (s_Results.ContainsKey("user")) { return(s_Results["user"]); } return(new List <ResultData>()); }; Post["/songs/import"] = p_Parameters => { var s_Request = this.Bind <ImportSongsFromUserRequest>(); var s_PreviousSongCount = QueueManager.CollectionSongs.Count; var s_SongEntries = new List <SongEntry>(); // Fetch collection songs. if (!s_Request.Only) { var s_Songs = Application.Library.User.GetSongsInLibrary(s_Request.User); foreach (var s_Song in s_Songs) { try { var s_SongEntry = new SongEntry() { SongID = Int64.Parse(s_Song.SongID), SongName = s_Song.Name, ArtistID = Int64.Parse(s_Song.ArtistID), ArtistName = s_Song.ArtistName, AlbumID = Int64.Parse(s_Song.AlbumID), AlbumName = s_Song.AlbumName }; s_SongEntries.Add(s_SongEntry); } catch { continue; } } } // Fetch favorite songs. if (s_Request.Favorites || s_Request.Only) { var s_Favorites = Application.Library.User.GetFavorites("Songs", s_Request.User); foreach (var s_Song in s_Favorites) { try { var s_SongEntry = new SongEntry() { SongID = Int64.Parse(s_Song.SongID), SongName = s_Song.Name, ArtistID = Int64.Parse(s_Song.ArtistID), ArtistName = s_Song.ArtistName, AlbumID = Int64.Parse(s_Song.AlbumID), AlbumName = s_Song.AlbumName }; s_SongEntries.Add(s_SongEntry); } catch { continue; } } } // Remove duplicates. s_SongEntries = s_SongEntries.DistinctBy(p_Entry => p_Entry.SongID).ToList(); // Store using (var s_Db = Database.GetConnection()) s_Db.SaveAll(s_SongEntries); // Update loaded collection QueueManager.FetchCollectionSongs(); // Create the broadcast (if needed). if (s_PreviousSongCount < 2 && QueueManager.CollectionSongs.Count >= 2) { BroadcastManager.CreateBroadcast(); } return(new RedirectResponse("/songs")); }; Get["/songs/wipe"] = p_Parameters => { using (var s_Db = Database.GetConnection()) { // Get all songs. var s_Songs = s_Db.Select <SongEntry>(); if (s_Songs.Count <= 2) { return(new RedirectResponse("/songs")); } // Drop all playlists. PlaylistManager.DeleteAllPlaylists(); var s_IDs = s_Songs.Select(p_Song => p_Song.SongID).ToList(); // Keep the first two songs. s_IDs.RemoveRange(0, 2); // Delete all songs. s_Db.DeleteByIds <SongEntry>(s_IDs); } return(new RedirectResponse("/songs")); }; }