Пример #1
0
		public void ExecutionBlocks ()
		{
			using (var bo = NSBlockOperation.Create (Create_Null)) {
				bo.AddExecutionBlock (Add_Null);
				Assert.That (bo.ExecutionBlocks.Length, Is.EqualTo (2), "ExecutionBlocks");
			}
		}
		public override void DidUpdateFocus (UIFocusUpdateContext context, UIFocusAnimationCoordinator coordinator)
		{
			var nextFocusedView = context.NextFocusedView;

			if (!nextFocusedView.IsDescendantOfView (TableView))
				return;

			NSIndexPath indexPath = ((UITableViewFocusUpdateContext)context).NextFocusedIndexPath;
			if (indexPath == null)
				return;

			// Cancel any previously queued segues.
			delayedSeguesOperationQueue.CancelAllOperations ();

			// Create an `NSBlockOperation` to perform the detail segue after a delay.
			var performSegueOperation = new NSBlockOperation ();
			var segueIdentifier = SegueIdentifierMap[indexPath.Section][indexPath.Row];

			performSegueOperation.AddExecutionBlock (() => {
				NSThread.SleepFor (performSegueDelay);
				if (performSegueOperation.IsCancelled && segueIdentifier == lastPerformedSegueIdentifier)
					return;

				NSOperationQueue.MainQueue.AddOperation (() => {
					PerformSegue (segueIdentifier, nextFocusedView);
					lastPerformedSegueIdentifier = segueIdentifier;
					TableView.SelectRow (indexPath, true, UITableViewScrollPosition.None);
				});
			});

			delayedSeguesOperationQueue.AddOperation (performSegueOperation);
		}
Пример #3
0
		public void Add_Null ()
		{
			using (var bo = NSBlockOperation.Create (Create_Null)) {
				// Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: *** -[NSBlockOperation addExecutionBlock:]: block is nil
				Assert.Throws<ArgumentNullException> (() => bo.AddExecutionBlock (null));
			}
		}
Пример #4
0
        public void ComposeCell(DataItemCollectionViewCell cell, DataItem dataItem)
        {
            var operationQueue = OperationQueueForCell(cell);

            operationQueue.CancelAllOperations();

            cell.RepresentedDataItem = dataItem;
            cell.Label.Text          = dataItem.Title;
            cell.ImageView.Alpha     = 1f;
            cell.ImageView.Image     = (UIImage)processedImageCache.ObjectForKey((NSString)dataItem.Identifier);

            if (cell.ImageView.Image != null)
            {
                return;
            }

            var processImageOperation = new NSBlockOperation();

            processImageOperation.AddExecutionBlock(() => {
                if (processImageOperation.IsCancelled)
                {
                    return;
                }

                UIImage image = null;
                DispatchQueue.MainQueue.DispatchSync(() => {
                    image = ProcessImageNamed(dataItem.ImageName);
                });

                if (image == null)
                {
                    return;
                }

                processedImageCache.SetObjectforKey(image, (NSString)dataItem.Identifier);
                NSOperationQueue.MainQueue.AddOperation(() => {
                    if (cell.RepresentedDataItem == null)
                    {
                        return;
                    }

                    cell.ImageView.Alpha = 0f;
                    cell.ImageView.Image = image;
                    UIView.Animate(0.25, () => cell.ImageView.Alpha = 1f);
                });
            });

            operationQueue.AddOperation(processImageOperation);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Shipping Rates";

            // Setup both operations to run
            var shopOperation = new GetShopOperation(client);

            shopOperation.DidReceiveShop += (op, shop) => {
                currencyFormatter              = new NSNumberFormatter();
                currencyFormatter.NumberStyle  = NSNumberFormatterStyle.Currency;
                currencyFormatter.CurrencyCode = shop.Currency;
            };
            shopOperation.FailedToReceiveShop += (op, error) => {
                Console.WriteLine("Failed to retrieve shop: {0}", error);
            };
            NSOperationQueue.MainQueue.AddOperation(shopOperation);

            var shippingOperation = new GetShippingRatesOperation(client, checkout);

            shippingOperation.DidReceiveShippingRates += (op, rates) => {
                shippingRates = rates;
            };
            shippingOperation.FailedToReceiveShippingRates += (op, error) => {
                Console.WriteLine("Failed to retrieve shipping rates: {0}", error);
            };
            NSOperationQueue.MainQueue.AddOperation(shippingOperation);

            UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;

            // Ensure both operations are completed before we reload the table view
            var blockOperation = NSBlockOperation.Create(() => {
                UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
                TableView.ReloadData();
            });

            blockOperation.AddDependency(shopOperation);
            blockOperation.AddDependency(shippingOperation);
            NSOperationQueue.MainQueue.AddOperation(blockOperation);

            allOperations = new NSOperation[] {
                blockOperation,
                shopOperation,
                shippingOperation
            };
        }
		public void ComposeCell (DataItemCollectionViewCell cell, DataItem dataItem)
		{
			var operationQueue = OperationQueueForCell (cell);
			operationQueue.CancelAllOperations ();

			cell.RepresentedDataItem = dataItem;
			cell.Label.Text = dataItem.Title;
			cell.ImageView.Alpha = 1f;
			cell.ImageView.Image = (UIImage)processedImageCache.ObjectForKey ((NSString)dataItem.Identifier);

			if (cell.ImageView.Image != null)
				return;

			var processImageOperation = new NSBlockOperation ();
			processImageOperation.AddExecutionBlock (() => {
				if (processImageOperation.IsCancelled)
					return;

				UIImage image = null;
				DispatchQueue.MainQueue.DispatchSync (() => {
					image = ProcessImageNamed (dataItem.ImageName);
				});

				if (image == null)
					return;

				processedImageCache.SetObjectforKey (image, (NSString)dataItem.Identifier);
				NSOperationQueue.MainQueue.AddOperation (() => {
					if (cell.RepresentedDataItem == null)
						return;

					cell.ImageView.Alpha = 0f;
					cell.ImageView.Image = image;
					UIView.Animate (0.25, () => cell.ImageView.Alpha = 1f);
				});
			});

			operationQueue.AddOperation (processImageOperation);
		}
        public override void DidUpdateFocus(UIFocusUpdateContext context, UIFocusAnimationCoordinator coordinator)
        {
            var nextFocusedView = context.NextFocusedView;

            if (!nextFocusedView.IsDescendantOfView(TableView))
            {
                return;
            }

            NSIndexPath indexPath = ((UITableViewFocusUpdateContext)context).NextFocusedIndexPath;

            if (indexPath == null)
            {
                return;
            }

            // Cancel any previously queued segues.
            delayedSeguesOperationQueue.CancelAllOperations();

            // Create an `NSBlockOperation` to perform the detail segue after a delay.
            var performSegueOperation = new NSBlockOperation();
            var segueIdentifier       = SegueIdentifierMap[indexPath.Section][indexPath.Row];

            performSegueOperation.AddExecutionBlock(() => {
                NSThread.SleepFor(performSegueDelay);
                if (performSegueOperation.IsCancelled && segueIdentifier == lastPerformedSegueIdentifier)
                {
                    return;
                }

                NSOperationQueue.MainQueue.AddOperation(() => {
                    PerformSegue(segueIdentifier, nextFocusedView);
                    lastPerformedSegueIdentifier = segueIdentifier;
                    TableView.SelectRow(indexPath, true, UITableViewScrollPosition.None);
                });
            });

            delayedSeguesOperationQueue.AddOperation(performSegueOperation);
        }
 public void Create_Null()
 {
     // Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: *** -[NSBlockOperation addExecutionBlock:]: block is nil
     NSBlockOperation.Create(null);
 }