コード例 #1
0
ファイル: frmAdmin.cs プロジェクト: sylvainr/MacomberMap
        /// <summary>
        /// Create a new TCP proxy to our server
        /// </summary>
        /// <param name="Address"></param>
        /// <returns></returns>
        private MM_Administrator_Types CreateProxy(String Address)
        {
            NetTcpBinding tcpBinding = MM_Binding_Configuration.CreateBinding();
            MM_AdministratorMessage_Types Callback = new MM_AdministratorMessage_Types();
            MM_Administrator_Types        OutComm  = new MM_Administrator_Types(Callback.Context, tcpBinding, new EndpointAddress(Address));

            Callback.Server = OutComm;
            return(OutComm);
        }
コード例 #2
0
        /// <summary>
        /// Handle our open button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            NetTcpBinding tcpBinding = MM_Binding_Configuration.CreateBinding();

            ClientFactory = new DuplexChannelFactory <IMM_WCF_Interface>(new MM_Server_Callback_Handler(), tcpBinding, txtServer.Text);
            ClientFactory.Open();
            Client = ClientFactory.CreateChannel();
            frmWindowsSecurityDialog SecurityDialog = new frmWindowsSecurityDialog();

            SecurityDialog.CaptionText = Application.ProductName + " " + Application.ProductVersion;
            SecurityDialog.MessageText = "Enter the credentials to log into Macomber Map Server";
            string    Username, Password, Domain;
            Exception LoginError;

            if (SecurityDialog.ShowLoginDialog(out Username, out Password, out Domain))
            {
                Client.HandleUserLogin(Username, Password);
                MessageBox.Show(this, "Connected.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #3
0
        /// <summary>
        /// Start our WCF server. Thanks to https://social.msdn.microsoft.com/Forums/vstudio/en-US/7195129e-12b7-4dcf-9104-6d6530c33c7f/is-it-possible-to-configure-wcf-service-programmatically-without-using-webconfig?forum=wcf
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="BaseAddress"></param>
        private static ServiceHost StartWCFServer <T>(String[] BaseAddress)
        {
            List <Uri> Addresses = new List <Uri>();

            foreach (String str in BaseAddress)
            {
                Addresses.Add(new Uri(str));
            }
            ServiceHost ServerHost = new ServiceHost(typeof(T), Addresses.ToArray());

            //Add our net.TCP binding
            NetTcpBinding   TcpBinding  = MM_Binding_Configuration.CreateBinding();
            ServiceEndpoint TcpEndpoint = ServerHost.AddServiceEndpoint(typeof(T).GetInterfaces()[0], TcpBinding, Addresses[0]);

            ServiceMetadataBehavior MetadataBehavior = ServerHost.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (MetadataBehavior != null)
            {
                MetadataBehavior.HttpGetEnabled = MetadataBehavior.HttpsGetEnabled = false;
            }
            else
            {
                ServerHost.Description.Behaviors.Add(new ServiceMetadataBehavior()
                {
                    HttpGetEnabled = false, HttpsGetEnabled = false
                });
            }

            //Build our metadata behavior

            /*ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
             * smb.HttpGetEnabled = true;
             * smb.HttpsGetEnabled = true;
             * smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
             * ServerHost.Description.Behaviors.Add(smb);*/
            ServerHost.Open();
            MM_Notification.WriteLine(ConsoleColor.Green, "WCF Server for {0} listening at {1}", typeof(T).Name, Addresses[0].ToString());
            return(ServerHost);
        }
コード例 #4
0
        /// <summary>
        /// Attempt to log in to a MM Server
        /// </summary>
        /// <param name="ServerName"></param>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <param name="ConnectionURI"></param>
        /// <param name="Error"></param>
        /// <returns></returns>
        public static bool TryLogin(String ServerName, Uri ConnectionURI, String UserName, String Password, out Exception Error)
        {
            if (Client != null)
            {
                try
                {
                    Client.Dispose();
                }
                catch
                {
                }
                Thread.Sleep(500);
            }
            Client          = null;
            CallbackHandler = null;

            try
            {
                MM_Server_Interface.ServerName    = ServerName;
                MM_Server_Interface.ConnectionURI = ConnectionURI;
                MM_Server_Interface.UserName      = UserName;
                MM_Server_Interface.Password      = Password;

                NetTcpBinding tcpBinding = MM_Binding_Configuration.CreateBinding();

                Client = new MM_WCF_Interface(new MM_Server_Callback_Handler().Context, tcpBinding, new EndpointAddress(ConnectionURI.ToString()));
                Client.ChannelFactory.Faulted += ChannelFactory_Faulted;
                Client.ChannelFactory.Opened  += ChannelFactory_Opened;
                MM_Server_Interface.CallbackHandler.Context.Faulted += ChannelFactory_Faulted;
                MM_Server_Interface.CallbackHandler.Context.Opened  += ChannelFactory_Opened;

                MM_Server_Interface.UserName = UserName;
                MM_Server_Interface.Password = Password;
                MM_Server_Interface.ClientAreas.Clear();
                foreach (String str in Client.HandleUserLogin(UserName, Password))
                {
                    MM_Server_Interface.ClientAreas.Add(str, true);
                }
                if (MM_Server_Interface.ClientAreas.Count == 0)
                {
                    MM_System_Interfaces.LogError("Unable to log in to the Macomber Map Server");
                    Client.InnerChannel.Close();
                    throw new InvalidOperationException("Unable to log in to the Macomber Map server. The username and password combination was invalid, and/or there were no operatorship areas for the client.");
                }
                else if (ClientAreas.ContainsKey("ERCOT"))
                {
                    MM_System_Interfaces.LogError("Logged in to Macomber Map Server, MASTER " + MM_Server_Interface.ClientAreas.Count.ToString("0") + " operatorships.");
                }
                else
                {
                    MM_System_Interfaces.LogError("Logged in to Macomber Map Server, " + MM_Server_Interface.ClientAreas.Count.ToString("0") + " operatorships.");
                }

                Error = null;
                return(true);
            }
            catch (Exception ex)
            {
                Error = ex;
                return(false);
            }
        }