Beispiel #1
0
        protected virtual void OnUnhandledException(Exception ex, ExecutedNotifyEventArgs agrs)
        {
            ExceptionEventArgs t = new ExceptionEventArgs(ex, agrs.Folder, agrs.TaskID, agrs.Description)
            {
                ExecuteDuration  = agrs.ExecuteDuration,
                ExecutePath      = agrs.ExecutePath,
                ExecuteResult    = agrs.ExecuteResult,
                ExecuteStartTime = agrs.ExecuteStartTime,
                LastExecuteTime  = agrs.LastExecuteTime,
                NextExecuteTime  = agrs.NextExecuteTime,
                ServerName       = agrs.ServerName
            };

            Logger.Error(t);
            ExceptionEventHandler handler = m_UnhandledException;

            if (handler != null)
            {
                try
                {
                    handler(this, t);
                }
                catch (Exception ex1)
                {
                    Logger.Error(m_FolderPath, TaskID, ex1, "执行SpTaskExecutor.OnUnhandledException时出错");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the game engine.
        /// </summary>
        public void Init()
        {
            // Test if working directory is set correctly => VS.NET 2003 bug
            System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(Environment.CurrentDirectory);
            if (info.Name.ToLower().IndexOf("debug") != -1 || info.Name.ToLower().IndexOf("release") != -1)
            {
                throw new Exception("Please set the working directory (project settings) to the project root (within VS.NET) " +
                                    "or copy the binaries to the project root (to start from the command line)!");
            }

            ExceptionEventHandler handler = exceptionHandler;

            if (handler != null)
            {
                try {
                    // fire onInit event
                    if (OnInit != null)
                    {
                        OnInit();
                    }
                } catch (Exception ex) {
                    handler(ex);
                } catch {
                    handler(new Exception("Guru Mediation Error!"));
                }
            }
            else
            // fire onInit event
            if (OnInit != null)
            {
                OnInit();
            }
        }
Beispiel #3
0
        public void Execute(object sender, DateTime dtBegin, DateTime dtEnd, ExceptionEventHandler handler)
        {
            if (!Enabled)
            {
                return;
            }

            var listEvent = new List <Object>();

            Schedule.AddEventsInInterval(dtBegin, dtEnd, listEvent);

            if (Filter != null)
            {
                Filter.FilterResultsInInterval(dtBegin, dtEnd, listEvent);
            }

            foreach (DateTime EventTime in listEvent)
            {
                if (IsSyncronized)
                {
                    _ExecuteHandler(sender, EventTime, handler);
                }
                else
                {
                    _ExecuteHandler.BeginInvoke(sender, EventTime, handler, null, null);
                }
            }
        }
        /// <summary>
        /// Raises the Exception event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected internal void OnException(object sender, ExceptionEventArgs e)
        {
            // trace the exception if the server is in verbose mode
            Trace.WriteLineIf(_verbose, string.Format("Encountered the following exception.\n\t{0}", e.Exception.ToString()), MY_TRACE_CATEGORY);

            try
            {
                if (this.Exception == null)
                {
                    return;
                }

                Delegate[] delegates = this.Exception.GetInvocationList();
                if (delegates != null)
                {
                    foreach (Delegate d in delegates)
                    {
                        try
                        {
                            ExceptionEventHandler handler = (ExceptionEventHandler)d;
                            handler(sender, e);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
Beispiel #5
0
        private async void submitCam_Click(object sender, EventArgs e)
        {
            if (!Uri.IsWellFormedUriString(hostUrlField.Text, UriKind.Absolute))
            {
                var eventArgs = new ExceptionEventArgs {
                    ExceptionMessage = Resources.Error_BadUri
                };
                ExceptionEventHandler?.Invoke(this, eventArgs);
                return;
            }
            ;
            var camObj = new CameraInfo()
            {
                HostUrl         = hostUrlField.Text,
                Latitude        = (double)latField.Value,
                Longitude       = (double)longField.Value,
                IsTrustedSource = isTrustedBox.Checked
            };

            try
            {
                await cameraClient.InsertCamera(camObj);
            }
            catch (Exception ex)
            {
                var eventArgs = new ExceptionEventArgs {
                    ExceptionMessage = ex.Message
                };
                ExceptionEventHandler?.Invoke(this, eventArgs);
            }
            await UpdateCameraDataSource();
        }
Beispiel #6
0
        public void SignIn(string Email, string Password, string Imap = "", int iport = 0)
        {
            UserManagement userManagement = new UserManagement(Email: Email, Password: Password);
            int            userId         = userManagement.GetUser().U_Id;

            try
            {
                Random r = new Random();
                MailKitClient = new SmtpClient(new ProtocolLogger("smtp" + r.Next(1, 100).ToString() + ".log"));
                ProgressEventHandler pg = Progress;
                pg?.Invoke("Validating server");
                pg?.Invoke("Authenticating server");
                MailKitClient.Connect(Imap, iport, SecureSocketOptions.StartTlsWhenAvailable);
                pg?.Invoke("Signing in");
                MailKitClient.Authenticate(Email, Password);
            }
            catch (Exception ex)
            {
                errorstring = "Failed to authenticate user " + Environment.NewLine + "Details : " + ex.ToString();
                ExceptionEventHandler error = ErrorOccured;
                error?.Invoke(ex.ToString());
            }
            if (errorstring == "")
            {
                AuthSuccessEventHandler Success = AuthSuccess;
                Success?.Invoke(userId);
            }
        }
Beispiel #7
0
        public void Execute(object sender, DateTime Begin, DateTime End, ExceptionEventHandler Error)
        {
            if (!this.Enabled)
            {
                return;
            }
            List <DateTime> list = new List <DateTime>();

            this.Schedule.AddEventsInInterval(Begin, End, list);
            if (this.Filter != null)
            {
                this.Filter.FilterResultsInInterval(Begin, End, list);
            }
            foreach (DateTime current in list)
            {
                if (this.SyncronizedEvent)
                {
                    this._ExecuteHandler(sender, current, Error);
                }
                else
                {
                    this._ExecuteHandler.BeginInvoke(sender, current, Error, null, null);
                }
            }
        }
Beispiel #8
0
        public void Execute(object sender, DateTime Begin, DateTime End, ExceptionEventHandler Error)
        {
            if (!Enabled)
            {
                return;
            }

            ArrayList EventList = new ArrayList();

            Schedule.AddEventsInInterval(Begin, End, EventList);

            if (Filter != null)
            {
                Filter.FilterResultsInInterval(Begin, End, EventList);
            }

            foreach (DateTime EventTime in EventList)
            {
                if (SyncronizedEvent)
                {
                    _ExecuteHandler(sender, EventTime, Error);
                }
                else
                {
                    _ExecuteHandler.BeginInvoke(sender, EventTime, Error, null, null);
                }
            }
        }
Beispiel #9
0
        //---------------------------------------------------------------
        #endregion
        //---------------------------------------------------------------

        //---------------------------------------------------------------
        #region Initialisation
        //---------------------------------------------------------------
        private Engine()
        {
            //System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            Tools.TypeRegistry.Init();
            fileSystem = new FileSystem("");
#if !DEBUG
            ExceptionHandler = new ExceptionEventHandler(ExceptionForm.ExceptionHandler);
#endif
        }
        /// <summary>
        /// Called when [learning module exception].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="MLifterSettingsManager.ExceptionEventArgs"/> instance containing the event data.</param>
        /// <remarks>Documented by Dev08, 2009-07-18</remarks>
        private void OnLearningModuleException(object sender, ExceptionEventArgs e)
        {
            ExceptionEventHandler handler = LearningModuleException;

            if (handler != null)
            {
                handler(sender, e);
            }
        }
        private void OnUnhandledException(Exception ex, string folder, string taskID, string desc)
        {
            ExceptionEventHandler handler = m_UnhandledException;

            if (handler != null)
            {
                handler(this, new ExceptionEventArgs(ex, folder, taskID, desc));
            }
        }
        private void OnUnhandledException(object sender, ExceptionEventArgs args)
        {
            ExceptionEventHandler handler = m_UnhandledException;

            if (handler != null)
            {
                handler(sender, args);
            }
        }
Beispiel #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ex"></param>
        private void OnException(Exception ex)
        {
            ExceptionEventArgs e = new ExceptionEventArgs(ex);

            if (this.ExceptionEvent != null)
            {
                ExceptionEventHandler t = this.ExceptionEvent;
                t(this, e);
            }
        }
Beispiel #14
0
        public int Exception(ref EXCEPTION_RECORD64 Exception, uint FirstChance)
        {
            ExceptionEventHandler evt = (FirstChance == 1) ? FirstChanceExceptionEvent : SecondChanceExceptionEvent;

            if (evt != null)
            {
                evt(this, Exception);
            }

            return((int)DEBUG_STATUS.BREAK);
        }
		private void ExecuteInternal(object sender, DateTime EventTime, ExceptionEventHandler Error)
		{
			try 
			{
				TimerParameterSetter Setter = new TimerParameterSetter(EventTime, sender);
				Method.Execute(Setter);
			}
			catch (Exception ex)
			{
				if (Error != null)
					try { Error(this, new ExceptionEventArgs(EventTime, ex)); } catch {}
			}
		}
 /// <summary>
 /// 注册全局异常处理。
 /// onUnhandledException 异常处理事件,如果未null则使用DefaultExcetionHandle
 /// </summary>
 public static void RegisterGlobalException(ExceptionEventHandler onUnhandledException = null, EnumErrorHandle handle = EnumErrorHandle.Default)
 {
     _onExceptionEventHandler = onUnhandledException ?? DefaultExcetionHandle;
     _ErrorHandle             = handle;
     //AppDomain中的异常
     AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
     //主UI线程
     Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
     //task scheduler
     TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
     //SEH
     RegisterSEHException();
 }
Beispiel #17
0
 private void ExecuteInternal(object sender, DateTime EventTime, ExceptionEventHandler Error)
 {
     try
     {
         TimerParameterSetter Setter = new TimerParameterSetter(EventTime, sender);
         Method.Execute(Setter);
     }
     catch (Exception ex)
     {
         if (Error != null)
         {
             try { Error(this, new ExceptionEventArgs(EventTime, ex)); } catch {}
         }
     }
 }
        public void RegisterNonFatalErrorBookmark(string bookmarkName)
        {
            if (this.ActionInvoker == null)
            {
                throw new InvalidOperationException();
            }

            ExceptionEventHandler handler = delegate(object sender, ExceptionEventArgs e)
            {
                this.ActionInvoker.ScheduleAction(bookmarkName, sender, e);
            };

            this.NonFatalErrorHandlers.Add(new Tuple <string, ExceptionEventHandler>(bookmarkName, handler));
            this.Server.NonFatalError += handler;
        }
        public void OnUnhandledException(string exMessage, string desc)
        {
            ExceptionEventHandler handler = m_UnhandledException;

            if (handler != null)
            {
                try
                {
                    handler(this, new ExceptionEventArgs(exMessage, m_FolderPath, TaskID, desc));
                }
                catch (Exception ex1)
                {
                    Logger.Error(m_FolderPath, TaskID, ex1, "执行AppDomainTaskExecutor.OnUnhandledException时出错");
                }
            }
        }
        public void OnUnhandledException(ExceptionEventArgs ea)
        {
            ExceptionEventHandler handler = m_UnhandledException;

            if (handler != null)
            {
                try
                {
                    handler(this, ea);
                }
                catch (Exception ex1)
                {
                    Logger.Error(m_FolderPath, TaskID, ex1, "执行AppDomainTaskExecutor.OnUnhandledException时出错");
                }
            }
        }
        static UnhandledExceptionHander()
        {
            DefaultExcetionHandle = new ExceptionEventHandler((ex, handle, exSource) =>
            {
                switch (handle)
                {
                case EnumErrorHandle.Exit:
                    Application.Current.Shutdown();;
                    break;

                case EnumErrorHandle.Restart:
                    Restart();
                    break;
                }
            });
        }
Beispiel #22
0
 void ExecuteInternal(object sender, DateTime dtEvent, ExceptionEventHandler handler)
 {
     try
     {
         var setter = new TimerParameterSetter(dtEvent, sender);
         Method.Execute(setter);
     }
     catch (Exception ex)
     {
         if (null != handler)
             try
             {
                 handler(this, new ExceptionEventArgs(dtEvent, ex));
             }
             catch { }
     }
 }
Beispiel #23
0
 void ExecuteInternal(object sender, DateTime dtEvent, ExceptionEventHandler handler)
 {
     try
     {
         var setter = new TimerParameterSetter(dtEvent, sender);
         Method.Execute(setter);
     }
     catch (Exception ex)
     {
         if (null != handler)
         {
             try
             {
                 handler(this, new ExceptionEventArgs(dtEvent, ex));
             }
             catch { }
         }
     }
 }
Beispiel #24
0
        public void Execute(object sender, DateTime dtBegin, DateTime dtEnd, ExceptionEventHandler handler)
        {
            if (!Enabled)
                return;

            var listEvent = new List<Object>();
            Schedule.AddEventsInInterval(dtBegin, dtEnd, listEvent);

            if (Filter != null)
                Filter.FilterResultsInInterval(dtBegin, dtEnd, listEvent);

            foreach (DateTime EventTime in listEvent)
            {
                if (IsSyncronized)
                    _ExecuteHandler(sender, EventTime, handler);
                else
                    _ExecuteHandler.BeginInvoke(sender, EventTime, handler, null, null);
            }
        }
Beispiel #25
0
        private async void submitButton_Click(object sender, EventArgs e)
        {
            var plateNumber = lettersBox.Text + digitsBox.Text;

            if (!plateNumber.ValidatePlateNumber())
            {
                var eventArgs = new ExceptionEventArgs {
                    ExceptionMessage = Resources.Error_BadLicensePlateNumber
                };
                ExceptionEventHandler?.Invoke(this, eventArgs);
                return;
            }

            await mlpClient.InsertPlateRecord(plateNumber, DateTime.Now);

            await MissingLicensePlateList.CreateIfNotExistsAndGetInstance(mlpClient, this).UpdateDatasource();

            await UpdateDlpDataSource();
        }
Beispiel #26
0
        public void Execute(object sender, DateTime Begin, DateTime End, ExceptionEventHandler Error)
        {
            if (Enabled == false)
                return;

            ArrayList EventList = new ArrayList();
            Schedule.AddEventsInInterval(Begin, End, EventList);

            if (Filter != null)
                Filter.FilterResultsInInterval(Begin, End, EventList);

            foreach(DateTime EventTime in EventList)
            {
                if (SyncronizedEvent)
                    _ExecuteHandler(sender, EventTime, Error);
                else
                    _ExecuteHandler.BeginInvoke(sender, EventTime, Error, null, null);
            }
        }
Beispiel #27
0
        protected virtual void OnUnhandledException(Exception ex, string desc)
        {
            var e = new ExceptionEventArgs(ex, m_FolderPath, TaskID, desc);

            Logger.Error(e);
            ExceptionEventHandler handler = m_UnhandledException;

            if (handler != null)
            {
                try
                {
                    handler(this, new ExceptionEventArgs(ex, m_FolderPath, TaskID, desc));
                }
                catch (Exception ex1)
                {
                    Logger.Error(m_FolderPath, TaskID, ex1, "执行SpTaskExecutor.OnUnhandledException时出错");
                }
            }
        }
Beispiel #28
0
        /// <summary>
        /// Can be used to manually update the game => without Engine.Run().
        /// </summary>
        public void Update()
        {
            ExceptionEventHandler handler = exceptionHandler;

            if (handler != null)
            {
                try {
                    InternalUpdate();
                } catch (Exception ex) {
                    handler(ex);
                } catch {
                    handler(new Exception("Guru Mediation Error!"));
                }
            }
            else
            {
                InternalUpdate();
            }
        }
        public static void Start <TException>(
            this ExceptionEventHandler <TException> Handler,
            object Sender,
            ExceptionEventHandlerArgs <TException> e) where TException : Exception
        {
            var handler = Handler;

            if (handler is null)
            {
                return;
            }
            var invocations = handler.GetInvocationList();

            for (var i = 0; i < invocations.Length; i++)
            {
                var invocation = invocations[i];
                if (invocation.Target is ISynchronizeInvoke {
                    InvokeRequired: true
                } invocation_target)
                {
                    invocation_target.Invoke(invocation, new[] { Sender, e });
                }
Beispiel #30
0
        private void FireClose()
        {
            ExceptionEventHandler handler = exceptionHandler;

            if (handler != null)
            {
                try {
                    if (OnClose != null)
                    {
                        OnClose();
                    }
                } catch (Exception ex) {
                    handler(ex);
                } catch {
                    handler(new Exception("Guru Mediation Error!"));
                }
            }
            else
            if (OnClose != null)
            {
                OnClose();
            }
        }
Beispiel #31
0
 /// <summary>
 /// Runs the specified action in the UI thread when the main <see cref="DoWork"/> action
 /// throws an exception.
 /// </summary>
 /// <param name="fail">Action to run in the UI thread</param>
 /// <returns>Reference to this <c>TaskBuilder</c></returns>
 public TaskBuilder Fail(ExceptionEventHandler fail)
 {
     _fail = fail;
     return this;
 }
Beispiel #32
0
 public Task<bool> CreateMetadataTask(CancellationToken cancellationToken, TaskStartedEventHandler start, ExceptionEventHandler fail, TaskSucceededEventHandler succeed, string mkvPath = null)
 {
     var token = cancellationToken;
     var optionalPhases = new[] { CreateGetMetadataPhase(token), CreateAutoDetectPhase(token), CreateRenamePhase(token, mkvPath) };
     return CreateStageTask(
         token,
         start,
         () => true,
         optionalPhases,
         fail,
         succeed
     );
 }
        public void Receive(StringEventHandler callback,
							 ExceptionEventHandler exCallback,
							 string split)
        {
            Debug.Assert(split != null);
            Debug.Assert(callback != null);
            Debug.Assert(exCallback != null);

            this.callback = callback;
            this.exCallback = exCallback;
            this.split = Regex.Escape(split);
            this.doSplit = true;

            Receive();
        }
Beispiel #34
0
 public void InvokeHandler(ExceptionEventArgs eventArgs)
 {
     ExceptionEventHandler?.Invoke(this, eventArgs);
 }
Beispiel #35
0
        /// <summary>
        /// Creates an asynchronous Task object that executes the given critical phase and optional phases in a background thread
        /// and invokes all other callbacks on the UI thread.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <param name="beforeStart">Invoked on UI thread</param>
        /// <param name="criticalPhase">First phase to run.  Must succeed (by returning <c>true</c> and not throwing an exception) for the optional phases to run.  Invoked on the background thread.</param>
        /// <param name="optionalPhases">Collection of phases that can fail (by throwing an exception) without preventing subsequent phases from running.  Invoked on the background thread.</param>
        /// <param name="fail">Called if the operation is canceled or the critical phase throws an exception.  Invoked on the UI thread.</param>
        /// <param name="succeed">Called if the operation completes successfully without being canceled.  Invoked on the UI thread.</param>
        /// <returns>
        /// Task object that returns <c>false</c> if the operation was canceled by the user or
        /// the critical phase threw an exception; otherwise <c>true</c>.
        /// </returns>
        private Task <bool> CreateStageTask(CancellationToken cancellationToken, TaskStartedEventHandler beforeStart, CriticalPhase criticalPhase, IEnumerable <OptionalPhase> optionalPhases, ExceptionEventHandler fail, TaskSucceededEventHandler succeed)
        {
            var canContinue = CreateCanContinueFunc(cancellationToken);

            return(new TaskBuilder()
                   .OnThread(_callbackScheduler)
                   .CancelWith(cancellationToken)
                   .BeforeStart(beforeStart)
                   .Fail(fail)
                   .DoWork(delegate(IThreadInvoker invoker, CancellationToken token)
            {
                cancellationToken.Register(() => Logger.Warn("User canceled current operation"));

                if (criticalPhase())
                {
                    foreach (var phase in optionalPhases.TakeWhile(phase => canContinue()))
                    {
                        phase();
                    }

                    if (canContinue())
                    {
                        invoker.InvokeOnUIThreadAsync(_ => succeed());
                        return;
                    }
                }

                // TODO: How should we handle exceptions here?
                // The rest of the code assumes exceptions are being handled by the plugin runner.
                invoker.InvokeOnUIThreadAsync(_ => fail(new ExceptionEventArgs()));
            })
                   .Build()
                   );
        }
Beispiel #36
0
        public Task <bool> CreateMetadataTask(CancellationToken cancellationToken, TaskStartedEventHandler start, ExceptionEventHandler fail, TaskSucceededEventHandler succeed, string mkvPath = null)
        {
            var token          = cancellationToken;
            var optionalPhases = new[] { CreateGetMetadataPhase(token), CreateAutoDetectPhase(token), CreateRenamePhase(token, mkvPath) };

            return(CreateStageTask(
                       token,
                       start,
                       () => true,
                       optionalPhases,
                       fail,
                       succeed
                       ));
        }
        // ===================================
        // PUBLIC Methods
        // ===================================
        public void Receive(StringEventHandler callback,
							 ExceptionEventHandler exCallback)
        {
            Debug.Assert(callback != null);
            Debug.Assert(exCallback != null);

            this.callback = callback;
            this.exCallback = exCallback;
            this.doSplit = false;

            Receive();
        }
Beispiel #38
0
        /// <summary>
        /// Creates an asynchronous Task object that executes the given critical phase and optional phases in a background thread
        /// and invokes all other callbacks on the UI thread.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <param name="beforeStart">Invoked on UI thread</param>
        /// <param name="criticalPhase">First phase to run.  Must succeed (by returning <c>true</c> and not throwing an exception) for the optional phases to run.  Invoked on the background thread.</param>
        /// <param name="optionalPhases">Collection of phases that can fail (by throwing an exception) without preventing subsequent phases from running.  Invoked on the background thread.</param>
        /// <param name="fail">Called if the operation is canceled or the critical phase throws an exception.  Invoked on the UI thread.</param>
        /// <param name="succeed">Called if the operation completes successfully without being canceled.  Invoked on the UI thread.</param>
        /// <returns>
        /// Task object that returns <c>false</c> if the operation was canceled by the user or
        /// the critical phase threw an exception; otherwise <c>true</c>.
        /// </returns>
        private Task<bool> CreateStageTask(CancellationToken cancellationToken, TaskStartedEventHandler beforeStart, CriticalPhase criticalPhase, IEnumerable<OptionalPhase> optionalPhases, ExceptionEventHandler fail, TaskSucceededEventHandler succeed)
        {
            var canContinue = CreateCanContinueFunc(cancellationToken);
            return new TaskBuilder()
                .OnThread(_callbackScheduler)
                .CancelWith(cancellationToken)
                .BeforeStart(beforeStart)
                .Fail(fail)
                .DoWork(delegate(IThreadInvoker invoker, CancellationToken token)
                    {
                        cancellationToken.Register(() => Logger.Warn("User canceled current operation"));

                        if (criticalPhase())
                        {
                            foreach (var phase in optionalPhases.TakeWhile(phase => canContinue()))
                            {
                                phase();
                            }

                            if (canContinue())
                            {
                                invoker.InvokeOnUIThreadAsync(_ => succeed());
                                return;
                            }
                        }

                        // TODO: How should we handle exceptions here?
                        // The rest of the code assumes exceptions are being handled by the plugin runner.
                        invoker.InvokeOnUIThreadAsync(_ => fail(new ExceptionEventArgs()));
                    })
                .Build()
            ;
        }
Beispiel #39
0
 private void CloudManager_Exception(ExceptionEventHandler obj)
 {
 }