-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsshPlugin.cs
More file actions
102 lines (87 loc) · 3.27 KB
/
sshPlugin.cs
File metadata and controls
102 lines (87 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using VMware.VIClient.Plugins2;
using System.Windows.Forms;
using MOR = VMware.VIClient.Plugins2.ManagedObjectReference;
namespace sshAutoConnect
{
public class sshPlugin : Plugin
{
public VIApp _viApp;
private SynchronizationContext _loaderSyncContext;
private bool _unloaded = false;
#region Plugin Members
public void Load(VIApp app)
{
if (app == null)
{
throw new Exception("Plugin.Load() viApp is null. Failing load!");
}
_viApp = app;
ExtensionPoint.VI_APP = _viApp;
_loaderSyncContext = System.Threading.SynchronizationContext.Current;
AddSeparatorMenu();
AddConstrainedInventoryMenu();
_unloaded = false;
}
public void Unload()
{
_viApp = null;
_loaderSyncContext = null;
_unloaded = true;
File.Delete(System.IO.Path.GetTempPath() + "sshAutoConnect.putty.exe");
}
void OnConstrainedMenuActivated(Extension sender)
{
OnAnyCallback();
if (!(sender is ToolStripMenuItem))
{
sender.Content = new ExtensionPoint(sender);
sender.Activated -= OnConstrainedMenuActivated;
}
}
void OnConstrainedSeparator(Extension sender)
{
OnAnyCallback();
if (!(sender is ToolStripMenuItem))
{
sender.Content = new ExtensionSeparator(sender);
}
}
private void AddConstrainedInventoryMenu()
{
Extension ext = _viApp.NewExtension();
InventoryDisplayConstraint invConstraint = ext.AddNewDisplayConstraint<InventoryDisplayConstraint>();
invConstraint.DisplayStyles.Add(InventoryStyles.Physical);
ext.Activated += new ExtensionEvent(OnConstrainedMenuActivated);
ext.Name = "Constrained Menu";
_viApp.AddExtension(ExtensionPoints.Menus.Inventory.Host, ext);
}
private void AddSeparatorMenu()
{
Extension ext = _viApp.NewExtension();
InventoryDisplayConstraint invConstraint = ext.AddNewDisplayConstraint<InventoryDisplayConstraint>();
invConstraint.DisplayStyles.Add(InventoryStyles.Physical);
ext.Activated += new ExtensionEvent(OnConstrainedSeparator);
ext.Name = "Separator";
_viApp.AddExtension(ExtensionPoints.Menus.Inventory.Host, ext);
}
#endregion
void OnAnyCallback()
{
if (_unloaded)
{
MessageBox.Show("Callback(Check client logs) even though the plug-in was unloaded!!");
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1, true);
StringBuilder sb = new StringBuilder("Callback after unload identified");
sb.AppendLine("");
sb.Append(st.ToString());
System.Diagnostics.Debug.WriteLine(sb.ToString());
}
}
}
}