Exemplo n.º 1
0
        public static ResizeBatch FromCommandLine(TextReader standardInput, string[] args)
        {
            var batch = new ResizeBatch();

            // NB: We read these from stdin since there are limits on the number of args you can have
            string file;

            if (standardInput != null)
            {
                while ((file = standardInput.ReadLine()) != null)
                {
                    batch.Files.Add(file);
                }
            }

            for (var i = 0; i < args?.Length; i++)
            {
                if (args[i] == "/d")
                {
                    batch.DestinationDirectory = args[++i];
                    continue;
                }

                batch.Files.Add(args[i]);
            }

            return(batch);
        }
Exemplo n.º 2
0
        public static ResizeBatch FromCommandLine(TextReader standardInput, string[] args)
        {
            var          batch          = new ResizeBatch();
            const string pipeNamePrefix = "\\\\.\\pipe\\";
            string       pipeName       = null;

            for (var i = 0; i < args?.Length; i++)
            {
                if (args[i] == "/d")
                {
                    batch.DestinationDirectory = args[++i];
                    continue;
                }
                else if (args[i].Contains(pipeNamePrefix))
                {
                    pipeName = args[i].Substring(pipeNamePrefix.Length);
                    continue;
                }

                batch.Files.Add(args[i]);
            }

            if (string.IsNullOrEmpty(pipeName))
            {
                // NB: We read these from stdin since there are limits on the number of args you can have
                string file;
                if (standardInput != null)
                {
                    while ((file = standardInput.ReadLine()) != null)
                    {
                        batch.Files.Add(file);
                    }
                }
            }
            else
            {
                using (NamedPipeClientStream pipeClient =
                           new NamedPipeClientStream(".", pipeName, PipeDirection.In))
                {
                    // Connect to the pipe or wait until the pipe is available.
                    pipeClient.Connect();

                    using (StreamReader sr = new StreamReader(pipeClient, Encoding.Unicode))
                    {
                        string file;

                        // Display the read text to the console
                        while ((file = sr.ReadLine()) != null)
                        {
                            batch.Files.Add(file);
                        }
                    }
                }
            }

            return(batch);
        }
Exemplo n.º 3
0
        public void FromCommandLineWorks()
        {
            var standardInput =
                "Image1.jpg" + EOL +
                "Image2.jpg";
            var args = new[]
            {
                "/d", "OutputDir",
                "Image3.jpg",
            };

            var result = ResizeBatch.FromCommandLine(
                new StringReader(standardInput),
                args);

            Assert.Equal(new List<string> { "Image1.jpg", "Image2.jpg", "Image3.jpg" }, result.Files);

            Assert.Equal("OutputDir", result.DestinationDirectory);
        }
Exemplo n.º 4
0
        public static ResizeBatch FromCommandLine(TextReader standardInput, string[] args)
        {
            var batch = new ResizeBatch();

            string file;

            while ((file = standardInput.ReadLine()) != null)
            {
                batch.Files.Add(file);
            }

            for (var i = 0; i < args.Length; i++)
            {
                if (args[i] == "/d")
                {
                    batch.DestinationDirectory = args[++i];
                    continue;
                }

                batch.Files.Add(args[i]);
            }

            return(batch);
        }