/// <summary> /// Run the given code under an exception handler that will display any errors. /// </summary> /// <param name="operation">Code.</param> private void RunUnderExceptionHandler(VoidVoid operation) { try { operation(); this.SetError(operation.Method.Name, null); } catch (Exception ex) { this.SetError(operation.Method.Name, ex); } }
/// <summary> /// Switch states, log the transition, and execute an operation that /// must be atomic with the state change. /// </summary> private bool TryStateTransition(State newState, VoidVoid atomicOperation) { lock (this.stateLock) { string message = string.Format( CultureInfo.InvariantCulture, "SuspendResumeStream.TryStateTransition: from {0} to {1} on thread {2}", this.state, newState, Thread.CurrentThread.ManagedThreadId); Trace.WriteLine(message); switch (newState) { case State.Initial: throw new InvalidOperationException("Should never transition to state Initial."); case State.Active: if (this.state != State.Resuming && this.state != State.Initial) { Trace.WriteLine("SuspendResumeStream is neither Initial nor Resuming"); return(false); } break; case State.Resuming: if (this.state != State.Suspended) { Trace.WriteLine("SuspendResumeStream is not suspended."); return(false); } break; case State.Suspended: if (this.state != State.Active) { Trace.WriteLine("SuspendResumeStream is not active."); return(false); } break; } Trace.WriteLine("SsmLogger.TryStateTransition: legal transition."); this.state = newState; if (atomicOperation != null) { atomicOperation(); } } return(true); }
/// <summary> /// Log state changes /// </summary> private void SetState(LoggerState newState, string message, VoidVoid atomicOperation) { lock (this.stateLock) { Trace.WriteLine("SsmBasicLogger.SetState: invoked by " + message); Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "SsmBasicLogger.SetState: from {0} to {1}", this.state, newState)); this.state = newState; if (atomicOperation != null) { atomicOperation(); } } }
private bool TryRunUnderExceptionHandler(VoidVoid code) { Exception exception = null; try { code(); return(true); } catch (Exception ex) { exception = ex; } this.ReportException(exception); return(false); }
virtual public void normalOverload(VoidVoid a) { }
public static partial void InvokeAfterGC(VoidVoid cb);
private void Delegated_ShowOutput() { if (this.InvokeRequired) { VoidVoid d = new VoidVoid(Delegated_ShowOutput); this.Invoke(d); } else ShowOutput(); }
private void Delegated_ClearErrorList() { if (this.InvokeRequired) { VoidVoid d = new VoidVoid(Delegated_ClearErrorList); this.Invoke(d); } else ClearErrorList(); }
/// <summary> /// Switch states, log the transition, and execute an operation that /// must be atomic with the state change. /// </summary> private bool TryStateTransition(State newState, VoidVoid atomicOperation) { lock (this.stateLock) { string message = string.Format( CultureInfo.InvariantCulture, "SuspendResumePort.TryStateTransition: from {0} to {1} on thread {2}", this.state, newState, Thread.CurrentThread.ManagedThreadId); Trace.WriteLine(message); switch (newState) { case State.Initial: throw new InvalidOperationException("Should never transition to state Initial."); case State.Active: if (this.state != State.Resuming && this.state != State.Restarting && this.state != State.Initial) { Trace.WriteLine("SuspendResumePort.TryStateTransition: neither Initial, Resuming, nor Restarting."); return(false); } break; case State.Restarting: if (this.state != State.Active) { Trace.WriteLine("SuspendResumePort.TryStateTransition: not active, aborting the restart attempt."); return(false); } break; case State.Resuming: if (this.state != State.Suspended) { Trace.WriteLine("SuspendResumePort.TryStateTransition: not suspended."); return(false); } break; case State.Suspended: if (this.state != State.Active && this.state != State.Restarting && this.state != State.Resuming) { Trace.WriteLine("SuspendResumePort.TryStateTransition: not active, restarting, or resuming."); return(false); } // Disable the resume timer, if there is one. if (this.resumeTimer != null) { Trace.WriteLine("SuspendResumePort.TryStateTransition: disabling resume timer."); this.resumeTimer.Change(Timeout.Infinite, Timeout.Infinite); } break; case State.Closed: break; } Trace.WriteLine("SsmLogger.TryStateTransition: legal transition."); this.state = newState; if (atomicOperation != null) { atomicOperation(); } } return(true); }
public DiscordBotWorker(Form1 ControlPannel, string[] _GamesToPlay, SoundBoardList _SoundBoardBinding) { _ControlPannel = ControlPannel; #if DEBUG ConsoleWrite("is Debug build\n"); #else ConsoleWrite("is Chidori build\n"); #endif ConsoleWrite("Building Client......"); _DiscordClient = new DiscordClient() .UsingAudio(x => { x.Mode = AudioMode.Both; x.EnableEncryption = true; x.Bitrate = AudioServiceConfig.MaxBitrate; x.BufferLength = 10000; }); //configsfor things #if DEBUG //the sound cloud client config SCClient = new SoundCloudClient("9789f855276cf2c76bf4c6b62a09155e"); track.ToStringOverRide = x => { return(x != null ? "```Title: " + x.title + "\nID : " + x.id + "\nstreamable : " + x.streamable + "\nstream_url:" + x.stream_url + "```" : null); }; #endif //the anime client config _MyAnimeListClient = new MyAnimeListClient("The_True_Trooper", "Jim456852,.,"); Manga.ToStringOverRide = x => { return(x != null ? "```Title: " + x.title + "\nEnglish: " + x.english + "\nSynonyms: " + x.synonyms + "\nChapters: " + x.chapters + "\nVolumes: " + x.volumes + "\nScore: " + x.score + "\nType: " + x.type + "\nStatus: " + x.status + "\nStart Date: " + x.start_date + "\nEnd Date: " + x.end_date + "\nSynopsis: " + x.synopsis.Replace("<br />", "").Replace("[i]", "").Replace("[/i]", "").HtmlDecode() + "```" + "\nhttp://myanimelist.net/manga/" + x.id : null); }; Anime.ToStringOverRide = x => { return(x != null ? "```Title: " + x.title + "\nEnglish: " + x.english + "\nSynonyms: " + x.synonyms + "\nEpisodes: " + x.episodes + "\nScore: " + x.score + "\nType: " + x.type + "\nStatus: " + x.status + "\nStart Date: " + x.start_date + "\nEnd Date: " + x.end_date + "\nSynopsis: " + x.synopsis.Replace("<br />", "").Replace("[i]", "").Replace("[/i]", "").HtmlDecode() + "```" + "\nhttp://myanimelist.net/anime/" + x.id : null); }; //bot callbacks and event bindings MasterAndCommander = new ControlPannelCommand(_MasterAndCommander); SoundBoardListUpDate = new VoidVoid(_SoundBoardListUpDate); _DiscordClient.Ready += Ready; _DiscordClient.MessageReceived += MessRec; //_DiscordClient.MessageUpdated += MessRec; _DiscordClient.UserJoined += JoinHello; _DiscordClient.JoinedServer += JoinServer; _DiscordClient.UserUpdated += UserUpHello; _DiscordClient.RoleCreated += RoleCreate; _DiscordClient.RoleDeleted += RoleDelete; _DiscordClient.RoleUpdated += RoleUpdate; _DiscordClient.UserBanned += UserBanned; _DiscordClient.UserUnbanned += UserUnbanned; _DiscordClient.ChannelCreated += ChannelCreated; _DiscordClient.ChannelDestroyed += ChannelDeleted; _DiscordClient.ChannelUpdated += ChannelUpdated; ConsoleWrite("Building support classes......"); //ticks info Ticker.Elapsed += Tick; MaxTickOnNewGames = Rand.Next(30); //list populating ConsoleWrite("Populating lists......"); GamesToPlay = null; lock (GamesToPlay) GamesToPlay = GamesToPlay.Concat(_GamesToPlay).ToArray(); SoundBoardBinding = null; lock (SoundBoardBinding) SoundBoardBinding = _SoundBoardBinding; Connect(); }
/// <summary> /// Switch states, log the transition, and execute an operation that /// must be atomic with the state change. /// </summary> private bool TryStateTransition(State newState, VoidVoid atomicOperation) { lock (this.stateLock) { string message = string.Format( CultureInfo.InvariantCulture, "SsmLogger.StateTransition: from {0} to {1} on thread {2}", this.state, newState, Thread.CurrentThread.ManagedThreadId); Trace.WriteLine(message); switch (newState) { case State.Initial: throw new InvalidOperationException("Should never transition to state Initial."); case State.Resyncing: case State.Opening: case State.Ready: if (this.state == State.Closing || this.state == State.Closed || this.state == State.Disposed) { Trace.WriteLine("SsmLogger.TryStateTransition: illegal transition."); return(false); } break; case State.WaitingForWindows: if (this.state != State.Closed) { Trace.WriteLine("SsmLogger.TryStateTransition: illegal transition."); return(false); } break; case State.Closing: break; case State.Closed: if (this.state != State.Closing) { Trace.WriteLine(string.Format( CultureInfo.InvariantCulture, "SsmLogger.TryStateTransition: suspicious transition: from {0} to Closed", this.state)); } break; case State.Disposed: break; } Trace.WriteLine("SsmLogger.TryStateTransition: legal transition."); this.state = newState; if (atomicOperation != null) { atomicOperation(); } } return(true); }