Example #1
0
        private static void DeserializeCatalog(string[] args)
        {
            string fileName            = args[0];
            string serializationFormat = args[1];

            try
            {
                MyDirectory dir = MySerializer.DeserializeFromFile(fileName, serializationFormat);

                if (dir != null)
                {
                    PrintSubDirectoriesAndFiles(dir);
                }
                else
                {
                    Console.WriteLine($"File \"{fileName}\" does not exist, or wrong serialization format. {Help}");
                }
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine(@"The file is damaged, or not the result of the program ""CatalogSerializer""");
            }
            catch (SerializationException)
            {
                Console.WriteLine(@"Trying to deserialize file, serialized to another format");
            }
        }
Example #2
0
        private static void SerializeCatalog(string[] args)
        {
            string path                = args[0].Trim('"');
            string fileName            = args[1];
            string serializationFormat = args[2];

            try
            {
                if (Directory.Exists(path))
                {
                    MyDirectory dir = new MyDirectory(path);
                    MyDirectory.Init(dir);

                    switch (serializationFormat)
                    {
                    case "-bin":
                        MySerializer.SerializeBinary(dir, fileName);
                        Console.WriteLine("Binary serialization was successful");
                        break;

                    case "-xml":
                        MySerializer.SerializeXml(dir, fileName);
                        Console.WriteLine("Xml serialization was successful");
                        break;

                    default:
                        Console.WriteLine($"Wrong serialization format. {Help}");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Directory not found");
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Illegal characters in file name");
            }
            catch (UnauthorizedAccessException)
            {
                Console.WriteLine("File can't be overwriten");
            }
        }