public InlineScriptActionFromFileInAssembly(string resourceName, Assembly resourceAssembly = null) { ResourceAssembly = resourceAssembly ?? Assembly.GetEntryAssembly(); var candidates = ResourceAssembly.GetManifestResourceNames().Where(name => name.EndsWith(resourceName)).ToArray(); if (!candidates.Any()) { throw new ArgumentException($"There is no embedded resource in {ResourceAssembly.GetName().Name} like {resourceName}. Available resources are:{Environment.NewLine}{string.Join(Environment.NewLine, ResourceAssembly.GetManifestResourceNames().OrderBy(x => x))}"); } if (candidates.Length > 1) { throw new ArgumentException($"There are {candidates.Length} embedded resources in {ResourceAssembly.GetName().Name} like {resourceName}, which one do you want?{Environment.NewLine}{string.Join(Environment.NewLine, candidates.OrderBy(x => x))}"); } ResourceName = candidates.Single(); }
protected string ReadInEmbeddedResource(string filename) { string[] res = ResourceAssembly.GetManifestResourceNames(); filename = filename.Replace("/", "."); var res_filename = ResourcePath + "." + filename; var file = res.Where(r => res_filename == r).FirstOrDefault(); if (file == null) { return(null); } var stream = ResourceAssembly.GetManifestResourceStream(file); string file_content = new StreamReader(stream).ReadToEnd(); return(file_content); }
/// Get list of embedded streams URIs. For example, for embedded stream "AAA.BBB" the URI will be "embed:///AAA.BBB" public string[] GetEmbeddedResources() { Dictionary <string, bool> s = new Dictionary <string, bool>(); foreach (var name in ResourceAssembly.GetManifestResourceNames()) { s[name] = true; } foreach (var n in _embed) { s[n.Key] = true; } List <string> ret = new List <string>(); foreach (var pair in s) { ret.Add("embed:///" + pair.Key); } return(ret.ToArray()); }
private void Application_Startup(object sender, StartupEventArgs e) { string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SentinelsJson"); string file = ""; if (e.Args.Length > 0) { if (File.Exists(e.Args[0])) { file = e.Args[0]; } } if (SystemParameters.HighContrast) { if (Settings.HighContrastTheme == NO_HIGH_CONTRAST) { ColorScheme ncs; MessageDialog md = new MessageDialog(); md.Message = "It appears that you have Windows High Contrast mode activated. Did you want to activate High Contrast mode in SentinelsJson as well?"; md.OkButtonText = "Yes"; md.CancelButtonText = "No"; md.Image = MessageDialogImage.Question; md.Title = "SentinelsJson - High Contrast Mode"; // check the control color if (SystemColors.ControlColor == Colors.Black) { // black color scheme? if (SystemColors.WindowTextColor == Colors.White) { ncs = ColorScheme.GetHighContrastScheme(HighContrastOption.WhiteOnBlack); md.ColorScheme = ncs; if (md.ShowDialog() == MessageDialogResult.OK) { // white on black Settings.HighContrastTheme = "1"; } } else { ncs = ColorScheme.GetHighContrastScheme(HighContrastOption.GreenOnBlack); md.ColorScheme = ncs; if (md.ShowDialog() == MessageDialogResult.OK) { // green on black Settings.HighContrastTheme = "2"; } } } else { ncs = ColorScheme.GetHighContrastScheme(HighContrastOption.BlackOnWhite); md.ColorScheme = ncs; if (md.ShowDialog() == MessageDialogResult.OK) { // black on white Settings.HighContrastTheme = "3"; } } try { Settings.Save(Path.Combine(appDataPath, "settings.json")); } catch (UnauthorizedAccessException) { MessageBox.Show("The settings file for SentinelsJson could not be saved. Please check the permissions for your AppData folder.", "Settings Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (System.Security.SecurityException) { MessageBox.Show("The settings file for SentinelsJson could not be saved. Please check the permissions for your AppData folder.", "Settings Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (IOException) { MessageBox.Show("The settings file for SentinelsJson could not be saved. Please check the permissions for your AppData folder.", "Settings Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } foreach (string s in ResourceAssembly.GetManifestResourceNames()) { Console.WriteLine(s); } MainWindow mw = new MainWindow(); MainWindow = mw; if (file != "") { mw.OpenFile(file); } mw.Show(); }