Beispiel #1
0
        public void Parse(FileV8Reader fileV8Reader, V8FileSystem fileSystem, string output, int threads = 1)
        {
            foreach (var reference in fileSystem.References)
            {
                fileV8Reader.Seek(reference.RefToData, SeekOrigin.Begin);
                string path = output + reference.FileHeader.FileName;

                using (MemoryStream memStream = new MemoryStream())
                {
                    using (MemoryStream memReader = new MemoryStream(fileV8Reader.ReadBytes(fileV8Reader.ReadBlockHeader())))
                    {
                        if (reference.IsInFlated)
                        {
                            using (DeflateStream deflateStream = new DeflateStream(memReader, CompressionMode.Decompress))
                            {
                                deflateStream.CopyTo(memStream);
                            }
                        }
                        else
                        {
                            memReader.CopyTo(memStream);
                        }
                    }

                    if (fileV8Reader.IsV8FileSystem(memStream))
                    {
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        memStream.Seek(0, SeekOrigin.Begin);
                        using (FileV8Reader tmpV8Reader = new FileV8Reader(new BinaryReader(memStream, Encoding.Default, true)))
                        {
                            reference.Folder = tmpV8Reader.ReadV8FileSystem(false);
                            Parse(tmpV8Reader, reference.Folder, path + "\\");
                        }
                    }
                    else
                    {
                        using (FileStream fileStream = File.Create(path))
                        {
                            memStream.Seek(0, SeekOrigin.Begin);
                            memStream.CopyTo(fileStream);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public ActionResult FileUpload()
        {
            List<TreeModel> model = null;
            Guid guid = Guid.NewGuid();
            string directory = AppDomain.CurrentDomain.BaseDirectory + "temp\\" + guid + "\\";

            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i]; //Uploaded file
                //Use the following properties to get file's name, size and MIMEType
                //int fileSize = file.ContentLength;
                //string fileName = file.FileName;
                //string mimeType = file.ContentType;
                //Stream fileContent = file.InputStream;

                

                using (BinaryReader reader = new BinaryReader(file.InputStream))
                {
                    using (FileV8Reader v8Reader = new FileV8Reader(reader))
                    {
                        var fileSystem = v8Reader.ReadV8FileSystem();
                        new V8Commit20(_hashService, _convertionService).Parse(v8Reader, fileSystem, directory);
                    }
                }
                
                //To save file, use SaveAs method
                //file.SaveAs(Server.MapPath("~/") + fileName); //File will be saved in application root
            }

            if (Directory.Exists(directory))
            {
                model = new List<TreeModel>();
                string[] dirs = Directory.GetDirectories(directory);
                FillTreeModel(model, dirs);
                //foreach (string dir in dirs)
                //{
                //    model.Add(new TreeModel() { File = Path.GetFileName(dir)});

                //}
            }

            return PartialView("TreeViewPartial", model);
        }
Beispiel #3
0
        /// <summary>
        /// Checks the stream matching 1CV8 file
        /// </summary>
        /// <param name="stream">
        /// <see cref="System.IO.MemoryStream"/>, passed by reference,
        /// that contains the data to be checked
        /// </param>
        /// <returns>
        /// Returns the result of the comparison
        /// <see cref="System.IO.MemoryStream"/> with file description 1CV8
        /// </returns>
        /// <example> This sample shows how to use
        /// the IsV8FileSystem method from your plugin
        /// <code>
        ///
        /// using (FileV8Reader v8Reader = new FileV8Reader(Input))
        /// {
        ///     var fileSystem = v8Reader.ReadV8FileSystem();
        ///     foreach (var reference in fileSystem.References)
        ///     {
        ///         v8Reader.Seek(reference.RefToData, SeekOrigin.Begin);
        ///         using (MemoryStream memStream = new MemoryStream())
        ///         {
        ///             using (MemoryStream memReader = new MemoryStream(v8Reader.ReadBytes(v8Reader.ReadBlockHeader())))
        ///             {
        ///                 if (reference.IsInFlated)
        ///                 {
        ///                     using (DeflateStream deflateStream = new DeflateStream(memReader, CompressionMode.Decompress))
        ///                     {
        ///                         deflateStream.CopyTo(memStream);
        ///                     }
        ///                 }
        ///                 else
        ///                 {
        ///                     memReader.CopyTo(memStream);
        ///                 }
        ///             }
        ///
        ///             if (v8Reader.IsV8FileSystem(memStream))
        ///             {
        ///                 // some yours сode
        ///             }
        ///             else
        ///             {
        ///                 // some yours сode
        ///             }
        ///         }
        ///     }
        /// }
        ///
        /// </code>
        /// </example>
        /// <permission cref="System.Security.PermissionSet">Everyone
        /// can access this method.
        /// </permission>
        public bool IsV8FileSystem(MemoryStream stream)
        {
            if (stream.Capacity < V8ContainerHeader.Size() + V8BlockHeader.Size())
            {
                return(false);
            }

            stream.Seek(0, SeekOrigin.Begin);
            using (FileV8Reader tmpV8Reader = new FileV8Reader(new BinaryReader(stream, Encoding.Default, true)))
            {
                try
                {
                    tmpV8Reader.ReadContainerHeader();
                    tmpV8Reader.ReadBlockHeader();
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #4
0
 public void Parse(FileV8Reader fileV8Reader, V8FileSystem fileSystem, string output, int threads = 1)
 {
     throw new NotImplementedException();
 }
Beispiel #5
0
        public int Invoke()
        {
            /* Common check input file */
            try
            {
                if (!File.Exists(Input))
                {
                    Console.WriteLine("File does not exist.");
                    return 1;
                }
            }
            catch
            {
                Console.WriteLine("Unexpected error. Invalid file.");
                return 1;
            }

            /* Common check output directory */
            try
            {
                Output += "\\";
                if (!Directory.Exists(Output))
                {
                    Directory.CreateDirectory(Output);
                }
            }
            catch
            {
                Console.WriteLine("Unexpected error. Invalid directory.");
                return 1;
            }

            /* Try to parse with plugin (lazy loading .dll) */
            try
            {
                /* Checking plugins directory */ 
                string pluginDirectory = AppDomain.CurrentDomain.BaseDirectory + "\\plugins\\";
                if (!Directory.Exists(pluginDirectory))
                {
                    Console.WriteLine("Loading plugin error. Plugins folder does not exist.");
                    return 1;
                }

                /* Initializing DirectoryCatalog for CompositionContainer  */
                using (var directory = new DirectoryCatalog(pluginDirectory))
                {
                    /* Initializing CompositionContainer for composing parts. */
                    using (var container = new CompositionContainer(directory))
                    {
                        /* Constructor plugin injection */
                        container.ComposeExportedValue("HashService", ServiceLocator.Current.GetInstance<IHashService>());
                        container.ComposeExportedValue("CovertionService", ServiceLocator.Current.GetInstance<IConversionService<UInt64, DateTime>>());
                        
                        /* Lazy loading plugins in _plugins */
                        container.ComposeParts(this);

                        /* Initialize FileV8Reader, V8FileSystem */
                        using (FileV8Reader v8Reader = new FileV8Reader(Input))
                        {
                            var fileSystem = v8Reader.ReadV8FileSystem();
                            foreach (var plugin in _plugins)
                            {
                                if (String.Equals(plugin.Metadata.Name, Plugin, StringComparison.OrdinalIgnoreCase))
                                {
                                    /* Lazy loading matched plugin and try to parse input file */
                                    plugin.Value.Parse(v8Reader, fileSystem, Output, Threads);
                                    return 0;
                                }
                            }
                        }
                    }
                }   
            }
            catch(Exception exception)
            {
                Console.WriteLine("{0} Exception caught.", exception);
                return 1;
            }

            Console.WriteLine("Plugin with name: {0} not found.", Plugin);
            return 1;
        }
Beispiel #6
0
        public void Parse(FileV8Reader fileV8Reader, V8FileSystem fileSystem, string output, int threads = 1)
        {
            FileV8Tree rootTree = GetDescriptionTree(fileV8Reader, fileSystem, String.Empty, @"root");
            FileV8Tree rootPropertiesTree = GetDescriptionTree(fileV8Reader, fileSystem, String.Empty, rootTree.GetLeaf(1).Value);
           
            FileV8Tree objectModule = rootPropertiesTree.GetLeaf(3, 1, 1, 3, 1, 1, 2);
            FileV8Tree forms = GetFormsTree(rootPropertiesTree);
            FileV8Tree models = GetModelsTree(rootPropertiesTree);

            if (fileV8Reader.FindFileSystemReferenceByFileHeaderName(fileSystem.References, objectModule.Value + ".0") != null)
            {
                FileV8Tree objectModuleTree = GetDescriptionTree(fileV8Reader, fileSystem, objectModule.Value + ".0", @"text");
                {
                    string path = output + "\\МодульОбъекта\\";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    string module = '\uFEFF' + objectModuleTree.GetLeaf(0).Value;

                    string filePath = path + "МодульОбъекта.txt";
                    string hashFile = _hashService.HashFile(filePath);
                    string hashModule = _hashService.HashString(module);

                    if (!hashModule.Equals(hashFile))
                    {
                        using (StreamWriter fileStream = new StreamWriter(filePath))
                        {
                            fileStream.Write(module);
                        }
                    }
                }
            }
                    
            if(!Directory.Exists(output + "Form"))
            {
                Directory.CreateDirectory(output + "Form");
            }

            if (!Directory.Exists(output + "СКД"))
            {
                Directory.CreateDirectory(output + "СКД");
            }
            /* Directories that are mighty to be deleted */
            List<string> directories = new List<string>();
            directories.AddRange(Directory.GetDirectories(output + "Form"));
            directories.AddRange(Directory.GetDirectories(output + "СКД"));

            if (forms != null)
            {
                int count = Convert.ToInt32(forms.GetNode(1).Value);
                for(int i = 2; i < count + 2; i++)
                {
                    FileV8Tree formTree = GetDescriptionTree(fileV8Reader, fileSystem, String.Empty, forms.GetNode(i).Value + ".0");
                    FileV8Tree formPropertiesTree = GetDescriptionTree(fileV8Reader, fileSystem, String.Empty, forms.GetNode(i).Value);

                    string formName = formPropertiesTree.GetLeaf(1, 1, 1, 1, 2).Value.Replace("\"", "");
                    string path = output + "Form\\" + formName;
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    // This directory is no needed to be deleted
                    directories.Remove(path);
                
                    string tmpSheet = formTree.GetLeaf(2).Value;
                    string formModule = '\uFEFF' + tmpSheet.Substring(1, tmpSheet.Length - 2).Replace("\"\"", "\"");

                    string filePath = path + "\\" + formName + ".txt";
                    string hashFile = _hashService.HashFile(filePath);
                    string hashForm = _hashService.HashString(formModule);

                    if (!hashForm.Equals(hashFile))
                    {
                        using (StreamWriter fileStream = new StreamWriter(filePath))
                        {
                            fileStream.Write(formModule);
                        }
                    }
                }
            }

            if (models != null)
            {
                int count = Convert.ToInt32(models.GetNode(1).Value);
                for (int i = 2; i < count + 2; i++)
                {
                    FileV8Tree modelTree = GetDescriptionTree(fileV8Reader, fileSystem, String.Empty, models.GetNode(i).Value + ".0");
                    FileV8Tree modelPropertiesTree = GetDescriptionTree(fileV8Reader, fileSystem, String.Empty, models.GetNode(i).Value);

                    string modelName = modelPropertiesTree.GetLeaf(1, 2, 2).Value.Replace("\"", "");
                    string path = output + "СКД\\" + modelName;
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    /* This directory is no needed to be deleted */
                    directories.Remove(path);

                    string tmpSheet = modelTree.GetLeaf(0).Value;

                    int index = tmpSheet.IndexOf("<?xml");
                    string modelModule;
                    if (tmpSheet.IndexOf("<?xml") == -1)
                    {
                        modelModule = tmpSheet;
                    }
                    else
                    {
                        modelModule = tmpSheet.Substring(tmpSheet.IndexOf("<?xml"));
                    }

                    string filePath = path + "\\" + modelName + ".txt";
                    string hashFile = _hashService.HashFile(filePath);
                    string hashModel = _hashService.HashString(modelModule);

                    if (!hashModel.Equals(hashFile))
                    {
                        using (StreamWriter fileStream = new StreamWriter(filePath))
                        {
                            fileStream.Write(modelModule);
                        }
                    }
                }
            }

            // This directories are need to be deleted
            DeleteDirectories(directories);
        }
Beispiel #7
0
        private FileV8Tree GetDescriptionTree(FileV8Reader fileV8Reader, V8FileSystem fileSystem, string folderName, string fileName)
        {
            if (String.IsNullOrEmpty(folderName))
            {
                var file = fileV8Reader.FindFileSystemReferenceByFileHeaderName(fileSystem.References, fileName);
                if (file == null)
                {
                    RaiseFileNotExistsException(fileName);
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    fileV8Reader.ReadV8FileRawData(stream, file);
                    return fileV8Reader.ParseV8File(stream, fileName);
                }
            }
            else
            {
                var folder = fileV8Reader.FindFileSystemReferenceByFileHeaderName(fileSystem.References, folderName);
                if (folder == null)
                {
                    RaiseFileNotExistsException(folderName);
                }

                using (MemoryStream stream = new MemoryStream())
                {
                    fileV8Reader.ReadV8FileRawData(stream, folder);
                    if (fileV8Reader.IsV8FileSystem(stream))
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        using (FileV8Reader tmpV8Reader = new FileV8Reader(new BinaryReader(stream, Encoding.Default, true)))
                        {
                            folder.Folder = tmpV8Reader.ReadV8FileSystem(false);
                            return GetDescriptionTree(tmpV8Reader, folder.Folder, String.Empty, fileName);
                        }
                    }
                    else
                    {
                        RaiseItIsNotV8FolderException(folderName);
                    }
                }
            }

            return null; 
        }
Beispiel #8
0
        /// <summary>
        /// Checks the stream matching 1CV8 file 
        /// </summary>
        /// <param name="stream">
        /// <see cref="System.IO.MemoryStream"/>, passed by reference, 
        /// that contains the data to be checked
        /// </param>
        /// <returns>
        /// Returns the result of the comparison 
        /// <see cref="System.IO.MemoryStream"/> with file description 1CV8
        /// </returns>
        /// <example> This sample shows how to use 
        /// the IsV8FileSystem method from your plugin
        /// <code>
        /// 
        /// using (FileV8Reader v8Reader = new FileV8Reader(Input))
        /// {
        ///     var fileSystem = v8Reader.ReadV8FileSystem();
        ///     foreach (var reference in fileSystem.References)
        ///     {
        ///         v8Reader.Seek(reference.RefToData, SeekOrigin.Begin);
        ///         using (MemoryStream memStream = new MemoryStream())
        ///         {
        ///             using (MemoryStream memReader = new MemoryStream(v8Reader.ReadBytes(v8Reader.ReadBlockHeader())))
        ///             {
        ///                 if (reference.IsInFlated)
        ///                 {
        ///                     using (DeflateStream deflateStream = new DeflateStream(memReader, CompressionMode.Decompress))
        ///                     {
        ///                         deflateStream.CopyTo(memStream);
        ///                     }
        ///                 }
        ///                 else
        ///                 {
        ///                     memReader.CopyTo(memStream);
        ///                 }
        ///             }
        ///
        ///             if (v8Reader.IsV8FileSystem(memStream))
        ///             {
        ///                 // some yours сode
        ///             }
        ///             else
        ///             {
        ///                 // some yours сode        
        ///             }
        ///         }
        ///     }
        /// }
        /// 
        /// </code>
        /// </example>
        /// <permission cref="System.Security.PermissionSet">Everyone 
        /// can access this method.
        /// </permission>
        public bool IsV8FileSystem(MemoryStream stream)
        {
            if (stream.Capacity < V8ContainerHeader.Size() + V8BlockHeader.Size())
            {
                return false;
            }

            stream.Seek(0, SeekOrigin.Begin);
            using (FileV8Reader tmpV8Reader = new FileV8Reader(new BinaryReader(stream, Encoding.Default, true)))
            {
                try
                {
                    tmpV8Reader.ReadContainerHeader();
                    tmpV8Reader.ReadBlockHeader();
                }
                catch
                {
                    return false;
                }
            }

            return true;
        }