Exemplo n.º 1
0
        public SharedTextEditorP2PLogic(string memberName, SharedTextEditor editor, ISharedTextEditorC2S clientService, string c2sHost)
        {
            _memberName = memberName;

            _editor = editor;
            _editor.ConnectToP2P        += Editor_ConnectToP2P;
            _editor.FindDocumentRequest += Editor_FindDocumentRequest;
            _clientService = clientService;
            _c2shost       = c2sHost;
        }
        public SharedTextEditorP2PLogic(string memberName,  SharedTextEditor editor, ISharedTextEditorC2S clientService, string c2sHost)
        {
            _memberName = memberName;

            _editor = editor;
            _editor.ConnectToP2P += Editor_ConnectToP2P;
            _editor.FindDocumentRequest += Editor_FindDocumentRequest;
            _clientService = clientService;
            _c2shost = c2sHost;
        }
Exemplo n.º 3
0
 public SharedTextEditorPatchingLogic(string memberName, string serverHost, SharedTextEditor editor, IClientServerCommunication clientServerCommunication)
 {
     _memberName    = memberName;
     _serverHost    = serverHost;
     _editor        = editor;
     _communication = clientServerCommunication;
     _editor.FindDocumentRequest      += Editor_FindDocumentRequest;
     _editor.CreateDocument           += Editor_CreateDocument;
     _editor.RemoveDocument           += Editor_RemoveDocument;
     _editor.UpdateDocument           += Editor_UpdateDocument;
     _editor.TakeOwnershipForDocument += Editor_TakeOwnershipForDocument;
     ;
 }
 public SharedTextEditorPatchingLogic(string memberName, string serverHost, SharedTextEditor editor, IClientServerCommunication clientServerCommunication)
 {
     _memberName = memberName;
     _serverHost = serverHost;
     _editor = editor;
     _communication = clientServerCommunication;
     _editor.FindDocumentRequest += Editor_FindDocumentRequest;
     _editor.CreateDocument += Editor_CreateDocument;
     _editor.RemoveDocument += Editor_RemoveDocument;
     _editor.UpdateDocument += Editor_UpdateDocument;
     _editor.TakeOwnershipForDocument += Editor_TakeOwnershipForDocument;
       ;
 }
Exemplo n.º 5
0
        private static bool StartServerHost(int port, string memberName, SharedTextEditor editor, SharedTextEditorPatchingLogic patchingLogic)
        {
            var serviceHost = ServiceHostAddress(port);
            var serviceUrl  = new Uri(serviceHost);

            var serviceAddress = ServiceHostEndpoint(port);

            var host = new ServiceHost(patchingLogic, serviceUrl);

            host.Description.Behaviors.Find <ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
            host.AddServiceEndpoint(typeof(ISharedTextEditorC2S), new BasicHttpBinding(), serviceAddress);
            host.OpenTimeout = new TimeSpan(10000);

            host.Closed += (sender, args) =>
            {
                Console.WriteLine("host closed");
            };

            host.Faulted += (sender, args) =>
            {
                Console.WriteLine("host faulted");
            };


            try
            {
                host.Open();

                Console.WriteLine("Service up and running at:");
                foreach (var ea in host.Description.Endpoints)
                {
                    Console.WriteLine(ea.Address);
                }

                return(true);
            }
            catch (AddressAlreadyInUseException)
            {
                return(false);
            }
            catch (AddressAccessDeniedException)
            {
                MessageBox.Show(
                    "Unable to use port " + port + ", please allow access to ports between 9000 and 9010.",
                    "No port available",
                    MessageBoxButtons.RetryCancel,
                    MessageBoxIcon.Warning);

                return(false);
            }
        }
Exemplo n.º 6
0
        private static bool StartServerHost(int port,  string memberName, SharedTextEditor editor, SharedTextEditorPatchingLogic patchingLogic)
        {
            var serviceHost = ServiceHostAddress(port);
            var serviceUrl = new Uri(serviceHost);

            var serviceAddress = ServiceHostEndpoint(port);

            var host = new ServiceHost(patchingLogic, serviceUrl);

                host.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
                host.AddServiceEndpoint(typeof(ISharedTextEditorC2S), new BasicHttpBinding(), serviceAddress);
                host.OpenTimeout = new TimeSpan(10000);

                host.Closed += (sender, args) =>
                {
                    Console.WriteLine("host closed");
                };

                host.Faulted += (sender, args) =>
                {
                    Console.WriteLine("host faulted");
                };

            try
            {
                host.Open();

                Console.WriteLine("Service up and running at:");
                foreach (var ea in host.Description.Endpoints)
                {
                    Console.WriteLine(ea.Address);
                }

                return true;
            }
            catch (AddressAlreadyInUseException)
            {
                return false;
            }
            catch (AddressAccessDeniedException)
            {
                MessageBox.Show(
                "Unable to use port " + port + ", please allow access to ports between 9000 and 9010.",
                "No port available",
                  MessageBoxButtons.RetryCancel,
                  MessageBoxIcon.Warning);

                return false;
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var memberName = GetMemberName(args);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var editor = new SharedTextEditor(memberName);


            bool hostOpen;
            var  portRetries = 0;

            do
            {
                var serverPort          = GetRandomPortForServer();
                var patchingClientLogic = new SharedTextEditorPatchingLogic(memberName, ServiceHostEndpoint(serverPort), editor, new ClientServerCommunication());

                hostOpen = StartServerHost(serverPort, memberName, editor, patchingClientLogic);

                if (hostOpen)
                {
                    new SharedTextEditorP2PLogic(memberName, editor, patchingClientLogic, ServiceHostEndpoint(serverPort));
                }

                portRetries++;
            } while (!hostOpen && portRetries < 10);


            if (!hostOpen)
            {
                MessageBox.Show(
                    "Unable to find open port to start service host",
                    "No port available",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);

                Application.Exit();
            }

            Application.Run(editor);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            var memberName = GetMemberName(args);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var editor = new SharedTextEditor(memberName);

            bool hostOpen;
            var portRetries = 0;
            do
            {
                var serverPort = GetRandomPortForServer();
                var patchingClientLogic = new SharedTextEditorPatchingLogic(memberName, ServiceHostEndpoint(serverPort), editor, new ClientServerCommunication());

                hostOpen = StartServerHost(serverPort, memberName, editor, patchingClientLogic);

                if (hostOpen)
                {
                    new SharedTextEditorP2PLogic(memberName, editor, patchingClientLogic, ServiceHostEndpoint(serverPort));
                }

                portRetries++;
            } while (!hostOpen && portRetries < 10);

            if (!hostOpen)
            {
                MessageBox.Show(
                  "Unable to find open port to start service host",
                  "No port available",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);

                Application.Exit();
            }

            Application.Run(editor);
        }