Beispiel #1
0
 void ConnectUser()
 {
     if (!IsConnected)
     {
         Client      = new ServiceChat.ServiceChatClient(new System.ServiceModel.InstanceContext(this));
         ID          = Client.Connect(UserName);
         IsConnected = true;
         ConDiscon   = "Выйти";
     }
 }
Beispiel #2
0
        //public static bool GetConnectionStatus()
        //{
        //    return isConnected;
        //}

        public static void Join(string Name, bool SelfServer = false)
        {
            //if (ClientStateChanged==null)
            if (!Subscribed)
            {
                ClientStateChanged += CurrentStateChanged;
                Subscribed          = true;
            }


            //if (bw.DoWork==null)
            //{
            //    bw.DoWork += Update;
            //}
            //bw.Dispose();
            bw = new BackgroundWorker();
            bw.WorkerSupportsCancellation = true;
            bw.DoWork += RepetableUpdate;
            //bw.DoWork += Timer;
            ClientStateChanged?.Invoke(ClientState.Connecting);

            if (SelfServer)
            {
                client = new BookMyFood.ServiceChat.ServiceChatClient(
                    new System.ServiceModel.InstanceContext(new ChatClientHandler()));

                isSelfServer = true;
                //ClientStateChanged?.Invoke(ClientState.Connecting);
            }
            else
            {
                client = new BookMyFood.ServiceChat.ServiceChatClient(
                    new System.ServiceModel.InstanceContext(new ChatClientHandler())
                    , "WSDualHttpBinding_IServiceChat",
                    $"http://{LeaderServer.Leader.ServerIP}:{LeaderServer.Leader.Port}/Chat");
                isSelfServer = false;
                Log.Instance.W(client, $"Client Endpoint http://{LeaderServer.Leader.ServerIP}:{LeaderServer.Leader.Port}/");
                //Log.Instance.W(client, $"Client Endpoint net.tcp://{LeaderServer.Leader.ServerIP}:{LeaderServer.Leader.Port}/");
                //client.Endpoint.Address = new EndpointAddress($"net.tcp://{LeaderServer.Leader.ServerIP}:{LeaderServer.Leader.Port}/");
                //client
                //    = new ServiceChatClient(
                //    new InstanceContext(new ChatClientHandler()), "NetTcpBinding_IServiceChat",
                //    $"net.tcp://{LeaderServer.Leader.ServerIP}:{LeaderServer.Leader.Port}/");
                //ServiceChatClient<IServiceChat> cf =
                //    new ServiceChatClient<IServiceChat>(
                //        new Uri("http://localhost:8090/MyService/EmployeeService"));
                //IServiceChat client = cf.CreateChannel();
                //var d = client.GetEmployee(1);
            }


            try
            {
                Log.Instance.W(client, "Trying to connect ");
                ID = client.Connect(Name, isSelfServer);
                Log.Instance.W(client, "Connected ");

                isConnected      = true;
                FinalUsersStatus = new List <ServiceChat.ServerUser>();

                if (SelfServer)
                {
                    ClientStateChanged?.Invoke(ClientState.DelivererSet);
                }
                else
                {
                    ClientStateChanged?.Invoke(ClientState.DelivererWait);
                }
            }
            catch (EndpointNotFoundException exception)
            {
                isSelfServer = false;
                MessageBox((IntPtr)0, exception.Message, ClientUIPresenter.GetString("Timeout")
                           , 0);
            }
            catch (System.ServiceModel.Security.SecurityNegotiationException exception)
            {
                isSelfServer = false;
                MessageBox((IntPtr)0, ClientUIPresenter.GetString("Thedomainnameyouhaveusedisnotavailableinthisnetwork")
                           + Environment.NewLine + exception.Message +
                           Environment.NewLine + exception.InnerException.InnerException, ClientUIPresenter.GetString("NoDomainName")
                           , 0);
            }
            catch (Exception exception)
            {
                isSelfServer = false;
                MessageBox((IntPtr)0, ClientUIPresenter.GetString("Anerroroccuredwhiletryingtoconnect")
                           + Environment.NewLine + exception.Message, ClientUIPresenter.GetString("Commonerror")
                           , 0);
            }

            bw.RunWorkerAsync();
            //Update();
        }