Exemple #1
0
        /// <summary>
        /// Main method, pass folder name as argument.
        /// </summary>
        public static int Main(string[] args)
        {
            Utils.ConfigureLogging();
            PathRepresentationConverter.SetConverter(new WindowsPathRepresentationConverter());

            CmisSyncOnce once = new CmisSyncOnce();

            // Load the specified synchronized folders, or all if none is specified.
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    once.AddSynchronizedFolder(args[i]);
                }
            }
            else
            {
                Config config = ConfigManager.CurrentConfig;
                foreach (CmisSync.Lib.Config.SyncConfig.Folder folder in config.Folders)
                {
                    RepoInfo repoInfo = folder.GetRepoInfo();
                    once.repos.Add(repoInfo);
                }
            }

            // Synchronize all
            bool success = once.Sync();

            // Exit code 0 if synchronization was successful or not needed,
            // 1 if synchronization failed, or could not run.
            return(success ? 0 : 1);
        }
Exemple #2
0
        public Controller() : base()
        {
            using (var a = new NSAutoreleasePool())
            {
                NSApplication.Init();
            }

            // We get the Default notification Center
            notificationCenter = NSUserNotificationCenter.DefaultUserNotificationCenter;

            // Clear old notifications
            foreach (var n in notificationCenter.DeliveredNotifications)
            {
                notificationCenter.RemoveDeliveredNotification(n);
            }

            notificationCenter.DidDeliverNotification += (s, e) =>
            {
                Console.WriteLine("Notification Delivered");
            };

            // If the notification is clicked, displays the entire message.
            notificationCenter.DidActivateNotification += (object sender, UNCDidActivateNotificationEventArgs e) =>
            {
                var notification = (UserNotification)e.Notification;

                if (notification.Kind == UserNotification.NotificationKind.Normal)
                {
                    notificationCenter.RemoveDeliveredNotification(e.Notification);
                    string  msg   = notificationMessages[notification.Id];
                    NSAlert alert = NSAlert.WithMessage(notification.Title, "OK", null, null, msg);
                    notificationMessages.Remove(notification.Id);
                    alert.Icon = new NSImage(System.IO.Path.Combine(NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error.icns"));
                    alert.Window.OrderFrontRegardless();
                    alert.RunModal();
                }
                else
                {
                    LocalFolderClicked(Path.GetDirectoryName(e.Notification.InformativeText));
                }
            };

            // If we return true here, Notification will show up even if your app is TopMost.
            notificationCenter.ShouldPresentNotification = (c, n) => { return(true); };

            AlertNotificationRaised += delegate(string title, string message) {
                var alert = new NSAlert {
                    MessageText = message,
                    AlertStyle  = NSAlertStyle.Informational
                };

                alert.AddButton("OK");

                alert.RunModal();
            };

            Utils.SetUserNotificationListener(this);
            PathRepresentationConverter.SetConverter(new OSXPathRepresentationConverter());
        }
Exemple #3
0
        /// <summary>
        /// Main method, pass folder name as argument.
        /// </summary>
        public static int Main(string[] args)
        {
            System.Console.WriteLine("Started CmisSyncOnce");
            Utils.ConfigureLogging();
            Logger.Info("Starting. Version: " + CmisSync.Lib.Backend.Version);

            // Uncomment this line to disable SSL checking (for self-signed certificates)
            // ServicePointManager.CertificatePolicy = new YesCertPolicyHandler();

            PathRepresentationConverter.SetConverter(new WindowsPathRepresentationConverter());

            CmisSyncOnce once = new CmisSyncOnce();

            // Load the specified synchronized folders, or all if none is specified.
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    once.AddSynchronizedFolder(args[i]);
                }
            }
            else
            {
                Config config = ConfigManager.CurrentConfig;
                foreach (CmisSync.Lib.Config.SyncConfig.Folder folder in config.Folders)
                {
                    RepoInfo repoInfo = folder.GetRepoInfo();
                    once.repos.Add(repoInfo);
                }
            }

            // Synchronize all
            bool success = once.Sync();

            //System.Console.WriteLine("Press enter to close...");
            //System.Console.ReadLine();

            // Exit code 0 if synchronization was successful or not needed,
            // 1 if synchronization failed, or could not run.
            return(success ? 0 : 1);
        }
Exemple #4
0
        public Controller() : base()
        {
            using (var a = new NSAutoreleasePool())
            {
                NSApplication.Init();
            }

            // We get the Default notification Center
            notificationCenter = NSUserNotificationCenter.DefaultUserNotificationCenter;

            // Clear old notifications
            foreach (var n in notificationCenter.DeliveredNotifications)
            {
                notificationCenter.RemoveDeliveredNotification(n);
            }

            notificationCenter.DidDeliverNotification += (s, e) =>
            {
                Console.WriteLine("Notification Delivered");
            };

            // If the notification is clicked, displays the entire message.
            notificationCenter.DidActivateNotification += (object sender, UNCDidActivateNotificationEventArgs e) =>
            {
                var notification = (UserNotification)e.Notification;

                if (notification.Kind == UserNotification.NotificationKind.Normal)
                {
                    notificationCenter.RemoveDeliveredNotification(e.Notification);
                    string  msg   = notificationMessages[notification.Id];
                    NSAlert alert = NSAlert.WithMessage(notification.Title, "OK", null, null, msg);
                    notificationMessages.Remove(notification.Id);
                    alert.Icon = new NSImage(System.IO.Path.Combine(NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error.icns"));
                    alert.Window.OrderFrontRegardless();
                    alert.RunModal();
                }
                else
                {
                    LocalFolderClicked(Path.GetDirectoryName(e.Notification.InformativeText));
                }
            };

            // If we return true here, Notification will show up even if your app is TopMost.
            notificationCenter.ShouldPresentNotification = (c, n) => { return(true); };

            OnTransmissionListChanged += delegate {
                using (var a = new NSAutoreleasePool()) {
                    notificationCenter.BeginInvokeOnMainThread(delegate {
                        lock (transmissionLock) {
                            List <FileTransmissionEvent> transmissions      = ActiveTransmissions();
                            NSUserNotification[] notifications              = notificationCenter.DeliveredNotifications;
                            List <NSUserNotification> finishedNotifications = new List <NSUserNotification> ();
                            foreach (NSUserNotification notification in notifications)
                            {
                                FileTransmissionEvent transmission = transmissions.Find((FileTransmissionEvent e) => { return(e.Path == notification.InformativeText); });
                                if (transmission == null)
                                {
                                    finishedNotifications.Add(notification);
                                }
                                else
                                {
                                    if (transmissionFiles.ContainsKey(transmission.Path))
                                    {
                                        transmissions.Remove(transmission);
                                    }
                                    else
                                    {
                                        notificationCenter.RemoveDeliveredNotification(notification);
                                    }
                                }
                            }
                            finishedNotifications.Sort(new ComparerNSUserNotification());
                            for (int i = 0; i < (notifications.Length - notificationKeep) && i < finishedNotifications.Count; ++i)
                            {
                                notificationCenter.RemoveDeliveredNotification(finishedNotifications[i]);
                            }
                            foreach (FileTransmissionEvent transmission in transmissions)
                            {
                                if (transmission.Status.Aborted == true)
                                {
                                    continue;
                                }
                                if (transmission.Status.Completed == true)
                                {
                                    continue;
                                }
                                if (transmission.Status.FailedException != null)
                                {
                                    continue;
                                }
                                var notification = new UserNotification(UserNotification.NotificationKind.Transmission);
                                // NSUserNotification notification = new NSUserNotification();
                                notification.Title           = Path.GetFileName(transmission.Path);
                                notification.Subtitle        = TransmissionStatus(transmission);
                                notification.InformativeText = transmission.Path;
                                notificationMessages.Add(notification.Id, transmission.Path);
//                                notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName;
                                transmission.TransmissionStatus += TransmissionReport;
                                // notification.DeliveryDate = NSDate.Now;
                                notificationCenter.DeliverNotification(notification);
                                transmissionFiles.Add(transmission.Path, notification.DeliveryDate);
                                UpdateFileStatus(transmission, null);
                            }
                        }
                    });
                }
            };

            AlertNotificationRaised += delegate(string title, string message) {
                var alert = new NSAlert {
                    MessageText = message,
                    AlertStyle  = NSAlertStyle.Informational
                };

                alert.AddButton("OK");

                alert.RunModal();
            };

            Utils.SetUserNotificationListener(this);
            PathRepresentationConverter.SetConverter(new OSXPathRepresentationConverter());
        }
Exemple #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public Controller()
     : base()
 {
     CmisSync.Lib.Utils.SetUserNotificationListener(this);
     PathRepresentationConverter.SetConverter(new WindowsPathRepresentationConverter());
 }
Exemple #6
0
        /// <summary>
        /// Main method, pass folder name as argument.
        /// </summary>
        public static int Main(string[] args)
        {
            System.Console.WriteLine("Started CmisSyncOnce");
            Utils.ConfigureLogging();
            Logger.Info("Starting. Version: " + CmisSync.Lib.Backend.Version);

            // Uncomment this line to disable SSL checking (for self-signed certificates)
            // ServicePointManager.CertificatePolicy = new YesCertPolicyHandler();

            PathRepresentationConverter.SetConverter(new WindowsPathRepresentationConverter());

            bool perpetual = false;

            CmisSyncConsole instance = null;

            // -p means perpetual.
            if (args.Length > 0 && "-p".Equals(args[0]))
            {
                perpetual = true;
            }

            // Get optional config file from command line argument -c

            instance = new CmisSyncConsole(perpetual);

            // Load the specified synchronized folders, or all if none is specified.
            if (args.Length > 1 || (!perpetual && args.Length > 0))
            {
                int i = 0;

                // Skip the -p argument if present.
                if ("-p".Equals(args[0]))
                {
                    i++;
                }

                for (; i < args.Length; i++)
                {
                    instance.AddSynchronizedFolder(args[i]);
                }
            }
            else
            {
                // No specific folders given, so load all folders.

                Config config = ConfigManager.CurrentConfig;
                foreach (CmisSync.Lib.Config.SyncConfig.Folder folder in config.Folders)
                {
                    RepoInfo repoInfo = folder.GetRepoInfo();
                    CmisRepo cmisRepo = new CmisRepo(repoInfo, controller, false, perpetual);
                    instance.repos.Add(cmisRepo);
                }
            }

            // Synchronize all
            bool success = instance.Run();

            System.Console.WriteLine("Press enter to close...");
            System.Console.ReadLine();

            // Exit code 0 if synchronization was successful or not needed,
            // 1 if synchronization failed, or could not run.
            return(success ? 0 : 1);
        }
Exemple #7
0
        /// <summary>
        /// Main method, pass folder name as argument.
        /// </summary>
        public static int Main(string[] argumentsArray)
        {
            System.Console.WriteLine("Started CmisSyncOnce");

            // Uncomment this line to disable SSL checking (for self-signed certificates)
            // ServicePointManager.CertificatePolicy = new YesCertPolicyHandler();

            PathRepresentationConverter.SetConverter(new WindowsPathRepresentationConverter());

            var  argumentsList = new List <string>(argumentsArray);
            bool perpetual     = false;

            CmisSyncConsole instance = null;

            // -p means perpetual.
            if (argumentsList.Count >= 1 && "-p".Equals(argumentsList[0]))
            {
                perpetual = true;
                argumentsList.RemoveAt(0);
            }

            // Get optional config file from command line argument -c
            if (argumentsList.Count >= 2 && "-c".Equals(argumentsList[0]))
            {
                System.Console.WriteLine("argument -c");
                // Set the config file to use.
                ConfigManager.CurrentConfigFile = argumentsList[1];

                argumentsList.RemoveAt(0); // Remove -c
                argumentsList.RemoveAt(0); // Remove the path
            }
            System.Console.WriteLine("config: " + ConfigManager.CurrentConfigFile);

            // Now that we have the config, we can start logging (the log file location is in the config).
            Utils.ConfigureLogging();
            Logger.Info("Starting. Version: " + CmisSync.Lib.Backend.Version);

            instance = new CmisSyncConsole(perpetual);

            // Load the specified synchronized folders, or all if none is specified.
            bool enableWatcher = perpetual; // We consider that the watcher is only desirable for perpetual synchronization.

            if (argumentsList.Count >= 1)
            {
                foreach (var argument in argumentsList)
                {
                    instance.AddSynchronizedFolder(argument, enableWatcher);
                }
            }
            else
            {
                // No specific folders given, so load all folders.

                foreach (CmisSync.Lib.Config.SyncConfig.Folder folder in ConfigManager.CurrentConfig.Folders)
                {
                    RepoInfo repoInfo = folder.GetRepoInfo();
                    CmisRepo cmisRepo = new CmisRepo(repoInfo, controller, enableWatcher, perpetual);
                    instance.repos.Add(cmisRepo);
                }
            }

            // Synchronize all
            bool success = instance.Run();

            // Only for testing in an IDE, to see what happened in the console window before it gets closed by the IDE.
            //System.Console.WriteLine("Press enter to close...");
            //System.Console.ReadLine();

            // Exit code 0 if synchronization was successful or not needed,
            // 1 if synchronization failed, or could not run.
            return(success ? 0 : 1);
        }