示例#1
0
        public void Guid_SelectConsistency()
        {
            const string tableDDL = @"CREATE TABLE [Table] (
	ID INTEGER PRIMARY KEY AUTOINCREMENT,
	Data1 UNIQUEIDENTIFIER NOT NULL
)";
            var          dbFile   = Tools.Paths.GenerateTempFilename();

            try {
                SystemLog.RegisterLogger(new ConsoleLogger());
                var guid = Guid.NewGuid();
                SystemLog.Debug("Generated Guid: {0}", guid);

                var dac = Tools.Sqlite.Create(dbFile, logger: SystemLog.Logger);
                dac.ExecuteNonQuery(tableDDL);

                dac.Insert("Table", new[] { new ColumnValue("Data1", guid) });

                var read = dac.Select("Table", new[] { "Data1" }, columnMatches: new[] { new ColumnValue("Data1", guid), }).Single().Get <Guid>(0);
                Assert.AreEqual(guid, read);
            } finally {
                if (File.Exists(dbFile))
                {
                    File.Delete(dbFile);
                }
            }
        }
示例#2
0
        public static void AdjustScrollView(UIScrollView scrollView, UIView contentView, Guid fixerID)
        {
            var scrollViewFrameSize = scrollView.Frame.Size;
            var scaleWidth          = scrollViewFrameSize.Width / contentView.IntrinsicContentSize.Width;
            var scaleHeight         = scrollViewFrameSize.Height / contentView.IntrinsicContentSize.Height;
            // Unnecessary, if uncommenting note that these get added every orientation change, which is a bug

            /* scrollView.AddConstraints(new[] {
             *                   NSLayoutConstraint.Create(scrollView, NSLayoutAttribute.Width, NSLayoutRelation.LessThanOrEqual, null, NSLayoutAttribute.NoAttribute, 1.0f, contentView.IntrinsicContentSize.Width),
             *                   NSLayoutConstraint.Create(scrollView, NSLayoutAttribute.Height, NSLayoutRelation.LessThanOrEqual, null, NSLayoutAttribute.NoAttribute, 1.0f, contentView.IntrinsicContentSize.Height)
             *           });*/
            var minScale = (nfloat)Math.Max(scaleWidth, scaleHeight);

            scrollView.MinimumZoomScale = minScale;
            scrollView.MaximumZoomScale = 4.0f;
            SystemLog.Debug("[{0}] ScrollView.Handle = {1}", fixerID, scrollView.Handle);
            scrollView.ZoomScale = (nfloat)minScale.ClipTo(scrollView.MinimumZoomScale, scrollView.MaximumZoomScale);
        }
示例#3
0
        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);
            }
        }
            // called when the transaction status is updated
            public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            {
                SystemLog.Debug("UpdatedTransactions - {0}", transactions.Length);

                foreach (var transaction in transactions)
                {
                    // ISSUE: The transaction (and any dangling ones) are marked as finished straight away. Apple recommends we finish after app has done
                    // what it needs to. What happens if user's phone turns off right after finish? The app may not
                    // have registered purchase and the user will have to re-buy again!
                    //
                    // Solution is to to return a scope in the "PurchaseMethod" that
                    // finishes the transaction on dispose
                    //
                    // using(inAppPurchaseManager.Purchase("productid")) {
                    //  UpgradeApp();
                    // }  <-- dispose will finish transaction
                    //
                    if (transaction.TransactionState != SKPaymentTransactionState.Purchasing)
                    {
                        SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    }
                }

                if (transactions.Any(p => p.TransactionState.IsIn(SKPaymentTransactionState.Purchased, SKPaymentTransactionState.Restored)))
                {
                    var paymentTransaction = transactions.First(t => t.TransactionState.IsIn(SKPaymentTransactionState.Purchased, SKPaymentTransactionState.Restored));

                    switch (paymentTransaction.TransactionState)
                    {
                    case SKPaymentTransactionState.Purchased:
                        SystemLog.Info("PURCHASED");
                        _result =
                            new PurchaseResult {
                            AppStoreProductID = paymentTransaction.Payment.ProductIdentifier,
                            Result            = TransactionResult.Purchased,
                            PurchaseDate      = paymentTransaction.TransactionDate.ToNullableDateTime()
                        };
                        break;

                    case SKPaymentTransactionState.Restored:
                        SystemLog.Info("RESTORED");
                        _result =
                            new PurchaseResult {
                            AppStoreProductID = paymentTransaction.Payment.ProductIdentifier,
                            Result            = TransactionResult.Restored,
                            PurchaseDate      = paymentTransaction.OriginalTransaction.TransactionDate.ToNullableDateTime()
                        };
                        break;
                    }
                    _waiter.Set();
                }
                else if (transactions.All(t => t.TransactionState == SKPaymentTransactionState.Failed))
                {
                    SystemLog.Info("FAILED");
                    var paymentTransaction = transactions.First(t => t.TransactionState == SKPaymentTransactionState.Failed);
                    SystemLog.Info("WITH ERROR {0}", paymentTransaction.Error);
                    _result =
                        new PurchaseResult {
                        AppStoreProductID = paymentTransaction.Payment.ProductIdentifier,
                        Result            = TransactionResult.Failed,
                        Error             = paymentTransaction.Error,
                        PurchaseDate      = null
                    };
                    _waiter.Set();
                }
                else
                {
                    // still waiting for response (this was just dangling response from prior requests)
                }
            }