Exemplo n.º 1
0
            public ParallelAsyncResult(TIteratorAsyncResult iteratorAsyncResult, ICollection <TWorkItem> workItems, BeginCall <TWorkItem> beginCall, EndCall <TWorkItem> endCall, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.iteratorAsyncResult = iteratorAsyncResult;
                this.workItems           = workItems;
                this.endCall             = endCall;
                this.actions             = this.workItems.Count + 1;

                foreach (TWorkItem source in workItems)
                {
                    try
                    {
                        beginCall(iteratorAsyncResult, source, timeout, completed, new CallbackState(this, source));
                    }
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        TryComplete(e, true);
                    }
                }

                TryComplete(null, true);
            }
Exemplo n.º 2
0
 public sealed override string ToString()
 {
     return($"Start: {StartCall.ToShortTimeString()}\n" +
            $"End: {EndCall.ToShortTimeString()}\n" +
            $"Target number: {TargetTelephoneNumber}\n" +
            $"Sender number: {SenderTelephoneNumber}\n" +
            $"Id: {Id.ToString()}\n" +
            $"Call duration: {CallDuration}\n\n");
 }
Exemplo n.º 3
0
 public AsyncStep(
     BeginCall beginCall,
     EndCall endCall,
     Call call,
     ExceptionPolicy policy)
 {
     this.policy    = policy;
     this.beginCall = beginCall;
     this.endCall   = endCall;
     this.call      = call;
 }
Exemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        itemManager = GameObject.Find("ItemManager").GetComponent <ItemManager>();

        startCall  = gameObjectStartCall.GetComponent <StartCall>();
        endCall    = gameObjectEndCall.GetComponent <EndCall>();
        effectCall = gameObjectEffectCall.GetComponent <EffectCall>();

        audioSources = GetComponents <AudioSource>();

        gameObjectStartCall.SetActive(true);
    }
Exemplo n.º 5
0
        private void Connect(IPEndPoint endPoint)
        {
            hostTcpClient = new TcpClient();
            var result  = hostTcpClient.BeginConnect(endPoint.Address, endPoint.Port, null, null);
            var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(3));

            if (!success)
            {
                if (EndCall != null)
                {
                    EndCall.Invoke();
                }
                throw new Exception("Przekroczono czas połączenia.");
            }
            connected = true;
        }
Exemplo n.º 6
0
        public void BreakCall(bool sendCancelCommand = false)
        {
            if (sendCancelCommand)
            {
                SendText(Commands.Bye);
                Trace.WriteLine(Commands.Bye);
            }

            if (hostTcpClient != null)
            {
                if (hostTcpClient.Connected)
                {
                    hostTcpClient.GetStream().Close();
                    hostTcpClient.Close();
                }
            }

            if (EndCall != null)
            {
                EndCall.Invoke();
            }
            isCalling = false;
        }
Exemplo n.º 7
0
Arquivo: Port.cs Projeto: MozderUC/ATE
 public void EnddCall(object obj, EndCallArgs e)
 {
     EndCall?.Invoke(this, e);
 }
Exemplo n.º 8
0
 protected AsyncStep CallParallelAsync <TWorkItem>(ICollection <TWorkItem> workItems, BeginCall <TWorkItem> beginCall, EndCall <TWorkItem> endCall, TimeSpan timeout, ExceptionPolicy policy)
 {
     return(this.CallAsync(
                (thisPtr, t, c, s) => new ParallelAsyncResult <TWorkItem>(thisPtr, workItems, beginCall, endCall, timeout, c, s),
                (thisPtr, r) => ParallelAsyncResult <TWorkItem> .End(r),
                policy));
 }
Exemplo n.º 9
0
 protected AsyncStep CallAsync(BeginCall beginCall, EndCall endCall, ExceptionPolicy policy)
 {
     return(new AsyncStep(beginCall, endCall, null, policy));
 }
Exemplo n.º 10
0
        //sender methods

        public async void MakeCall(IPEndPoint endPoint, string userName, string receiverName)
        {
            Trace.WriteLine("username: "******"receiver: " + receiverName);

            if (!isCalling)
            {
                remoteEndPointToSendVoice = endPoint;

                isCalling = true;

                if (MakeCallEvent != null)
                {
                    MakeCallEvent.Invoke("Dzwonię do: " + receiverName);
                }

                try
                {
                    Connect(endPoint);
                    string localIp = (((IPEndPoint)hostTcpClient.Client.LocalEndPoint).Address.ToString());
                    if (EncryptedCallSender)
                    {
                        SendText(Commands.Invite + ":" + localIp + ":" + userName + ":" + PrepareDHRequestString());
                    }
                    else
                    {
                        SendText(Commands.Invite + ":" + localIp + ":" + userName);
                    }

                    while (isCalling)
                    {
                        var msg = await ReceiveTextAsync();

                        if (msg.StartsWith(Commands.Busy))
                        {
                            ErrorEvent.Invoke("Zajęte");
                            BusyUserInfoEvent.Invoke("Użytkownik jest w trakcie rozmowy!");
                        }
                        else if (msg.StartsWith(Commands.Reject))
                        {
                            BreakCall();
                        }
                        else if (msg.StartsWith(Commands.Ack))
                        {
                            var msgAfterSplit = msg.Split(new char[] { ':' }, 2);
                            if (msgAfterSplit.Length == 2)
                            {
                                DHServer.HandleResponse(msgAfterSplit[1]);
                                DHKey = DHServer.Key;
                            }

                            if (UDPSenderStart != null)
                            {
                                UDPSenderStart.Invoke(remoteEndPointToSendVoice);
                            }

                            if (UDPListenerStart != null)
                            {
                                UDPListenerStart.Invoke(localEndPoint);
                            }

                            //Akceptacja połączenia - zmiana gui
                            if (TalkEvent != null)
                            {
                                TalkEvent.Invoke(receiverName);
                            }
                        }
                        else
                        {
                            ErrorEvent.Invoke(msg);
                        }
                    }
                }
                catch (Exception e)
                {
                    isCalling = false;

                    if (ErrorEvent != null)
                    {
                        ErrorEvent.Invoke(e.Message);
                    }

                    if (EndCall != null)
                    {
                        EndCall.Invoke();
                    }
                }
            }
        }
Exemplo n.º 11
0
        private void HandleConnection(TcpClient client)
        {
            StreamReader streamReader = new StreamReader(client.GetStream());
            StreamWriter streamWriter = new StreamWriter(client.GetStream())
            {
                AutoFlush = true
            };

            try
            {
                if (isBusy || isCalling)
                {
                    //odrzuc polaczenie
                    streamWriter.WriteLine(Commands.Busy);
                }
                else
                {
                    isBusy = true;
                    //akceptuj polaczenie
                    while (isBusy)
                    {
                        var message = streamReader.ReadLine();

                        if (message.StartsWith(Commands.Invite))
                        {
                            var msgAfterSplit = message.Split(new char[] { ':' }, 4);
                            if (msgAfterSplit.Length == 3)
                            {
                                EncryptedCallReceiver = false;
                                IncomingCallEvent.Invoke(msgAfterSplit[2]);
                                remoteEndPointToSendVoice = new IPEndPoint(IPAddress.Parse(msgAfterSplit[1]), localEndPoint.Port);
                            }
                            else if (msgAfterSplit.Length == 4)
                            {
                                EncryptedCallReceiver = true;
                                DHRequest             = msgAfterSplit[3];
                                //poinformuj o szyfrowaniu, potem odeslanie DH
                                IncomingCallEvent.Invoke(msgAfterSplit[2] + Environment.NewLine + "Rozmowa szyfrowana");
                                remoteEndPointToSendVoice = new IPEndPoint(IPAddress.Parse(msgAfterSplit[1]), localEndPoint.Port);
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (message.StartsWith(Commands.Cancel))
                        {
                            if (EndCall != null)
                            {
                                EndCall.Invoke();
                            }

                            if (UDPSenderStop != null)
                            {
                                UDPSenderStop.Invoke();
                            }
                            break;
                        }

                        if (message.StartsWith(Commands.Bye))
                        {
                            if (EndCall != null)
                            {
                                EndCall.Invoke();
                            }

                            if (UDPSenderStop != null)
                            {
                                UDPSenderStop.Invoke();
                            }
                            break;
                        }
                    }
                }
                if (ConnectedClient == client)
                {
                    ConnectedClient = null;
                    isBusy          = false;
                }

                client.GetStream().Close();
                client.Close();
            }
            catch (Exception e)
            {
                //disconnected
                if (ConnectedClient == client)
                {
                    ConnectedClient = null;
                    isBusy          = false;
                }

                if (client != null)
                {
                    client.Close();
                }
                ErrorEvent.Invoke(e.Message);
            }
        }
 protected virtual void OnEndCall(EventArgs e)
 {
     EndCall?.Invoke(this, e);
 }
Exemplo n.º 13
0
 public static AsyncStep CallParallel(BeginCall begin, EndCall end, IAsyncCatch[] catches)
 {
     return(new AsyncStep(begin, end, true, catches));
 }
Exemplo n.º 14
0
        /// <summary>
        /// Data retrieved from server
        /// </summary>
        /// <param name="serverConnection">TCP connection with server</param>
        private static void ListenServer(TcpClient serverConnection)
        {
            serverConnection.ReceiveBufferSize = BUFFER_SIZE;
            serverConnection.SendBufferSize    = BUFFER_SIZE;

            NetworkStream networkStream = serverConnection.GetStream();

            while (serverConnection.Connected)
            {
                ServerObject data;
                try
                {
                    data = (ServerObject)formatter.Deserialize(networkStream);
                }
                #region POSSIBLE EXCEPTIONS
                catch (IOException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (SerializationException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (DecoderFallbackException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (OverflowException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (OutOfMemoryException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (NullReferenceException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (IndexOutOfRangeException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (FormatException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (InvalidCastException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (ArgumentOutOfRangeException)
                {
                    ExceptionHandler(networkStream);
                    continue;
                }
                catch (Exception e)
                {
                    ExceptionHandler(networkStream);
                    MessageBox.Show(e.Message, e.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
                    continue;
                }
                #endregion POSSIBLE EXCEPTIONS

                switch (data.ServerFlag)
                {
                case ServerFlag.ConnectionState:
                    Task.Run(() => SetConnectionState((KeyValuePair <ConnectionState, int>)data.Data));
                    break;

                case ServerFlag.Call:
                    IncomingCall?.Invoke((int)data.Data);
                    break;

                case ServerFlag.SendMessage:
                    Task.Run(() => SendMessage((SenderObjectRelation)data.Data));
                    break;

                case ServerFlag.SendingData:
                    Task.Run(() => SendingData((SenderObject)data.Data));
                    break;

                case ServerFlag.NewUserInCall:
                    NewUserCall?.Invoke((int)data.Data);
                    break;

                case ServerFlag.CallingToGroup:
                    CallingToGroup?.Invoke((int)data.Data);
                    break;

                case ServerFlag.DeclineCall:
                    CallDeclined?.Invoke((int)data.Data);
                    break;

                case ServerFlag.UserLeftRoom:
                    UserLeftRoom?.Invoke((int)data.Data);
                    break;

                case ServerFlag.RoomClosed:
                case ServerFlag.EndCall:
                    EndCall?.Invoke();
                    break;

                case ServerFlag.ConnectionChecking:
                    Task.Run(() => SendToServer(new ServerObject(ServerFlag.ConnectionChecking, Id)));
                    break;

                case ServerFlag.ApiConnection:
                    Task.Run(() => CheckApiConnectionFlag((ApiObject)data.Data));
                    break;

                default:
                    break;
                }
            }
            MessageBox.Show("Disconnected from server");
        }
Exemplo n.º 15
0
 public static AsyncStep CallParallel(BeginCall begin, EndCall end)
 {
     return(new AsyncStep(begin, end, true));
 }
Exemplo n.º 16
0
 public static AsyncStep CallAsync(BeginCall begin, EndCall end, IAsyncCatch[] catches)
 {
     return(new AsyncStep(begin, end, false, catches));
 }
Exemplo n.º 17
0
 public static AsyncStep CallAsync(BeginCall begin, EndCall end)
 {
     return(new AsyncStep(begin, end, false));
 }
Exemplo n.º 18
0
 public AsyncStep(BeginCall begin, EndCall end, bool isParallel, IAsyncCatch[] catches)
     : this(begin, end, isParallel)
 {
     this.Catches = catches;
 }
Exemplo n.º 19
0
 public AsyncStep(BeginCall begin, EndCall end, bool isParallel)
 {
     this.Begin      = begin;
     this.End        = end;
     this.IsParallel = isParallel;
 }