public static TM_FileStorage                     clear_GuidanceItemsCache(this TM_FileStorage tmFileStorage)
        {
            var tmXmlDatabase = tmFileStorage.tmXmlDatabase();

            if (tmFileStorage.isNull() || tmXmlDatabase.isNull())
            {
                return(tmFileStorage);
            }

            "[TM_Xml_Database] clear_GuidanceItemsCache".info();

            var cacheFile = tmFileStorage.getCacheLocation();

            if (cacheFile.notNull() && cacheFile.fileExists())
            {
                Files.deleteFile(cacheFile);
                "cache file deleted OK:{0}".info(cacheFile.fileExists().isFalse());
            }
            tmXmlDatabase.Cached_GuidanceItems.Clear();
            return(tmFileStorage);
        }
        public static TM_FileStorage                    xmlDB_Load_GuidanceItems_and_Create_CacheFile(this TM_FileStorage tmFileStorage)
        {
            var tmXmlDatabase = tmFileStorage.tmXmlDatabase();

            if (tmFileStorage.isNull() || tmXmlDatabase.isNull())
            {
                return(tmFileStorage);
            }

            var pathXmlLibraries = tmFileStorage.Path_XmlLibraries;

            if (pathXmlLibraries.notNull() && pathXmlLibraries.notNull())
            {
                lock (pathXmlLibraries)
                {
                    "[TM_FileStorage] in xmlDB_Load_GuidanceItems, creating cache file".debug();
                    var o2Timer = new O2Timer("[TM_FileStorage] loaded GuidanceItems from disk").start();
                    //Load GuidanceItem from the disk
                    foreach (var item in tmFileStorage.GuidanceExplorers_Paths)
                    {
                        var guidanceExplorer           = item.Key;
                        var pathToLibraryGuidanceItems = item.Value.parentFolder();
                        var libraryId = guidanceExplorer.library.name.guid();
                        "libraryId: {0} : {1}".info(libraryId, pathToLibraryGuidanceItems);
                        var filesToLoad = pathToLibraryGuidanceItems.files(true, "*.xml");
                        tmXmlDatabase.xmlDB_Load_GuidanceItemsV3(libraryId, filesToLoad);
                    }

                    //save it to the local cache file (reduces load time from 8s to 0.5s)
                    tmFileStorage.save_GuidanceItemsToCache();

                    tmXmlDatabase.ensureFoldersAndViewsIdsAreUnique();
                    tmXmlDatabase.removeMissingGuidanceItemsIdsFromViews();
                    o2Timer.stop();
                }
            }
            return(tmFileStorage);
        }
Ejemplo n.º 3
0
        public static bool siteData_Handle_VirtualPath(this TM_FileStorage tmFileStorage, string virtualPath)
        {
            if (tmFileStorage.isNull() || virtualPath.isNull())
            {
                return(false);
            }

            //temp_SwapSiteDataUtil(virtualPath.removeFirstChar());

            var pathSiteData = tmFileStorage.path_SiteData();

            if (pathSiteData.isNull())
            {
                return(false);
            }

            var fullPath = pathSiteData.pathCombine(virtualPath);

            if (fullPath.fileExists().isFalse())
            {
                fullPath = pathSiteData.pathCombine(virtualPath.fileName()); // see if the file is in the root
            }
            if (fullPath.contains(pathSiteData).isFalse())                   // prevent file transversal
            {
                return(false);
            }
            if (fullPath.fileExists())
            {
                return(fullPath.siteData_WriteFileToResponseStream());
            }

            if (virtualPath == "siteData")
            {
                return(true);
            }
            return(false);
        }
        public static string install_LibraryFromZip(this TM_FileStorage tmFileStorage, string pathToGitHubZipBall, string libraryName)
        {
            UserGroup.Admin.assert();
            try
            {
                var tmXmlDatabase = tmFileStorage.tmXmlDatabase();
                if (tmFileStorage.isNull() || tmXmlDatabase.isNull())
                {
                    return(null);
                }

                var tmLibrary = tmXmlDatabase.tmLibrary(libraryName);
                if (tmLibrary.notNull())
                {
                    "[Install_LibraryFromZip] Skyping library {0} because it already existed".debug(libraryName);
                    return(tmFileStorage.xmlDB_Path_Library_RootFolder(tmLibrary));
                }
                var tmLibraries_Before = tmXmlDatabase.tmLibraries();

                var result = tmFileStorage.xmlDB_Libraries_ImportFromZip(pathToGitHubZipBall, "");

                var tmLibraries_After = tmXmlDatabase.tmLibraries();
                var installedLibrary  = tmXmlDatabase.tmLibrary(libraryName);

                Assert.IsTrue(result, "xmlDB_Libraries_ImportFromZip");
                Assert.IsNotEmpty(tmLibraries_After, "Libraries should be there after install");
                Assert.AreNotEqual(tmLibraries_After.size(), tmLibraries_Before.size(), "Libraries size should be different before and after");
                Assert.IsNotNull(installedLibrary, "Could not find installed library: {0}".format(libraryName));
                Assert.AreEqual(installedLibrary.Caption, libraryName, "After install library names didn't match");
                return(tmFileStorage.xmlDB_Path_Library_RootFolder(installedLibrary));
            }
            finally
            {
                UserGroup.None.assert();
            }
        }