示例#1
0
        private bool CopyFiles(FileSystemPath pluginDir)
        {
            var updatedFileCount    = 0;
            var existingPluginFiles = pluginDir.GetChildFiles();

            foreach (var filename in ourPluginFiles)
            {
                var path = pluginDir.Combine(filename);
                if (existingPluginFiles.Contains(path))
                {
                    continue;
                }

                var resourceName = resourceNamespace + filename;
                using (var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    if (resourceStream == null)
                    {
                        myLogger.LogMessage(LoggingLevel.ERROR, "Plugin file not found in manifest resources. " + filename);
                        return(false);
                    }

                    using (var fileStream = path.OpenStream(FileMode.CreateNew))
                    {
                        resourceStream.CopyTo(fileStream);
                        updatedFileCount++;
                    }
                }
            }

            return(updatedFileCount > 0);
        }
示例#2
0
        private bool TryFindExistingPluginOnDisk(FileSystemPath directory, Version newVersion, [NotNull] out InstallationInfo result)
        {
            myLogger.Verbose("Looking for plugin on disk: '{0}'", directory);
            var oldPluginFiles = directory
                                 .GetChildFiles("*.cs")
                                 .Where(f => PluginCsFile == f.Name)
                                 .ToList();

            var pluginFiles = directory
                              .GetChildFiles("*.dll")
                              .Where(f => f.Name == PluginPathsProvider.BasicPluginDllFile)
                              .ToList();

            pluginFiles.AddRange(oldPluginFiles);
            if (pluginFiles.Count == 0)
            {
                result = InstallationInfo.DoNotInstall;
                return(false);
            }

            result = GetInstallationInfoFromFoundInstallation(pluginFiles, newVersion);
            return(true);
        }
        private bool TryFindOnDisk(FileSystemPath directory, [NotNull] out InstallationInfo result)
        {
            myLogger.Verbose("Looking for plugin on disk: '{0}'", directory);
            var oldPluginFiles = directory
                                 .GetChildFiles("*.cs")
                                 .Where(f => ourPluginCsFile.Contains(f.Name))
                                 .ToList();

            var pluginFiles = directory
                              .GetChildFiles("*.dll")
                              .Where(f => f.Name == PluginDllFile)
                              .ToList();

            pluginFiles.AddRange(oldPluginFiles);

            if (pluginFiles.Count == 0)
            {
                result = ShouldNotInstall;
                return(false);
            }

            result = ExistingInstallation(pluginFiles);
            return(true);
        }
示例#4
0
        private bool TryFindExistingPluginOnDiskInFolderRecursive(FileSystemPath directory, Version newVersion, [NotNull] out InstallationInfo result)
        {
            myLogger.Verbose("Looking for plugin on disk: '{0}'", directory);

            var pluginFiles = directory
                              .GetChildFiles("*.dll", PathSearchFlags.RecurseIntoSubdirectories)
                              .Where(f => f.Name == PluginPathsProvider.BasicPluginDllFile)
                              .ToList();

            if (pluginFiles.Count == 0)
            {
                result = InstallationInfo.DoNotInstall;
                return(false);
            }

            result = GetInstallationInfoFromFoundInstallation(pluginFiles, newVersion);
            return(true);
        }
示例#5
0
        public FindAndLoadSettings(Lifetime lifetimeComponent, SettingsStorageProvidersCollection publisher, SolutionFileLocationLive solfile, IThreading threading, IFileSystemTracker filetracker, FileSettingsStorageBehavior behavior, ISolution solution, IShellLocks locks)
        {
            // In case the solution path changes, watch each value anew
            solfile.SolutionFileLocation.ForEachValue_NotNull(lifetimeComponent, (lifetimeLocation, location) =>
            {
                double priority = ProjectModelSettingsStorageMountPointPriorityClasses.SolutionShared;
                for (FileSystemPath dir = location.Directory; !dir.IsNullOrEmpty(); dir = dir.Directory)
                {
                    try
                    {
                        priority *= .9; // The upper folder, the lower priority (regular solution-shared file takes over all of them)

                        // Walk up folders
                        // TODO: add file-system-watcher here
                        foreach (FileSystemPath settingsfile in dir.GetChildFiles("*." + AutoLoadExtension, PathSearchFlags.ExcludeDirectories | PathSearchFlags.ExcludeHidden))
                        {
                            var relativePath = settingsfile.MakeRelativeTo(location.Directory).FullPath;
                            var name         = relativePath.Replace("." + AutoLoadExtension, "");

                            // Physical storage
                            IProperty <FileSystemPath> livepath = new Property <FileSystemPath>(lifetimeLocation, "StoragePath", settingsfile);
                            var storage = new XmlFileSettingsStorage(lifetimeLocation, name, livepath, SettingsStoreSerializationToXmlDiskFile.SavingEmptyContent.KeepFile, threading, filetracker, behavior, null);

                            // Mount as a layer
                            IIsAvailable availability        = new IsAvailableByDataConstant <ISolution>(lifetimeLocation, ProjectModelDataConstants.SOLUTION, solution, locks); // Only when querying in solution context (includes Application-Wide)
                            ISettingsStorageMountPoint mount = new SettingsStorageMountPoint(storage.Storage, SettingsStorageMountPoint.MountPath.Default, 0, priority, availability, name);

                            // Metadata
                            livepath.FlowInto(lifetimeLocation, mount.Metadata.GetOrCreateProperty(UserFriendlySettingsLayers.DiskFilePath, null, true));
                            mount.Metadata.Set(UserFriendlySettingsLayers.Origin, string.Format("Automatically loaded from solution parent folder, \"{0}\"", relativePath));
                            mount.Metadata.Set(UserInjectedSettingsLayers.IsHostingUserInjections, true);

                            // Publish
                            publisher.Storages.Add(lifetimeLocation, storage.Storage);
                            publisher.MountPoints.Add(lifetimeLocation, mount);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(ex);
                    }
                }
            });
        }