Esempio n. 1
0
        /// <summary>
        /// Loads the contents of a physical folder into structured storage
        /// </summary>
        /// <param name="path">The current physical path to load</param>
        /// <param name="container">The StorageContainer to be loaded</param>
        void ProcessStorageFolder(string path, StorageContainer container, WorkerProgressHandler progress)
        {
            byte[] buffer = new byte[8192];                     // Local file buffer array
            int    read;                                        // Bytes read from the file

            Invoke(progress, new object[] { "Processing folder " + path });

            // Add all of the files into the StorageContainer by creating new
            // StorageObjects for each of them and copying the data 8KB at a time

            foreach (string filename in Directory.GetFiles(path))
            {
                StorageObject obj = container.Objects.Add(Path.GetFileName(filename));

                using (FileStream reader = File.OpenRead(filename))
                {
                    using (StorageObjectStream writer = obj.GetWriter())
                    {
                        do
                        {
                            read = reader.Read(buffer, 0, 8192);
                            if (read > 0)
                            {
                                writer.Write(buffer, 0, read);
                            }
                        } while (read > 0);
                    }
                }
            }

            // Now recursively create all of the subdirectories and process them

            foreach (string folder in Directory.GetDirectories(path))
            {
                StorageContainer cont = container.Containers.Add(Path.GetFileName(folder));
                ProcessStorageFolder(folder, cont, progress);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Special case version of ProcessStorage folder to deal with the root ASP.NET
        /// folder exclusions like web.config, \bin, \app_code, etc.
        /// </summary>
        /// <param name="path">The current physical path to load</param>
        /// <param name="container">The StorageContainer to be loaded</param>
        void ProcessRootStorageFolderSpecial(string path, StorageContainer container, WorkerProgressHandler progress)
        {
            byte[] buffer = new byte[8192];                     // Local file buffer array
            int    read;                                        // Bytes read from the file
            string nameOnly;                                    // File name only portion of the path

            Invoke(progress, new object[] { "Processing folder " + path });

            // Add all of the files into the StorageContainer by creating new
            // StorageObjects for each of them and copying the data 8KB at a time

            foreach (string filename in Directory.GetFiles(path))
            {
                nameOnly = Path.GetFileName(filename);                          // Get the file name

                // SPECIAL CASE FILES
                if (nameOnly.StartsWith("global.asax", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (nameOnly.Equals("web.config", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if ((Path.GetExtension(nameOnly) == ".xml") && (IsFileSiteMapXml(filename)))
                {
                    continue;
                }

                StorageObject obj = container.Objects.Add(Path.GetFileName(nameOnly));

                using (FileStream reader = File.OpenRead(filename))
                {
                    using (StorageObjectStream writer = obj.GetWriter())
                    {
                        do
                        {
                            read = reader.Read(buffer, 0, 8192);
                            if (read > 0)
                            {
                                writer.Write(buffer, 0, read);
                            }
                        } while (read > 0);
                    }
                }
            }

            // Now recursively create all of the subdirectories and process them

            foreach (string folder in Directory.GetDirectories(path))
            {
                nameOnly = Path.GetFileName(folder);                            // Get the folder name

                // SPECIAL CASE FOLDERS
                if (nameOnly.Equals("bin", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (nameOnly.Equals("app_code", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (nameOnly.Equals("app_data", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (nameOnly.Equals("app_globalresources", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (nameOnly.Equals("app_localresources", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                StorageContainer cont = container.Containers.Add(Path.GetFileName(nameOnly));
                ProcessStorageFolder(folder, cont, progress);
            }
        }