Ejemplo n.º 1
0
        public void PhoneAnswer(object sender, AnswerEventArgs e)
        {
            if (_listPhoneNumbers.Contains(e.PhoneNumber))
            {
                CallInfo            info = null;
                CallInfo            call = new CallInfo();
                System.Timers.Timer t    = new System.Timers.Timer();
                int index         = _listPhoneNumbers.IndexOf(e.PhoneNumber);
                int indexContract = -1;
                _listContracts.First(x => { indexContract++; return(x.PhoneNumber == e.PhoneNumber); });

                if (_listPorts[index].State == PortState.Connect && e.StateCall == CallState.Answered)
                {
                    _listPorts[index].AnswerCall(e.TargetPhoneNumber, e.PhoneNumber, e.StateCall);
                    t.Start();
                    call.MyPhoneNumber     = e.PhoneNumber;
                    call.TargetPhoneNumber = e.TargetPhoneNumber;
                    call.Start             = DateTime.Now;
                    Console.ReadKey();
                    t.Stop();
                    call.Duration = DateTime.Now - call.Start;
                    var costOfTalk = _listContracts[indexContract].Tariff.CostOfMinutes *
                                     call.Duration.TotalMinutes; //TotalSeconds
                    call.CostOfTalk = (int)costOfTalk;
                    _listContracts[indexContract].Client.RemoveMoney(call.CostOfTalk);
                    info = new CallInfo(call.Start, call.Duration, call.MyPhoneNumber,
                                        call.TargetPhoneNumber, call.CostOfTalk);
                    _callList.Add(info);
                }
                else
                {
                    _listPorts[index].AnswerCall(e.TargetPhoneNumber, e.PhoneNumber, e.StateCall);
                }
            }
        }
Ejemplo n.º 2
0
 public static void GetAnswers(object sender, AnswerEventArgs args)
 {
     if (acceptData == AcceptState.Ready)
     {
         if (args.data is DirectoryInfo)
         {
             Directory.CreateDirectory(((DirectoryInfo)args.data).FullName);
         }
         if (args.data is FileStream)
         {
             FileStream f   = (FileStream)args.data;
             FileStream tag = new FileStream(f.Name, FileMode.Create);
             f.CopyTo(tag);
         }
         else if (args.data.Equals("Done"))
         {
             acceptData = AcceptState.Done;
         }
         else
         {
             client.Send("Data");
         }
     }
     else if (acceptData == AcceptState.NotReady)
     {
         if (args.data is DirectoryInfo)
         {
             mainWindow.ShowShareFolder((DirectoryInfo)(args.data));
         }
     }
     else if (acceptData == AcceptState.Done)
     {
     }
 }
Ejemplo n.º 3
0
        public static void Answer(object sender, AnswerEventArgs args)
        {
            if (args.data.ToString().Equals("Info"))
            {
                if (di != null)
                {
                    server.ServerSendAll(di);
                }
            }
            else if (args.data.ToString().Equals("Data"))
            {
                Queue <DirectoryInfo> qd = new Queue <DirectoryInfo>();
                if (di != null)
                {
                    DirectoryInfo tmp = di;
                    qd.Enqueue(tmp);
                    while (qd.Count > 0)
                    {
                        server.ServerSendAll(qd.Peek());
                        foreach (FileInfo fi in qd.Peek().GetFiles())
                        {
                            FileStream fs = new FileStream(fi.FullName, FileMode.Open);

                            server.ServerSendAll(fs);
                        }
                        foreach (DirectoryInfo d in qd.Peek().GetDirectories())
                        {
                            qd.Enqueue(d);
                        }
                        qd.Dequeue();
                    }
                    server.ServerSendAll("Done");
                }
            }
        }
Ejemplo n.º 4
0
 public static void OnUserGotQuestionWrong(object theClallingClass, AnswerEventArgs e)
 {
     if (UserGotQuestionWrong != null)
     {
         UserGotQuestionWrong(theClallingClass, e);
     }
 }
Ejemplo n.º 5
0
 public static void OnUserGotQuestionRight(object theClallingClass, AnswerEventArgs e)
 {
     if (UserGotQuestionRight != null)
     {
         UserGotQuestionRight(theClallingClass, e);
     }
 }
Ejemplo n.º 6
0
 public static void OnUserAnsweredQuestion(object theClallingClass, AnswerEventArgs e)
 {
     if (UserAnsweredQuestion != null)
     {
         UserAnsweredQuestion(theClallingClass, e);
     }
 }
Ejemplo n.º 7
0
 public static void OnUserAnsweredQuestion(object theClallingClass, AnswerEventArgs e)
 {
     if (UserAnsweredQuestion != null)
     {
         UserAnsweredQuestion(theClallingClass, e);
     }
 }
Ejemplo n.º 8
0
        private static void GetAnswers(object sender, AnswerEventArgs args)
        {
            string hello = args.data as string;

            Console.WriteLine(hello);
            //     Image a = args.data as Image;  //强制转换为一个Image对象
            //    a.Save("yyy.gif");  //将此文件保存为yyy.gif,保存在本地了(这是何意),呃,测试保存性能?
            //    Console.WriteLine("saved! yyy.gif");  //输出至控制台
        }
Ejemplo n.º 9
0
Archivo: Port.cs Proyecto: Dloz/Task3
 public void Answer(object sender, AnswerEventArgs e)
 {
     if (State != PortState.Busy)
     {
         return;
     }
     e.Id = CurrentCallId;
     Console.WriteLine(@"Port -> CallStarted: id {0}", CurrentCallId);
     PortAnswerEvent?.Invoke(sender, e);
 }
Ejemplo n.º 10
0
        protected virtual void OnAnswered(AnswerEventArgs e)
        {
            Answered?.Invoke(this, e);

            if (e.invalid)
            {
                Console.WriteLine("Invalid Answer");
                Execute();
            }
        }
Ejemplo n.º 11
0
 public void Answer(object sender, AnswerEventArgs e)
 {
     if (e.CallState == CallState.Answered)
     {
         Console.WriteLine("Terminal with number: {0}, have answer on call from number: {1}", e.TargetPhoneNumber, e.PhoneNumber);
     }
     else
     {
         Console.WriteLine("Terminal with number: {0}, have rejected call", e.PhoneNumber);
     }
 }
Ejemplo n.º 12
0
 protected virtual void RaiseAnswerToEvent(AnswerEventArgs eventArgs)
 {
     if (AnswerEvent != null)
     {
         AnswerEvent(this, new AnswerEventArgs(
                         eventArgs.TelephoneNumber,
                         eventArgs.TargetTelephoneNumber,
                         eventArgs.StateInCall,
                         eventArgs.Id));
     }
 }
Ejemplo n.º 13
0
 private void AnalyzeAnswer(object sender, AnswerEventArgs e)
 {
     if (TheTestStats.CurrentEquation.Answer == e.Answer)
     {
         UserEvents.OnUserGotQuestionRight(this, e);
     }
     else if (TheTestStats.CurrentEquation.Answer != e.Answer)
     {
         UserEvents.OnUserGotQuestionWrong(this, e);
     }
 }
Ejemplo n.º 14
0
 private void AnalyzeAnswer(object sender, AnswerEventArgs e)
 {
     if(TheTestStats.CurrentEquation.Answer == e.Answer)
     {
         UserEvents.OnUserGotQuestionRight(this, e);
     }
     else if (TheTestStats.CurrentEquation.Answer != e.Answer)
     {
         UserEvents.OnUserGotQuestionWrong(this, e);
     }
 }
Ejemplo n.º 15
0
 public void TakeAnswer(object sender, AnswerEventArgs e)
 {
     _id = e.Id;
     if (e.StateInCall == CallState.Answered)
     {
         Console.WriteLine("Terminal with number: {0}, have answer on call a number: {1}", e.TelephoneNumber, e.TargetTelephoneNumber);
     }
     else
     {
         Console.WriteLine("Terminal with number: {0}, have rejected call", e.TelephoneNumber);
     }
 }
Ejemplo n.º 16
0
        public void TakeAnswer(object sender, AnswerEventArgs e)
        {
            if (e.StateCall == CallState.Answered)
            {
                Console.WriteLine("Terminal with number: {0}, answered a call number: {1}",
                                  e.TargetPhoneNumber, e.PhoneNumber);
            }

            else if (e.StateCall == CallState.Rejected)
            {
                Console.WriteLine("Terminal with number: {0}, rejected a call number: {1}", e.TargetPhoneNumber, e.PhoneNumber);
            }
        }
Ejemplo n.º 17
0
 private void MainForm_AnswerEvent(object sender, AnswerEventArgs e)
 {
     gamerService.AddPoints(e.num);
     mainForm.SetGamer(gamerService.GetGamer());
     if (gamerService.GetGamer().NumPoint == 1000000)
     {
         mainForm.WinGame();
     }
     if (e.answer.IsCorrect)
     {
         mainForm.Answer_True();
     }
     else
     {
         mainForm.GameOver();
     }
 }
Ejemplo n.º 18
0
        static void server_answer(object sender, AnswerEventArgs args)
        {
            Debug.WriteLine("Received!");
            var message = args.data as UserMessage;

            if (message.type == 2)
            {
                var s = sender as TcpClient;
                tcpmap.Add(s, message.name);
                var ns   = s.GetStream();
                var data = new List <string>();
                data.Add(MainData.Me.name);
                data.AddRange(MainData.user_dic.Keys);
                var u = new UserMessage(3, "Server", data);
                server.formatter.Serialize(ns, u);
            }
        }
Ejemplo n.º 19
0
        protected virtual void OnAnswerProvided(int questionNumber)
        {
            string correctAnswer = string.Empty;

            foreach (DataRow dr in Question.Rows)
            {
                if (questionNumber == (int)dr["QuestionID"])
                {
                    correctAnswer = dr["Correct"].ToString();
                    break;
                }
            }

            Answers         answer = new Answers(questionNumber, correctAnswer);
            AnswerEventArgs e      = new AnswerEventArgs(answer);

            AnswerProvided(this, e);
        }
Ejemplo n.º 20
0
 void terminal_AnswerEvent(object sender, AnswerEventArgs e)
 {
     OnAnswerEvent(e.PhoneNumber, e.TargetPhoneNumber, e.CallState);
 }
Ejemplo n.º 21
0
 public void ProvideAnswer(object sender, AnswerEventArgs e)
 {
     Answers.Add(e.Answer);
 }
Ejemplo n.º 22
0
        static void client_answer(object sender, AnswerEventArgs args)
        {
            var message = args.data as UserMessage;

            try{
                switch (message.type)
                {
                case 1://传输线条
                {
                    //  MessageBox.Show(String.Format("线条来自{0}", message.name));
                    MyStroke p = message.data as MyStroke;
                    Custom   c;
                    MainData.user_dic.TryGetValue(message.name, out c);
                    if (c != null && p != null)
                    {
                        c.AddStroke(p);
                    }
                }
                break;

                case 2://登录,表示有某个人登录了
                {
                    //  MessageBox.Show(String.Format("登录{0}", message.name));
                    if (MainData.user_dic.ContainsKey(message.name))
                    {
                        MessageBox.Show("Error 请不要重复登录");
                    }
                    var p = new Custom();
                    p.name = message.name;

                    MainData.user_dic.Add(message.name, p);
                }
                break;

                case 3://登录反馈,收到的服务器发过来的在线人的名字列表
                {
                    List <string> s   = message.data as List <string>;
                    string        str = "";
                    foreach (var item in s)
                    {
                        str = str + item + " ";
                    }
                    //  if (s != null) MessageBox.Show(str);
                    // else MessageBox.Show("Get But No Data");
                    foreach (var item in s)
                    {
                        var p = new Custom();
                        p.name = item;
                        MainData.user_dic.Add(item, p);
                    }
                }
                break;

                case 4://线宽变化
                {
                    var    d = (double)message.data;
                    Custom c;
                    MainData.user_dic.TryGetValue(message.name, out c);
                    if (c != null)
                    {
                        c.ChangeWidth(d);
                    }
                }
                break;

                case 5://颜色变化
                {
                    var cc = message.data as string;
                    //  MessageBox.Show(cc);
                    Custom c;
                    MainData.user_dic.TryGetValue(message.name, out c);
                    if (c != null)
                    {
                        c.ChangeColor(cc);
                    }
                }
                break;

                case 6:
                {
                    Custom c;
                    MainData.user_dic.TryGetValue(message.name, out c);
                    if (c != null)
                    {
                        c.Undo();
                    }
                }
                break;

                case 7:
                {
                    Custom c;
                    MainData.user_dic.TryGetValue(message.name, out c);
                    if (c != null)
                    {
                        c.Clear();
                    }
                }
                break;

                case 8://下线通知 此时name是下线者
                {
                    //  MessageBox.Show("Offline");
                    Custom c;
                    MainData.user_dic.TryGetValue(message.name, out c);
                    if (c != null)
                    {
                        c.Remove();
                    }
                    MainData.user_dic.Remove(message.name);
                }
                break;

                default:
                    break;
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("Client.client_answer" + e1.Message);
            }
        }
Ejemplo n.º 23
0
        static void client_answer(object sender, AnswerEventArgs args)
        {
            var message = args.data as UserMessage;

            switch (message.type)
            {
            case 1:    //传输文本
            {
                Custom c = null;
                MainData.user_dic.TryGetValue(message.name, out c);
                if (c != null)
                {
                    c.AddString(message.data as string);
                }
            }
            break;

            case 2:    //登录,表示有某个人登录了
            {
                //  MessageBox.Show(String.Format("登录{0}", message.name));
                if (MainData.user_dic.ContainsKey(message.name))
                {
                    MessageBox.Show("Error 请不要重复登录");
                }
                var p = new Custom();
                p.name = message.name;

                MainData.user_dic.Add(message.name, p);
            }
            break;

            case 3:    //登录反馈,收到的服务器发过来的在线人的名字列表
            {
                List <string> s   = message.data as List <string>;
                string        str = "";
                foreach (var item in s)
                {
                    str = str + item + " ";
                }
                //  if (s != null) MessageBox.Show(str);
                // else MessageBox.Show("Get But No Data");
                foreach (var item in s)
                {
                    var p = new Custom();
                    p.name = item;
                    MainData.user_dic.Add(item, p);
                }
            }
            break;

            case 4:    //线宽变化
            {
            }
            break;

            case 5:    //颜色变化
            {
            }
            break;

            case 6:
            {
            }
            break;

            case 7:
            {
            }
            break;

            case 8:    //下线通知 此时name是下线者
            {
                //  Custom c;
                //  MainData.user_dic.TryGetValue(message.name, out c);
                MainData.user_dic.Remove(message.name);
            }
            break;

            default:
                break;
            }
        }
Ejemplo n.º 24
0
 void answers_grid_AnswerSelect(object sender, AnswerEventArgs arg)
 {
     this.lb_errors.Text = "Вопросов без ответа: " + answers_grid.Answers.CountWithEmpty.ToString();
     SetTollTips(arg.CurrentAnsverControl);
 }
Ejemplo n.º 25
0
 private void AnswerTo(object sender, AnswerEventArgs e)
 {
     RaiseAnswerToEvent(e);
 }
Ejemplo n.º 26
0
 private static void Answer(object sender, AnswerEventArgs args)
 {
     Console.WriteLine("Data Connection!"); //输出至控制台
     //      string s = args.data.ToString();   //将传递的信息转为字符串形式(不忒准确)
     //      Console.WriteLine(s);  //输出值控制台
 }