logic: network port option
Added options to Coati and VS plugin to set network ports
This commit is contained in:
Binary file not shown.
@@ -14,7 +14,7 @@
|
||||
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SnowForest.CoatiPlugin</RootNamespace>
|
||||
<RootNamespace>CoatiSoftware.CoatiPlugin</RootNamespace>
|
||||
<AssemblyName>CoatiPlugin</AssemblyName>
|
||||
<SignAssembly>True</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
|
||||
@@ -127,7 +127,9 @@
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
<Compile Include="CoatiPluginPackage.cs" />
|
||||
<Compile Include="CoatiPluginPackage.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PkgCmdID.cs" />
|
||||
<Compile Include="SystemUtility.cs" />
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using Microsoft.Win32;
|
||||
using Microsoft.VisualStudio;
|
||||
@@ -17,16 +18,81 @@ using System.Threading;
|
||||
using EnvDTE;
|
||||
using EnvDTE80;
|
||||
|
||||
namespace SnowForest.CoatiPlugin
|
||||
namespace CoatiSoftware.CoatiPlugin
|
||||
{
|
||||
public class OptionPageGrid : DialogPage
|
||||
{
|
||||
private uint _serverPort = 6666;
|
||||
private uint _clientPort = 6667;
|
||||
|
||||
public delegate void Callback();
|
||||
public static Callback _serverPortChangeCallback = null;
|
||||
public static Callback _clientPortChangeCallback = null;
|
||||
|
||||
[Category("Coati")]
|
||||
[DisplayName("VS Port")]
|
||||
[Description("The port on which Visual Studio will receive messages")]
|
||||
public uint ServerPort
|
||||
{
|
||||
get { return _serverPort; }
|
||||
set
|
||||
{
|
||||
_serverPort = value;
|
||||
if (_serverPortChangeCallback != null)
|
||||
{
|
||||
_serverPortChangeCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Category("Coati")]
|
||||
[DisplayName("Coati Port")]
|
||||
[Description("The port on which Coati will receive messages")]
|
||||
public uint ClientPort
|
||||
{
|
||||
get { return _clientPort; }
|
||||
set
|
||||
{
|
||||
_clientPort = value;
|
||||
if (_clientPortChangeCallback != null)
|
||||
{
|
||||
_clientPortChangeCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public OptionPageGrid()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[PackageRegistration(UseManagedResourcesOnly = true)]
|
||||
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
|
||||
[ProvideMenuResource("Menus.ctmenu", 1)]
|
||||
[Guid(GuidList.guidCoatiPluginPkgString)]
|
||||
[ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids80.NoSolution)]
|
||||
[ProvideOptionPage(typeof(OptionPageGrid), "Coati", "Coati Settings", 0, 0, true)]
|
||||
|
||||
public sealed class CoatiPluginPackage : Package
|
||||
{
|
||||
public uint ServerPort
|
||||
{
|
||||
get
|
||||
{
|
||||
OptionPageGrid page = (OptionPageGrid)GetDialogPage(typeof(OptionPageGrid));
|
||||
return page.ServerPort;
|
||||
}
|
||||
}
|
||||
|
||||
public uint ClientPort
|
||||
{
|
||||
get
|
||||
{
|
||||
OptionPageGrid page = (OptionPageGrid)GetDialogPage(typeof(OptionPageGrid));
|
||||
return page.ClientPort;
|
||||
}
|
||||
}
|
||||
|
||||
System.Threading.Thread _serverThread = null;
|
||||
|
||||
public CoatiPluginPackage()
|
||||
@@ -36,16 +102,13 @@ namespace SnowForest.CoatiPlugin
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
AsynchronousSocketListener server = new AsynchronousSocketListener();
|
||||
AsynchronousSocketListener._onReadCallback = new AsynchronousSocketListener.OnReadCallback(OnNetworkReadCallback);
|
||||
AsynchronousSocketListener._onErrorCallback = new AsynchronousSocketListener.OnReadCallback(OnNetworkErrorCallback);
|
||||
_serverThread = new System.Threading.Thread(server.DoWork);
|
||||
_serverThread.Start();
|
||||
|
||||
AsynchronousClient._onErrorCallback = new AsynchronousSocketListener.OnReadCallback(OnNetworkErrorCallback);
|
||||
InitNetwork();
|
||||
|
||||
FileUtility._errorCallback = new FileUtility.ErrorCallback(OnFileUtilityError);
|
||||
|
||||
OptionPageGrid._serverPortChangeCallback = new OptionPageGrid.Callback(OnServerPortChanged);
|
||||
OptionPageGrid._clientPortChangeCallback = new OptionPageGrid.Callback(OnClientPortChanged);
|
||||
|
||||
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
|
||||
if ( null != mcs )
|
||||
{
|
||||
@@ -55,6 +118,19 @@ namespace SnowForest.CoatiPlugin
|
||||
}
|
||||
}
|
||||
|
||||
private void InitNetwork()
|
||||
{
|
||||
AsynchronousSocketListener._port = ServerPort;
|
||||
AsynchronousSocketListener server = new AsynchronousSocketListener();
|
||||
AsynchronousSocketListener._onReadCallback = new AsynchronousSocketListener.OnReadCallback(OnNetworkReadCallback);
|
||||
AsynchronousSocketListener._onErrorCallback = new AsynchronousSocketListener.OnReadCallback(OnNetworkErrorCallback);
|
||||
_serverThread = new System.Threading.Thread(server.DoWork);
|
||||
_serverThread.Start();
|
||||
|
||||
AsynchronousClient._port = ClientPort;
|
||||
AsynchronousClient._onErrorCallback = new AsynchronousSocketListener.OnReadCallback(OnNetworkErrorCallback);
|
||||
}
|
||||
|
||||
private void MenuItemCallback(object sender, EventArgs e)
|
||||
{
|
||||
MenuCommand menuCommand = sender as MenuCommand;
|
||||
@@ -65,6 +141,8 @@ namespace SnowForest.CoatiPlugin
|
||||
{
|
||||
if (menuCommand.CommandID.ID == (int)PkgCmdIDList.cmdidCoatiSetActiveToken)
|
||||
{
|
||||
DisplayMessage("Coati", "" + ServerPort.ToString());
|
||||
|
||||
string fileName = FileUtility.GetActiveDocumentName(dte);
|
||||
string filePath = FileUtility.GetActiveDocumentPath(dte);
|
||||
|
||||
@@ -104,6 +182,21 @@ namespace SnowForest.CoatiPlugin
|
||||
DisplayMessage("Coati File Error", message);
|
||||
}
|
||||
|
||||
private void OnServerPortChanged()
|
||||
{
|
||||
AsynchronousSocketListener._port = ServerPort;
|
||||
|
||||
_serverThread.Abort();
|
||||
AsynchronousSocketListener server = new AsynchronousSocketListener();
|
||||
_serverThread = new System.Threading.Thread(server.DoWork);
|
||||
_serverThread.Start();
|
||||
}
|
||||
|
||||
private void OnClientPortChanged()
|
||||
{
|
||||
AsynchronousClient._port = ClientPort;
|
||||
}
|
||||
|
||||
private void DisplayMessage(string title, string message)
|
||||
{
|
||||
IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EnvDTE;
|
||||
|
||||
namespace SnowForest.CoatiPlugin
|
||||
namespace CoatiSoftware.CoatiPlugin
|
||||
{
|
||||
class FileUtility
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// MUST match guids.h
|
||||
using System;
|
||||
|
||||
namespace SnowForest.CoatiPlugin
|
||||
namespace CoatiSoftware.CoatiPlugin
|
||||
{
|
||||
static class GuidList
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowForest.CoatiPlugin
|
||||
namespace CoatiSoftware.CoatiPlugin
|
||||
{
|
||||
class NetworkProtocolUtility
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
|
||||
namespace SnowForest.CoatiPlugin
|
||||
namespace CoatiSoftware.CoatiPlugin
|
||||
{
|
||||
public class StateObject
|
||||
{
|
||||
@@ -28,6 +28,8 @@ namespace SnowForest.CoatiPlugin
|
||||
public static OnReadCallback _onErrorCallback = null;
|
||||
|
||||
private static string _endOfMessageToken = "<EOM>";
|
||||
|
||||
public static uint _port = 6666;
|
||||
|
||||
public AsynchronousSocketListener()
|
||||
{
|
||||
@@ -40,13 +42,12 @@ namespace SnowForest.CoatiPlugin
|
||||
|
||||
public static void StartListening()
|
||||
{
|
||||
const int port = 6666;
|
||||
const string ipAddressString = "127.0.0.1";
|
||||
|
||||
byte[] bytes = new Byte[1024];
|
||||
|
||||
IPAddress ipAddress = IPAddress.Parse(ipAddressString);
|
||||
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
|
||||
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, (int)_port);
|
||||
|
||||
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
||||
@@ -139,7 +140,7 @@ namespace SnowForest.CoatiPlugin
|
||||
|
||||
public class AsynchronousClient
|
||||
{
|
||||
private const int _port = 6667;
|
||||
public static uint _port = 6667;
|
||||
|
||||
private static ManualResetEvent connectDone = new ManualResetEvent(false);
|
||||
private static ManualResetEvent sendDone = new ManualResetEvent(false);
|
||||
@@ -151,7 +152,7 @@ namespace SnowForest.CoatiPlugin
|
||||
public static void Send(string message)
|
||||
{
|
||||
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
|
||||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, _port);
|
||||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, (int)_port);
|
||||
|
||||
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// MUST match PkgCmdID.h
|
||||
using System;
|
||||
|
||||
namespace SnowForest.CoatiPlugin
|
||||
namespace CoatiSoftware.CoatiPlugin
|
||||
{
|
||||
static class PkgCmdIDList
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace SnowForest.CoatiPlugin {
|
||||
namespace CoatiSoftware.CoatiPlugin {
|
||||
using System;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace SnowForest.CoatiPlugin {
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SnowForest.CoatiPlugin.Resources", typeof(Resources).Assembly);
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CoatiSoftware.CoatiPlugin.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CoatiSoftware.CoatiPlugin
|
||||
{
|
||||
class SystemUtility
|
||||
{
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
||||
static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
||||
static extern IntPtr SetActiveWindow(IntPtr hWnd);
|
||||
|
||||
public static void GetWindowFocus()
|
||||
{
|
||||
System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
|
||||
IntPtr windowHandle = process.MainWindowHandle;
|
||||
|
||||
if (windowHandle != null)
|
||||
{
|
||||
SetForegroundWindow(windowHandle);
|
||||
SetActiveWindow(windowHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
|
||||
<Metadata>
|
||||
<Identity Id="acf15780-03b5-440e-a41e-db79b7043fc2" Version="0.1.2" Language="en-US" Publisher="Coati Software" />
|
||||
<Identity Id="acf15780-03b5-440e-a41e-db79b7043fc2" Version="0.1.3" Language="en-US" Publisher="Coati Software" />
|
||||
<DisplayName>CoatiPlugin</DisplayName>
|
||||
<Description xml:space="preserve">This package allows Coati to communicate with Visual Studio and vice versa.</Description>
|
||||
<Icon>coati.ico</Icon>
|
||||
|
||||
Reference in New Issue
Block a user