예제 #1
0
        public MVacuum(CObjectInfo objInfo, IIO pIO, CVacuumData data)
            : base(objInfo)
        {
            m_IO = pIO;

            SetData(data);
        }
예제 #2
0
 public Game(Board board, IIO io)
 {
     _board                    = board;
     _io                       = io;
     _displayBoard             = new string[board.Width, board.Height];
     _totalNumberOfSafeSquares = _board.Width * _board.Height - _board.NumberOfMines;
 }
예제 #3
0
        public void Initialize()
        {
            bucket = new Bucket();
            config = new Config();

            bucket.SetConfig(config);

            root      = Helper.GetTestFolder <TestsInstallerLibrary>();
            vendorDir = Path.Combine(root, "vendor");
            binDir    = Path.Combine(root, "bin");

            var merged = new JObject()
            {
                { "config", new JObject() }
            };

            merged["config"][Settings.VendorDir] = vendorDir;
            merged["config"][Settings.BinDir]    = binDir;

            config.Merge(merged);

            downloadManager = new Mock <DownloadManager>(null, false);
            bucket.SetDownloadManager(downloadManager.Object);

            repository = new Mock <IRepositoryInstalled>();
            tester     = new TesterIOConsole();
            io         = tester.Mock();

            Cleanup();

            Directory.CreateDirectory(vendorDir);
            Directory.CreateDirectory(binDir);
        }
예제 #4
0
        /// <inheritdoc />
        protected override void Initialize(IInput input, IOutput output)
        {
            if (GetIO() == IONull.That)
            {
                // In the absence of a given Application maybe
                // in debug mode so we give an IOConsole.
                io = new IOConsole(input, output);
            }

            var disablePlugins = input.HasRawOption("--no-plugins");

#pragma warning disable S1117
            var bucket = GetBucket(false, disablePlugins);
#pragma warning restore S1117
            if (!bucket)
            {
                bucket = Factory.CreateGlobal(GetIO(), disablePlugins);
            }

            if (bucket)
            {
                var commandEvent = new PreCommandRunEventArgs(PluginEvents.PreCommandRun, input, Name);
                bucket.GetEventDispatcher().Dispatch(this, commandEvent);
            }

            if (input.HasRawOption("--no-ansi") && input.HasOption("no-progress"))
            {
                input.SetOption("no-progress", true);
            }

            base.Initialize(input, output);
        }
예제 #5
0
 public void Initialize()
 {
     jsonFile            = new Mock <JsonFile>(string.Empty, null, null);
     installationManager = new Mock <InstallationManager>();
     tester = new TesterIOConsole();
     io     = tester.Mock();
 }
예제 #6
0
        /// <summary>
        /// Whether the driver support the specified uri.
        /// </summary>
        /// <param name="io">The input/output instance.</param>
        /// <param name="config">The config instance.</param>
        /// <param name="uri">Thr specified uri.</param>
        /// <param name="deep">Whether is deep checker.</param>
        /// <returns>True if the driver is supported.</returns>
        public static bool IsSupport(IIO io, Config config, string uri, bool deep = false)
        {
            if (Regex.IsMatch(uri, @"(^git://|\.git/?$|git(?:olite)?@|//git\.|//github\.com/|//gitlib\.com/)", RegexOptions.IgnoreCase))
            {
                return(true);
            }

            bool ProcessCheck(string command, string cwd)
            {
                var process = new BucketProcessExecutor(io);

                return(process.Execute(command, cwd) == 0);
            }

            if (FileSystemLocal.IsLocalPath(uri))
            {
                uri = FileSystemLocal.GetPlatformPath(uri);
                if (!Directory.Exists(uri))
                {
                    return(false);
                }

                return(ProcessCheck("git tag", uri));
            }

            if (!deep)
            {
                return(false);
            }

            return(ProcessCheck($"git ls-remote --heads {ProcessExecutor.Escape(uri)}", null));
        }
예제 #7
0
 /// <summary>
 /// Writes a message to the error output.
 /// </summary>
 /// <param name="io">The input/output instance.</param>
 /// <param name="messages">An array of message.</param>
 /// <param name="newLine">Whether to add a newline or not.</param>
 /// <param name="verbosity">Verbosity level from the verbosity * constants.</param>
 public static void WriteError(this IIO io, IEnumerable <string> messages, bool newLine = true, Verbosities verbosity = Verbosities.Normal)
 {
     foreach (var message in messages)
     {
         io.WriteError(message, newLine, verbosity);
     }
 }
예제 #8
0
        public MCylinder(CObjectInfo objInfo, IIO pIO, CCylinderData data)
            : base(objInfo)
        {
            m_IO = pIO;

            SetData(data);
        }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Git"/> class.
 /// </summary>
 public Git(IIO io, Config config, IProcessExecutor process, IFileSystem fileSystem)
 {
     this.io         = io;
     this.config     = config;
     this.process    = process;
     this.fileSystem = fileSystem;
 }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScriptEventArgs"/> class.
 /// </summary>
 /// <param name="name">The event name.</param>
 /// <param name="bucket">The bucket instance.</param>
 /// <param name="io">The input/output instance.</param>
 /// <param name="devMode">Whether is operations with dev packages.</param>
 /// <param name="args">Arguments passed by the user.</param>
 public ScriptEventArgs(string name, Bucket bucket, IIO io, bool devMode = false, string[] args = null)
     : base(name, args)
 {
     this.bucket = bucket;
     this.io     = io;
     IsDevMode   = devMode;
 }
예제 #11
0
 public void Initialize()
 {
     fileSystemMock = new Mock <IFileSystem>();
     tester         = new TesterIOConsole();
     io             = tester.Mock();
     installer      = new InstallerBinary(io, "vendor/bin", "auto", fileSystemMock.Object);
 }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InstallerBinary"/> class.
 /// </summary>
 /// <param name="io">The input/output instance.</param>
 /// <param name="binDir">The binary folder.</param>
 /// <param name="binCompat">Indicates that the binary file dynamically generates compatibility.</param>
 /// <param name="fileSystem">The file system instance.</param>
 public InstallerBinary(IIO io, string binDir, string binCompat, IFileSystem fileSystem = null)
 {
     this.io = io;
     this.binDir = binDir;
     this.binCompat = binCompat;
     this.fileSystem = fileSystem ?? new FileSystemLocal();
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DownloaderVcs"/> class.
 /// </summary>
 protected DownloaderVcs(IIO io, Config config, IProcessExecutor process = null, IFileSystem fileSystem = null)
 {
     IO         = io;
     Config     = config;
     Process    = process ?? new BucketProcessExecutor();
     FileSystem = fileSystem ?? new FileSystemLocal(null, Process);
 }
예제 #14
0
파일: Github.cs 프로젝트: yekoufeng/bucket
 /// <summary>
 /// Initializes a new instance of the <see cref="Github"/> class.
 /// </summary>
 public Github(IIO io, Config config, IProcessExecutor process = null, ITransport transport = null)
 {
     this.io        = io;
     this.config    = config;
     this.process   = process ?? new BucketProcessExecutor(io);
     this.transport = transport ?? new Factory().CreateTransport(io, config);
 }
예제 #15
0
        /// <summary>
        /// Trigger notification.
        /// </summary>
        /// <param name="io">The input/output instance.</param>
        /// <param name="config">The config instance.</param>
        public virtual void Notify(IIO io, Config config)
        {
            var seen = new HashSet <string>();

            foreach (var item in notifiablePackages)
            {
                if (!Uri.TryCreate(item.Key, UriKind.RelativeOrAbsolute, out Uri uri))
                {
                    continue;
                }

                var authHeader = string.Empty;
                if (io.HasAuthentication(uri.Host))
                {
                    var(username, password) = io.GetAuthentication(uri.Host);
                    var authBytes = Encoding.UTF8.GetBytes($"{username}:{password}");
                    authHeader = $"Basic {Convert.ToBase64String(authBytes)}";
                }

                seen.Clear();
                var postData = new PostNotifyData();
                foreach (var package in item.Value)
                {
                    if (!seen.Add(package.GetName()))
                    {
                        continue;
                    }

                    postData.Downloads.Add((package.GetNamePretty(), package.GetVersion()));
                }

                using (var httpClient = HttpClientFactory.CreateHttpClient(config))
                {
                    var content = new StringContent(postData, Encoding.UTF8, "application/json");
                    if (!string.IsNullOrEmpty(authHeader))
                    {
                        content.Headers.Add("Authorization", authHeader);
                    }

                    try
                    {
                        using (var response = httpClient.PostAsync(uri.ToString(), content).Result)
                        {
                            response.EnsureSuccessStatusCode();
                        }
                    }
#pragma warning disable CA1031
                    catch (SException ex)
#pragma warning restore CA1031
                    {
                        io.WriteError($"Notify {uri.ToString()} failed: {ex.Message}", true, Verbosities.Debug);
                    }
                    finally
                    {
                        httpClient.CancelPendingRequests();
                    }
                }
            }
        }
예제 #16
0
        /// <summary>
        /// Create the <see cref="Config"/> object.
        /// </summary>
        /// <param name="io">The input/output instance.</param>
        /// <param name="cwd">Current working directory.</param>
        public virtual Config CreateConfig(IIO io = null, string cwd = null)
        {
            cwd = cwd ?? Environment.CurrentDirectory;
            var config = new Config(true, cwd);
            var home   = GetBucketHomeDirectory();

            var merged = new JObject()
            {
                { "config", new JObject() }
            };

            merged["config"][Settings.Home]     = home;
            merged["config"][Settings.CacheDir] = GetCacheDirectory(home);
            config.Merge(merged);

            home = config.Get(Settings.Home);

            void MergeConfig(JsonFile file, bool isAuthFile = false)
            {
                if (file.Exists())
                {
                    io?.WriteError($"Loading config file {file.GetPath()}", true, Verbosities.Debug);
                    MergeObject(file.Read(), isAuthFile);
                }
            }

            void MergeObject(JObject conf, bool isAuthFile = false)
            {
                config.Merge(isAuthFile ? new JObject()
                {
                    ["config"] = conf
                } : conf);
            }

            // load global source.
            var globalConfigFile = new JsonFile($"{home}/config.json", null, io);

            MergeConfig(globalConfigFile);
            config.SetSourceBucket(new JsonConfigSource(globalConfigFile));

            // load global auth source.
            var globalAuthFile = new JsonFile($"{home}/auth.json", null, io);

            MergeConfig(globalAuthFile, true);
            config.SetSourceAuth(new JsonConfigSource(globalAuthFile, true));

            // load auth from environment variable.
            string bucketAuth = Terminal.GetEnvironmentVariable(EnvironmentVariables.BucketAuth);

            if (string.IsNullOrEmpty(bucketAuth))
            {
                return(config);
            }

            io?.WriteError($"Loading auth config from {EnvironmentVariables.BucketAuth}");
            MergeObject(JsonFile.Parse(bucketAuth), true);

            return(config);
        }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BucketVersions"/> class.
 /// </summary>
 public BucketVersions(IIO io, Config config, ITransport transport, IFileSystem fileSystem = null, IProcessExecutor process = null)
 {
     this.io         = io;
     this.config     = config;
     this.transport  = transport;
     this.fileSystem = fileSystem ?? new FileSystemLocal();
     this.process    = process ?? new BucketProcessExecutor(io);
 }
예제 #18
0
        /***************** Common Implementation *************************************/

        public int AssignComponents(IIO pIO)
        {
            Assert(pIO != null);

            m_IO = pIO;

            return(SUCCESS);
        }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheFileSystem"/> class.
 /// </summary>
 /// <param name="cacheDirectory">Location of the cache.</param>
 /// <param name="io">The input/output instance used in debugger.</param>
 /// <param name="whitelist">List of characters that are allowed in path names (used in a regex character class).</param>
 /// <param name="fileSystem">Optional filesystem instance.</param>
 public CacheFileSystem(string cacheDirectory, IIO io, string whitelist = "a-z0-9.", IFileSystem fileSystem = null)
 {
     CacheDirectory  = cacheDirectory;
     this.io         = io;
     this.whitelist  = whitelist;
     this.fileSystem = fileSystem ?? new FileSystemLocal(cacheDirectory);
     Enable          = IsUsable(cacheDirectory);
 }
예제 #20
0
 public void Initialize()
 {
     tester  = new TesterIOConsole();
     io      = tester.Mock();
     config  = new Mock <Config>(true, null);
     manager = new Mock <RepositoryManager>(IONull.That, config.Object, null, null);
     loader  = new LoaderPackageRoot(manager.Object, config.Object, io);
 }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransportHttp"/> class.
 /// </summary>
 public TransportHttp(IIO io, Config config, HttpClient httpClient = null)
 {
     this.io         = io;
     this.config     = config;
     this.httpClient = httpClient ?? HttpClientFactory.CreateHttpClient(config);
     buffer          = new byte[8192];
     displayedHostAuthentications = new HashSet <string>();
 }
예제 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Application"/> class.
 /// </summary>
 public Application()
     : base("Bucket", Bucket.GetVersionPretty())
 {
     Regex.CacheSize = Math.Max(Regex.CacheSize, 32);
     io = IONull.That;
     disablePluginsByDefault = false;
     hasPluginCommands       = false;
 }
예제 #23
0
파일: Locker.cs 프로젝트: yekoufeng/bucket
 /// <summary>
 /// Initializes a new instance of the <see cref="Locker"/> class.
 /// </summary>
 /// <param name="io">The input/output instance.</param>
 /// <param name="lockFile">The lock file loader instance.</param>
 /// <param name="installationManager">The installation manager instance.</param>
 /// <param name="bucketFileContents">The contents of the bucket.json file.</param>
 public Locker(IIO io, JsonFile lockFile, InstallationManager installationManager, string bucketFileContents)
 {
     this.io                  = io;
     this.lockFile            = lockFile;
     this.installationManager = installationManager;
     contentHash              = GetContentHash(bucketFileContents);
     loader = new LoaderPackage(null);
 }
예제 #24
0
        /// <summary>
        /// Check if the specified driver is supported.
        /// </summary>
        /// <param name="name">The checked driver name.</param>
        /// <param name="io">The input/output instance.</param>
        /// <param name="config">The global config instance.</param>
        /// <param name="uri">The vcs uri.</param>
        /// <param name="deep">Whether to conduct an in-depth inspection.</param>
        /// <returns>True if supported.</returns>
        public static bool IsSupport(string name, IIO io, Config config, string uri, bool deep = false)
        {
            if (DriverSupportChecker.checker.TryGetValue(name, out ShouldSupport checker))
            {
                return(checker(io, config, uri, deep));
            }

            return(false);
        }
예제 #25
0
 public void Initialize()
 {
     fileSystem = new FileSystemLocal();
     root       = Helper.GetTestFolder <TestsDownloaderGit>().Replace("\\", "/", StringComparison.Ordinal);
     tester     = new TesterIOConsole();
     io         = tester.Mock();
     bucketPath = WinCompat("bucketPath");
     fileSystem.Delete(root);
 }
예제 #26
0
        private static IRepository CreationBucket(ConfigRepository configRepository, IIO io, Config config, IEventDispatcher eventDispatcher, IVersionParser versionParser)
        {
            if (!(configRepository is ConfigRepositoryBucket configRepositoryBucket))
            {
                throw new InvalidArgumentException($"The repository configuration parameter is invalid and must be of type {nameof(ConfigRepositoryBucket)}");
            }

            return(new RepositoryBucket(configRepositoryBucket, io, config, null, eventDispatcher, versionParser));
        }
예제 #27
0
        protected DownloaderGit CreateDownloaderMock(IIO io = null, Config config = null, IProcessExecutor process = null, IFileSystem fileSystem = null)
        {
            io         = io ?? this.io;
            config     = SetupConfig(config);
            process    = process ?? new BucketProcessExecutor();
            fileSystem = fileSystem ?? this.fileSystem;

            return(new DownloaderGit(io, config, process, fileSystem));
        }
예제 #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RepositoryManager"/> class.
 /// </summary>
 public RepositoryManager(IIO io, Config config, IEventDispatcher eventDispatcher = null, IVersionParser versionParser = null)
 {
     this.io              = io;
     this.config          = config;
     this.eventDispatcher = eventDispatcher;
     this.versionParser   = versionParser ?? new BVersionParser();
     repositories         = new LinkedList <IRepository>();
     repositoryCreaters   = new Dictionary <string, RepositoryCreater>();
 }
예제 #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventDispatcher"/> class.
 /// </summary>
 public EventDispatcher(Bucket bucket, IIO io, IProcessExecutor process = null, IFileSystem fileSystem = null)
 {
     this.bucket     = bucket;
     this.io         = io;
     this.process    = process ?? new BucketProcessExecutor(io);
     listeners       = new Dictionary <string, IList <EventHandler> >();
     eventStack      = new Stack <string>();
     this.fileSystem = fileSystem ?? new FileSystemLocal();
 }
예제 #30
0
 public void Initialize()
 {
     repository = new Mock <IRepositoryInstalled>();
     tester     = new TesterIOConsole();
     io         = tester.Mock(AbstractTester.OptionStdErrorSeparately(true));
     installer  = new InstallerMetaPackage(io);
     package    = new Mock <IPackage>();
     package.Setup((o) => o.Clone()).Returns(package.Object);
 }