public bool Open(string skypPath, IEnumerable <Server> servers, FormEx parentWindow = null) { try { var skyp = SkypFile.Create(skypPath, servers); using (var longWaitDlg = new LongWaitDlg { Text = Resources.SkypSupport_Open_Downloading_Skyline_Document_Archive, }) { longWaitDlg.PerformWork(parentWindow ?? _skyline, 1000, progressMonitor => Download(skyp, progressMonitor, parentWindow)); if (longWaitDlg.IsCanceled) { return(false); } } return(_skyline.OpenSharedFile(skyp.DownloadPath)); } catch (Exception e) { var message = TextUtil.LineSeparate(Resources.SkypSupport_Open_Failure_opening_skyp_file_, e.Message); MessageDlg.ShowWithException(parentWindow ?? _skyline, message, e); return(false); } }
private static string AddPanoramaServerMessage(SkypFile skyp) { return(string.Format( Resources .SkypSupport_Download_You_may_have_to_add__0__as_a_Panorama_server_from_the_Tools___Options_menu_in_Skyline_, skyp.SkylineDocUri.Host)); }
private void Download(SkypFile skyp, IProgressMonitor progressMonitor, FormEx parentWindow = null) { var progressStatus = new ProgressStatus(string.Format(Resources.SkypSupport_Download_Downloading__0_, skyp.SkylineDocUri)); progressMonitor.UpdateProgress(progressStatus); if (DownloadClient == null) { DownloadClient = new WebDownloadClient(progressMonitor, progressStatus); } DownloadClient.Download(skyp.SkylineDocUri, skyp.DownloadPath, skyp.Server?.Username, skyp.Server?.Password); if (progressMonitor.IsCanceled || DownloadClient.IsError) { FileEx.SafeDelete(skyp.DownloadPath, true); } if (DownloadClient.IsError) { var message = string.Format( Resources .SkypSupport_Download_There_was_an_error_downloading_the_Skyline_document_specified_in_the_skyp_file___0__, skyp.SkylineDocUri); if (DownloadClient.Error != null) { var exceptionMsg = DownloadClient.Error.Message; message = TextUtil.LineSeparate(message, exceptionMsg); if (exceptionMsg.Contains(ERROR401)) { message = TextUtil.LineSeparate(message, string.Format( Resources .SkypSupport_Download_You_may_have_to_add__0__as_a_Panorama_server_from_the_Tools___Options_menu_in_Skyline_, skyp.SkylineDocUri.Host)); } else if (exceptionMsg.Contains(ERROR403)) { message = TextUtil.LineSeparate(message, string.Format( Resources.SkypSupport_Download_You_do_not_have_permissions_to_download_this_file_from__0__, skyp.SkylineDocUri.Host)); } } throw new Exception(message, DownloadClient.Error); } }
public static SkypFile Create(string skypPath, IEnumerable <Server> servers) { if (string.IsNullOrEmpty(skypPath)) { return(null); } var skyp = new SkypFile { SkypPath = skypPath, SkylineDocUri = GetSkyFileUrl(skypPath), }; skyp.Server = servers?.FirstOrDefault(server => server.URI.Host.Equals(skyp.SkylineDocUri.Host)); var downloadDir = Path.GetDirectoryName(skyp.SkypPath); skyp.DownloadPath = GetNonExistentPath(downloadDir ?? string.Empty, skyp.GetSkylineDocName()); return(skyp); }