public static void SetUserAssemblyNames(SoftDebuggerStartInfo dsi, IList <string> files) { if (files == null || files.Count == 0) { return; } var names = new List <AssemblyName> (); foreach (var file in files) { if (!File.Exists(file)) { dsi.LogMessage = GettextCatalog.GetString("User assembly '{0}' is missing. " + "Debugger will now debug all code, not just user code.", file); return; } try { var asm = Mono.Cecil.AssemblyDefinition.ReadAssembly(file); if (string.IsNullOrEmpty(asm.Name.Name)) { throw new InvalidOperationException("Assembly has no assembly name"); } names.Add(new AssemblyName(asm.Name.FullName)); } catch (Exception ex) { dsi.LogMessage = GettextCatalog.GetString("Could not get assembly name for user assembly '{0}'. " + "Debugger will now debug all code, not just user code.", file); MDLS.LogError("Error getting assembly name for user assembly '" + file + "'", ex); return; } } dsi.UserAssemblyNames = names; }
public static List <AssemblyName> GetAssemblyNames(IList <string> files, out string error) { error = null; if (files == null || files.Count == 0) { return(null); } var names = new List <AssemblyName> (); foreach (var file in files) { if (!File.Exists(file)) { error = GettextCatalog.GetString("User assembly '{0}' is missing. " + "Debugger will now debug all code, not just user code.", file); return(null); } try { var asm = Mono.Cecil.AssemblyFactory.GetAssemblyManifest(file); if (string.IsNullOrEmpty(asm.Name.Name)) { throw new InvalidOperationException("Assembly has no assembly name"); } names.Add(new AssemblyName(asm.Name.FullName)); } catch (Exception ex) { error = GettextCatalog.GetString("Could not get assembly name for user assembly '{0}'. " + "Debugger will now debug all code, not just user code.", file); MDLS.LogError("Error getting assembly name for user assembly '" + file + "'", ex); return(null); } } return(names); }
public static Task <bool> UpdateDownloadedCacheFile(string url, string cacheFile, Func <Stream, bool> validateDownload = null, CancellationToken ct = default(CancellationToken)) { return(WebRequestHelper.GetResponseAsync( () => (HttpWebRequest)WebRequest.Create(url), r => { //check to see if the online file has been modified since it was last downloaded var localNewsXml = new FileInfo(cacheFile); if (localNewsXml.Exists) { r.IfModifiedSince = localNewsXml.LastWriteTime; } }, ct ).ContinueWith(t => { bool deleteTempFile = true; var tempFile = cacheFile + ".temp"; try { ct.ThrowIfCancellationRequested(); if (t.IsFaulted) { var wex = t.Exception.Flatten().InnerException as WebException; if (wex != null) { var resp = wex.Response as HttpWebResponse; if (resp != null && resp.StatusCode == HttpStatusCode.NotModified) { return false; } } } //TODO: limit this size in case open wifi hotspots provide junk data var response = t.Result; if (response.StatusCode == HttpStatusCode.OK) { using (var fs = File.Create(tempFile)) response.GetResponseStream().CopyTo(fs, 2048); } //check the document is valid, might get bad ones from wifi hotspots etc if (validateDownload != null) { ct.ThrowIfCancellationRequested(); using (var f = File.OpenRead(tempFile)) { bool validated; try { validated = validateDownload(f); } catch (Exception ex) { throw new Exception("Failed to validate downloaded file", ex); } if (!validated) { throw new Exception("Failed to validate downloaded file"); } } } ct.ThrowIfCancellationRequested(); SystemRename(tempFile, cacheFile); deleteTempFile = false; return true; } finally { if (deleteTempFile) { try { File.Delete(tempFile); } catch (Exception ex) { LoggingService.LogError("Failed to delete temp download file", ex); } } } }, ct)); }
static void OnLoadError(object s, AddinErrorEventArgs args) { string msg = "Add-in error (" + args.AddinId + "): " + args.Message; LoggingService.LogError(msg, args.Exception); }
static BrandingService() { try { FilePath asmPath = typeof(BrandingService).Assembly.Location; brandingDir = asmPath.ParentDirectory.Combine("branding"); if (!Directory.Exists(brandingDir)) { brandingDir = null; } else { var langCode = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName; localizedBrandingDir = brandingDir.Combine(langCode); if (!Directory.Exists(localizedBrandingDir)) { localizedBrandingDir = null; } } //read the files after detecting both directories, in case there's an error if (brandingDir != null) { var brandingFile = brandingDir.Combine("Branding.xml"); if (File.Exists(brandingFile)) { brandingDocument = XDocument.Load(brandingFile); } if (localizedBrandingDir != null) { var localizedBrandingFile = brandingDir.Combine("Branding.xml"); if (File.Exists(localizedBrandingFile)) { localizedBrandingDocument = XDocument.Load(localizedBrandingFile); } } } ApplicationName = GetString("ApplicationName"); ApplicationLongName = GetString("ApplicationLongName") ?? ApplicationName; SuiteName = GetString("SuiteName"); ProfileDirectoryName = GetString("ProfileDirectoryName"); StatusSteadyIconId = GetString("StatusAreaSteadyIcon"); HelpAboutIconId = GetString("HelpAboutIcon"); } catch (Exception ex) { LoggingService.LogError("Could not read branding document", ex); } if (string.IsNullOrEmpty(SuiteName)) { SuiteName = ApplicationName; } if (string.IsNullOrEmpty(ProfileDirectoryName)) { ProfileDirectoryName = ApplicationName; } if (string.IsNullOrEmpty(StatusSteadyIconId)) { StatusSteadyIconId = "md-status-steady"; } if (string.IsNullOrEmpty(HelpAboutIconId)) { HelpAboutIconId = "md-about"; } }
static void HandleUserDataMigration(object sender, ExtensionNodeEventArgs args) { if (args.Change != ExtensionChange.Add) { return; } var node = (UserDataMigrationNode)args.ExtensionNode; if (!CheckVersion(node, version)) { return; } FilePath source = FilePath.Null; FilePath target = FilePath.Null; try { source = profile.GetLocation(node.SourceKind).Combine(node.SourcePath); target = UserProfile.Current.GetLocation(node.TargetKind).Combine(node.TargetPath); bool sourceIsDirectory = Directory.Exists(source); if (sourceIsDirectory) { if (Directory.Exists(target)) { return; } } else { if (File.Exists(target) || Directory.Exists(target) || !File.Exists(source)) { return; } } LoggingService.LogInfo("Migrating '{0}' to '{1}'", source, target); if (!sourceIsDirectory) { FileService.EnsureDirectoryExists(target.ParentDirectory); } var handler = node.GetHandler(); if (handler != null) { handler.Migrate(source, target); return; } if (sourceIsDirectory) { DirectoryCopy(source, target); } else { File.Copy(source, target); } } catch (Exception ex) { string message = string.Format("{0}: Failed to migrate '{1}' to '{2}'", node.Addin.Id, source.ToString() ?? "", target.ToString() ?? ""); LoggingService.LogError(message, ex); } }