示例#1
0
 public override void InitializeApplication()
 {
     NSApplication.Init();
     //Hijack ();
     if (pool != null)
     {
         pool.Dispose();
     }
     pool        = new NSAutoreleasePool();
     appDelegate = new AppDelegate(IsGuest);
     NSApplication.SharedApplication.Delegate = appDelegate;
 }
示例#2
0
        public override bool Reload(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }
            var pool = new NSAutoreleasePool();

            SuppressChangeEvents = true;
            try {
                list.Clear();
                var nsa = NSArray.FromFile(fileName);
                if (nsa != null)
                {
                    var arr = NSArray.ArrayFromHandle <NSObject> (nsa.Handle);
                    foreach (var f in arr)
                    {
                        Add(PDictionary.FromNSObject(f));
                    }
                }
                else
                {
                    return(false);
                }
            } finally {
                SuppressChangeEvents = false;
                pool.Dispose();
            }
            OnChanged(EventArgs.Empty);
            return(true);
        }
示例#3
0
        public override bool Reload(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }
            var pool = new NSAutoreleasePool();

            SuppressChangeEvents = true;
            try {
                dict.Clear();
                order.Clear();
                var nsd = NSDictionary.FromFile(fileName);
                if (nsd != null)
                {
                    foreach (var pair in nsd)
                    {
                        string k = pair.Key.ToString();
                        this [k] = FromNSObject(pair.Value);
                    }
                }
                else
                {
                    return(false);
                }
            } finally {
                SuppressChangeEvents = false;
                pool.Dispose();
            }
            OnChanged(EventArgs.Empty);
            return(true);
        }
示例#4
0
            void Init()
            {
                NSAutoreleasePool pool = new NSAutoreleasePool();

                _callback = new CoreServices.FSEventStreamCallback(OnFsEvent);

                var pathptrs = new List <IntPtr>();

                foreach (string path in _paths)
                {
                    pathptrs.Add(CoreFoundation.CFSTR(new StringBuilder(path)));
                }

                _stream = CoreServices.FSEventStreamCreate(IntPtr.Zero,
                                                           _callback,
                                                           IntPtr.Zero,
                                                           CoreFoundation.CFArrayCreate(pathptrs.ToArray()),
                                                           CoreServices.kFSEventStreamEventIdSinceNow,
                                                           1.0,
                                                           CoreServices.kFSEventStreamCreateFlagWatchRoot);

                CoreServices.FSEventStreamScheduleWithRunLoop(_stream,
                                                              RunLoopHelper.GetRunLoop(),
                                                              CoreFoundation.kCFRunLoopDefaultMode);

                CoreServices.FSEventStreamStart(_stream);

                //CoreServices.FSEventStreamShow(_stream);

                pool.Dispose();
            }
示例#5
0
        static void Main(string [] args)
        {
            NSAutoreleasePool pool = new NSAutoreleasePool();

            UIApplication.Main(args, null, "AppDelegate");
            pool.Dispose();
        }
示例#6
0
        public override void InitializeApplication()
        {
            NSApplication.Init();
            //Hijack ();
            if (pool != null)
            {
                pool.Dispose();
            }
            pool        = new NSAutoreleasePool();
            appDelegate = new AppDelegate(IsGuest);
            NSApplication.SharedApplication.Delegate = appDelegate;

            // If NSPrincipalClass is not set, set it now. This allows running
            // the application without a bundle
            var info = NSBundle.MainBundle.InfoDictionary;

            if (info.ValueForKey((NSString)"NSPrincipalClass") == null)
            {
                info.SetValueForKey((NSString)"NSApplication", (NSString)"NSPrincipalClass");
            }
        }
        public void NoStrongCycles()
        {
            bool finalizedAnyCtor       = false;
            bool finalizedAnyAddTarget1 = false;
            bool finalizedAnyAddTarget2 = false;

            // Add the gesture recognizers to a list so that they're not collected until after the test
            // This is to avoid false positives (the callback should be collectible already after disposing the gesture recognizer).
            var list = new List <UIGestureRecognizer> ();

            var pool = new NSAutoreleasePool();

            for (var k = 0; k < 10; k++)
            {
                {
                    var notifier = new FinalizerNotifier(() => finalizedAnyCtor = true);
                    using (var gr = new UIGestureRecognizer(() => {
                        GC.KeepAlive(notifier);                          // Make sure the 'notifier' instance is only collected if the delegate to UIGestureRecognizer is collectable.
                    })) {
                        list.Add(gr);
                    }
                }
                {
                    var notifier = new FinalizerNotifier(() => finalizedAnyAddTarget1 = true);
                    using (var gr = new UIGestureRecognizer()) {
                        gr.AddTarget(() => { GC.KeepAlive(notifier); });
                        list.Add(gr);
                    }
                }
                {
                    var notifier = new FinalizerNotifier(() => finalizedAnyAddTarget2 = true);
                    using (var gr = new UIGestureRecognizer()) {
                        gr.AddTarget((obj) => { GC.KeepAlive(notifier); });
                        list.Add(gr);
                    }
                }
            }
            pool.Dispose();

            TestRuntime.RunAsync(DateTime.Now.AddSeconds(1), () => { GC.Collect(); }, () => finalizedAnyCtor && finalizedAnyAddTarget1 && finalizedAnyAddTarget2);
            Assert.IsTrue(finalizedAnyCtor, "Any finalized");
            Assert.IsTrue(finalizedAnyAddTarget1, "AddTarget1 finalized");
            Assert.IsTrue(finalizedAnyAddTarget2, "AddTarget2 finalized");

            GC.KeepAlive(list);
        }
示例#8
0
文件: MacEngine.cs 项目: TelsaV/xwt
        public override void DispatchPendingEvents()
        {
            var until = NSDate.DistantPast;
            var app   = NSApplication.SharedApplication;
            var p     = new NSAutoreleasePool();

            while (true)
            {
                var ev = app.NextEvent(NSEventMask.AnyEvent, until, NSRunLoop.NSDefaultRunLoopMode, true);
                if (ev != null)
                {
                    app.SendEvent(ev);
                }
                else
                {
                    break;
                }
            }
            p.Dispose();
        }
示例#9
0
        static void Main(string[] args)
        {
            NSApplication.Init();
            var pool = new NSAutoreleasePool();
            var dict = new NSMutableDictionary();

            dict.SetValueForKey(new NSString("ALttP Random - <seed>.sfc"), new NSString(PreferenceNames.OutputFile));
            dict.SetValueForKey(new NSNumber((int)RandomizerDifficulty.Casual), new NSString(PreferenceNames.RandomizerDifficulty));
            dict.SetValueForKey(new NSNumber(false), new NSString(PreferenceNames.CreateSpoilerLog));
            dict.SetValueForKey(new NSNumber(false), new NSString(PreferenceNames.SramTrace));
            dict.SetValueForKey(new NSNumber((int)HeartBeepSpeed.Normal), new NSString(PreferenceNames.HeartBeepSpeed));
            dict.SetValueForKey(new NSNumber(5), new NSString(PreferenceNames.BulkCreateCount));
            dict.SetValueForKey(new NSNumber(true), new NSString(PreferenceNames.ShowComplexity));
            var docURL = NSFileManager.DefaultManager.GetUrl(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, null, false, out NSError unused);

            dict.SetValueForKey(docURL, new NSString(PreferenceNames.ParentDirectory));
            NSUserDefaults.StandardUserDefaults.RegisterDefaults(dict);
            dict = null;
            pool.Dispose();
            pool = null;
            NSApplication.Main(args);
        }
示例#10
0
 public override void RunApplication()
 {
     pool.Dispose();
     NSApplication.Main(new string [0]);
     pool = new NSAutoreleasePool();
 }
示例#11
0
        public void ShowImagePicker(bool needsHighQuality)
        {
            //Create the image gallery picker.
            var picker = new GMImagePickerController
            {
                Title = "Select Photo",
                CustomDoneButtonTitle       = "Finished",
                CustomCancelButtonTitle     = "Cancel",
                ColsInPortrait              = 4,
                ColsInLandscape             = 7,
                MinimumInteritemSpacing     = 2.0f,
                DisplaySelectionInfoToolbar = true,
                AllowsMultipleSelection     = true,
                ShowCameraButton            = true,
                AutoSelectCameraImages      = true,
                ModalPresentationStyle      = UIModalPresentationStyle.Popover,
                MediaTypes             = new[] { PHAssetMediaType.Image },
                CustomSmartCollections = new[]
                {
                    PHAssetCollectionSubtype.SmartAlbumUserLibrary,
                    PHAssetCollectionSubtype.AlbumRegular
                },
                NavigationBarTextColor    = Color.White.ToUIColor(),
                NavigationBarBarTintColor = Color.FromHex("#c5dd36").ToUIColor(),
                PickerTextColor           = Color.Black.ToUIColor(),
                ToolbarTextColor          = Color.FromHex("#c5dd36").ToUIColor(),
                NavigationBarTintColor    = Color.White.ToUIColor()
            };

            //Set a limit on the number of photos the user can select. I use 12 selected photos beause of memory limitations on iOS.
            picker.ShouldSelectAsset += (sender, args) => args.Cancel = picker.SelectedAssets.Count > 11;

            // select image handler
            GMImagePickerController.MultiAssetEventHandler[] handler = { null };
            //cancel handler
            EventHandler[] cancelHandler = { null };

            //define the handler
            handler[0] = (sender, args) =>
            {
                var tcs = Interlocked.Exchange(ref _completionSource, null);
                picker.FinishedPickingAssets -= handler[0];
                picker.Canceled -= cancelHandler[0];
                System.Diagnostics.Debug.WriteLine("User finished picking assets. {0} items selected.", args.Assets.Length);
                var imageManager       = new PHImageManager();
                var RequestImageOption = new PHImageRequestOptions();

                if (needsHighQuality)
                {
                    RequestImageOption.DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat;
                }
                else
                {
                    RequestImageOption.DeliveryMode = PHImageRequestOptionsDeliveryMode.FastFormat;
                }

                RequestImageOption.ResizeMode           = PHImageRequestOptionsResizeMode.Fast;
                RequestImageOption.NetworkAccessAllowed = true;
                RequestImageOption.Synchronous          = false;
                _preselectedAssets = args.Assets;
                if (!_preselectedAssets.Any())
                {
                    //no image selected
                    tcs.TrySetResult(null);
                }
                else
                {
                    var images             = new List <string>();
                    var documentsDirectory = Environment.GetFolderPath
                                                 (Environment.SpecialFolder.Personal);
                    int cnt = 1;
                    foreach (var asset in _preselectedAssets)
                    {
                        DispatchQueue.MainQueue.DispatchAsync(() =>
                        {
                            //For each image, create a file path for it.
                            imageManager.RequestImageForAsset(asset,
                                                              PHImageManager.MaximumSize,
                                                              PHImageContentMode.Default,
                                                              RequestImageOption,
                                                              (image, info) =>
                            {
                                using (NSAutoreleasePool autoreleasePool = new NSAutoreleasePool())
                                {
                                    System.Diagnostics.Debug.WriteLine("Total memory being used: {0}", GC.GetTotalMemory(false));
                                    var filename = Guid.NewGuid().ToString();
                                    System.Diagnostics.Debug.WriteLine("filename: " + filename);
                                    string filepath = Save(image, filename.ToString(), documentsDirectory);
                                    System.Diagnostics.Debug.WriteLine("filepath: " + filepath);
                                    images.Add(filepath);

                                    //When we are on the last image, send the images to the carousel view.
                                    if (cnt == args.Assets.Length)
                                    {
                                        Device.BeginInvokeOnMainThread(() =>
                                        {
                                            MessagingCenter.Send <App, List <string> >((App)Xamarin.Forms.Application.Current, "ImagesSelectediOS", images);
                                        });
                                    }
                                    cnt++;

                                    //Dispose of objects and call the garbage collector.
                                    asset.Dispose();
                                    autoreleasePool.Dispose();
                                    GC.Collect();
                                }
                            });
                        });
                    }
                    tcs.TrySetResult(images);
                }
            };
            picker.FinishedPickingAssets += handler[0];

            cancelHandler[0] = (sender, args) =>
            {
                var tcs = Interlocked.Exchange(ref _completionSource, null);
                picker.FinishedPickingAssets -= handler[0];
                picker.Canceled -= cancelHandler[0];
                tcs.TrySetResult(null);
            };
            picker.Canceled += cancelHandler[0];

            //show picker
            picker.PresentUsingRootViewController();
        }
示例#12
0
        private void ProcessRequests()
        {
            while (true)
            {
                // wait for an artwork request
                iPendingRequests.Wait();

                // get the first request in the queue - leave the request in the queue for now so that if
                // the main thread requests it again, it will not get re-added and downloaded again
                string uri;
                ScalingUriConverter uriConverter;
                lock (iLock)
                {
                    uri          = iPendingRequests.FirstRequest;
                    uriConverter = iUriConverter;
                }

                // download the image
                NSAutoreleasePool pool = new NSAutoreleasePool();
                pool.Init();

                UIImage image = null;
                try
                {
                    string requestUri = uri;
                    if (uriConverter != null)
                    {
                        requestUri = uriConverter.Convert(uri);
                    }
                    NSData data = NSData.FromUrl(NSUrl.FromString(requestUri));
                    image = ImageToFitSize(new UIImage(data), new CGSize(kDownscaleSize, kDownscaleSize));
                }
                catch (Exception e)
                {
                    UserLog.WriteLine("ArtworkCache.ProcessRequests: " + uri + " (" + e.Message + ")");
                }

                pool.Dispose();

                // insert the image into the cache
                List <Item> staleItems;
                lock (iLock)
                {
                    // add to the cache
                    Item item = new Item(uri, image);
                    staleItems = iCacheData.Add(item);

                    // remove the request
                    iPendingRequests.Remove(uri);
                }

                // send notification that the image was added to the cache
                if (EventImageAdded != null)
                {
                    EventImageAdded(this, new EventArgsArtwork(uri));
                }

                // clean up all stale items outside of the lock
                foreach (Item item in staleItems)
                {
                    if (item.Image != null)
                    {
                        item.Image.Dispose();
                    }
                }
            }
        }
示例#13
0
		static void Main (string [] args)
		{
			NSAutoreleasePool pool = new NSAutoreleasePool();
			UIApplication.Main (args,null,"AppDelegate");
			pool.Dispose();
		}