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);
        }
        /// <summary>
        /// Fill the data which is missing due to new columns in the database.
        /// </summary>
        public static void FillMissingData(Config.SyncConfig.Folder syncFolder, SQLiteConnection connection)
        {
            Utils.NotifyUser("CmisSync needs to upgrade its own local data for folder \"" + syncFolder.RepositoryId +
                             "\".\nPlease stay on the network during that time, sorry for the inconvenience." +
                             "\nIt can take up to HOURS if you have many files, thank you for your patience." +
                             "\nA notification will pop up when it is done.");

            var session = Auth.Authentication.GetCmisSession(
                ((Uri)syncFolder.RemoteUrl).ToString(),
                syncFolder.UserName,
                Crypto.Deobfuscate(syncFolder.ObfuscatedPassword),
                syncFolder.RepositoryId);

            var filters = new HashSet <string>();

            filters.Add("cmis:objectId");
            string remoteRootFolder = syncFolder.RemotePath;
            string localRootFolder  = syncFolder.LocalPath.Substring(ConfigManager.CurrentConfig.FoldersPath.Length + 1);

            try
            {
                using (var command = new SQLiteCommand(connection))
                {
                    // Fill missing columns of all files.
                    command.CommandText = "SELECT path FROM files WHERE id IS NULL or localPath IS NULL;";
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            // Example: "old-db-1.0.13/テスト・テスト/テスト用ファイル.pptx"
                            string legacyPath = reader["path"].ToString();

                            // Example:  テスト・テスト/テスト用ファイル.pptx
                            string remoteRelativePath = legacyPath.Substring(localRootFolder.Length + 1);

                            // Example: /Sites/cmissync/documentLibrary/tests/テスト・テスト/テスト用ファイル.pptx
                            string remotePath = remoteRootFolder + "/" + remoteRelativePath;

                            // Example: テスト・テスト/テスト用ファイル.pptx
                            string localPath = PathRepresentationConverter.RemoteToLocal(legacyPath.Substring(localRootFolder.Length + 1));

                            string id = null;
                            try
                            {
                                id = session.GetObjectByPath(remotePath, true).Id;
                            }
                            catch (DotCMIS.Exceptions.CmisObjectNotFoundException e)
                            {
                                Logger.Info(String.Format("File Not Found: \"{0}\"", remotePath), e);
                            }
                            catch (DotCMIS.Exceptions.CmisPermissionDeniedException e)
                            {
                                Logger.Info(String.Format("PermissionDenied: \"{0}\"", remotePath), e);
                            }

                            var parameters = new Dictionary <string, object>();
                            parameters.Add("@id", id);
                            parameters.Add("@remotePath", remoteRelativePath);
                            parameters.Add("@localPath", localPath);
                            parameters.Add("@path", legacyPath);
                            ExecuteSQLAction(connection, "UPDATE files SET id = @id, path = @remotePath, localPath = @localPath WHERE path = @path;", parameters);
                        }
                    }

                    // Fill missing columns of all folders.
                    command.CommandText = "SELECT path FROM folders WHERE id IS NULL or localPath IS NULL;";
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string legacyPath         = reader["path"].ToString();
                            string remoteRelativePath = legacyPath.Substring(localRootFolder.Length + 1);
                            string remotePath         = remoteRootFolder + "/" + remoteRelativePath;
                            string localPath          = PathRepresentationConverter.RemoteToLocal(legacyPath.Substring(localRootFolder.Length + 1));
                            string id = null;
                            try
                            {
                                id = session.GetObjectByPath(remotePath, true).Id;
                            }
                            catch (DotCMIS.Exceptions.CmisObjectNotFoundException e)
                            {
                                Logger.Info(String.Format("File Not Found: \"{0}\"", remotePath), e);
                            }
                            catch (DotCMIS.Exceptions.CmisPermissionDeniedException e)
                            {
                                Logger.Info(String.Format("PermissionDenied: \"{0}\"", remotePath), e);
                            }

                            var parameters = new Dictionary <string, object>();
                            parameters.Add("@id", id);
                            parameters.Add("@remotePath", remoteRelativePath);
                            parameters.Add("@localPath", localPath);
                            parameters.Add("@path", legacyPath);
                            ExecuteSQLAction(connection, "UPDATE folders SET id = @id, path = @remotePath, localPath = @localPath WHERE path = @path;", parameters);
                        }
                    }

                    {
                        // Replace repository path prefix.
                        // Before: C:\Users\myuser\CmisSync
                        // After:  C:\Users\myuser\CmisSync\myfolder

                        // Read existing prefix.

                        string newPrefix = syncFolder.LocalPath;

                        var parameters = new Dictionary <string, object>();
                        parameters.Add("prefix", newPrefix);
                        ExecuteSQLAction(connection, "INSERT OR REPLACE INTO general (key, value) VALUES (\"PathPrefix\", @prefix)", parameters);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Info("Failed to migrate \"" + syncFolder.RepositoryId + "\".", e);
                Utils.NotifyUser("Failure while migrating folder \"" + syncFolder.RepositoryId + "\".");
                throw;
            }

            Utils.NotifyUser("CmisSync has finished upgrading its own local data for folder \"" + syncFolder.RepositoryId + "\".");
        }
Exemple #5
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 #6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public Controller()
     : base()
 {
     CmisSync.Lib.Utils.SetUserNotificationListener(this);
     PathRepresentationConverter.SetConverter(new WindowsPathRepresentationConverter());
 }
Exemple #7
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 #8
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);
        }