Пример #1
0
        static void Main(string[] args)
        {
            int result = 2;

            while (result == 2)
            {
                IGarageManager          garageManager      = new GarageManagerFactory().Create();
                IConsoleInputOutput     consoleInputOutput = new ConsoleInputOutput();
                IVehicleManager         vehicleManager     = VehicleManagerFactory.Create(garageManager);
                IVehicleParser          vehicleParser      = new VehicleParser();
                IGarageParser           garageParser       = new GarageParser();
                IFileInputOutput        file                   = new FileInputOutput();
                ICsvImporter            csvImporter            = new CsvImporter(file, vehicleParser);
                ICommandExecuterFactory commandExecuterFactory = new CommandExecuterFactory(vehicleManager, consoleInputOutput, vehicleParser, garageManager, garageParser, csvImporter, file);
                var commandLineParser = new CommandLineParser(consoleInputOutput, CommandDictionaryFactory.Create(), vehicleManager, commandExecuterFactory);
                while ((result = commandLineParser.ReadCommand()) == 1)
                {
                    ;
                }
                if (result == 2)
                {
                    consoleInputOutput.WriteInfo("Daten werden wiederhergestellt.");
                }
            }
        }
Пример #2
0
 /// <exception cref="EncodingNotSupportedException">Thrown if the encoding is not supported by the platform.</exception>
 internal string ReadPlain(string path, out Encoding encoding)
 {
     using (FileStream fileStream = FileInputOutput.OpenFileForReading(path)) {
         SubtitleFormat format = null;
         return(ReadSubtitleText(false, fileStream, out encoding, out format));
     }
 }
Пример #3
0
        private void OpenFileButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileInputOutput fileInput = new FileInputOutput(openFileDialog.OpenFile());
                fileInput.CreateList();

                foreach (string[] shape in fileInput.streamList)
                {
                    if (shape[0] == "rectangle")
                    {
                        Command addShape = new AddShapeCommand(shapeList, new RectangleShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                        history.Add(addShape);
                    }

                    if (shape[0] == "ellipse")
                    {
                        Command addShape = new AddShapeCommand(shapeList, new EllipseShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                        history.Add(addShape);
                    }
                }
            }
            Invalidate();
        }
Пример #4
0
        private string TestEncoding(FileStream fileStream, Encoding encoding)
        {
            Logger.Info("[SubtitleInput] Trying encoding \"{0}\"", encoding.WebName);
            /* Get the text */
            string text = FileInputOutput.ReadFile(fileStream, encoding, true);

            return(text);
        }
Пример #5
0
        static void Main(string[] args)
        {
            const string PATH = "../../IOFile.txt";

            string fileContents = FileInputOutput.ReadFileContents(PATH);

            FileInputOutput.OutputSum(Calculus.CalculateSum(fileContents), PATH);
            Console.WriteLine(File.ReadAllText(PATH));
            Console.ReadLine();
        }
Пример #6
0
        // Save current file
        private void SaveFileButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileInputOutput fileOutput = new FileInputOutput(saveFileDialog.OpenFile());
                fileOutput.WriteFile(shapeList);
            }
        }
Пример #7
0
        /* Public methods */

        /// <summary>Saves subtitles to the file with the specified properties.</summary>
        /// <param name="subtitles">The subtitles to save.</param>
        /// <param name="properties">The properties of the file to save the subtitles to. Its <see cref="TimingMode" /> property is used to
        /// choose the timing mode for subtitle formats that support both time and frame modes.</param>
        /// <param name="textType">The type of text content to save.</param>
        /// <remarks>An updated <see cref="SubLib.FileProperties" /> object can be accessed with <see cref="FileProperties" /> after saving.</remarks>
        public void Save(Subtitles subtitles, FileProperties properties, SubtitleTextType textType)
        {
            SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType);
            SubtitleOutput output = new SubtitleOutput(format, textType);

            string text = output.Build(subtitles.Collection, subtitles.Properties, properties);

            FileInputOutput.WriteFile(properties.Path, text, properties.Encoding);

            fileProperties = GetUpdatedFileProperties(properties);
            Logger.Info("[SubtitleSaver] Saved {0} \"{1}\" with encoding \"{2}\", format \"{3}\" and frame rate \"{4}\"",
                        textType, properties.Path, properties.Encoding, format.Name, subtitles.Properties.CurrentFrameRate);
        }
Пример #8
0
        // Open existing file
        private void OpenFileButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileInputOutput fileInput = new FileInputOutput(openFileDialog.OpenFile());
                fileInput.CreateList();
                List <string[]> tempList = fileInput.streamList;

                Stack <Command> commandStack = new Stack <Command>();

                foreach (string[] shape in fileInput.streamList)
                {
                    if (shape[0] == "rectangle")
                    {
                        Command addShape = new AddShapeCommand(shapeList, new RectangleShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                        commandStack.Push(addShape);
                    }

                    if (shape[0] == "ellipse")
                    {
                        Command addShape = new AddShapeCommand(shapeList, new EllipseShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                        commandStack.Push(addShape);
                    }

                    if (shape[0] == "group")
                    {
                        ShapeComposite newGroup = new ShapeComposite(shape[0]);
                        // TODO: pop groupsize add composite shape
                        //newGroup.AddChild(commandStack.Pop());
                    }
                }

                //foreach (string[] shape in fileInput.streamList)
                //{
                //    if (shape[0] == "rectangle")
                //    {
                //        Command addShape = new AddShapeCommand(shapeList, new RectangleShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                //        history.Add(addShape);
                //    }

                //    if (shape[0] == "ellipse")
                //    {
                //        Command addShape = new AddShapeCommand(shapeList, new EllipseShape(shape[0], Int32.Parse(shape[1]), Int32.Parse(shape[2]), Int32.Parse(shape[3]), Int32.Parse(shape[4])));
                //        history.Add(addShape);
                //    }
                //}
            }
            Invalidate();
        }
Пример #9
0
        // Save current file
        private void SaveFileButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileInputOutput   fileOutput        = new FileInputOutput(saveFileDialog.OpenFile());
                FileOutputVisitor fileOutPutVisitor = new FileOutputVisitor(fileOutput);

                foreach (Shape shape in shapeList)
                {
                    shape.Accept(fileOutPutVisitor);
                }
                fileOutput.CloseStreamWriter();

                //fileOutput.WriteFile(shapeList);
            }
        }
Пример #10
0
        /* Private methods */

        /// <summary>Checks the encoding of a file.</summary>
        /// <param name="isSubtitleFile">If it is a subtitle file or a plain text one.</param>
        /// <param name="fileStream">The stream for reading the file.</param>
        /// <param name="usedEncoding">The encoding supposedly used.</param>
        /// <param name="usedFormat">The subtitle format used.</param>
        /// <exception cref="EncodingNotSupportedException">Thrown if the encoding is not supported by the platform.</exception>
        /// <exception cref="UnknownSubtitleFormatException">Thrown if the subtitle format could not be detected.</exception>
        private string ReadSubtitleText(bool isSubtitleFile, FileStream fileStream, out Encoding usedEncoding, out SubtitleFormat usedFormat)
        {
            /* Init the out arguments */
            usedEncoding = null;
            usedFormat   = null;

            /* Detect code pages */
            int[] codePages = FileInputOutput.DetectCodePages(fileStream);

            /* Check if no codepage was detected */
            if (codePages.Length == 0)
            {
                Logger.Info("[SubtitleInput] No encoding was automatically detected. Using the fall-back encoding \"{0}\"", fallbackEncoding.WebName);
                string text;
                if (isSubtitleFile)
                {
                    text = TestEncoding(fileStream, fallbackEncoding, out usedFormat);
                }
                else
                {
                    text = TestEncoding(fileStream, fallbackEncoding);
                }
                usedEncoding = fallbackEncoding;
                return(text);
            }

            /* The first code page represents the most probable encoding. If any problem occurs when trying to use
             * that code page, this problem is registered. The remaining code pages are then tried, and if none works,
             * the first occuring error is the one to be reported. */
            Exception firstEncodingException       = null;
            Exception firstSubtitleFormatException = null;
            int       firstCodePage = codePages[0];

            try {
                string text;
                if (isSubtitleFile)
                {
                    text = TestCodePage(fileStream, firstCodePage, out usedEncoding, out usedFormat);
                }
                else
                {
                    text = TestCodePagePlain(fileStream, firstCodePage, out usedEncoding);
                }
                return(text);
            }
            catch (EncodingNotSupportedException e) {
                firstEncodingException = e;
            }
            catch (UnknownSubtitleFormatException e) {
                firstSubtitleFormatException = e;
            }

            /* Problems were found, going to try additional code pages */
            for (int count = 1; count < codePages.Length; count++)
            {
                try {
                    int    codePage = codePages[count];
                    string text;
                    if (isSubtitleFile)
                    {
                        text = TestCodePage(fileStream, codePage, out usedEncoding, out usedFormat);
                    }
                    else
                    {
                        text = TestCodePagePlain(fileStream, codePage, out usedEncoding);
                    }
                    return(text);
                }
                catch (Exception) {
                    //Don't do anything, will try the next code page
                }
            }

            /* No code page worked, throwing the exceptions caught for the first (more probable) code page */
            if (firstEncodingException != null)
            {
                throw firstEncodingException;
            }
            else
            {
                throw firstSubtitleFormatException;
            }
        }
Пример #11
0
 /// <exception cref="EncodingNotSupportedException">Thrown if the encoding is not supported by the platform.</exception>
 internal string ReadPlain(string path, Encoding encoding)
 {
     using (FileStream fileStream = FileInputOutput.OpenFileForReading(path)) {
         return(TestEncoding(fileStream, encoding));
     }
 }
Пример #12
0
 /// <exception cref="UnknownSubtitleFormatException">Thrown if the subtitle format could not be detected.</exception>
 internal string Read(string path, Encoding encoding, out SubtitleFormat format)
 {
     using (FileStream fileStream = FileInputOutput.OpenFileForReading(path)) {
         return(TestEncoding(fileStream, encoding, out format));
     }
 }
Пример #13
0
 /// <exception cref="EncodingNotSupportedException">Thrown if the encoding is not supported by the platform.</exception>
 /// <exception cref="UnknownSubtitleFormatException">Thrown if the subtitle format could not be detected.</exception>
 internal string Read(string path, out Encoding encoding, out SubtitleFormat format)
 {
     using (FileStream fileStream = FileInputOutput.OpenFileForReading(path)) {
         return(ReadSubtitleText(true, fileStream, out encoding, out format));
     }
 }
Пример #14
0
        static void Main(string[] args)
        {
            TodoApp todoApp;

            Console.WriteLine("- console - to use System.Console as input/output");
            Console.WriteLine("- inmemory - to use in-memory input / output");
            Console.WriteLine("- file - to use file input / output");

            var choice = Console.ReadLine();

            switch (choice.ToLower())
            {
            case "console":
                var consoleIO = new ConsoleInputOutput();

                todoApp = new TodoApp(consoleIO);
                break;

            case "inmemory":
                var inputs     = new string[] { "buy a milk", "go to dentist" };
                var inMemoryIO = new MemoryInputOutput(inputs);

                todoApp = new TodoApp(inMemoryIO);
                break;

            case "file":
                var fileIO = new FileInputOutput();

                todoApp = new TodoApp(fileIO);
                break;

            default:
                throw new Exception("bad choice");
            }

            while (true)
            {
                Console.WriteLine("Available commands: add, print");
                choice = Console.ReadLine();

                switch (choice.ToLower())
                {
                case "add":
                    try
                    {
                        todoApp.Add();
                    }
                    catch (NotImplementedException)
                    {
                        Console.WriteLine("Option is not supported yet");
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                    }
                    break;

                case "print":
                    try
                    {
                        todoApp.Print();
                    }
                    catch (NotImplementedException)
                    {
                        Console.WriteLine("Option is not supported yet");
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                    }
                    break;

                default: continue;
                }
            }
        }
Пример #15
0
 public FileOutputVisitor(FileInputOutput fileOutput)
 {
     this.fileOutput = fileOutput;
 }