/// <summary>
        /// Kill command with maximum prejudice
        /// </summary>
        /// <param name="error">The error to terminate with</param>
        private void Terminate(CallbackException error)
        {
            ScriptBlock errorBlock = ScriptBlock.Create(_ErrorScript);

            object[] arguments = new object[] { $"Failed to execute callback {error.Callback.Name}", error, _Caller.CallerFunction, _Caller.CallerModule, _Caller.CallerFile, _Caller.CallerLine, PSCmdlet, EnableException };
            PSCmdlet.InvokeCommand.InvokeScript(false, errorBlock, null, arguments);
        }
Example #2
0
        void WrapCallback(Action action)
        {
            try
            {
                try
                {
                    action();
                }
                catch (Exception ex)
                {
                    if (CallbackException != null)
                    {
                        CallbackException.Invoke(this, ex);
                    }
                }
            }
#if DEBUG && BREAK_ON_EXCEPTED_CALLBACK
            catch (Exception unhandled)
            {
                System.Diagnostics.Debug.Print("UNHANDLED EXCEPTION IN CALLBACK: {0}: {1} @ {2}", unhandled.GetType(), unhandled.Message, unhandled.StackTrace);
                System.Diagnostics.Debugger.Break();
            }
#else
            catch { }
#endif
        }
Example #3
0
 public override void callbackEx(Ice.Current current)
 {
     callback(current);
     CallbackException ex = new CallbackException();
     ex.someValue = 3.14;
     ex.someString = "3.14";
     throw ex;
 }
Example #4
0
    callbackEx(Ice.Current current)
    {
        callback(current);
        CallbackException ex = new CallbackException();

        ex.someValue  = 3.14;
        ex.someString = "3.14";
        throw ex;
    }
Example #5
0
        /// <summary>
        /// Returns a JSON error response to the client
        /// </summary>
        /// <param name="ex">Exception that generates the error message and info to return</param>
        /// <param name="statusCode">Optional status code</param>
        /// <returns></returns>
        public JsonResult ReturnAjaxError(Exception ex, int statusCode = 500)
        {
            Response.Clear();
            Response.StatusCode = statusCode;

            var cb = new CallbackException() {message = ex.Message};
            cb.stackTrace = ex.StackTrace;
                        
            return Json(cb, JsonRequestBehavior.AllowGet);
        }
Example #6
0
        protected ActionResult ExceptionResult(string message)
        {
            Response.StatusCode = 500;

            CallbackException exception = new CallbackException(message);

            exception.IsError = true;

            // return result based on ?Format=
            return(ApiResult(exception));
        }
Example #7
0
        protected ActionResult ExceptionResult(Exception ex)
        {
            Response.StatusCode = 500;

            CallbackException exception = new CallbackException(ex.GetBaseException().Message);

            //if (HttpContext.IsDebuggingEnabled)
            //    exception.StackTrace = ex.StackTrace;

            exception.IsError = true;

            // return result based on ?Format=
            return(ApiResult(exception));
        }
Example #8
0
 private void WrapCallback(Action action)
 {
     try
     {
         try
         {
             action();
         }
         catch (Exception ex)
         {
             CallbackException?.Invoke(this, ex);
         }
     }
     catch (Exception)
     {
     }
 }
 private void WrapCallback(Action action)
 {
     try
     {
         try
         {
             action();
         }
         catch (Exception ex)
         {
             CallbackException?.Invoke(this, ex);
         }
     }
     catch (Exception ex)
     {
         Tools.Log(ex.StackTrace);
     }
 }
Example #10
0
        /// <summary>
        /// Ensure that exceptions are returned in the API format
        /// Excpetion is rendered as a Callback Exception
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);

            // only handle API results here: Format must be set
            // otherwise fall through and return
            if (string.IsNullOrEmpty(Format))
            {
                return;
            }

            Response.StatusCode = 500;

            CallbackException exception = new CallbackException(filterContext.Exception.Message);

            //if (HttpContext.IsDebuggingEnabled)
            //    exception.StackTrace = filterContext.Exception.StackTrace;

            exception.IsError = true;

            filterContext.Result           = ApiResult(exception);
            filterContext.ExceptionHandled = true;
        }
Example #11
0
        private void WrapCallback(Action action)
        {
            try
            {
                try
                {
                    action();
                }
                catch (Exception ex)
                {
                    CallbackException?.Invoke(this, ex);
                    throw ex;
                }
            }
#if DEBUG
            catch (Exception unhandled)
            {
                System.Diagnostics.Debug.Print("回调时发生了未知的异常: {0}: {1} @ {2}", unhandled.GetType(), unhandled.Message, unhandled.StackTrace);
                System.Diagnostics.Debugger.Break();
            }
#else
            catch { }
#endif
        }
Example #12
0
            private void ZInvokeWorker(cTrace.cContext pParentContext)
            {
                var lContext = pParentContext.NewMethod(nameof(cCallbackSynchroniser), nameof(ZInvokeWorker));

                while (mInvokes.TryDequeue(out var lInvoke))
                {
                    try
                    {
                        switch (lInvoke.EventArgs)
                        {
                        case cMessagePropertyChangedEventArgs lEventArgs:

                            MessagePropertyChanged?.Invoke(mSender, lEventArgs);
                            break;

                        case cMailboxPropertyChangedEventArgs lEventArgs:

                            MailboxPropertyChanged?.Invoke(mSender, lEventArgs);
                            break;

                        case PropertyChangedEventArgs lEventArgs:

                            PropertyChanged?.Invoke(mSender, lEventArgs);
                            break;

                        case cResponseTextEventArgs lEventArgs:

                            ResponseText?.Invoke(mSender, lEventArgs);
                            break;

                        case cNetworkReceiveEventArgs lEventArgs:

                            NetworkReceive?.Invoke(mSender, lEventArgs);
                            break;

                        case cNetworkSendEventArgs lEventArgs:

                            NetworkSend?.Invoke(mSender, lEventArgs);
                            break;

                        case cMailboxMessageDeliveryEventArgs lEventArgs:

                            MailboxMessageDelivery?.Invoke(mSender, lEventArgs);
                            break;

                        case cActionIntEventArgs lEventArgs:

                            lEventArgs.Action(lEventArgs.Int);
                            break;

                        default:

                            lContext.TraceError("unknown event type", lInvoke.EventArgs);
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        lContext.TraceException("error when invoking event handler", e);
                        try { CallbackException?.Invoke(mSender, new cCallbackExceptionEventArgs(e)); }
                        catch { }
                    }

                    if (lInvoke.Releaser != null)
                    {
                        lInvoke.Releaser.Release(lContext);
                    }
                }
            }
Example #13
0
 private void Model_CallbackException(object sender, CallbackExceptionEventArgs e)
 {
     CallbackException?.Invoke(sender, e);
 }
Example #14
0
        public override void Update()
        {
            base.Update();
            const String CrawlerPath = @"D:\ip1\travox.com\www\crawler\documents\";
            const String ViewerPath = @"C:\ip1\travox.com\www\mos\mos_demo\report_viewer\";

            SecretaryEvent Period = SecretaryEvent.Unknow;

            SQLCollection param = new SQLCollection("@id", DbType.Int32, base.State.CompanyID);
            List<HandlerItem> EventEmail = new List<HandlerItem>();

            foreach (DataRow Row in new DB("travox_system").GetTable(base.GetResource("secretary_report.sql"), param).Rows)
            {
                ParameterDate SystemDate;

                switch(Row["period"].ToString())
                {
                    case "Daily": Period = SecretaryEvent.Daily; break;
                    case "Weekly": Period = SecretaryEvent.Weekly; break;
                    case "Monthly": Period = SecretaryEvent.Monthly; break;
                }

                SystemDate.From = DateTime.Now.Date;
                SystemDate.To = DateTime.Now.Date;
                DateTime DateEndMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1);
                String PeriodDate = "";
                String OutputEmailType = Row["output_email"].ToString().Trim();
                String OutputPrinter = Row["output_printer"].ToString().Trim();

                if (Period == SecretaryEvent.Monthly && DateTime.Now.Date == DateEndMonth)
                {
                    PeriodDate = SystemDate.From.ToString("yyyy");
                    SystemDate.From  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                    SystemDate.To  = DateEndMonth;
                }
                else if (Period == SecretaryEvent.Weekly && DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                {
                    PeriodDate = SystemDate.From.ToString("MM-yyyy");
                    SystemDate.From = SystemDate.From.AddDays(-7);
                }
                else if (Period == SecretaryEvent.Daily)
                {
                    PeriodDate = SystemDate.From.ToString("dd-MM-yyyy");
                }
                else
                {
                    Period = SecretaryEvent.Unknow;
                }

                if ((!MBOS.Null(OutputEmailType) || MBOS.Bool(OutputPrinter)) && Period != SecretaryEvent.Unknow)
                {
                    RequestBuilder ReportViewer = new RequestBuilder((!App.DebugMode) ? "mos.travox.com/mos_v2/report_viewer/default.aspx" : "localhost:8026/Default.aspx");
                    ReportViewer.By = RequestBuilder.Method.POST;
                    ReportViewer.SetCookie("ASP.NET_SessionId", "xxxxxxxxxxxxxxxxxxxxxxxx");
                    ReportViewer.SetCookie("COMPANY_ACCESS", base.State.CompanyCode);
                    ReportViewer.SetCookie("ID", "-4");
                    ReportViewer.SetCookie("Code", "TX");
                    ReportViewer.SetCookie("Name", "Travox Sentinel");

                    //ReportViewer.POST("ItemType", JSON.Serialize<ItemType>(new ItemType { ExportType = OutputEmailType }));
                    //ReportViewer.POST("Report", JSON.Serialize<ItemReport>(new ItemReport { Name = Row["report_key"].ToString(), Filename = Row["report_key"].ToString() + ".rpt" }));
                    ReportViewer.AddBody("period_begin", SystemDate.From.ToString("dd-MM-yyyy"));
                    ReportViewer.AddBody("period_end", SystemDate.To.ToString("dd-MM-yyyy"));

                    param.Add("@s_id", DbType.Int32, Row["secretary_id"].ToString());
                    param.Add("@name", DbType.String, Row["report_name"].ToString());
                    param.Add("@email", DbType.String, Row["email"].ToString());
                    param.Add("@code", DbType.String, base.State.CompanyCode);
                    param.Add("@file", DbType.String, null);

                    String[] ArgsString = { Row["period"].ToString(), PeriodDate, Row["report_name"].ToString() };
                    HandlerItem Item = new HandlerItem();
                    Item.Subject = String.Format("Secretary({0} {1}) Report of \"{2}\"", ArgsString);
                    Item.OnEmail = !MBOS.Null(OutputEmailType);
                    Item.OnPrinter = MBOS.Bool(OutputPrinter);
                    Item.Mail = Row["email"].ToString();
                    Item.Ajax = ReportViewer;
                    EventEmail.Add(Item);
                }
            }

            foreach (HandlerItem Item in EventEmail)
            {
                //CallbackException data = JSON.Deserialize<CallbackException>(XHR.Connect(Item.Ajax));
                CallbackException data = new CallbackException();
                String getItems = Regex.Match(data.getItems, @"[\\|/]Temp[\\|/](?<path>.*)").Groups["path"].Value;
                String AttachFile = null;
                if (!data.onError)
                {
                    String FolderName = Path.GetDirectoryName(CrawlerPath + getItems) + "\\";
                    String FileName = Path.GetFileName(getItems);
                    if (!App.DebugMode)
                    {
                        if (Directory.Exists(FolderName)) Directory.CreateDirectory(FolderName);
                        File.Copy(ViewerPath + data.getItems, FolderName + FileName);
                        File.Delete(ViewerPath + data.getItems);
                        AttachFile = FolderName + FileName;
                    }
                    else
                    {
                        AttachFile = @"D:\Travox Mid-Back\TravoxViewer\TravoxViewer\Temp\" + getItems;
                    }
                }

                if (Item.OnEmail)
                {
                    DB db = new DB("travox_system");
                    NameValueCollection MailParam = new NameValueCollection();
                    TypeMAIL ReportSecretary = new TypeMAIL("*****@*****.**", Item.Subject, false);
                    ReportSecretary.Add(Item.Mail);
                    ReportSecretary.Body(base.GetResource("MailTemplate.html"));

                    String SQL = db.Execute("INSERT INTO crawler.secretary_email (secretary_id, company_code, report_name, email) VALUES (@s_id, @code, @name, @email)", param);

                    MailParam.Add("message_email", data.exMessage);
                    MailParam.Add("print_date", DateTime.Now.Date.ToString("dd-MM-yyyy"));
                    if (!data.onError && data.exTitle != "ManualException")
                    {
                        ReportSecretary.Attach(AttachFile);
                        param["@file"].DefaultValue = getItems;
                    }
                    else
                    {
                        param["@file"].DefaultValue = data.exMessage;
                    }
                    param.Add("@e_id", DbType.Int32, SQL);
                    db.Execute("UPDATE crawler.secretary_email SET filename=@file WHERE email_id=@e_id", param);

                    ReportSecretary.DataSource(MailParam);
                    if (!ReportSecretary.Sending())
                    {
                        param["@file"].DefaultValue = ReportSecretary.ErrorMessage;
                        db.Execute("UPDATE crawler.secretary_email SET filename=@file WHERE email_id=@e_id", param);
                    }
                    db.Apply();
                }

                if (Item.OnPrinter)
                {

                }
            }
            param = null;
            EventEmail = null;
            Console.WriteLine("{0} Updated", base.State.DatabaseName);

        }