protected virtual void OnCellMouseUp(int col, int row, MouseEventArgs mouseEvent)
        {
            try {
                const bool allowMultiColumnSelect = false;
                switch (SelectState)
                {
                case GridSelectingState.Selecting:
                    col = allowMultiColumnSelect ? col : SelectionStart.Item1;
                    if (CanSelect(col, row))
                    {
                        SelectionEnd = Tuple.Create(col, row);
                    }
                    if (AcceptSelection(SelectionStart, SelectionEnd))
                    {
                        SelectState = GridSelectingState.Selected;
                        FireSelectionChanged(col, row);
                        FireSelectionFinished(SelectionStart.Item1, SelectionStart.Item2, col, row);
                    }
                    else
                    {
                        ClearSelection();
                        FireSelectionFinished(SelectionStart.Item1, SelectionStart.Item2, col, row);
                    }
                    break;

                case GridSelectingState.Selected:
                case GridSelectingState.None:
                default:
                    break;
                }
            } catch (Exception error) {
                SystemLog.Exception(error);
                ExceptionDialog.Show(this, error);
            }
        }
        private void _filenameTextBox_Validating(object sender, CancelEventArgs e)
        {
            try {
                var textOnLeave = _filenameTextBox.Text;
                if (!string.IsNullOrEmpty(textOnLeave) && _textOnEnter != textOnLeave && ForcePathExists)
                {
                    if (Mode.IsIn(PathSelectionMode.Folder))
                    {
                        e.Cancel = !Directory.Exists(textOnLeave);
                    }
                    else
                    {
                        e.Cancel = !File.Exists(textOnLeave);
                    }
                }
                if (e.Cancel)
                {
                    return;
                }

                if (!string.IsNullOrEmpty(textOnLeave) && _textOnEnter != textOnLeave)
                {
                    NotifyPathChanged();
                }
                _textOnEnter = null;
            } catch (Exception error) {
                SystemLog.Exception(error);
                ExceptionDialog.Show(error);
            }
        }
        private void _fileSelectorButton_Click(object sender, EventArgs e)
        {
            try {
                switch (Mode)
                {
                case PathSelectionMode.OpenFile:
                    ShowOpenDialog();
                    break;

                case PathSelectionMode.SaveFile:
                    ShowSaveDialog();
                    break;

                case PathSelectionMode.File:
                    ShowOpenSaveDialog();
                    break;

                case PathSelectionMode.Folder:
                    ShowSelectFolderDialog();
                    break;
                }
            } catch (Exception error) {
                SystemLog.Exception(error);
                ExceptionDialog.Show(error);
            }
        }
        protected virtual void OnCellMouseDown(int col, int row, MouseEventArgs mouseEvent)
        {
            try {
                switch (SelectState)
                {
                case GridSelectingState.None:
                case GridSelectingState.Selected:
                    if (CanSelect(col, row))
                    {
                        SelectState    = GridSelectingState.Selecting;
                        SelectionStart = Tuple.Create(col, row);
                        SelectionEnd   = SelectionStart;
                        FireSelectingStarted(col, row);
                        FireSelecting(col, row);
                    }
                    break;

                case GridSelectingState.Selecting:
                default:
                    break;
                }
            } catch (Exception error) {
                SystemLog.Exception(error);
                ExceptionDialog.Show(this, error);
            }
        }
        protected virtual void OnCellMouseMoved(int col, int row, MouseEventArgs mouseEvent)
        {
            try {
                const bool allowMultiColumnSelect = false;
                switch (SelectState)
                {
                case GridSelectingState.Selecting:
                    col = allowMultiColumnSelect ? col : SelectionStart.Item1;
                    if (CanSelect(col, row))
                    {
                        SelectionEnd = Tuple.Create(col, row);
                    }
                    FireSelecting(SelectionEnd.Item1, SelectionEnd.Item2);
                    break;

                default:
                    if (_lastMouseDown != null)
                    {
                        if (mouseEvent.Button.HasFlag(MouseButtons.Left) &&
                            _grid.PointToClient(Cursor.Position).DistanceTo(_lastMouseDown.Item4) >= DistanceMovedToInitiateDragging &&
                            CanDragCell(_lastMouseDown.Item1, _lastMouseDown.Item2)
                            )
                        {
                            BeginDragging(_lastMouseDown.Item1, _lastMouseDown.Item2, _lastMouseDown.Item4);
                        }
                    }
                    break;
                }
            } catch (Exception error) {
                SystemLog.Exception(error);
                ExceptionDialog.Show(this, error);
            }
        }
 private void _filenameTextBox_Validated(object sender, EventArgs e)
 {
     try {
     } catch (Exception error) {
         SystemLog.Exception(error);
         ExceptionDialog.Show(error);
     }
 }
 public override void ViewDidLoad()
 {
     try {
         _paintingView = new UIPaintingView(GetPaintingViewFrame());
         View.AddSubview(_paintingView);
     } catch (Exception error) {
         SystemLog.Exception(error);
     }
 }
Exemple #8
0
 protected override void SetVisibleColumns()
 {
     try {
         base.SetVisibleColumns();
         RecreateCellDisplays();
     } catch (Exception error) {
         SystemLog.Exception(error);
         ExceptionDialog.Show(error);
     }
 }
 protected override void OnEnabledChanged(EventArgs e)
 {
     try {
         base.OnEnabledChanged(e);
         _filenameTextBox.Enabled        =
             _fileSelectorButton.Enabled = this.Enabled;
     } catch (Exception error) {
         SystemLog.Exception(error);
         ExceptionDialog.Show(error);
     }
 }
Exemple #10
0
        protected virtual void SetVisibleColumns()
        {
            try {
                _blockLookup.Clear();

                //// filter out unnecessary appointment columns and blocks
                DateTime startTime;
                DateTime endTime;
                switch (TimeView)
                {
                case TimePeriodType.Monthly:
                    startTime = TimePeriodStart.ToBeginningOfMonth();
                    endTime   = TimePeriodStart.ToEndOfMonth();
                    break;

                case TimePeriodType.DailyHourly:
                case TimePeriodType.DailyHalfHourly:
                case TimePeriodType.DailyQuaterHourly:
                default:
                    startTime = TimePeriodStart.ToMidnight();
                    endTime   = TimePeriodStart.To1159PM();
                    break;
                }


                switch (ColumnFilter)
                {
                case AppointmentBookViewModelFilter.All:
                    _visibleColumns = _allColumns;
                    break;

                case AppointmentBookViewModelFilter.ExcludeEmptyColumns:
                    _visibleColumns = (
                        from appointment in _allColumns
                        where appointment.Appointments.Any(block => block.VisibleStartTime <endTime && block.VisibleEndTime> startTime)
                        select appointment
                        ).ToArray();
                    break;

                case AppointmentBookViewModelFilter.ShowOnlyEmptyColumns:
                    _visibleColumns = (
                        from appointment in _allColumns
                        where !appointment.Appointments.Any(block => block.VisibleStartTime <= endTime && block.VisibleEndTime >= startTime)
                        select appointment
                        ).ToArray();;
                    break;
                }

                RecreateCellDisplays();
            } catch (Exception error) {
                SystemLog.Exception(error);
                ExceptionDialog.Show(error);
            }
        }
Exemple #11
0
 public static Action HandlingExceptions(Action action)
 {
     return(() => {
         try {
             action();
         } catch (Exception error) {
             SystemLog.Exception(error);
             MessageBox.Show(error.ToDisplayString());
         }
     });
 }
Exemple #12
0
        public void Start()
        {
            lock (_threadLock) {
                if (!Started)
                {
                    _resetEvent = new ManualResetEvent(false);
                    new Thread(() => {
                        var host =
                            _singletonImpl != null ?
                            new ServiceHost(_singletonImpl, new[] { ServiceUri }) :
                            new ServiceHost(typeof(TServiceImpl), new[] { ServiceUri });
                        using (host) {
                            host.Description.Behaviors.Add(
                                new ServiceMetadataBehavior {
                                HttpGetEnabled = true,
                                //MetadataExporter = {
                                //PolicyVersion = PolicyVersion.Policy15
                                //}
                            }
                                );
                            var debugBehavior = host.Description.Behaviors.Find <ServiceDebugBehavior>();
                            if (debugBehavior == null)
                            {
                                host.Description.Behaviors.Add(
                                    new ServiceDebugBehavior {
                                    IncludeExceptionDetailInFaults = true
                                });
                            }

                            host.Description.Behaviors.Find <ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
                            host.Description.Behaviors.Find <ServiceDebugBehavior>().HttpHelpPageUrl = ServiceUri;

                            var behaviour = host.Description.Behaviors.Find <ServiceBehaviorAttribute>();
                            behaviour.InstanceContextMode = ContextMode;


                            host.AddServiceEndpoint(typeof(TServiceContract), Binding, ServiceUri);

                            SystemLog.Info("Service '{0}' Starting", typeof(TServiceImpl).FullName);
                            try {
                                host.Open();
                            } catch (Exception error) {
                                SystemLog.Exception(error);
                                return;
                            }
                            SystemLog.Info("Service '{0}' Started", typeof(TServiceImpl).FullName);
                            Started = true;
                            _resetEvent.WaitOne();
                            SystemLog.Info("Service '{0}' Stopped", typeof(TServiceImpl).FullName);
                        }
                    }).Start();
                }
            }
        }
 private void _filenameTextBox_Enter(object sender, EventArgs e)
 {
     try {
         if (_textOnEnter == null)
         {
             _textOnEnter = this._filenameTextBox.Text;
         }
     } catch (Exception error) {
         SystemLog.Exception(error);
         ExceptionDialog.Show(error);
     }
 }
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            List <Action> cleanupActions = filterContext.Controller.ViewBag.Cleanup;

            foreach (var cleanupAction in cleanupActions)
            {
                try {
                    cleanupAction();
                } catch (Exception error) {
                    SystemLog.Exception(error);
                }
            }
        }
        public static void ShowLoadingHUD(this UIView view, string title, Action <IProgressDelegate> action)
        {
            bool      isCompleted = false;
            Exception error       = null;
            //	view.InvokeOnMainThread(
            //	() => {
            var hudView  = new LoadingHUDView(title, "processing");
            var hudFrame = hudView.Frame;

            hudFrame.Height += (float)(view.Window.Frame.GetMidY());
            hudView.Frame    = hudFrame;
            view.Window.Add(hudView);

            hudView.StartAnimating();

            Tools.Threads.QueueAction(
                () => {
                try {
                    action(new ActionProgressDelegate((msg) => view.InvokeOnMainThread(() => hudView.Message = msg)));
                } catch (Exception actionError) {
                    error = actionError;
                } finally {
                    view.InvokeOnMainThread(
                        () => {
                        try {
                            hudView.StopAnimating();
                            hudView.RemoveFromSuperview();
                        } catch {
                            // ignore errors here
                        } finally {
                            isCompleted = true;
                        }
                    }
                        );
                    isCompleted = true;
                }
            }
                );
            //	});
            while (!isCompleted)
            {
                NSRunLoop.Current.RunUntil(NSDate.FromTimeIntervalSinceNow(0.2));
            }

            if (error != null)
            {
                SystemLog.Exception(error);
                throw new SoftwareException(error, "An unexpected error occured in an asyncronous task");
            }
        }
Exemple #16
0
 public static CellViewModel[] CreateArray(int count)
 {
     try {
         var arr = new CellViewModel[count];
         for (int i = 0; i < count; i++)
         {
             arr[i] = CellViewModel.Empty;
         }
         return(arr);
     } catch (Exception error) {
         SystemLog.Exception(error);
         ExceptionDialog.Show(error);
         return(new CellViewModel[0]);
     }
 }
        private async Task GetProductDataInternal(IEnumerable <string> productIDs)
        {
            if (productIDs == null)
            {
                return;
            }

            SystemLog.Info("GetProductDataInternal - count of products requested {0}", productIDs.Count());

            productIDs.ForEach(x => {
                SystemLog.Info(x);
            });
            const int numRetry = 3;

            var productIdentifiers = productIDs.ToArray();

            if (productIdentifiers.Length == 0)
            {
                return;
            }

            for (int i = 0; i < numRetry; i++)
            {
                try {
                    using (_productCache.EnterWriteScope()) {
                        var requestor = new ProductDataRequestor();
                        foreach (var product in (await requestor.GetProductData(productIdentifiers)).Products)
                        {
                            _productCache [product.ProductIdentifier] = product;
                            SystemLog.Info("RECEIVED iTUNES RESPONSE {0}", product.ProductIdentifier);
                        }
                    }
                    break;
                } catch (Exception error) {
                    SystemLog.Exception(error);
                    if (i == numRetry - 1)
                    {
                        throw new Exception(string.Format("An error occured fetching product(s) '{0}' from iTunes.", productIdentifiers.ToDelimittedString(", ")), error);
                    }
                }
            }
        }
        public static void DisposeEx(this UIView view)
        {
            const bool enableLogging = true;

            try {
                if (view.IsDisposedOrNull())
                {
                    return;
                }

                var viewDescription = string.Empty;

                if (enableLogging)
                {
                    viewDescription = view.Description;
                    SystemLog.Debug("Destroying " + viewDescription);
                }

                var disposeView              = true;
                var disconnectFromSuperView  = true;
                var disposeSubviews          = true;
                var removeGestureRecognizers = false; // WARNING: enable at your own risk, may causes crashes
                var removeConstraints        = true;
                var removeLayerAnimations    = true;
                var associatedViewsToDispose = new List <UIView>();
                var otherDisposables         = new List <IDisposable>();

                if (view is UIActivityIndicatorView)
                {
                    var aiv = (UIActivityIndicatorView)view;
                    if (aiv.IsAnimating)
                    {
                        aiv.StopAnimating();
                    }
                }
                else if (view is UITableView)
                {
                    var tableView = (UITableView)view;

                    if (tableView.DataSource != null)
                    {
                        otherDisposables.Add(tableView.DataSource);
                    }
                    if (tableView.BackgroundView != null)
                    {
                        associatedViewsToDispose.Add(tableView.BackgroundView);
                    }

                    tableView.Source         = null;
                    tableView.Delegate       = null;
                    tableView.DataSource     = null;
                    tableView.WeakDelegate   = null;
                    tableView.WeakDataSource = null;
                    associatedViewsToDispose.AddRange(tableView.VisibleCells ?? new UITableViewCell[0]);
                    //return;
                }
                else if (view is UITableViewCell)
                {
                    var tableViewCell = (UITableViewCell)view;
                    disposeView             = false;
                    disconnectFromSuperView = false;
                    if (tableViewCell.ImageView != null)
                    {
                        associatedViewsToDispose.Add(tableViewCell.ImageView);
                    }
                }
                else if (view is UICollectionView)
                {
                    var collectionView = (UICollectionView)view;
                    disposeView = false;
                    if (collectionView.DataSource != null)
                    {
                        otherDisposables.Add(collectionView.DataSource);
                    }
                    if (!collectionView.BackgroundView.IsDisposedOrNull())
                    {
                        associatedViewsToDispose.Add(collectionView.BackgroundView);
                    }
                    //associatedViewsToDispose.AddRange(collectionView.VisibleCells ?? new UICollectionViewCell[0]);
                    collectionView.Source         = null;
                    collectionView.Delegate       = null;
                    collectionView.DataSource     = null;
                    collectionView.WeakDelegate   = null;
                    collectionView.WeakDataSource = null;
                }
                else if (view is UICollectionViewCell)
                {
                    var collectionViewCell = (UICollectionViewCell)view;
                    disposeView             = false;
                    disconnectFromSuperView = false;
                    if (collectionViewCell.BackgroundView != null)
                    {
                        associatedViewsToDispose.Add(collectionViewCell.BackgroundView);
                    }
                }
                else if (view is UIWebView)
                {
                    var webView = (UIWebView)view;
                    if (webView.IsLoading)
                    {
                        webView.StopLoading();
                    }
                    webView.LoadHtmlString(string.Empty, null); // clear display
                    webView.Delegate     = null;
                    webView.WeakDelegate = null;
                }
                else if (view is UIImageView)
                {
                    var imageView = (UIImageView)view;
                    if (imageView.Image != null)
                    {
                        otherDisposables.Add(imageView.Image);
                        imageView.Image = null;
                    }
                }
                else if (view is UIScrollView)
                {
                    var scrollView = (UIScrollView)view;
                    scrollView.UnsetZoomableContentView();
                }

                var gestures = view.GestureRecognizers;
                if (removeGestureRecognizers && gestures != null)
                {
                    foreach (var gr in gestures)
                    {
                        view.RemoveGestureRecognizer(gr);
                        gr.Dispose();
                    }
                }

                if (removeLayerAnimations && view.Layer != null)
                {
                    view.Layer.RemoveAllAnimations();
                }

                if (disconnectFromSuperView && view.Superview != null)
                {
                    view.RemoveFromSuperview();
                }

                var constraints = view.Constraints;
                if (constraints != null && constraints.Any() && constraints.All(c => c.Handle != IntPtr.Zero))
                {
                    view.RemoveConstraints(constraints);
                    foreach (var constraint in constraints)
                    {
                        constraint.Dispose();
                    }
                }

                foreach (var otherDisposable in otherDisposables)
                {
                    otherDisposable.Dispose();
                }

                foreach (var otherView in associatedViewsToDispose)
                {
                    otherView.DisposeEx();
                }

                var subViews = view.Subviews;
                if (disposeSubviews && subViews != null)
                {
                    subViews.ForEach(DisposeEx);
                }

                if (view is ISpecialDisposable)
                {
                    ((ISpecialDisposable)view).SpecialDispose();
                }
                else if (disposeView)
                {
                    if (view.Handle != IntPtr.Zero)
                    {
                        view.Dispose();
                    }
                }

                if (enableLogging)
                {
                    SystemLog.Debug("Destroyed {0}", viewDescription);
                }
            } catch (Exception error) {
                SystemLog.Exception(error);
            }
        }