示例#1
0
        public static List <Models.Package> GetPackages()
        {
            var packages   = new List <Models.Package>();
            var widgets    = new List <Models.Package>();
            var data       = new List <Models.Package>();
            var packageDir = Portal.ResolvePath(PackageDir);

            if (!Directory.Exists(packageDir))
            {
                Directory.CreateDirectory(packageDir);
            }

            //todo: hacky as we copy logic for each file type... refactor!
            foreach (var file in Directory.GetFiles(packageDir, "*.manifest"))
            {
                var package = file.GetFileJSONObject <Models.Package>(true);
                if (package.Type == "Widget")
                {
                    widgets.Add(package);
                }
                else
                {
                    data.Add(package);
                }
            }
            packages.AddRange(widgets);
            packages.AddRange(data);
            return(packages);
        }
示例#2
0
文件: UI.cs 项目: crazyants/videre
        public static List <Models.Layout> GetLayouts()
        {
            var layouts = new List <Models.Layout>();

            foreach (var file in Directory.GetFiles(Portal.ResolvePath(LayoutPath), "*.manifest"))
            {
                layouts.Add(file.GetFileJSONObject <Models.Layout>(true));
            }
            return(layouts);
        }
示例#3
0
文件: UI.cs 项目: crazyants/videre
        private static bool DeleteResource(string path) //todo: need this???
        {
            var fileName = Portal.ResolvePath(path);

            if (System.IO.File.Exists(fileName))
            {
                System.IO.File.Delete(fileName);
                return(true);
            }
            return(false);
        }
示例#4
0
        public static bool InstallPackage(string name, string portalId)
        {
            var package = GetPackages().Where(p => p.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (package != null)
            {
                InstallFile(Path.Combine(Portal.ResolvePath(PackageDir), package.FileName), portalId, false);
                //System.IO.File.Copy(Path.Combine(Portal.ResolvePath(PackageDir), package.FileName), Path.Combine(Portal.ResolvePath(UpdateDir), package.FileName), true);
                return(true);
            }
            return(false);
        }
示例#5
0
文件: UI.cs 项目: crazyants/videre
        private static string DownloadResource(string url, string relativePath)
        {
            if (url.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase))
            {
                var fileName = url.Split('/').Last();
                relativePath = relativePath.PathCombine(fileName);
                url.DownloadFile(Portal.ResolvePath(relativePath));
                return(relativePath);
            }

            return(url);
        }
示例#6
0
文件: UI.cs 项目: crazyants/videre
        public static List <Models.Theme> GetThemes()
        {
            var themes   = new List <Models.Theme>();
            var themeDir = Portal.ResolvePath(ThemePath);

            if (!Directory.Exists(themeDir))
            {
                Directory.CreateDirectory(themeDir);
            }
            foreach (var file in Directory.GetFiles(themeDir, "*.manifest"))
            {
                themes.Add(file.GetFileJSONObject <Models.Theme>(true));
            }
            return(themes);
        }
示例#7
0
文件: UI.cs 项目: crazyants/videre
        public static void UninstallTheme(string name)
        {
            var theme = GetTheme(name);

            if (theme != null)
            {
                var themeDir = Portal.ResolvePath(ThemePath.PathCombine(theme.Name));
                if (Directory.Exists(themeDir))
                {
                    Directory.Delete(themeDir, true);
                }
                DeleteResource(ThemePath.PathCombine(theme.Name + ".manifest"));
            }
            else
            {
                throw new Exception(string.Format(Localization.GetLocalization(LocalizationType.Exception, "NotFound.Error", "{0} not found.", "Core"), name));
            }
        }
示例#8
0
        private static bool InstallFile(string fileName, string portalId = null, bool removeFile = true)
        {
            var rootDir = Portal.ResolvePath("~/");
            var file    = new FileInfo(fileName);

            if (file != null)
            {
                switch (file.Extension.ToLower())
                {
                case ".zip":
                {
                    Logging.Logger.InfoFormat("Applying update for file: {0}", file.FullName);
                    var zip = new FastZip();
                    zip.ExtractZip(file.FullName, rootDir, FastZip.Overwrite.Always, null, null, null, true);
                    if (removeFile)
                    {
                        System.IO.File.Delete(file.FullName);
                    }
                    return(true);
                }

                case ".json":
                {
                    Logging.Logger.InfoFormat("Applying import for file: {0}", file.FullName);
                    var portalExport = file.FullName.GetFileJSONObject <Models.PortalExport>(false);
                    Services.Portal.Import(portalExport, portalId);
                    if (removeFile)
                    {
                        System.IO.File.Delete(file.FullName);
                    }
                    return(true);
                }

                default:
                {
                    Logging.Logger.Error("Unknown File Extension: " + file.Extension);
                    break;
                    //throw new Exception("Unknown File Extension: " + file.Extension);
                }
                }
            }
            return(false);
        }
示例#9
0
文件: UI.cs 项目: crazyants/videre
        public static void InstallTheme(Models.Theme theme)
        {
            var filePath = Portal.ResolvePath(ThemePath);
            var fileName = filePath + theme.Name + ".manifest";

            if (!System.IO.File.Exists(filePath + theme.Name + ".manifest"))
            {
                theme.Thumbnail = DownloadResource(theme.Thumbnail, ThemePath.PathCombine(theme.Name));
                foreach (var file in theme.Files)
                {
                    file.Path = DownloadResource(file.Path, ThemePath.PathCombine(theme.Name));
                }
                theme.ToJson().WriteText(fileName);
            }
            else
            {
                throw new Exception(string.Format(Localization.GetLocalization(LocalizationType.Exception, "DuplicateResource.Error", "{0} already exists.   Duplicates Not Allowed.", "Core"), "Theme"));
            }
        }
示例#10
0
        public static int ApplyUpdates()
        {
            var updateDir = UpdateDir; //Portal.ResolvePath(ConfigurationManager.AppSettings.GetSetting("UpdateDir", "~/_updates"));
            var rootDir   = Portal.ResolvePath("~/");

            if (!Directory.Exists(updateDir))
            {
                Directory.CreateDirectory(updateDir);
            }
            var dir   = new DirectoryInfo(updateDir);
            var count = 0;
            var files = dir.GetFiles("*.zip");

            foreach (var file in files)
            {
                count += InstallFile(file.FullName) ? 1 : 0;
            }

            //These are specific to a portal!
            //files = dir.GetFiles("*.json");
            //foreach (var file in files)
            //    count += InstallFile(file.FullName) ? 1 : 0;
            return(count);
        }