public int Run(Action <string> logger) { string tempfile = null; try { tempfile = Path.GetTempFileName(); var destfile = Path.GetFullPath(ToolName); logger.Invoke($"Baixando arquivo... {ToolName}"); RemoteFiles.CopyFile($"dist/{Platform}/{ToolName}", tempfile); File.Copy(tempfile, destfile, overwrite: true); logger.Invoke($"[OK]Arquivo baixado: {ToolName}"); return(0); } finally { try { if (File.Exists(tempfile)) { File.Delete(tempfile); } } catch { /* Nada a fazer */ } } }
public void Test_ValidateURLFile() { RemoteFiles RF = new RemoteFiles(); DateTime lastMod = DateTime.MinValue; // Test existing file Assert.IsTrue(RF.CheckURLFileExists("http://www.powersdk.com/sample/test.xml", out lastMod), "existing file not found"); // Test non-existing file Assert.IsFalse(RF.CheckURLFileExists("http://www.FakeWWWAddress.com/FakeFileNameWhichDoesNotExist.xml", out lastMod), "non-existing file found"); // Text non-exising, but redirected file Assert.IsFalse(RF.CheckURLFileExists("http://www.cnn.com/FakeFileNameWhichDoesNotExist.xml", out lastMod), "non-existing, redirected file found"); // Test Intranet URL // You have to log on to auteam to access our intranet, so this test always failed // Assert.IsTrue(RF.CheckURLFileExists("http://auteam/sites/product/Documents/XBRL/us-gaap-ci-2004-06-15.xsd", out lastMod), "intranet url not found"); // Test a non-existing & invalid path local file Assert.IsFalse(RF.CheckURLFileExists("c:\\Test.xml", out lastMod), "invalid path double slash found"); Assert.IsFalse(RF.CheckURLFileExists("c:Test.xml", out lastMod), "invalid path no slash found"); // ICI-RR comes back as text/plain make sure the utility returns true on its Exists check Assert.IsTrue(RF.CheckURLFileExists("http://xbrl.ici.org/rr/2006/ici-rr.xsd", out lastMod), "ICI-RR file was not found"); // Test content type of text/plain that does not parse as valid xml Assert.IsFalse(RF.CheckURLFileExists("http://dev1/DTTestSchemas/InvalidSchema.txt", out lastMod), "Non Xml Text File returned true"); }
public void TestIsValidURL() { string str = @"http://xbrl.us/dis/con/2008-03-31/us-gaap-dis-con-cal-2008-03-31.xml"; string tmp; Assert.IsFalse(RemoteFiles.IsValidURL(str, out tmp)); str = @"http://xbrl.us/us-gaap/1.0beta2/ind/ci/us-gaap-ci-stm-2008-01-31.xsd"; Assert.IsTrue(RemoteFiles.IsValidURL(str, out tmp)); }
private void RefreshRemoteFiles() { using (var client = new FilerServerProxyService.FileServerClient()) { RemoteFiles.Clear(); try { string[] availableFiles = client.GetAvailableFiles(); foreach (string file in availableFiles) { RemoteFiles.Add(file); } } // Display error and continue catch (Exception ex) { Trace.TraceError(ex.Message); MessageBox.Show(ex.Message, "Error"); } } }
public void Test_ValidateURLFile() { RemoteFiles RF = new RemoteFiles(); DateTime lastMod = DateTime.MinValue; // Test existing file Assert.IsTrue(RF.CheckURLFileExists("http://www.powersdk.com/sample/test.xml", out lastMod ), "existing file not found"); // Test non-existing file Assert.IsFalse(RF.CheckURLFileExists("http://www.FakeWWWAddress.com/FakeFileNameWhichDoesNotExist.xml", out lastMod), "non-existing file found"); // Text non-exising, but redirected file Assert.IsFalse(RF.CheckURLFileExists("http://www.cnn.com/FakeFileNameWhichDoesNotExist.xml", out lastMod), "non-existing, redirected file found"); // Test Intranet URL // You have to log on to auteam to access our intranet, so this test always failed // Assert.IsTrue(RF.CheckURLFileExists("http://auteam/sites/product/Documents/XBRL/us-gaap-ci-2004-06-15.xsd", out lastMod), "intranet url not found"); // Test a non-existing & invalid path local file Assert.IsFalse(RF.CheckURLFileExists("c:\\Test.xml", out lastMod),"invalid path double slash found"); Assert.IsFalse( RF.CheckURLFileExists( "c:Test.xml", out lastMod ), "invalid path no slash found" ); // ICI-RR comes back as text/plain make sure the utility returns true on its Exists check Assert.IsTrue(RF.CheckURLFileExists("http://xbrl.ici.org/rr/2006/ici-rr.xsd", out lastMod), "ICI-RR file was not found"); // Test content type of text/plain that does not parse as valid xml Assert.IsFalse(RF.CheckURLFileExists("http://dev1/DTTestSchemas/InvalidSchema.txt", out lastMod), "Non Xml Text File returned true"); }
public void TestGetBaseTaxonomyURLMapping() { Dictionary <string, string> ret = RemoteFiles.GetBaseTaxonomyURLMapping(); Assert.IsTrue(ret.Count > 100); }
private bool TryLoadWebFile(string filename) { string actualFileName = filename; theDocument = null; RemoteFiles rf = new RemoteFiles(); rf.CachePolicy = this.CachePolicy; if (rf.LoadWebFile(filename, ref actualFileName, out theDocument)) { schemaFile = actualFileName; this.schemaFilename = System.IO.Path.GetFileName(actualFileName); this.schemaPath = actualFileName.Replace(schemaFilename, string.Empty); theManager = new XmlNamespaceManager(theDocument.NameTable); PopulateNamespaceManager(theManager, theDocument); SetDocumentXBRLIPrefix(); return true; } return false; }
private bool LookForFile(string filename, bool setProperties, out bool FileIsLocal, out string ResolvedLocalFilePath, out DateTime lastModified , out bool URLExists) { URLExists = false; bool LocalExists = false; FileIsLocal = LocalExists; ResolvedLocalFilePath = filename; // Determine if file is @ URL or local file RemoteFiles RF = new RemoteFiles(); RF.CachePolicy = this.CachePolicy; if (URLExists = RF.CheckURLFileExists(filename, out lastModified )) { if ( setProperties ) { this.schemaFilename = System.IO.Path.GetFileName(filename); this.schemaPath = filename.Replace(schemaFilename, string.Empty); } ResolvedLocalFilePath = filename; } // bug 705 - if we can't find the file, we just pass the filename (no directory or URL) // expecting it to fail. Sometimes, however, the FileInfo object will pick up the last // used directory from the OpenFileDialog dialog. To ensure that our file shouldn't be found // make sure the filename being passed in contains the :\ as in c:\ or \\ as in \\app1 else //if ( filename.IndexOf( @":\" ) != -1 || filename.IndexOf( @"\\" ) != -1 ) { // we changed this to use System.IO.File.Exists() so that we don't have to worry // about checking all the stuff above with the file name contents. // Also, File.Exists() should not pick up the last used directory from OpenFileDialog... try { // FileInfo fi = new FileInfo(filename); // if (fi.Exists) if ( File.Exists( filename ) ) { LocalExists = true; FileIsLocal = LocalExists; //schemaFilename = fi.Name; //schemaPath = fi.DirectoryName; // ResolvedLocalFilePath = fi.FullName; ResolvedLocalFilePath = Path.GetFullPath( filename ); } } catch (System.ArgumentException) { } catch (System.NotSupportedException) { return false; } } // if the file is not found to exist either @ a URL location or a local location, // figure out if the file was intended (by path) to be local. if (!(URLExists|LocalExists)) FileIsLocal = (filename.LastIndexOf(Path.DirectorySeparatorChar) > 0); return (URLExists|LocalExists); }
public async void NavigateRemote(string path) { RemotePath = path; RemoteFiles.Clear(); var json = await SendCommand("list:" + path); JArray array; try { array = JArray.Parse(json); } catch { return; } var temp = new List <FileItem>(); foreach (var obj in array) { var rpath = obj.Value <string>("path"); var folder = obj.Value <bool>("folder"); if (!folder && mss.currentItem != null && mss.currentItem.Path.Equals(rpath)) { temp.Add(mss.currentItem); continue; } var name = obj.Value <string>("name"); long size = 0; if (!folder) { size = obj.Value <long>("size"); } var ext = Path.GetExtension(name).ToUpper(); if (ext.Length > 0) { ext = ext.Substring(1); } var date = new DateTime(1970, 1, 1, 0, 0, 0); date = date.AddMilliseconds(obj.Value <long>("date")); FileItem item; if (MusicFileItem.IsMusicFile(rpath)) { item = new MusicFileItem(); } else if (PictureFileItem.IsPictureFile(rpath)) { item = new PictureFileItem(); } else { item = new FileItem(); } item.Model = this; item.Path = rpath; item.Name = name; item.Size = size; item.Extension = folder ? "FOLDER" : ext; item.Date = date.ToString(); item.IsFolder = folder; item.IsRemote = true; temp.Add(item); } temp.Sort(new Comparison <FileItem>((t1, t2) => { if (t1.IsFolder && !t2.IsFolder) { return(-1); } else if (!t1.IsFolder && t2.IsFolder) { return(1); } return(string.Compare(t1.Name, t2.Name, true)); })); RemoteFiles = new ObservableCollection <FileItem>(temp); }