Example #1
0
 public CommitCop(HgRepository repository, ChorusFileTypeHandlerCollection handlers, IProgress progress)
 {
     _repository = repository;
     _handlerCollection = handlers;
     _progress = progress;
     ValidateModifiedFiles();
 }
Example #2
0
 public Synchronizer(string localRepositoryPath, ProjectFolderConfiguration project, IProgress progress)
 {
     _progress = progress;
     _project = project;
     _localRepositoryPath = localRepositoryPath;
     _handlers = ChorusFileTypeHandlerCollection.CreateWithInstalledHandlers();
     ExtraRepositorySources = new List<RepositoryAddress>();
     ExtraRepositorySources.Add(RepositoryAddress.Create(RepositoryAddress.HardWiredSources.UsbKey, "USB flash drive", false));
 }
Example #3
0
        public static ChorusFileTypeHandlerCollection CreateWithTestHandlerOnly()
        {
            var fileTypeHandlers = new ChorusFileTypeHandlerCollection();

            fileTypeHandlers.HandlersList.Add(new ChorusTestFileHandler());

            // NB: Never add the Default handler. [RBR says: "Not to worry, since a test makes sure it is not in 'fileTypeHandlers'."]
            return(fileTypeHandlers);
        }
        public ChangesInRevisionModel(RevisionInspector revisionInspector,
									  ChangedRecordSelectedEvent changedRecordSelectedEventToRaise,
									   NavigateToRecordEvent navigateToRecordEventToRaise,
									 RevisionSelectedEvent revisionSelectedEventToSubscribeTo,
									  ChorusFileTypeHandlerCollection fileHandlers)
        {
            _revisionInspector = revisionInspector;
            _changedRecordSelectedEventToRaise = changedRecordSelectedEventToRaise;
            _navigateToRecordEvent = navigateToRecordEventToRaise;
            _fileHandlers = fileHandlers;
            revisionSelectedEventToSubscribeTo.Subscribe(SetRevision);
        }
Example #5
0
        public ChangeReportView(ChorusFileTypeHandlerCollection handlers, ChangedRecordSelectedEvent changedRecordSelectedEvent, HgRepository repository, IEnumerable<IWritingSystem> writingSystems)
        {
            this.Font = SystemFonts.MessageBoxFont;
            _handlers = handlers;
            _repository = repository;
            InitializeComponent();
            _normalChangeDescriptionRenderer.Font = SystemFonts.MessageBoxFont;
            changedRecordSelectedEvent.Subscribe(r=>LoadReport(r));
            _normalChangeDescriptionRenderer.Navigated += webBrowser1_Navigated;

            _styleSheet = CreateStyleSheet(writingSystems);
        }
Example #6
0
        ///<summary>
        /// Filter the files, before the commit. Files that are too large are added to the exclude section of the configuration.
        ///</summary>
        ///<returns>An empty string or a string with a listing of files that were not added/modified.</returns>
        public static string FilterFiles(HgRepository repository, ProjectFolderConfiguration configuration, ChorusFileTypeHandlerCollection handlerCollection)
        {
            var messageBuilder = new StringBuilder();
            Dictionary<string, Dictionary<string, List<string>>> fileStatusDictionary = GetStatusOfFilesOfInterest(repository, configuration);
            Dictionary<string, uint> extensionToMaximumSize = CacheMaxSizesOfExtension(handlerCollection);

            foreach (KeyValuePair<string, Dictionary<string, List<string>>> filesOfOneStatus in fileStatusDictionary)
            {
                var userNotificationMessageBase = "File '{0}' is too large to include in the Send/Receive system. It is {1}, but the maximum allowed is {2}. The file is at {3}.";
                var forgetItIfTooLarge = false;

                switch (filesOfOneStatus.Key)
                {
                    case "M": // modified
                        // May have grown too large.
                        // Untrack it (forget), if is too large and keep out.
                        forgetItIfTooLarge = true;
                        userNotificationMessageBase = "File '{0}' has grown too large to include in the Send/Receive system.  It is {1}, but the maximum allowed is {2}. The file is at {3}.";
                        //FilterModifiedFiles(repository, configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository), statusCheckResultKvp.Value);
                        break;
                    case "A": // marked for 'add' with; hg add
                        // Untrack it (forget), if is too large and keep out.
                        forgetItIfTooLarge = true;
                        //FilterAddedFiles(repository, configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository), statusCheckResultKvp.Value);
                        break;
                    case "?": // untracked, but going to be added.
                        // Keep out, if too large.
                        //FilterUntrackedFiles(configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository), statusCheckResultKvp.Value);
                        break;

                    //case "!": // tracked but deleted. Fall through
                    //case "R": // tracked, and marked for removal with: hg rm
                        // No need to mess with these ones.
                    //	break;
                    // If there are other keys, we don't really care about them.
                }
                Dictionary<string, List<string>> extensionToFilesDictionary = filesOfOneStatus.Value;
                FilterFiles(repository, configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository),
                            extensionToFilesDictionary, userNotificationMessageBase, forgetItIfTooLarge);
            }

            var result = messageBuilder.ToString();
            return string.IsNullOrEmpty(result) ? null : result;
        }
Example #7
0
        /// <summary>
        /// This will eventually done using MEF or some other dynamic way of finding available HandlersList
        /// </summary>
        /// <returns></returns>
        public static ChorusFileTypeHandlerCollection CreateWithInstalledHandlers()
        {
            var fileTypeHandlers = new ChorusFileTypeHandlerCollection();

            var libChorusAssembly = Assembly.GetExecutingAssembly();

            //Set the codebase variable appropriately depending on the OS
            var codeBase = libChorusAssembly.CodeBase.Substring(LinuxUtils.IsUnix ? 7 : 8);

            var dirname = Path.GetDirectoryName(codeBase);
            //var baseDir = new Uri(dirname).AbsolutePath; // NB: The Uri class in Windows and Mono are not the same.
            var baseDir          = dirname;
            var pluginAssemblies = new List <Assembly>
            {
                libChorusAssembly
            };

            foreach (var pluginDllPathname in Directory.GetFiles(baseDir, "*ChorusPlugin.dll", SearchOption.TopDirectoryOnly))
            {
                pluginAssemblies.Add(Assembly.LoadFrom(Path.Combine(baseDir, pluginDllPathname)));
            }

            foreach (var pluginAssembly in pluginAssemblies)
            {
                var fileHandlerTypes = (pluginAssembly.GetTypes()
                                        .Where(typeof(IChorusFileTypeHandler).IsAssignableFrom)).ToList();
                foreach (var fileHandlerType in fileHandlerTypes)
                {
                    if (fileHandlerType.Name == "DefaultFileTypeHandler" || fileHandlerType.IsInterface)
                    {
                        continue;
                    }
                    var constInfo = fileHandlerType.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null);
                    if (constInfo == null)
                    {
                        continue;                         // It does need at least one public or non-public default constructor.
                    }
                    fileTypeHandlers.HandlersList.Add((IChorusFileTypeHandler)constInfo.Invoke(BindingFlags.Public | BindingFlags.NonPublic, null, null, null));
                }
            }

            // NB: Never add the Default handler. [RBR says: "Not to worry, since a test makes sure it is not in 'fileTypeHandlers'."]
            return(fileTypeHandlers);
        }
Example #8
0
        private static Dictionary<string, uint> CacheMaxSizesOfExtension(ChorusFileTypeHandlerCollection handlerCollection)
        {
            var cacheExtensionToMaxSize = new Dictionary<string, uint>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var handler in handlerCollection.Handlers)
            {
                var maxForHandler = handler.MaximumFileSize;
                foreach (var extension in handler.GetExtensionsOfKnownTextFileTypes())
                {
                    uint extantMax;
                    if (cacheExtensionToMaxSize.TryGetValue(extension, out extantMax))
                    {
                        // Use larger value, if two handlers are fighting for it.
                        cacheExtensionToMaxSize[extension] = (maxForHandler >= extantMax) ? maxForHandler : extantMax;
                    }
                    else
                    {
                        cacheExtensionToMaxSize.Add(extension, maxForHandler);
                    }
                }
            }

            return cacheExtensionToMaxSize;
        }
 public RevisionInspector(HgRepository repository, ChorusFileTypeHandlerCollection fileHandlerCollection)
 {
     Repository = repository;
     _fileHandlerCollection = fileHandlerCollection;
     ProgressIndicator = new NullProgress();
 }
        public static ChorusFileTypeHandlerCollection CreateWithTestHandlerOnly()
        {
            var fileTypeHandlers = new ChorusFileTypeHandlerCollection();

            fileTypeHandlers.HandlersList.Add(new ChorusTestFileHandler());

            // NB: Never add the Default handler. [RBR says: "Not to worry, since a test makes sure it is not in 'fileTypeHandlers'."]
            return fileTypeHandlers;
        }
        /// <summary>
        /// This will eventually done using MEF or some other dynamic way of finding available HandlersList
        /// </summary>
        /// <returns></returns>
        public static ChorusFileTypeHandlerCollection CreateWithInstalledHandlers()
        {
            var fileTypeHandlers = new ChorusFileTypeHandlerCollection();

            var libChorusAssembly = Assembly.GetExecutingAssembly();

            //Set the codebase variable appropriately depending on the OS
            var codeBase = libChorusAssembly.CodeBase.Substring(LinuxUtils.IsUnix ? 7 : 8);

            var dirname = Path.GetDirectoryName(codeBase);
            //var baseDir = new Uri(dirname).AbsolutePath; // NB: The Uri class in Windows and Mono are not the same.
            var baseDir = dirname;
            var pluginAssemblies = new List<Assembly>
                                    {
                                        libChorusAssembly
                                    };
            foreach (var pluginDllPathname in Directory.GetFiles(baseDir, "*ChorusPlugin.dll", SearchOption.TopDirectoryOnly))
                pluginAssemblies.Add(Assembly.LoadFrom(Path.Combine(baseDir, pluginDllPathname)));

            foreach (var pluginAssembly in pluginAssemblies)
            {
                var fileHandlerTypes = (pluginAssembly.GetTypes()
                    .Where(typeof (IChorusFileTypeHandler).IsAssignableFrom)).ToList();
                foreach (var fileHandlerType in fileHandlerTypes)
                {
                    if (fileHandlerType.Name == "DefaultFileTypeHandler" || fileHandlerType.IsInterface)
                        continue;
                    var constInfo = fileHandlerType.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null);
                    if (constInfo == null)
                        continue; // It does need at least one public or non-public default constructor.
                    fileTypeHandlers.HandlersList.Add((IChorusFileTypeHandler)constInfo.Invoke(BindingFlags.Public | BindingFlags.NonPublic, null, null, null));
                }
            }

            // NB: Never add the Default handler. [RBR says: "Not to worry, since a test makes sure it is not in 'fileTypeHandlers'."]
            return fileTypeHandlers;
        }
        public void TestFixtureSetup()
        {
            _handlersColl = ChorusFileTypeHandlerCollection.CreateWithTestHandlerOnly();
            var testHandler = (from handler in _handlersColl.Handlers
                               select handler).First();

            _goodData = "good" + Environment.NewLine;
            for (var i = 1; i < testHandler.MaximumFileSize; i += _goodData.Length)
                _goodData += _goodData;

            _longData = _goodData + _goodData;
        }