Example #1
0
        static void CopyDirectory(DirectoryInfo source, DirectoryInfo target, string pkgId, List <PackageFile> installedFiles)
        {
            var rootPath = HttpContext.Current.Server.MapPath(Utils.RelativeWebRoot);

            foreach (var dir in source.GetDirectories())
            {
                var filePath = Path.Combine(target.FullName, dir.Name);
                var relPath  = filePath.Replace(rootPath, "");

                // save directory if it is created by package
                // so we can remove it on package uninstall
                if (!Directory.Exists(filePath))
                {
                    fileOrder++;
                    var fileToCopy = new PackageFile
                    {
                        FilePath    = relPath,
                        PackageId   = pkgId,
                        FileOrder   = fileOrder,
                        IsDirectory = true
                    };
                    installedFiles.Add(fileToCopy);
                }
                CopyDirectory(dir, target.CreateSubdirectory(dir.Name), pkgId, installedFiles);
            }

            foreach (var file in source.GetFiles())
            {
                var filePath = Path.Combine(target.FullName, file.Name);
                var relPath  = filePath.Replace(rootPath, "");

                file.CopyTo(filePath);

                fileOrder++;
                var fileToCopy = new PackageFile
                {
                    FileOrder   = fileOrder,
                    IsDirectory = false,
                    FilePath    = relPath,
                    PackageId   = pkgId
                };

                // fix known interface changes
                if (filePath.ToLower().EndsWith(".cs") ||
                    filePath.ToLower().EndsWith(".aspx") ||
                    filePath.ToLower().EndsWith(".ascx") ||
                    filePath.ToLower().EndsWith(".master"))
                {
                    ReplaceInFile(filePath, "BlogSettings.Instance.StorageLocation", "Blog.CurrentInstance.StorageLocation");
                    ReplaceInFile(filePath, "BlogSettings.Instance.FileExtension", "BlogConfig.FileExtension");
                    ReplaceInFile(filePath, "\"login.aspx", "\"account/login.aspx");
                }

                installedFiles.Add(fileToCopy);
            }
        }
        /// <summary>
        /// Gets list of files for installed package
        /// </summary>
        /// <param name="packageId">Package ID</param>
        /// <returns>List of files for installed package</returns>
        public override List<PackageFile> FillPackageFiles(string packageId)
        {
            var files = new List<PackageFile>();

            using (var conn = this.CreateConnection())
            {
                if (conn.HasConnection)
                {
                    using (var cmd = conn.CreateTextCommand(string.Format("SELECT PackageId, FileOrder, FilePath, IsDirectory FROM {0}PackageFiles ", this.tablePrefix)))
                    {
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                var f = new PackageFile()
                                {
                                    PackageId = rdr.GetString(0),
                                    FileOrder = rdr.GetInt32(1),
                                    FilePath = rdr.GetString(2),
                                    IsDirectory = rdr.GetBoolean(3)
                                };

                                files.Add(f);
                            }
                        }
                    }
                }
            }

            return files;
        }
        static void CopyDirectory(DirectoryInfo source, DirectoryInfo target, string pkgId, List<PackageFile> installedFiles)
        {
            var rootPath = HttpContext.Current.Server.MapPath(Utils.RelativeWebRoot);

            foreach (var dir in source.GetDirectories())
            {
                var filePath = Path.Combine(target.FullName, dir.Name);
                var relPath = filePath.Replace(rootPath, "");

                // save directory if it is created by package
                // so we can remove it on package uninstall
                if (!Directory.Exists(filePath))
                {
                    fileOrder++;
                    var fileToCopy = new PackageFile
                    {
                        FilePath = relPath,
                        PackageId = pkgId,
                        FileOrder = fileOrder,
                        IsDirectory = true
                    };
                    installedFiles.Add(fileToCopy);
                }
                CopyDirectory(dir, target.CreateSubdirectory(dir.Name), pkgId, installedFiles);
            }

            foreach (var file in source.GetFiles())
            {
                var filePath = Path.Combine(target.FullName, file.Name);
                var relPath = filePath.Replace(rootPath, "");

                file.CopyTo(filePath);

                fileOrder++;
                var fileToCopy = new PackageFile
                {
                    FileOrder = fileOrder,
                    IsDirectory = false,
                    FilePath = relPath,
                    PackageId = pkgId
                };

                // fix known interface changes
                if (filePath.ToLower().EndsWith(".cs") ||
                    filePath.ToLower().EndsWith(".aspx") ||
                    filePath.ToLower().EndsWith(".ascx") ||
                    filePath.ToLower().EndsWith(".master"))
                {
                    ReplaceInFile(filePath, "BlogSettings.Instance.StorageLocation", "Blog.CurrentInstance.StorageLocation");
                    ReplaceInFile(filePath, "BlogSettings.Instance.FileExtension", "BlogConfig.FileExtension");
                    ReplaceInFile(filePath, "\"login.aspx", "\"account/login.aspx");
                }

                installedFiles.Add(fileToCopy);
            }
        }
Example #4
0
        static void CopyDirectory(DirectoryInfo source, DirectoryInfo target, string pkgId, List <PackageFile> installedFiles)
        {
            var rootPath = HttpContext.Current.Server.MapPath(Utils.RelativeWebRoot);

            foreach (var dir in source.GetDirectories())
            {
                var dirPath = Path.Combine(target.FullName, dir.Name);

                // Files moved to Custom folder
                dirPath = dirPath.Replace("App_Code", "Custom");
                dirPath = dirPath.Replace("\\themes", "\\Custom\\Themes");
                dirPath = dirPath.Replace("\\widgets", "\\Custom\\Widgets");
                dirPath = dirPath.Replace("\\User controls", "\\Custom\\Controls");

                var relPath = dirPath.Replace(rootPath, "");

                // save directory if it is created by package
                // so we can remove it on package uninstall
                if (!Directory.Exists(dirPath))
                {
                    fileOrder++;
                    var fileToCopy = new PackageFile
                    {
                        FilePath    = relPath,
                        PackageId   = pkgId,
                        FileOrder   = fileOrder,
                        IsDirectory = true
                    };
                    installedFiles.Add(fileToCopy);
                }

                CopyDirectory(dir, Directory.CreateDirectory(dirPath), pkgId, installedFiles);
            }

            foreach (var file in source.GetFiles())
            {
                var filePath = Path.Combine(target.FullName, file.Name);

                // Files moved to Custom folder
                filePath = filePath.Replace("App_Code", "Custom");
                filePath = filePath.Replace("\\themes", "\\Custom\\Themes");
                filePath = filePath.Replace("\\widgets", "\\Custom\\Widgets");
                filePath = filePath.Replace("\\User controls", "\\Custom\\Controls");

                var relPath = filePath.Replace(rootPath, "");

                file.CopyTo(filePath);

                fileOrder++;
                var fileToCopy = new PackageFile
                {
                    FileOrder   = fileOrder,
                    IsDirectory = false,
                    FilePath    = relPath,
                    PackageId   = pkgId
                };

                // fix known interface changes
                if (filePath.ToLower().EndsWith(".cs") ||
                    filePath.ToLower().EndsWith(".aspx") ||
                    filePath.ToLower().EndsWith(".ascx") ||
                    filePath.ToLower().EndsWith(".master"))
                {
                    ReplaceInFile(filePath, "BlogSettings.Instance.StorageLocation", "Blog.CurrentInstance.StorageLocation");
                    ReplaceInFile(filePath, "BlogSettings.Instance.FileExtension", "BlogConfig.FileExtension");
                    ReplaceInFile(filePath, "\"login.aspx", "\"account/login.aspx");

                    // fix older themes having reference to /themes/ folder
                    ReplaceInFile(filePath, "/themes", "/Custom/Themes");
                    ReplaceInFile(filePath, "themes/", "Custom/Themes/");
                    ReplaceInFile(filePath, "}themes", "}Custom/Themes");
                    ReplaceInFile(filePath, "themes{", "Custom/Themes{");

                    ReplaceInFile(filePath, "/User controls", "/Custom/Controls");
                    ReplaceInFile(filePath, "User controls/", "Custom/Controls/");
                }

                installedFiles.Add(fileToCopy);
            }
        }
        static void CopyDirectory(DirectoryInfo source, DirectoryInfo target, string pkgId, List<PackageFile> installedFiles)
        {
            var rootPath = HttpContext.Current.Server.MapPath(Utils.RelativeWebRoot);

            foreach (var dir in source.GetDirectories())
            {
                var dirPath = Path.Combine(target.FullName, dir.Name);

                // Files moved to Custom folder
                dirPath = dirPath.Replace("App_Code", "Custom");
                dirPath = dirPath.Replace("\\themes", "\\Custom\\Themes");
                dirPath = dirPath.Replace("\\widgets", "\\Custom\\Widgets");
                dirPath = dirPath.Replace("\\User controls", "\\Custom\\Controls");

                var relPath = dirPath.Replace(rootPath, "");

                // save directory if it is created by package
                // so we can remove it on package uninstall
                if (!Directory.Exists(dirPath))
                {
                    fileOrder++;
                    var fileToCopy = new PackageFile
                    {
                        FilePath = relPath,
                        PackageId = pkgId,
                        FileOrder = fileOrder,
                        IsDirectory = true
                    };
                    installedFiles.Add(fileToCopy);
                }

                CopyDirectory(dir, Directory.CreateDirectory(dirPath), pkgId, installedFiles);
            }
             
            foreach (var file in source.GetFiles())
            {
                var filePath = Path.Combine(target.FullName, file.Name);

                // Files moved to Custom folder
                filePath = filePath.Replace("App_Code", "Custom");
                filePath = filePath.Replace("\\themes", "\\Custom\\Themes");
                filePath = filePath.Replace("\\widgets", "\\Custom\\Widgets");
                filePath = filePath.Replace("\\User controls", "\\Custom\\Controls");

                var relPath = filePath.Replace(rootPath, "");

                file.CopyTo(filePath);

                fileOrder++;
                var fileToCopy = new PackageFile
                {
                    FileOrder = fileOrder,
                    IsDirectory = false,
                    FilePath = relPath,
                    PackageId = pkgId
                };

                // fix known interface changes
                if (filePath.ToLower().EndsWith(".cs") ||
                    filePath.ToLower().EndsWith(".aspx") ||
                    filePath.ToLower().EndsWith(".ascx") ||
                    filePath.ToLower().EndsWith(".master"))
                {
                    ReplaceInFile(filePath, "BlogSettings.Instance.StorageLocation", "Blog.CurrentInstance.StorageLocation");
                    ReplaceInFile(filePath, "BlogSettings.Instance.FileExtension", "BlogConfig.FileExtension");
                    ReplaceInFile(filePath, "\"login.aspx", "\"account/login.aspx");

                    // fix older themes having reference to /themes/ folder
                    ReplaceInFile(filePath, "/themes", "/Custom/Themes");
                    ReplaceInFile(filePath, "themes/", "Custom/Themes/");
                    ReplaceInFile(filePath, "}themes", "}Custom/Themes");
                    ReplaceInFile(filePath, "themes{", "Custom/Themes{");

                    ReplaceInFile(filePath, "/User controls", "/Custom/Controls");
                    ReplaceInFile(filePath, "User controls/", "Custom/Controls/");
                }

                installedFiles.Add(fileToCopy);
            }   
        }