public static string fetchTestFileFromDeployServer(string url) { string downloadedFile = new Web().downloadBinaryFile(url); Assert.That(downloadedFile != null, "no Unzip files returned"); Assert.That(File.Exists(downloadedFile), "downloadedFile doesn't exist" + downloadedFile); return downloadedFile; }
public static string fetchTestFileFromDeployServer_AndUnzipIt(string url) { List<string> unzipedFiles = new Web().downloadZipFileAndExtractFiles(url); Assert.That(unzipedFiles != null, "no Unzip files returned"); Assert.That(unzipedFiles.Count == 1, "There should only be only file inside the zip file"); Assert.That(File.Exists(unzipedFiles[0]), "unzipedFiles[0] doesn't exist!! " + unzipedFiles[0]); return unzipedFiles[0]; }
public ascx_Task_WebPost() { this.TaskType = "Web (Post request)"; this.TaskName = "..."; this.TaskFunction = () => { var response = new Web().getUrlContents_POST(TaskName, ""); messageLabel.set_Text("response size: {0}".format(response.size())); return response != ""; }; }
public static List<SvnMappedUrl> getSvnMappedUrls(string urlToFetch) { var svnMappedUrls = new List<SvnMappedUrl>(); var codeToParse = new Web().getUrlContents(urlToFetch); if (codeToParse != "") { var nodes = Majestic12ToXml.ConvertNodesToXml(codeToParse); foreach (var element in nodes.OfType<XElement>().Descendants("li").Descendants("a")) { var virtualPath = element.Attribute("href").Value; if (virtualPath != "../") svnMappedUrls.Add(new SvnMappedUrl(urlToFetch, virtualPath, element.Value)); } } return svnMappedUrls; }
public override bool execute() { if (sourceObject == null) return false; var fileToUnzip = (string) sourceObject; if (fileToUnzip.IndexOf("http://") > -1) fileToUnzip = new Web().downloadBinaryFile(fileToUnzip); if (!File.Exists(fileToUnzip)) return false; folderToUnzipFiles = folderToUnzipFiles ?? DI.config.TempFolderInTempDirectory; List<string> unzipedFiles = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(fileToUnzip, folderToUnzipFiles); if (unzipedFiles.Count == 0) return false; resultsObject = unzipedFiles; return true; }
public static string invokeWebServiceAndGetJSON(this string webServicesUrl, string method, string postData) { var requestUrl = "{0}/{1}".format(webServicesUrl, method); "[invokeWebServiceAndGetJSON] requestUrl: {0}".info(requestUrl); var web = new Web(); var response = web.getUrlContents_POST(requestUrl,"application/json; charset=UTF-8","",postData); "[invokeWebServiceAndGetJSON] response size: {0}".info(response.size()); return response; }
public static string getHtmlCode(string urlToFetch) { var urlContents = new Web().getUrlContents(urlToFetch); return urlContents; }
public bool checkIfRulesDatabaseIsAvailable() { var urlContents = new Web().getUrlContents(XRulesDatabase); Assert.That(false == string.IsNullOrEmpty(urlContents), "urlContents was empty"); return true; }
public void backup_Files(string backupFolder) { var files_BackupFolder = backupFolder.pathCombine("Files"); files_BackupFolder.createDir(); var files = WikiApi.allImages(); "there are {0} files to download".info(files.size()); Status_ProgressBar.maximum(files.size()); Status_ProgressBar.value(0); foreach(var file in files) { if (CancelBackup) { "In backup_Files, CancelBackup was set, so aborting backup".error(); break; } var web = new Web(); if (WikiApi.BasicAuth.valid()) web.Headers_Request.add("Authorization","Basic " + WikiApi.BasicAuth); web.downloadBinaryFile(file, files_BackupFolder); Status_ProgressBar.increment(1); } }
public bool checkIfSvnServerIsOnline() { var urlContents = new Web().getUrlContents(svnServer); Assert.That(false == string.IsNullOrEmpty(urlContents), "urlContents was empty"); return true; }
public static bool xmlDB_Libraries_ImportFromZip(this TM_Xml_Database tmDatabase, string zipFileToImport) { try { if (zipFileToImport.isUri()) { "[xmlDB_Libraries_ImportFromZip] provided value was an URL so, downloading it: {0}".info(zipFileToImport); zipFileToImport = new Web().downloadBinaryFile(zipFileToImport); //zipFileToImport = zipFileToImport.uri().download(); } "[xmlDB_Libraries_ImportFromZip] importing library from: {0}".info(zipFileToImport); if (zipFileToImport.fileExists().isFalse()) "[xmlDB_Libraries_ImportFromZip] could not find file to import".error(zipFileToImport); else { var currentLibraryPath = TM_Xml_Database.Path_XmlLibraries; var libraryName = Path.GetFileNameWithoutExtension(zipFileToImport); var libraryFilePath = tmDatabase.xmlDB_LibraryPath(libraryName); var guidanceItemsPath = tmDatabase.xmlDB_LibraryPath_GuidanceItems(libraryName); if (libraryFilePath.fileExists().isFalse() && guidanceItemsPath.dirExists().isFalse()) { new ICSharpCode.SharpZipLib.Zip.FastZip().ExtractZip(zipFileToImport, currentLibraryPath, ""); //zipFileToImport.unzip_File(currentLibraryPath); return true; } else "[xmlDB_Libraries_ImportFromZip] could not import library with name {0} since there was already one with that name".error(libraryName); } } catch (Exception ex) { ex.log("[xmlDB_Libraries_ImportFromZip]"); } return false; }
public static bool xmlDB_Libraries_ImportFromZip(this TM_Xml_Database tmDatabase, string zipFileToImport, string unzipPassword) { try { if (zipFileToImport.isUri()) { "[xmlDB_Libraries_ImportFromZip] provided value was an URL so, downloading it: {0}".info(zipFileToImport); zipFileToImport = new Web().downloadBinaryFile(zipFileToImport); //zipFileToImport = zipFileToImport.uri().download(); } "[xmlDB_Libraries_ImportFromZip] importing library from: {0}".info(zipFileToImport); if (zipFileToImport.fileExists().isFalse()) "[xmlDB_Libraries_ImportFromZip] could not find file to import".error(zipFileToImport); else { var currentLibraryPath = TM_Xml_Database.Path_XmlLibraries; // handle the zips we get from GitHub var tempDir = "_unzip".tempDir(); var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); fastZip.Password = unzipPassword ?? unzipPassword; fastZip.ExtractZip(zipFileToImport, tempDir, ""); var gitZipFolderName = tempDir.folders().first().folderName(); // the first folder should be the one created by gitHub's zip var xmlFile_location1 = tempDir.pathCombine(gitZipFolderName + ".xml"); var xmlFile_location2 = tempDir.pathCombine(gitZipFolderName).pathCombine(gitZipFolderName + ".xml"); if (xmlFile_location1.fileExists() || xmlFile_location2.fileExists()) // if these exists here, just copy the unziped files directly { Files.copyFolder(tempDir,currentLibraryPath,true,true,".git"); if (xmlFile_location1.fileExists()) Files.copy(xmlFile_location1, currentLibraryPath.pathCombine(gitZipFolderName)); return true; } //if (zipFileToImport.extension() == ".master") else { var gitZipDir = tempDir.pathCombine(gitZipFolderName); foreach (var libraryFolder in gitZipDir.folders()) { var libraryName = libraryFolder.folderName(); var targetFolder = currentLibraryPath.pathCombine(libraryName); //default behaviour is to override the existing libraries /*if (targetFolder.dirExists()) { "[xmlDB_Libraries_ImportFromZip] [from Git zip] could not import library with name {0} since there was already one with that name".error(libraryFolder.folderName()); return false; }*/ Files.copyFolder(libraryFolder, currentLibraryPath); //handle the case where the xml file is located outside the library folder var libraryXmlFile = gitZipDir.pathCombine("{0}.xml".format(libraryName)); if (libraryXmlFile.fileExists()) Files.copy(libraryXmlFile, targetFolder); // put it in the Library folder which is where it really should be } var virtualMappings = gitZipDir.pathCombine("Virtual_Articles.xml"); if (virtualMappings.fileExists()) { Files.copy(virtualMappings, currentLibraryPath); // copy virtual mappings if it exists tmDatabase.mapVirtualArticles(); } return true; } /*else { //if it is a normal zip, the expectation is that the zip is the library name var libraryName = Path.GetFileNameWithoutExtension(zipFileToImport); var libraryFilePath = tmDatabase.xmlDB_LibraryPath(libraryName); var guidanceItemsPath = tmDatabase.xmlDB_LibraryPath_GuidanceItems(libraryName); //default behaviour is to override the existing libraries //if (libraryFilePath.fileExists() && libraryFilePath.fileInfo().size() == 0 || // libraryFilePath.fileExists().isFalse() && guidanceItemsPath.dirExists().isFalse()) //{ var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); fastZip.Password = unzipPassword ?? unzipPassword; fastZip.ExtractZip(zipFileToImport, currentLibraryPath, ""); //zipFileToImport.unzip_File(currentLibraryPath); return true; //} //else // "[xmlDB_Libraries_ImportFromZip] could not import library with name {0} since there was already one with that name".error(libraryName); } */ } } catch (Exception ex) { ex.log("[xmlDB_Libraries_ImportFromZip]"); } return false; }
public static String tryToGetFileOrDirectoryFromDroppedObject(DragEventArgs dragEventArgs, bool downloadIfHttp) { var dataReceived = new List<object>(); String[] sFormats = dragEventArgs.Data.GetFormats(); foreach (string sFormat in sFormats) dataReceived.Add(dragEventArgs.Data.GetData(sFormat)); foreach (object item in dataReceived) { if (item != null) switch (item.GetType().Name) { case "String": if (File.Exists(item.ToString()) || Directory.Exists(item.ToString())) return item.ToString(); if ( item.ToString().ToLower().StartsWith("http")) { if (downloadIfHttp) { var savedUrlContents = new Web().saveUrlContents(item.ToString()); if (savedUrlContents != "" && File.Exists(savedUrlContents)) return savedUrlContents; } return item.ToString(); } break; case "String[]": foreach (string subItem in (string[]) item) if (File.Exists(subItem) || Directory.Exists(subItem)) return subItem; break; } } return ""; }
public static bool xmlDB_Libraries_ImportFromZip(this TM_Xml_Database tmDatabase, string zipFileToImport, string unzipPassword) { var result = false; try { var currentLibraryPath = tmDatabase.Path_XmlLibraries; if (currentLibraryPath.isNull()) return false; if (zipFileToImport.isUri()) { "[xmlDB_Libraries_ImportFromZip] provided value was an URL so, downloading it: {0}".info(zipFileToImport); zipFileToImport = new Web().downloadBinaryFile(zipFileToImport); //zipFileToImport = zipFileToImport.uri().download(); } "[xmlDB_Libraries_ImportFromZip] importing library from: {0}".info(zipFileToImport); if (zipFileToImport.fileExists().isFalse()) "[xmlDB_Libraries_ImportFromZip] could not find file to import".error(zipFileToImport); else { // handle the zips we get from GitHub var tempDir = @"..\_".add_RandomLetters(3).tempDir(false).fullPath(); //trying to make the unzip path as small as possible var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip {Password = unzipPassword ?? ""}; fastZip.ExtractZip(zipFileToImport, tempDir, ""); Files.copyFolder(tempDir, currentLibraryPath, true, true,""); // just copy all files into Library path result = true; /* var gitZipFolderName = tempDir.folders().first().folderName(); // the first folder should be the one created by gitHub's zip var xmlFile_Location1 = tempDir.pathCombine(gitZipFolderName + ".xml"); var xmlFile_Location2 = tempDir.pathCombine(gitZipFolderName).pathCombine(gitZipFolderName + ".xml"); if (xmlFile_Location1.fileExists() || xmlFile_Location2.fileExists()) // if these exists here, just copy the unziped files directly { Files.copyFolder(tempDir, currentLibraryPath, true, true, ".git"); if (xmlFile_Location1.fileExists()) Files.copy(xmlFile_Location1, currentLibraryPath.pathCombine(gitZipFolderName)); result = true; } else { //if (zipFileToImport.extension() == ".master") var gitZipDir = tempDir.pathCombine(gitZipFolderName); foreach (var libraryFolder in gitZipDir.folders()) { var libraryName = libraryFolder.folderName(); var targetFolder = currentLibraryPath.pathCombine(libraryName); //default behaviour is to override the existing libraries Files.copyFolder(libraryFolder, currentLibraryPath); //handle the case where the xml file is located outside the library folder var libraryXmlFile = gitZipDir.pathCombine("{0}.xml".format(libraryName)); if (libraryXmlFile.fileExists()) Files.copy(libraryXmlFile, targetFolder); // put it in the Library folder which is where it really should be } var virtualMappings = gitZipDir.pathCombine("Virtual_Articles.xml"); if (virtualMappings.fileExists()) { Files.copy(virtualMappings, currentLibraryPath); // copy virtual mappings if it exists tmDatabase.mapVirtualArticles(); } result = true; } */ } } catch (Exception ex) { ex.log("[xmlDB_Libraries_ImportFromZip]"); } if (result) tmDatabase.reloadGuidanceExplorerObjects(); //tmDatabase.loadLibraryDataFromDisk(); return result; }