public Result <IEnumerable <Template> > Explore(string sourcePath, IEnumerable <string> configurationFiles)
        {
            if (sourcePath == null)
            {
                throw new ArgumentNullException(nameof(sourcePath));
            }

            if (configurationFiles == null)
            {
                throw new ArgumentNullException(nameof(configurationFiles));
            }

            var additionalVars = new Dictionary <string, string>();

            using (_logger.CreateBlock("Explore"))
            {
                foreach (var configurationFile in configurationFiles)
                {
                    if (!_fileSystem.IsFileExist(configurationFile))
                    {
                        _logger.Log($"The configuration file \"{configurationFile}\"  (\"{Path.GetFullPath(configurationFile)}\") does not exist.", Result.Error);
                        return(new Result <IEnumerable <Template> >(Enumerable.Empty <Template>()));
                    }

                    using (_logger.CreateBlock(configurationFile))
                    {
                        additionalVars = UpdateVariables(additionalVars, GetVariables(configurationFile));
                    }
                }

                _logger.Log($"The configuration path is \"{sourcePath}\" (\"{Path.GetFullPath(sourcePath)}\")");
            }

            return(new Result <IEnumerable <Template> >(GetConfigurations(sourcePath, additionalVars)));
        }
Example #2
0
        public override void Intro( params object [] args )
        {
            variableTable = new VariableTable ();

            fileSystem = FileSystemManager.GetFileSystem ( "LocalFileSystem" );
            if ( fileSystem.IsFileExist ( "vartab.dat" ) )
                variableTable.Load ( fileSystem.OpenFile ( "vartab.dat" ) );
            else
            {
                variableTable.AddPackageVariableTable ( myGuid, 3 );
                variableTable.SetVariable ( myGuid, 0, 0 );
                variableTable.SetVariable ( myGuid, 1, 0.0 );
                variableTable.SetVariable ( myGuid, 2, false );
            }

            base.Intro ( args );
        }
Example #3
0
        public async Task <Result <Stream> > Create(string dockerFilesRootPath, IEnumerable <Dockerfile> dockerFiles)
        {
            if (dockerFilesRootPath == null)
            {
                throw new ArgumentNullException(nameof(dockerFilesRootPath));
            }

            if (dockerFiles == null)
            {
                throw new ArgumentNullException(nameof(dockerFiles));
            }

            using (_logger.CreateBlock("Context"))
            {
                var context = new MemoryStream();
                using (var archive = new TarOutputStream(context)
                {
                    IsStreamOwner = false
                })
                {
                    var number = 0;
                    if (!string.IsNullOrWhiteSpace(_options.ContextPath))
                    {
                        var path = Path.GetFullPath(_options.ContextPath);
                        if (!_fileSystem.IsDirectoryExist(path))
                        {
                            throw new InvalidOperationException($"The docker build context directory \"{path}\" does not exist.");
                        }

                        foreach (var file in _fileSystem.EnumerateFileSystemEntries(path))
                        {
                            if (!_fileSystem.IsFileExist(file))
                            {
                                continue;
                            }

                            number++;
                            using (var fileStream = _fileSystem.OpenRead(file))
                            {
                                var filePathInArchive = _pathService.Normalize(Path.GetRelativePath(path, file));
                                var result            = await AddEntry(archive, filePathInArchive, fileStream);

                                _logger.Details($"{number:0000} \"{filePathInArchive}\" was added.");
                                if (result == Result.Error)
                                {
                                    return(new Result <Stream>(new MemoryStream(), Result.Error));
                                }
                            }
                        }

                        _logger.Log($"{number} files were added to docker build context from the directory \"{_options.ContextPath}\" (\"{path}\").");
                    }
                    else
                    {
                        _logger.Log("The path for docker build context was not defined.", Result.Warning);
                    }

                    number = 0;
                    using (_logger.CreateBlock("Docker files"))
                    {
                        foreach (var dockerfile in dockerFiles)
                        {
                            number++;
                            var dockerFilePathInArchive = _pathService.Normalize(Path.Combine(dockerFilesRootPath, dockerfile.Path));
                            using (var dockerFileStream = new MemoryStream())
                            {
                                using (var writer = new StreamWriter(dockerFileStream, Encoding.UTF8, 0xff, true))
                                {
                                    foreach (var line in dockerfile.Lines)
                                    {
                                        writer.WriteLine(line.Text);
                                    }
                                }

                                dockerFileStream.Position = 0;
                                var result = await AddEntry(archive, dockerFilePathInArchive, dockerFileStream);

                                if (result == Result.Error)
                                {
                                    return(new Result <Stream>(new MemoryStream(), Result.Error));
                                }

                                _logger.Log($"{number:0000} \"{dockerFilePathInArchive}\" was added ({dockerFileStream.Length} bytes).");
                            }
                        }
                    }

                    archive.Close();
                    return(new Result <Stream>(context));
                }
            }
        }
Example #4
0
        public static PackageInfo LoadFromFileSystem( IFileSystem fileSystem )
        {
            if ( !fileSystem.IsFileExist ( "packageInfo.json" ) )
                throw new ArgumentException ();

            PackageInfo packageInfo = new PackageInfo ();
            JsonContainer entry = new JsonContainer ( fileSystem.OpenFile ( "packageInfo.json" ) );

            packageInfo.PackageName = entry [ "title" ] as string;

            packageInfo.Author = entry [ "author" ] as string;
            packageInfo.Copyright = entry [ "copyright" ] as string;
            packageInfo.Description = entry [ "description" ] as string;

            packageInfo.PackageID = new Guid ( entry [ "packId" ] as string );
            packageInfo.Version = new Version ( entry [ "version" ] as string );
            packageInfo.ReleaseDate = DateTime.Parse ( entry [ "release_date" ] as string );

            if ( packageInfo.IsSubPackage = ( bool ) entry [ "issubpack" ] )
            {
                List<Guid> mainGuid = new List<Guid> ();
                JsonContainer mainPackIds = entry [ "mainpacks" ] as JsonContainer;
                foreach ( object item in mainPackIds.GetListEnumerable () )
                    mainGuid.Add ( new Guid ( item as string ) );

                if ( !mainGuid.Contains ( Core.MainPackage.PackageID ) )
                {
                    bool isContains = false;
                    foreach ( PackageInfo subpack in Core.SubPackages )
                        if ( mainGuid.Contains ( subpack.PackageID ) )
                            isContains = true;
                    if ( !isContains )
                        throw new ArgumentException ( "This package is not allowed to this package." );
                }

                packageInfo.MainPackageIDs = mainGuid.ToArray ();
            }

            if ( fileSystem.IsFileExist ( "packageCover.png" ) )
            {
                ImageInfo imageInfo;
                new PngDecoder ().Decode ( fileSystem.OpenFile ( "packageCover.png" ), out imageInfo );
                packageInfo.PackageCover = imageInfo;
            }

            if ( fileSystem.IsFileExist ( "stringTable.stt" ) )
                packageInfo.StringTable = new StringTable ( fileSystem.OpenFile ( "stringTable.stt" ) );

            if ( fileSystem.IsFileExist ( "resourceTable.rst" ) )
                packageInfo.ResourceTable = new ResourceTable ( new ZipFileSystem ( fileSystem.OpenFile ( "resourceTable.rst" ) ) );

            return packageInfo;
        }
Example #5
0
        public static PackageInfo LoadFromFileSystem( IFileSystem fileSystem )
        {
            if ( !fileSystem.IsFileExist ( "packageInfo.json" ) )
                throw new ArgumentException ();

            PackageInfo packageInfo = new PackageInfo ();
            JsonEntry entry = JsonParser.Parse ( fileSystem.OpenFile ( "packageInfo.json" ) );

            packageInfo.PackageName = entry [ "title" ] as string;

            packageInfo.Author = entry [ "author" ] as string;
            packageInfo.Copyright = entry [ "copyright" ] as string;
            packageInfo.Description = entry [ "description" ] as string;

            packageInfo.PackageID = new Guid ( entry [ "packId" ] as string );
            packageInfo.Version = new Version ( entry [ "version" ] as string );
            packageInfo.ReleaseDate = DateTime.Parse ( entry [ "release_date" ] as string );

            if ( packageInfo.IsSubPackage = ( bool ) entry [ "issubpack" ] )
            {
                List<Guid> mainGuid = new List<Guid> ();
                JsonArray mainPackIds = entry [ "mainpacks" ] as JsonArray;
                foreach ( object item in mainPackIds )
                    mainGuid.Add ( new Guid ( item as string ) );

                if ( !mainGuid.Contains ( PackageSystem.MainPackage.PackageID ) )
                {
                    bool isContains = false;
                    foreach ( PackageInfo subpack in PackageSystem.SubPackages )
                        if ( mainGuid.Contains ( subpack.PackageID ) )
                            isContains = true;
                    if ( !isContains )
                        throw new SubPackageNotAllowedThisPackageException ();
                }

                packageInfo.MainPackageIDs = mainGuid.ToArray ();
            }

            if ( fileSystem.IsFileExist ( "packageCover.png" ) )
                packageInfo.PackageCover = new PngDecoder ().Decode ( fileSystem.OpenFile ( "packageCover.png" ) );

            if ( fileSystem.IsFileExist ( "stringTable.stt" ) )
                packageInfo.StringTable = new StringTable ( fileSystem.OpenFile ( "stringTable.stt" ) );

            if ( fileSystem.IsFileExist ( "resourceTable.rst" ) )
                packageInfo.ResourceTable = new ContentManager ( new ZipFileSystem ( fileSystem.OpenFile ( "resourceTable.rst" ) ) );

            if ( fileSystem.IsFileExist ( "scriptTable.scr" ) )
                packageInfo.ScriptTable = new ScriptTable ( fileSystem.OpenFile ( "scriptTable.scr" ) );

            return packageInfo;
        }