-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP (fixes some of the issues with multiple versions of same assembly)
- Loading branch information
John Leidegren
committed
May 24, 2019
1 parent
469b2f1
commit a556fbf
Showing
19 changed files
with
369 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ obj | |
*.user | ||
node_modules | ||
*.PublishSettings | ||
*_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Microsoft.Win32; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CloudPad { | ||
static class FirstRun { | ||
public static string Lockfile => Path.Combine(Env.GetLocalAppDataDirectory(), "first_run"); | ||
|
||
public static bool ShouldPrompt() { | ||
if (Environment.UserInteractive) { | ||
if (!File.Exists(Lockfile)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static void Prompt() { | ||
var mbType = Type.GetType("System.Windows.Forms.MessageBox, System.Windows.Forms"); | ||
|
||
var show = mbType.GetMethod("Show", BindingFlags.Public | BindingFlags.Static, null, new[] { | ||
typeof(string), | ||
typeof(string), | ||
Type.GetType("System.Windows.Forms.MessageBoxButtons, System.Windows.Forms"), | ||
Type.GetType("System.Windows.Forms.MessageBoxIcon, System.Windows.Forms"), | ||
}, null); | ||
|
||
var result = show.Invoke(null, new object[] { | ||
"Looks like this is your first run. Would you like to add a Explorer context menu item to help with deployment of scripts to Azure?", | ||
"Welcome to CloudPad!", | ||
4, // YesNo | ||
0x20 // Question | ||
}); | ||
|
||
if (Convert.ToInt32(result) == 6) { // Yes | ||
var startInfo = new ProcessStartInfo(); | ||
|
||
startInfo.FileName = @"C:\Program Files (x86)\LINQPad5\LPRun.exe"; | ||
startInfo.Arguments = $"\"{Util.CurrentQueryPath}\" -install"; | ||
startInfo.UseShellExecute = true; | ||
startInfo.Verb = "runas"; | ||
#if !DEBUG | ||
startInfo.WindowStyle = ProcessWindowStyle.Hidden; | ||
#endif | ||
|
||
using (var p = Process.Start(startInfo)) { | ||
p.WaitForExit(); | ||
} | ||
} | ||
|
||
File.WriteAllText(Lockfile, ""); | ||
} | ||
|
||
public static void Install() { | ||
using (var shell = Registry.ClassesRoot.OpenSubKey(@"LINQPad\shell", true)) { | ||
using (var publish = shell.CreateSubKey("publish", true)) { | ||
publish.SetValue("", "Publish LINQPad script to Azure"); | ||
publish.SetValue("Icon", @"C:\\Program Files (x86)\\LINQPad5\\LINQPad.EXE,0"); | ||
using (var command = publish.CreateSubKey("command", true)) { | ||
command.SetValue("", "\"C:\\Program Files (x86)\\LINQPad5\\LPRun.EXE\" \"%1\" -publish"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("CloudPad.FunctionApp")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace CloudPad.Internal { | ||
class AssemblyBindingRedirect { | ||
public Version OldMinVersion { get; set; } | ||
public Version OldMaxVersion { get; set; } | ||
|
||
public Version NewVersion { get; set; } | ||
} | ||
|
||
class AssemblyBindingConfig { | ||
public static AssemblyBindingConfig LoadFrom(string path) { | ||
var config = new AssemblyBindingConfig(); | ||
|
||
var funcConfig = System.Xml.Linq.XElement.Load(path); | ||
var runtime = funcConfig.Element("runtime"); | ||
|
||
System.Xml.Linq.XNamespace ns = "urn:schemas-microsoft-com:asm.v1"; | ||
var assemblyBinding = runtime.Element(ns + "assemblyBinding"); | ||
var assemblyIdentityName = ns + "assemblyIdentity"; | ||
var bindingRedirectName = ns + "bindingRedirect"; | ||
foreach (var dependentAssembly in assemblyBinding.Elements(ns + "dependentAssembly")) { | ||
var assemblyIdentity = dependentAssembly.Element(assemblyIdentityName); | ||
|
||
var fullName = (string)assemblyIdentity.Attribute("name"); | ||
|
||
if ((string)assemblyIdentity.Attribute("culture") != null) { | ||
fullName += ", Culture=" + (string)assemblyIdentity.Attribute("culture"); | ||
} | ||
|
||
if ((string)assemblyIdentity.Attribute("publicKeyToken") != null) { | ||
fullName += ", PublicKeyToken=" + (string)assemblyIdentity.Attribute("publicKeyToken"); | ||
} | ||
|
||
var assemblyName = new AssemblyName(fullName); | ||
|
||
var bindingRedirect = dependentAssembly.Element(bindingRedirectName); | ||
|
||
var oldVersion = ((string)bindingRedirect.Attribute("oldVersion")).Split('-'); | ||
var newVerison = (string)bindingRedirect.Attribute("newVersion"); | ||
|
||
var binding = new AssemblyBindingRedirect { | ||
OldMinVersion = new Version(oldVersion[0]), | ||
OldMaxVersion = new Version(oldVersion[1]), | ||
NewVersion = new Version(newVerison), | ||
}; | ||
|
||
config.Add(assemblyName.Name, binding); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
private Dictionary<string, List<AssemblyBindingRedirect>> config = new Dictionary<string, List<AssemblyBindingRedirect>>(); | ||
|
||
public void Add(string name, AssemblyBindingRedirect binding) { | ||
if (!config.TryGetValue(name, out var bindings)) { | ||
config.Add(name, bindings = new List<AssemblyBindingRedirect>()); | ||
} | ||
bindings.Add(binding); | ||
} | ||
|
||
public AssemblyBindingRedirect Find(AssemblyName name) { | ||
if (config.TryGetValue(name.Name, out var bindings)) { | ||
return bindings.Find(binding => binding.OldMinVersion <= name.Version && name.Version <= binding.OldMaxVersion); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace CloudPad.Internal { | ||
class AssemblyCandidate { | ||
public string FullName => Name.FullName; | ||
public AssemblyName Name { get; set; } | ||
public string Location { get; set; } | ||
public string Source { get; set; } | ||
} | ||
|
||
class AssemblyCandidateSet { | ||
private readonly Dictionary<string, List<AssemblyCandidate>> _d = new Dictionary<string, List<AssemblyCandidate>>(StringComparer.OrdinalIgnoreCase); | ||
|
||
public IEnumerable<KeyValuePair<string, List<AssemblyCandidate>>> Set { | ||
get { | ||
return _d.OrderBy(x => x.Key); // sort is just to make debugging easier | ||
} | ||
} | ||
|
||
public void Add(string location, AssemblyName name, string source) { | ||
if (!_d.TryGetValue(name.Name, out var list)) { | ||
_d.Add(name.Name, list = new List<AssemblyCandidate>()); | ||
} | ||
|
||
var candidiate = list.Find(c => c.FullName == name.FullName); | ||
if (candidiate == null) { | ||
list.Add(new AssemblyCandidate { Location = location, Name = name, Source = source }); | ||
} | ||
} | ||
|
||
public bool Unref(AssemblyName name) { | ||
if (_d.TryGetValue(name.Name, out var list)) { | ||
var candidiate = list.FindIndex(c => c.FullName == name.FullName); | ||
if (candidiate != -1) { | ||
list.RemoveAt(candidiate); | ||
if (list.Count == 0) { | ||
_d.Remove(name.Name); | ||
} | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.