예제 #1
0
        ///<summary>Non-blocking call. FormProgressExtended is an extremely tailored version of FormProgressStatus.
        ///It is a progress window that can have multiple progress bars showing at the same time with pause and cancel functionality.
        ///This "extended" progress window is exactly like the "Show()" progress window in that the close action that is returned must be invoked
        ///by the calling method in order to programmatically close.</summary>
        ///<param name="odEventType">Causes the progress window to only process ODEvents of this ODEventType.  Undefined will process all types.</param>
        ///<param name="eventType">Causes the progress window to only process ODEvents of this Type.  Null defaults to typeof(ODEvent).</param>
        ///<param name="currentForm">The form to activate once the progress is done. If you cannot possibly pass in a form, it is okay to pass in null.</param>
        ///<param name="tag">Optionally set tag to an object that should be sent as the first "event arg" to the new progress window.
        ///This will typically be a ProgressBarHelper or a string.</param>
        ///<param name="progCanceled">Optionally pass in a delegate that will get invoked when the user clicks Cancel.</param>
        ///<param name="progPaused">Optionally pass in a delegate that will get invoked when the user clicks Pause.</param>
        ///<returns>An action that will close the progress window.  Invoke this action whenever long computations are finished.</returns>
        public static Action ShowExtended(ODEventType odEventType, Type eventType, Form currentForm, object tag = null,
                                          ProgressCanceledHandler progCanceled = null, ProgressPausedHandler progPaused = null, string cancelButtonText = null)
        {
            Action actionCloseProgressWindow = ShowProgressBase(
                () => {
                FormProgressExtended FormPE = new FormProgressExtended(odEventType, eventType, cancelButtonText: cancelButtonText);
                if (progCanceled != null)
                {
                    FormPE.ProgressCanceled += progCanceled;
                }
                if (progPaused != null)
                {
                    FormPE.ProgressPaused += progPaused;
                }
                //FormProgressExtended should NOT be the top most form.  Other windows might be popping up requiring attention from the user.
                //FormPE.TopMost=true;//Make this window show on top of ALL other windows.
                if (tag != null)
                {
                    FormPE.ODEvent_Fired(new ODEventArgs(odEventType, tag));
                }
                return(FormPE);
            }, "Thread_ODProgress_ShowExtended_" + DateTime.Now.Ticks);

            return(() => {
                actionCloseProgressWindow();                //Make sure the progress window is closed first.
                //If a form was passed in, activate it so that it blinks or gets focus.
                if (currentForm != null && !currentForm.IsDisposed)
                {
                    currentForm.Activate();
                }
            });
        }
 ///<summary>Do not instatiate this class.  It is not meant for public use.  Use ODProgress.ShowProgressExtended() instead.
 ///Launches a progress window that will constantly spin and display status updates for global ODEvents with corresponding name.
 ///eventType must be a Type that contains an event called Fired.</summary>
 public FormProgressExtended(ODEventType odEventType, Type eventType, bool hasHistory = false, string cancelButtonText = null) : base(odEventType, eventType)
 {
     InitializeComponent();
     if (!string.IsNullOrEmpty(cancelButtonText))
     {
         butCancel.Text = cancelButtonText;
     }
 }
예제 #3
0
 ///<summary>Non-blocking call. Shows a progress window that will listen for ODEvents in order to update the label and progress bar.
 ///The progress window that is shown to the user is owned by a separate thread so that the main thread can continue to execute.
 ///This type of progress window is good for showing progress when manipulating UI elements on the main thread (filling grids).
 ///It is up to the calling method to let notify this progress window when it should close by invoking the action returned.</summary>
 ///<param name="odEventType">Causes the progress window to only process ODEvents of this ODEventType.  Undefined will process all types.</param>
 ///<param name="eventType">Causes the progress window to only process ODEvents of this Type.  Null defaults to typeof(ODEvent).</param>
 ///<param name="startingMessage">Sets the label of the progress window to the value passed in.  Defaults to "Please Wait..."
 ///It is always up to the calling method to translate this message before passing it in.  This is to avoid translating multiple times.</param>
 ///<param name="hasHistory">Set to true if the progress window should show a history of events that it has processed.
 ///This will cause the UI of the progress window to change slightly and will also make it so the user has to click a Close button.</param>
 ///<param name="hasMinimize">Set to true if the progress window should allow minimizing.  False by default.</param>
 ///<param name="progStyle">Sets the style of the progress bar within the progress window that is going to be shown to the user.</param>
 ///<returns>An action that will close the progress window.  Invoke this action whenever long computations are finished.</returns>
 public static Action Show(ODEventType odEventType = ODEventType.Undefined, Type eventType = null, string startingMessage = "Please Wait...",
                           bool hasHistory         = false, bool hasMinimize = false, ProgressBarStyle progStyle = ProgressBarStyle.Marquee)
 {
     return(ShowProgressBase(
                () => {
         return new FormProgressStatus(odEventType, eventType, hasHistory, hasMinimize, startingMessage, progStyle)
         {
             TopMost = true,                          //Make this window show on top of ALL other windows.
         };
     }, "Thread_ODProgress_Show_" + DateTime.Now.Ticks));
 }
예제 #4
0
 ///<param name="currentForm">The form to activate once the progress is done. If you cannot possibly pass in a form, it is okay to pass in null.
 ///</param>
 public ODProgressExtended(ODEventType odEventType, IODEvent odEvent, Form currentForm, object tag = null, ProgBarStyle progBarStyle = ProgBarStyle.Blocks,
                           string lanThis = "ProgressExtended", string cancelButtonText = null)
 {
     _actionCloser = ODProgress.ShowExtended(odEventType, odEvent.GetType(), currentForm, tag,
                                             new ProgressCanceledHandler((object sender, EventArgs e) => {
         IsCanceled = true;
     }),
                                             new ProgressPausedHandler((object sender, ProgressPausedArgs e) => {
         IsPaused = e.IsPaused;
     }), cancelButtonText);
     _event        = odEvent;
     _progBarStyle = progBarStyle;
     _odEventType  = odEventType;
     LanThis       = lanThis;
 }
예제 #5
0
 ///<summary>Do not instatiate this class.  It is not meant for public use.  Use ODProgress.ShowProgressStatus() instead.
 ///Launches a progress window that will constantly spin and display status updates for global ODEvents with corresponding name.
 ///eventType must be a Type that contains an event called Fired.</summary>
 public FormProgressStatus(ODEventType odEventType = ODEventType.Undefined, Type eventType = null, bool hasHistory = false, bool hasMinimize = true,
                           string startingMessage  = "", ProgressBarStyle progStyle        = ProgressBarStyle.Marquee) : base(odEventType, eventType)
 {
     InitializeComponent();
     labelMsg.Text     = startingMessage;
     progressBar.Style = progStyle;
     if (!hasMinimize)
     {
         panelMinimize.Visible = false;
     }
     this.ControlBox = false;
     _hasHistory     = hasHistory;
     if (_hasHistory)
     {
         this.Height           += 120;
         this.Width            += 60;
         _dateTimeLastEvent     = DateTime.MinValue;
         labelMsg.Visible       = false;
         textHistoryMsg.Visible = true;
     }
     _dateTimeInit = DateTime.Now;
 }
예제 #6
0
        ///<summary>funcShouldWindowClose should return a boolean indicating if this window should close or not.
        ///Optionally set errorMessage to override the label text that is displayed to the user.
        ///Optionally set a custom eventType in order to listen for specific types of ODEvent.Fired events.  Defaults to DataConnectionEvent.</summary>
        public FormConnectionLost(Func <bool> funcShouldWindowClose, ODEventType odEventType = ODEventType.Undefined, string errorMessage = ""
                                  , Type eventType = null)
        {
            InitializeComponent();
            labelErrMsg.Text       = errorMessage;
            _funcShouldWindowClose = funcShouldWindowClose;
            _odEventType           = odEventType;
            if (eventType == null)
            {
                eventType = typeof(DataConnectionEvent);
            }
            //Make sure that the event type passed in has a "Fired" event to listen to.
            ODException.SwallowAnyException(() => _eventInfoFired = eventType.GetEvent("Fired"));
            if (_eventInfoFired == null)
            {
                throw new ApplicationException("The 'eventType' passed into FormConnectionLost does not have a 'Fired' event.\r\n"
                                               + "Type passed in: " + eventType.GetType());
            }
            Delegate   delegateFired    = GetDelegateFired(_eventInfoFired.EventHandlerType);
            MethodInfo methodAddHandler = _eventInfoFired.GetAddMethod();

            methodAddHandler.Invoke(this, new object[] { delegateFired });
        }
예제 #7
0
        public FormProgressBase(ODEventType odEventType, Type eventType)
        {
            this.FormClosing += new FormClosingEventHandler(this.FormProgressStatus_FormClosing);
            this.FormClosed  += new FormClosedEventHandler(this.FormProgressStatus_FormClosed);
            this.Shown       += new EventHandler(this.FormProgressStatus_Shown);
            if (eventType == null)
            {
                eventType = typeof(ODEvent);
            }
            _eventType   = eventType;
            _odEventType = odEventType;
            //Registers this form for any progress status updates that happen throughout the entire program.
            ODException.SwallowAnyException(() => _eventInfoFired = _eventType.GetEvent("Fired"));
            if (_eventInfoFired == null)
            {
                throw new ApplicationException("The 'eventType' passed into FormProgressStatus does not have a 'Fired' event.\r\n"
                                               + "Type passed in: " + eventType.GetType());
            }
            //Register the "Fired" event to the ODEvent_Fired delegate.
            Delegate   delegateFired    = Delegate.CreateDelegate(_eventInfoFired.EventHandlerType, this, "ODEvent_Fired");
            MethodInfo methodAddHandler = _eventInfoFired.GetAddMethod();

            methodAddHandler.Invoke(this, new object[] { delegateFired });
        }
예제 #8
0
 public static void Fire(ODEventType odEventType, object tag)
 {
     Fired?.Invoke(new ODEventArgs(odEventType, tag));
 }
예제 #9
0
 ///<summary>Creates an ODEventArg with the specified ODEventType and Tag passed in that is designed to be Fired to a progress window.</summary>
 ///<param name="eventType">Progress windows registered to this ODEventType will consume this event arg and act upon the tag accordingly.
 ///An event type of Undefined will be treated as a generic ODEvent.</param>
 ///<param name="tag">Tag can be set to anything that the consumer may need.  E.g. a string for FormProgressStatus to show to users.</param>
 public ODEventArgs(ODEventType eventType, object tag)
 {
     _tag       = tag;
     _eventType = eventType;
 }
예제 #10
0
 ///<summary>Used when an ODEvent is needed but no object is needed in the consuming class.</summary>
 public ODEventArgs(ODEventType eventType) : this(eventType, null)
 {
 }
예제 #11
0
        ///<summary>This is a blocking call. Runs the action on the main thread and displays a progress window on another thread.
        ///Once the long computation has completed, then the progress window will automatically be closed.
        ///Throws any exceptions that occurred within the action if no exception delegate was provided.</summary>
        ///<param name="actionComputation">Any long computation.  Returns and does nothing if null.</param>
        ///<param name="startingMessage">Sets the label of the progress window to the value passed in.  Defaults to "Please Wait..."
        ///It is always up to the calling method to translate this message before passing it in.  This is to avoid translating multiple times.</param>
        ///<param name="actionException">A custom UE handler for the worker thread.  Null will cause this method to rethrow any exceptions.</param>
        ///<param name="eventType">Causes the progress window to only process ODEvents of this Type.  Null defaults to typeof(ODEvent).</param>
        ///<param name="odEventType">Causes the progress window to only process ODEvents of this ODEventType.  Undefined will process all types.</param>
        ///<param name="progStyle">Sets the style of the progress bar within the progress window that is going to be shown to the user.</param>
        ///<param name="hasMinimize">Set to true if the progress window should allow minimizing.  False by default.</param>
        ///<param name="hasHistory">Set to true if the progress window should show a history of events that it has processed.
        ///This will cause the UI of the progress window to change slightly and will also make it so the user has to click a Close button.</param>
        public static void ShowAction(Action actionComputation, string startingMessage = "Please Wait...",
                                      Action <Exception> actionException = null, Type eventType = null, ODEventType odEventType               = ODEventType.Undefined,
                                      ProgressBarStyle progStyle         = ProgressBarStyle.Marquee, bool hasMinimize = true, bool hasHistory = false)
        {
            if (actionComputation == null)
            {
                return;                //No work to be done.  Simply return.
            }
            Action actionCloseProgressWindow = Show(odEventType, eventType, startingMessage, hasHistory, hasMinimize, progStyle);

            //Invoke the action on the main thread that was passed in.
            try {
                actionComputation();
            }
            catch (Exception e) {
                if (actionException == null)
                {
                    throw;
                }
                else
                {
                    actionException(e);
                }
            }
            finally {
                actionCloseProgressWindow();
            }
        }
예제 #12
0
 public void Fire(ODEventType odEventType, object tag)
 {
     Fire(new ODEventArgs(odEventType, tag));
 }