コード例 #1
0
        public static void DecryptAndOpenFile(IRuntimeFileInfo encryptedDocument, Passphrase passphrase, ProgressContext progress, Action <string, ProgressContext> failure = null)
        {
            string tempPath = Path.GetTempPath();
            string decryptedFileName;

            lastUsedKey = passphrase.DerivedPassphrase;

            if (!TryDecrypt(encryptedDocument, tempPath, lastUsedKey, progress, out decryptedFileName))
            {
                failure("Could not open file", progress);
                return;
            }

            string           fullPathToDecryptedFile = Path.Combine(tempPath, decryptedFileName);
            IRuntimeFileInfo decryptedFile           = OS.Current.FileInfo(fullPathToDecryptedFile);

            NSDictionary   userInfo     = new NSDictionary(Launcher.TargetFileUserInfoKey, decryptedFile.FullName);
            NSNotification notification = NSNotification.FromName(Launcher.FileDecryptedNotification, new NSObject(), userInfo);

            NSNotificationCenter.DefaultCenter.PostNotification(notification);

            ILauncher launcher = OS.Current.Launch(fullPathToDecryptedFile);

            launcher.Exited += (sender, e) => {
                fileSystemState.CheckActiveFiles(ChangedEventMode.RaiseOnlyOnModified, new ProgressContext());
            };

            fileSystemState.Add(new ActiveFile(encryptedDocument, decryptedFile, lastUsedKey, ActiveFileStatus.AssumedOpenAndDecrypted, launcher));
            //fileSystemState.Save ();
        }
コード例 #2
0
    public void ObjectSame()
    {
        var a = NSNotification.FromName("WOOT");
        var b = Runtime.GetNSObject <NSNotification>(a.Handle);

        Assert.AreSame(a, b);
    }
コード例 #3
0
    public void Object()
    {
        var obj          = new NSObject();
        var notification = NSNotification.FromName("WOOT", obj);

        Assert.AreEqual(obj.Handle, notification.Object.Handle);
    }
コード例 #4
0
        private void SendOnTouchUpInside(object sender, EventArgs eventArgs)
        {
            var notification = NSNotification.FromName(UITextField.TextFieldTextDidChangeNotification, Input);

            TextFieldTextChanged(notification);
            //ChatInput.Text = string.Empty; // this will not generate change text event
            //ScrollToBottom(true);
        }
コード例 #5
0
    public void FromName()
    {
        string text         = Guid.NewGuid().ToString("N");
        var    notification = NSNotification.FromName(text);

        Assert.AreNotEqual(IntPtr.Zero, notification.Handle);
        Assert.AreEqual(text, notification.Name);
    }
コード例 #6
0
        public override bool MakeFirstResponder(NSResponder aResponder)
        {
            var result = base.MakeFirstResponder(aResponder);

            if (result)
            {
                var notification = NSNotification.FromName(CustomWindowNotifications.WindowMakeFirstResponder, aResponder);
                NSNotificationCenter.DefaultCenter.PostNotification(notification);
            }
            return(result);
        }
コード例 #7
0
        private static NSNotification CreateNotification(string notificationName, NativeEventArgs eventArgs)
        {
            long eventArgsPtr = eventArgs != null ? eventArgs.NativeHandle : 0;

            NSDictionary <NSObject, NSObject> userInfo = NSDictionary <NSObject, NSObject> .FromObjectsAndKeys(
                new [] { NSNumber.FromInt64(eventArgsPtr) }, new [] { (NSString)KEY_EVENTARGS }, 1
                );

            NSNotification notification = NSNotification.FromName(notificationName, null, userInfo);

            return(notification);
        }
コード例 #8
0
        public void Delete(IEnumerable <Item <T> > itemsToDelete, Action <DeleteResult <T> > completionHandler)
        {
            if (IsDeletionInProgress)
            {
                return;
            }

            IsDeletionInProgress = true;

            IList <Item <T> > deletedItems = new List <Item <T> >();
            IList <Item <T> > itemsNotDeletedDueToFailure = new List <Item <T> >();


            DispatchQueue.DefaultGlobalQueue.DispatchAsync(() =>
            {
                foreach (var item in itemsToDelete)
                {
                    try
                    {
                        NSError error;
                        _fileManager.Remove(item.Url, out error);
                        deletedItems.Add(item);
                    }
                    catch (Exception e)
                    {
                        itemsNotDeletedDueToFailure.Add(item);
                    }
                }
            });

            DispatchQueue.MainQueue.DispatchAsync(() =>
            {
                if (deletedItems.Count > 0)
                {
                    NSNotificationCenter.DefaultCenter.PostNotification(NSNotification.FromName("ItemsDeleted",
                                                                                                NSArray.FromObject(deletedItems.ToArray())));
                }
                IsDeletionInProgress = false;
                var deleteResult     = new DeleteResult <T>
                {
                    NotRemovedItems = itemsNotDeletedDueToFailure,
                    RemovedItems    = deletedItems
                };
                if (itemsNotDeletedDueToFailure.Any())
                {
                    deleteResult.ErrorMessage = "Failed to remove " + itemsNotDeletedDueToFailure.Count + " items";
                }
                completionHandler?.Invoke(deleteResult);
            });
        }
コード例 #9
0
        partial void UIButtonNjzX3Y5C_TouchUpInside(UIButton sender)
        {
            var r      = textfield.Text;
            var notice = NSNotification.FromName("AquesTalkDaDoneNotify", this, null);

            var ret = AquesTalk.AquesTalk.GetInstance.Play(r, 90, notice.Handle);

            if (ret != 0)
            {
                var alertController = UIAlertController.Create("Error", "音声記号列の指定が正しくありません", UIAlertControllerStyle.Alert);
                alertController.AddAction(UIAlertAction.Create("はい", UIAlertActionStyle.Default, (obj) => { }));
                PresentViewController(alertController, true, null);
                return;
            }

            onPlayLabel.Text = "Playing...";
        }
コード例 #10
0
ファイル: DataManager.cs プロジェクト: zain-tariq/ios-samples
        // createInitialData
        //
        // The Swift version of this app has a createInitialData method.
        // Each child class of the DataManager class overrides this method, and
        // then the DataManager base class calls the derived versions to get
        // the initial data. C# gives a compiler warning for this ("Virtual
        // member call in constructor"). Since in C# the base class constructor
        // is run before the child class constructor, having the base clas
        // constructor call out to a method on the derived class is calling
        // a method on an object that has not yet been fully constructed.
        // The C# version of this sample works around this problem by passing
        // in the initial data to the constructor.

        void ObserveChangesInUserDefaults()
        {
            var weakThis = new WeakReference <DataManager <ManagedDataType> >(this);
            Action <NSObservedChange> changeHandler = (change) =>
            {
                if (weakThis.TryGetTarget(out var dataManager))
                {
                    // Ignore any change notifications coming from data this
                    // instance just saved to `NSUserDefaults`.
                    if (dataManager is null || dataManager.IgnoreLocalUserDefaultsChanges)
                    {
                        return;
                    }

                    // The underlying data changed in `NSUserDefaults`, so
                    // update this instance with the change and notify clients
                    // of the change.
                    dataManager.LoadData();
                    dataManager.NotifyClientsDataChanged();
                }
            };

            UserDefaultsObserver = UserDefaults.AddObserver(
                StorageDescriptor.Key,
                NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New,
                changeHandler
                );
        }

        // Notifies clients the data changed by posting an `NSNotification` with
        // the key `NotificationKeys.DataChanged`
        void NotifyClientsDataChanged()
        {
            var notification = NSNotification.FromName(NotificationKeys.DataChanged, this);

            NSNotificationCenter.DefaultCenter.PostNotification(notification);
        }
コード例 #11
0
        // Type of UserInfo[AppStateUserInfoKey] : ViewControllerApplicationState;
        private NSNotification StateChangedNotification(AppState state)
        {
            NSDictionary userInfo = NSDictionary.FromObjectAndKey(new SimpleBox <AppState>(state), AppStateUserInfoKey);

            return(NSNotification.FromName(ApplicationStateChangedNotificationName, this, userInfo));
        }
コード例 #12
0
        public static void OnMessageReceived(NSDictionary userInfo)
        {
            var notification = NSNotification.FromName("message_received", userInfo);

            NSNotificationCenter.DefaultCenter.PostNotification(notification);
        }
コード例 #13
0
        public static void FinishRegistration(NSData deviceToken)
        {
            var notification = NSNotification.FromName("sucess_registered", deviceToken);

            NSNotificationCenter.DefaultCenter.PostNotification(notification);
        }
コード例 #14
0
    public void FromNameDispose()
    {
        var notification = NSNotification.FromName("WOOT");

        notification.Dispose();
    }
コード例 #15
0
        public static void startStopServer(NSToolbarItem item)
        {
            _serverToolbarItem = item;
            if (_serverToolbarDefaultImage == null)
            {
                _serverToolbarDefaultImage = item.Image;
            }

            // stop the server if it is running
            if (_serverProcess != null)
            {
                stopServer();
                item.Image = _serverToolbarDefaultImage;
                return;
            }


            item.Image = NSImage.ImageNamed("server-on.png");

            var startInfo = new ProcessStartInfo
            {
                Arguments              = "server -D",
                FileName               = getPathToHugo(),
                WindowStyle            = ProcessWindowStyle.Hidden,
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                WorkingDirectory       = Constants.hugoProjectPath
            };

            _serverProcess           = new Process();
            _serverProcess.StartInfo = startInfo;

            _serverProcess.OutputDataReceived += (sender, args) =>
            {
                if (args.Data == null)
                {
                    return;
                }

                try
                {
                    Console.WriteLine(args.Data);
                    NSNotificationCenter.DefaultCenter.PostNotification(NSNotification.FromName(Constants.logNotificationKey, new NSString(args.Data)));

                    if (args.Data.Contains("Web Server is available"))
                    {
                        NSNotificationCenter.DefaultCenter.PostNotificationName(Constants.serverStartedNotificationKey, null);

                        // get the port number and open the web page
                        var match = new Regex(@"\d+").Match(args.Data);
                        if (match.Success)
                        {
                            serverUrl = "http://localhost:" + match.Value;
                            Process.Start(serverUrl);
                            NSNotificationCenter.DefaultCenter.PostNotificationName(Constants.serverFoundUrlNotificationKey, null, new NSDictionary("url", serverUrl));
                        }
                    }
                    else if (args.Data.Contains("Press Ctrl+C to stop"))
                    {
                        Console.WriteLine("server appears to be running");
                    }
                    else if (args.Data.Contains("rebuilding site"))
                    {
                        NSNotificationCenter.DefaultCenter.PostNotification(NSNotification.FromName(Constants.siteRebuiltNotificationKey, null));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            };

            try
            {
                _serverProcess.Start();
                _serverProcess.BeginOutputReadLine();
                Console.ReadLine();
                //stdError = _serverProcess.StandardError.ReadToEnd();
                //_serverProcess.WaitForExit();
            }
            catch (Exception e)
            {
                throw new Exception("OS error while executing " + e.Message, e);
            }
        }