Esempio n. 1
0
        public bool TryAddDescriptorForLocation(Guid mountPointId, out IReadOnlyList <IInstallUnitDescriptor> descriptorList)
        {
            IMountPoint mountPoint = null;

            try
            {
                if (!((SettingsLoader)(_environmentSettings.SettingsLoader)).TryGetMountPointFromId(mountPointId, out mountPoint))
                {
                    descriptorList = null;
                    return(false);
                }

                if (InstallUnitDescriptorFactory.TryCreateFromMountPoint(_environmentSettings, mountPoint, out descriptorList))
                {
                    foreach (IInstallUnitDescriptor descriptor in descriptorList)
                    {
                        AddOrReplaceDescriptor(descriptor);
                    }
                }
                else
                {
                    return(false);
                }
            }
            finally
            {
                if (mountPoint != null)
                {
                    _environmentSettings.SettingsLoader.ReleaseMountPoint(mountPoint);
                }
            }

            return(true);
        }
 public FileSystemMountPoint(IEngineEnvironmentSettings environmentSettings, IMountPoint parent, MountPointInfo info)
 {
     EnvironmentSettings = environmentSettings;
     _paths = new Paths(environmentSettings);
     Info   = info;
     Root   = new FileSystemDirectory(this, "/", "", info.Place);
 }
Esempio n. 3
0
        private bool TryCopyForNonFileSystemBasedMountPoints(IMountPoint mountPoint, string sourceLocation, string targetBasePath, bool expandIfArchive, out string diskPath)
        {
            string targetPath = Path.Combine(targetBasePath, Path.GetFileName(sourceLocation));

            try
            {
                if (expandIfArchive)
                {
                    mountPoint.Root.CopyTo(targetPath);
                }
                else
                {
                    _paths.CreateDirectory(targetBasePath); // creates Packages/ or Content/ if needed
                    _paths.Copy(sourceLocation, targetPath);
                }
            }
            catch (IOException)
            {
                _environmentSettings.Host.LogDiagnosticMessage($"Error copying scanLocation: {sourceLocation} into the target dir: {targetPath}", "Install");
                diskPath = null;
                return(false);
            }

            diskPath = targetPath;
            return(true);
        }
Esempio n. 4
0
 public MockFile(string fullpath, IMountPoint mountPoint)
 {
     FullPath   = fullpath;
     Name       = fullpath.Trim('/').Split('/').Last();
     MountPoint = mountPoint;
     Exists     = false;
 }
Esempio n. 5
0
        public void CanValidatePostActionWithDefaultInstructionLocalization()
        {
            SimpleConfigModel baseConfig = new SimpleConfigModel()
            {
                Identity         = "Test",
                PostActionModels = new List <PostActionModel>
                {
                    new PostActionModel()
                    {
                        Id                    = "pa0",
                        Description           = "text",
                        ActionId              = Guid.NewGuid(),
                        ManualInstructionInfo = new List <ManualInstructionModel>()
                        {
                            new ManualInstructionModel(null, "my text")
                        }
                    },
                }
            };
            IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            string tempFolder       = _environmentSettingsHelper.CreateTemporaryFolder();
            string localizationFile = string.Format(DefaultLocalizeConfigRelativePath, "de-DE");

            WriteFile(Path.Combine(tempFolder, localizationFile), "{ \"postActions/pa0/manualInstructions/default/text\": \"localized\" }", environmentSettings);

            using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings);

            var runnableProjectConfig = new RunnableProjectConfig(environmentSettings, A.Fake <IGenerator>(), baseConfig);
            var localizationModel     = LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !);

            Assert.True(runnableProjectConfig.VerifyLocalizationModel(localizationModel));

            runnableProjectConfig.ConfigurationModel.Localize(localizationModel);
            runnableProjectConfig.PostActionModels.Single(model => model.Id == "pa0" && model.ManualInstructionInfo[0].Text == "localized");
        }
Esempio n. 6
0
        public IList <ITemplate> GetTemplatesAndLangpacksFromDir(IMountPoint source, out IList <ILocalizationLocator> localizations)
        {
            IDirectory folder = source.Root;

            Regex localeFileRegex = new Regex(@"
                ^
                (?<locale>
                    [a-z]{2}
                    (?:-[A-Z]{2})?
                )
                \."
                                              + Regex.Escape(TemplateConfigFileName)
                                              + "$"
                                              , RegexOptions.IgnorePatternWhitespace);

            IList <ITemplate> templateList = new List <ITemplate>();

            localizations = new List <ILocalizationLocator>();

            foreach (IFile file in folder.EnumerateFiles("*" + TemplateConfigFileName, SearchOption.AllDirectories))
            {
                if (string.Equals(file.Name, TemplateConfigFileName, StringComparison.OrdinalIgnoreCase))
                {
                    IFile hostConfigFile = file.MountPoint.EnvironmentSettings.SettingsLoader.FindBestHostTemplateConfigFile(file);

                    if (TryGetTemplateFromConfigInfo(file, out ITemplate template, hostTemplateConfigFile: hostConfigFile))
                    {
                        templateList.Add(template);
                    }

                    continue;
                }

                Match localeMatch = localeFileRegex.Match(file.Name);
                if (localeMatch.Success)
                {
                    string locale = localeMatch.Groups["locale"].Value;

                    if (TryGetLangPackFromFile(file, out ILocalizationModel locModel))
                    {
                        ILocalizationLocator locator = new LocalizationLocator()
                        {
                            Locale           = locale,
                            MountPointId     = source.Info.MountPointId,
                            ConfigPlace      = file.FullPath,
                            Identity         = locModel.Identity,
                            Author           = locModel.Author,
                            Name             = locModel.Name,
                            Description      = locModel.Description,
                            ParameterSymbols = locModel.ParameterSymbols
                        };
                        localizations.Add(locator);
                    }

                    continue;
                }
            }

            return(templateList);
        }
Esempio n. 7
0
        public void CanHandlePostActions()
        {
            IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            SettingsFilePaths          paths = new SettingsFilePaths(environmentSettings);

            Guid postAction1 = Guid.NewGuid();
            Guid postAction2 = Guid.NewGuid();

            ITemplate template = A.Fake <ITemplate>();

            A.CallTo(() => template.Identity).Returns("testIdentity");
            A.CallTo(() => template.Name).Returns("testName");
            A.CallTo(() => template.ShortNameList).Returns(new[] { "testShort" });
            A.CallTo(() => template.MountPointUri).Returns("testMount");
            A.CallTo(() => template.ConfigPlace).Returns(".template.config/template.json");
            A.CallTo(() => template.PostActions).Returns(new[] { postAction1, postAction2 });
            IMountPoint mountPoint = A.Fake <IMountPoint>();

            A.CallTo(() => mountPoint.MountPointUri).Returns("testMount");

            ScanResult    result        = new ScanResult(mountPoint, new[] { template }, Array.Empty <ILocalizationLocator>(), Array.Empty <(string AssemblyPath, Type InterfaceType, IIdentifiedComponent Instance)>());
            TemplateCache templateCache = new TemplateCache(new[] { result }, new Dictionary <string, DateTime>(), NullLogger.Instance);

            WriteObject(environmentSettings.Host.FileSystem, paths.TemplateCacheFile, templateCache);
            var readCache = new TemplateCache(ReadObject(environmentSettings.Host.FileSystem, paths.TemplateCacheFile), NullLogger.Instance);

            Assert.Single(readCache.TemplateInfo);
            var readTemplate = readCache.TemplateInfo[0];

            Assert.Equal(new[] { postAction1, postAction2 }, readTemplate.PostActions);
        }
Esempio n. 8
0
 protected FileSystemInfoBase(IMountPoint mountPoint, string fullPath, string name, FileSystemInfoKind kind)
 {
     FullPath   = fullPath;
     Name       = name;
     Kind       = kind;
     MountPoint = mountPoint;
 }
Esempio n. 9
0
 public FileSystemMountPoint(IEngineEnvironmentSettings environmentSettings, IMountPoint parent, string mountPointUri, string mountPointRootPath)
 {
     MountPointUri       = mountPointUri;
     MountPointRootPath  = mountPointRootPath;
     EnvironmentSettings = environmentSettings;
     _paths = new SettingsFilePaths(environmentSettings);
     Root   = new FileSystemDirectory(this, "/", "", MountPointRootPath);
 }
Esempio n. 10
0
 public bool TryGetMountPoint(string mountPointUri, out IMountPoint mountPoint)
 {
     if (_disposed)
     {
         throw new ObjectDisposedException(nameof(SettingsLoader));
     }
     return(MountPointManager.TryDemandMountPoint(mountPointUri, out mountPoint));
 }
Esempio n. 11
0
 public ZipFileMountPoint(IEngineEnvironmentSettings environmentSettings, IMountPoint parent, MountPointInfo info, ZipArchive archive)
 {
     Parent = parent;
     EnvironmentSettings = environmentSettings;
     Archive             = archive;
     Info = info;
     Root = new ZipFileDirectory(this, "/", "");
 }
Esempio n. 12
0
 public void RemoveMountPoint(IMountPoint mountPoint)
 {
     _mountPointManager.ReleaseMountPoint(mountPoint);
     RemoveMountPoints(new Guid[1]
     {
         mountPoint.Info.MountPointId
     });
 }
 public ZipFileMountPoint(IEngineEnvironmentSettings environmentSettings, IMountPoint parent, string mountPointUri, ZipArchive archive)
 {
     MountPointUri       = mountPointUri;
     Parent              = parent;
     EnvironmentSettings = environmentSettings;
     Archive             = archive;
     Root = new ZipFileDirectory(this, "/", "");
 }
Esempio n. 14
0
        public static void AddMountPoint(IMountPoint mountPoint)
        {
            _mountPoints[mountPoint.Info.MountPointId] = mountPoint.Info;
            _userSettings.MountPoints.Add(mountPoint.Info);
            JObject serialized = JObject.FromObject(_userSettings);

            Paths.User.SettingsFile.WriteAllText(serialized.ToString());
        }
Esempio n. 15
0
 public MountPointScanSource(string location, IMountPoint mountPoint, bool shouldStayInOriginalLocation, bool foundComponents, bool foundTemplates)
 {
     Location   = location;
     MountPoint = mountPoint;
     ShouldStayInOriginalLocation = shouldStayInOriginalLocation;
     FoundComponents = foundComponents;
     FoundTemplates  = foundTemplates;
 }
        public bool TryMount(IEngineEnvironmentSettings environmentSettings, IMountPoint parent, string mountPointUri, out IMountPoint mountPoint)
        {
            if (!Uri.TryCreate(mountPointUri, UriKind.Absolute, out var uri))
            {
                mountPoint = null;
                return(false);
            }

            if (!uri.IsFile)
            {
                mountPoint = null;
                return(false);
            }

            ZipArchive archive;

            if (parent == null)
            {
                if (!environmentSettings.Host.FileSystem.FileExists(uri.LocalPath))
                {
                    mountPoint = null;
                    return(false);
                }

                try
                {
                    archive = new ZipArchive(environmentSettings.Host.FileSystem.OpenRead(uri.LocalPath), ZipArchiveMode.Read, false);
                }
                catch
                {
                    mountPoint = null;
                    return(false);
                }
            }
            else
            {
                IFile file = parent.Root.FileInfo(uri.LocalPath);

                if (!file.Exists)
                {
                    mountPoint = null;
                    return(false);
                }

                try
                {
                    archive = new ZipArchive(file.OpenRead(), ZipArchiveMode.Read, false);
                }
                catch
                {
                    mountPoint = null;
                    return(false);
                }
            }

            mountPoint = new ZipFileMountPoint(environmentSettings, parent, mountPointUri, archive);
            return(true);
        }
Esempio n. 17
0
        public void CanReadChoiceSymbol(
            string fileContent,
            bool errorExpected,
            string expectedSymbolNamesStr,
            string expectedSymbolDisplayNamesStr,
            string expectedDescriptionsStr,
            string expectedChoicesStr)
        {
            IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            string tempFolder       = _environmentSettingsHelper.CreateTemporaryFolder();
            string localizationFile = string.Format(DefaultLocalizeConfigRelativePath, "de-DE");

            WriteFile(Path.Combine(tempFolder, localizationFile), fileContent, environmentSettings);

            using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings);
            if (!errorExpected)
            {
                var localizationModel = LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !);
                Assert.NotNull(localizationModel);

                if (string.IsNullOrEmpty(expectedSymbolNamesStr))
                {
                    Assert.Empty(localizationModel.ParameterSymbols);
                    return;
                }
                var expectedSymbolNames  = expectedSymbolNamesStr.Split('|');
                var expectedDisplayNames = expectedSymbolDisplayNamesStr.Split('|');
                var expectedDescriptions = expectedDescriptionsStr.Split('|');
                var expectedChoices      = expectedChoicesStr?.Split('|');

                for (int i = 0; i < expectedSymbolNames.Length; i++)
                {
                    Assert.True(localizationModel.ParameterSymbols.ContainsKey(expectedSymbolNames[i]));
                    Assert.Equal(expectedDisplayNames[i] == "(null)" ? null : expectedDisplayNames[i], localizationModel.ParameterSymbols[expectedSymbolNames[i]].DisplayName);
                    Assert.Equal(expectedDescriptions[i] == "(null)" ? null : expectedDescriptions[i], localizationModel.ParameterSymbols[expectedSymbolNames[i]].Description);

                    if (expectedChoices == null || expectedChoices[i] == "(null)")
                    {
                        Assert.Empty(localizationModel.ParameterSymbols[expectedSymbolNames[i]].Choices);
                        continue;
                    }
                    var expectedChoicePairs = expectedChoices[i].Split('%');
                    foreach (var pair in expectedChoicePairs)
                    {
                        var choiceName        = pair.Split('*')[0];
                        var choiceDescription = pair.Split('*')[1];
                        var choiceDisplayName = pair.Split('*')[2];
                        Assert.True(localizationModel.ParameterSymbols[expectedSymbolNames[i]].Choices.ContainsKey(choiceName));
                        Assert.Equal(choiceDescription == "(null)" ? null : choiceDescription, localizationModel.ParameterSymbols[expectedSymbolNames[i]].Choices[choiceName].Description);
                        Assert.Equal(choiceDisplayName == "(null)" ? null : choiceDisplayName, localizationModel.ParameterSymbols[expectedSymbolNames[i]].Choices[choiceName].DisplayName);
                    }
                }
            }
            else
            {
                Assert.ThrowsAny <Exception>(() => LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !));
            }
        }
Esempio n. 18
0
 public MockFile(IDirectory parent, string name, IMountPoint mountPoint, byte[] contents)
 {
     FullPath   = parent.FullPath + name;
     Name       = name;
     MountPoint = mountPoint;
     _contents  = contents;
     Parent     = parent;
     Exists     = true;
 }
Esempio n. 19
0
        public void DisposeMountPoint(IMountPoint mountPoint)
        {
            FileSystemMountPoint mp = mountPoint as FileSystemMountPoint;

            if (mp?.Parent != null)
            {
                mp.EnvironmentSettings.SettingsLoader.ReleaseMountPoint(mp.Parent);
            }
        }
        public bool TryCreateFromMountPoint(IMountPoint mountPoint, bool isPartOfAnOptionalWorkload, out IReadOnlyList <IInstallUnitDescriptor> descriptorList)
        {
            descriptorList = new List <IInstallUnitDescriptor>()
            {
                new DefaultInstallUnitDescriptor(Guid.NewGuid(), mountPoint.Info.MountPointId, mountPoint.Info.Place, isPartOfAnOptionalWorkload),
            };

            return(true);
        }
        public static IFileSystemInfo ConfigFileSystemInfo(IMountPoint mountPoint, string configFile = null)
        {
            if (string.IsNullOrEmpty(configFile))
            {
                configFile = DefaultConfigRelativePath;
            }

            return(mountPoint.FileInfo(configFile));
        }
 public bool TryDemandMountPoint(string mountPointUri, out IMountPoint mountPoint)
 {
     if (UnavailableMountPoints.Any(m => m == mountPointUri))
     {
         mountPoint = null;
         return(false);
     }
     mountPoint = new MockMountPoint(EnvironmentSettings);
     return(true);
 }
 public bool TryDemandMountPoint(Guid mountPointId, out IMountPoint mountPoint)
 {
     if (UnavailableMountPoints.Any(m => m.MountPointId == mountPointId))
     {
         mountPoint = null;
         return(false);
     }
     mountPoint = new MockMountPoint(EnvironmentSettings);
     return(true);
 }
Esempio n. 24
0
        public bool TryGetMountPointFromPlace(string mountPointPlace, out IMountPoint mountPoint)
        {
            if (!TryGetMountPointInfoFromPlace(mountPointPlace, out MountPointInfo info))
            {
                mountPoint = null;
                return(false);
            }

            return(_mountPointManager.TryDemandMountPoint(info.MountPointId, out mountPoint));
        }
        public IList <ITemplate> GetTemplatesAndLangpacksFromDir(IMountPoint source, out IList <ILocalizationLocator> localizations)
        {
            IDirectory folder = source.Root;

            Regex localeFileRegex = new Regex(@"
                ^
                (?<locale>
                    [a-z]{2}
                    (?:_[a-z]{2})?
                )
                \.netnew\.json
                $"
                                              , RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

            IList <ITemplate> templateList = new List <ITemplate>();

            localizations = new List <ILocalizationLocator>();

            foreach (IFile file in folder.EnumerateFiles("*.netnew.json", SearchOption.AllDirectories))
            {
                if (string.Equals(file.Name, ".netnew.json", StringComparison.OrdinalIgnoreCase))
                {
                    ITemplate template;
                    if (TryGetTemplateFromConfigInfo(file, out template))
                    {
                        templateList.Add(template);
                    }

                    continue;
                }

                Match localeMatch = localeFileRegex.Match(file.Name);
                if (localeMatch.Success)
                {
                    string locale = localeMatch.Groups["locale"].Value;

                    ILocalizationModel locModel;
                    if (TryGetLangPackFromFile(file, out locModel))
                    {
                        ILocalizationLocator locator = new LocalizationLocator()
                        {
                            Locale       = locale,
                            MountPointId = source.Info.MountPointId,
                            ConfigPlace  = file.FullPath,
                            Identity     = locModel.Identity,
                        };
                        localizations.Add(locator);
                    }

                    continue;
                }
            }

            return(templateList);
        }
Esempio n. 26
0
        public bool TryMount(IMountPointManager manager, MountPointInfo info, out IMountPoint mountPoint)
        {
            if (info.ParentMountPointId != Guid.Empty || !Directory.Exists(info.Place))
            {
                mountPoint = null;
                return(false);
            }

            mountPoint = new FileSystemMountPoint(manager.EnvironmentSettings, info);
            return(true);
        }
Esempio n. 27
0
        public void CanReadPostAction(
            string fileContent,
            bool errorExpected,
            string expectedPostActionsStr,
            string expectedDescriptionsStr,
            string expectedManualInstructionsStr)
        {
            IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true);
            string tempFolder       = _environmentSettingsHelper.CreateTemporaryFolder();
            string localizationFile = string.Format(DefaultLocalizeConfigRelativePath, "de-DE");

            WriteFile(Path.Combine(tempFolder, localizationFile), fileContent, environmentSettings);

            using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings);
            if (!errorExpected)
            {
                var localizationModel = LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !);
                Assert.NotNull(localizationModel);

                if (string.IsNullOrEmpty(expectedPostActionsStr))
                {
                    Assert.Empty(localizationModel.PostActions);
                    return;
                }
                var expectedPostActions  = expectedPostActionsStr.Split('|');
                var expectedDescriptions = expectedDescriptionsStr.Split('|');
                var expectedInsturctions = expectedManualInstructionsStr?.Split('|');

                for (int i = 0; i < expectedPostActions.Length; i++)
                {
                    Assert.True(localizationModel.PostActions.ContainsKey(expectedPostActions[i]));
                    Assert.Equal(expectedDescriptions[i] == "(null)" ? null : expectedDescriptions[i], localizationModel.PostActions[expectedPostActions[i]].Description);

                    if (expectedInsturctions == null || expectedInsturctions[i] == "(null)")
                    {
                        Assert.Empty(localizationModel.PostActions[expectedPostActions[i]].Instructions);
                        continue;
                    }
                    var expectedInstructionPairs = expectedInsturctions[i].Split('%');
                    foreach (var pair in expectedInstructionPairs)
                    {
                        var id   = pair.Split('*')[0];
                        var text = pair.Split('*')[1];
                        Assert.True(localizationModel.PostActions[expectedPostActions[i]].Instructions.ContainsKey(id));
                        Assert.Equal(text == "(null)" ? null : text, localizationModel.PostActions[expectedPostActions[i]].Instructions[id]);
                    }
                }
            }
            else
            {
                Assert.ThrowsAny <Exception>(() => LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !));
            }
        }
Esempio n. 28
0
        public MockDirectory(string fullPath, IMountPoint mountPoint)
        {
            if (fullPath[fullPath.Length - 1] != '/')
            {
                fullPath += '/';
            }

            FullPath   = fullPath;
            Name       = fullPath.Trim('/').Split('/').Last();
            MountPoint = mountPoint;
            Exists     = false;
        }
Esempio n. 29
0
        public bool TryDemandMountPoint(Guid mountPointId, out IMountPoint mountPoint)
        {
            using (Timing.Over(EnvironmentSettings.Host, "Get mount point"))
            {
                if (EnvironmentSettings.SettingsLoader.TryGetMountPointInfo(mountPointId, out MountPointInfo info))
                {
                    return(TryDemandMountPoint(info, out mountPoint));
                }

                mountPoint = null;
                return(false);
            }
        }
Esempio n. 30
0
        public void AddMountPoint(IMountPoint mountPoint)
        {
            if (_mountPoints.Values.Any(x => string.Equals(x.Place, mountPoint.Info.Place) && x.ParentMountPointId == mountPoint.Info.ParentMountPointId))
            {
                return;
            }

            _mountPoints[mountPoint.Info.MountPointId] = mountPoint.Info;
            _userSettings.MountPoints.Add(mountPoint.Info);
            JObject serialized = JObject.FromObject(_userSettings);

            _paths.WriteAllText(_paths.User.SettingsFile, serialized.ToString());
        }
Esempio n. 31
0
        public void AddMountPoint(IMountPoint mountPoint)
        {
            if (mountPoint == null)
            {
                throw new ArgumentNullException(nameof(mountPoint), "The mountPoint argument can not be null.");
            }

            if (this.MountPoints.Contains(mountPoint))
            {
                return;
            }

            this.MountPoints.Add(mountPoint);
        }
Esempio n. 32
0
 public void AddMountPoint(IMountPoint mountPoint)
 {
     throw new NotImplementedException();
 }