Example #1
0
        public IHttpActionResult Put(CallViewModel callVm)
        {
            try
            {
                int retVal = callVm.Update();
                switch (retVal)
                {
                case 1:
                    return(Ok("Call " + callVm.Id + " updated!"));

                case -1:
                    return(Ok("Call " + callVm.Id + " not updated!"));

                case -2:
                    return(Ok("Data is stale for " + callVm.Id + ", Call not updated!"));

                default:
                    return(Ok("Call " + callVm.Id + " Not updated!"));
                }
            }
            catch (Exception e)
            {
                return(BadRequest("Update failed - " + e.Message));
            }
        }
Example #2
0
        public FriendViewModel(IDataService dataService, int friendNumber)
        {
            _toxModel      = dataService.ToxModel;
            _avatarManager = dataService.AvatarManager;

            FriendNumber = friendNumber;

            Conversation  = new ConversationViewModel(dataService, this);
            FileTransfers = new FileTransfersViewModel(dataService, friendNumber);
            Call          = new CallViewModel(friendNumber);

            Name = _toxModel.GetFriendName(friendNumber);
            if (Name == string.Empty)
            {
                Name = _toxModel.GetFriendPublicKey(friendNumber).ToString();
            }

            StatusMessage = _toxModel.GetFriendStatusMessage(friendNumber);
            if (StatusMessage == string.Empty)
            {
                StatusMessage = "Friend request sent.";
            }

            SetFriendStatus(_toxModel.GetFriendStatus(friendNumber));
            IsConnected = _toxModel.IsFriendOnline(friendNumber);

            _avatarManager.FriendAvatarChanged += FriendAvatarChangedHandler;

            _toxModel.FriendNameChanged             += FriendNameChangedHandler;
            _toxModel.FriendStatusMessageChanged    += FriendStatusMessageChangedHandler;
            _toxModel.FriendStatusChanged           += FriendStatusChangedHandler;
            _toxModel.FriendConnectionStatusChanged += FriendConnectionStatusChangedHandler;
        }
        public dynamic acceptrejectcall(CallViewModel uM)
        {
            using (LystenEntities db = new LystenEntities())
            {
                Calling_Request qs = db.Calling_Request.Where(x => x.Id == uM.Id).FirstOrDefault();



                //TimeZoneInfo.ConvertTime(qs.AcceptDatetime.Value, qs.TimeZoneId, destinationTimeZone);

                var dt = DateTime.SpecifyKind(uM.AcceptDatetime == 1 ? qs.CallingDateTime1.Value : uM.AcceptDatetime == 2 ? qs.CallingDateTime2.Value : uM.AcceptDatetime == 3 ? qs.CallingDateTime3.Value : System.DateTime.Now, DateTimeKind.Local);

                qs.AcceptDatetime = uM.AcceptDatetime == 1 ? qs.CallingDateTime1 : uM.AcceptDatetime == 2 ? qs.CallingDateTime2 : uM.AcceptDatetime == 3 ? qs.CallingDateTime3 : System.DateTime.Now;



                TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById(qs.TimeZoneId);


                qs.AcceptDatetimeUTC = TimeZoneInfo.ConvertTimeToUtc(qs.AcceptDatetime.Value, easternZone);
                //= TimeZoneInfo.ConvertTimeToUtc(dt);



                qs.IsAccept        = uM.IsAccept == 1 ? true : false;
                qs.IsReject        = uM.IsAccept == 0 ? true : false;
                qs.RejectedNote    = uM.RejectedNote;
                db.Entry(qs).State = EntityState.Modified;
                db.SaveChanges();

                return(qs);
            }
        }
Example #4
0
        public async Task <ActionResult> Create([Bind(Include = "CallId,CongregationID,Title,nameFirst,nameLast,Street,Barangay,City,State,dateFirstVisit,dateLastVisit,Status,Remarks")] Call call)
        {
            /* This is an example of the magic of model binding, that is-
             * - An HTML form has been posted back in
             * - The system knows what a call object is
             * - Maps HTML form data (using Name attribute of an 'input' element, for example) to a call object
             *
             * Watch "Developing ASP.NET MVC 4 Applications: (03) Developing MVC 4 Controllers". Jump to Time: 24:30
             */
            if (ModelState.IsValid)  // Tip: Profuse model with validation attributes
            {
                try
                {
                    db.Calls.Add(call);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                    return(View(call));
                }
            }

            CallViewModel callViewModel = new CallViewModel(call);

            return(View(callViewModel));
        }
Example #5
0
        public async Task <ActionResult> Edit(int?id)
        {
            /*
             * if (id == null)
             * {
             *  return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
             * }
             * Call call = await db.Calls.FindAsync(id);
             * if (call == null)
             * {
             *  return HttpNotFound();
             * }
             * return View(call); */

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Call call = await db.Calls.FindAsync(id);

            if (call == null)
            {
                return(HttpNotFound());
            }
            ViewBag.InitialScreen = TempData["Set"];
            CallViewModel callViewModel = new CallViewModel(call);

            return(View(callViewModel));
        }
Example #6
0
        ///GET: Manager/CallViewModels
        public ActionResult Index()
        {
            CallViewModel model = new CallViewModel();

            var callData    = db.Calls.ToList();
            var itemsData   = db.Items.ToList();
            var custData    = db.Customers.ToList();
            var repData     = db.Representatives.ToList();
            var callDetails = db.CallDetails.ToList();



            var result = from cd in callData
                         join cust in custData on cd.CustomerID equals cust.CustomerID
                         join rep in repData on cust.RepresentativeID equals rep.RepresentativeID
                         select new { callID = cd.CallID, callDate = cd.CallDate.ToString(), callNumber = cd.DocNumber.ToString(), contractDate = cd.ContractDate.ToString(), docType = cd.DocType.ToString(), cName = cust.Name.ToString(), repFName = rep.FamilyName.ToString() };

            var result2 = from cd in callDetails
                          join itd in itemsData on cd.ItemID equals itd.ItemID
                          select new { callID = cd.CallID, itemName = cd.Item.ItemName, itQty = cd.ItemQty };


            ViewBag.CallData = result.ToList();
            ViewBag.ItemData = result2.ToList();



            return(View());
        }
Example #7
0
        // 'DELETE' method to remove and employee from the database
        public IHttpActionResult Delete(int id)
        {
            try
            {
                // Create and EmployeeViewModel object to store the employee data
                CallViewModel call = new CallViewModel();

                // The EmployeeViewModel Object ID is that of the ID past into the methods parameters
                // when called in the JavaScript
                call.Id = id;

                // If the number of employees deleted equals 1 then display the message that it was successful
                // else display a message that it was unsuccessful
                if (call.Delete() == 1)
                {
                    return(Ok("Call " + call.Id + " deleted!"));
                }
                else
                {
                    return(Ok("Call " + call.Id + " not deleted!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Delete failed - Contact Tech Support"));
            }
        }
Example #8
0
        public IHttpActionResult Delete(string id)
        {
            try
            {
                CallViewModel call = new CallViewModel();
                call.Id = id;
                long delRetCall = call.Delete();

                switch (delRetCall)
                {
                case 1:
                    return(Ok("Ok! Call has been deleted!"));

                case 2:
                    return(Ok("Error! Call does not Exist!"));

                default:
                    return(Ok("Call not Deleted!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Update Failed - Contact Tech Support"));
            }
        }
        public async Task <ActionResult> Call(CallViewModel callViewModel)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values.SelectMany(m => m.Errors)
                             .Select(e => e.ErrorMessage)
                             .ToList();
                var errorMessage = string.Join(". ", errors);
                return(Json(new { success = false, message = errorMessage }));
            }

            var twilioNumber = ConfigurationManager.AppSettings["TwilioNumber"];
            var uriHandler   = GetUri(callViewModel.SalesNumber);

            try
            {
                await _notificationService.MakePhoneCallAsync(callViewModel.UserNumber, twilioNumber, uriHandler);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Json(new { success = false, message = "Twilio API Error: " + e.Message }));
            }

            return(Json(new { success = true, message = "Phone call incoming!" }));
        }
Example #10
0
        public IHttpActionResult Put(CallViewModel call)
        {
            try
            {
                int retVal = call.Update();
                switch (retVal)
                {
                case 1:
                    return(Ok("Ok! Call updated!"));

                case -1:
                    return(Ok("Call not updated!"));

                case -2:
                    return(Ok("Data is Stale, Call not updated"));

                default:
                    return(Ok("Call not updated!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Update Failed - Contact Tech Support"));
            }
        }
 internal bool TerminateCall(CallViewModel viewModel, string message)
 {
     //**********************************************************************************************
     // Terminate/End call.
     //********************************************************************************************
     lock (CallsViewModelList)
     {
         if (FindCallViewModel(viewModel))
         {
             if (viewModel.CallState != VATRPCallState.Declined)
             {
                 LOG.Info(String.Format("Terminating call for {0}. {1}", viewModel.CallerInfo,
                                        viewModel.ActiveCall.NativeCallPtr));
                 try
                 {
                     _linphoneService.TerminateCall(viewModel.ActiveCall.NativeCallPtr, message);
                 }
                 catch (Exception ex)
                 {
                     ServiceManager.LogError("TerminateCall", ex);
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
Example #12
0
        // 'PUT' method to be called when the user wants to update an employee that
        // is already in the database.
        public IHttpActionResult Put(CallViewModel call)
        {
            try
            {
                // Retrieves the update status from the EmployeeViewModel, to say whether the update
                // was good, didn't happen or that the user had stale data which also would not update
                // the employee information. Then displays a message based on the value returned, saying
                // whether or not the update happened.
                int retVal = call.Update();
                switch (retVal)
                {
                case 1:
                    return(Ok("Call " + call.Id + " updated!"));

                case -1:
                    return(Ok("Call " + call.Id + " not update!"));

                case -2:
                    return(Ok("Data is stale for " + call.Id + ", Call not update!"));

                default:
                    return(Ok("Call " + call.Id + " not update!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("update failed - " + ex.Message));
            }
        }
        private static void Main(string[] args)
        {
            var call = new Call {
                Number = "001337", CustomerNumber = "000001"
            };
            var op = new Operation {
                ID = 1, CallNumber = "001337", TimeFrom = "08:00"
            };
            var customer = new Customer {
                Number = "000001", Name = "John Doe"
            };

            var model = new
            {
                Call      = call,
                Customer  = customer,
                Operation = op
            };

            var viewModel = new CallViewModel();

            viewModel.InjectFrom <FlatLoopValueInjection>(model);

            Console.WriteLine("Number:\t\t\t" + viewModel.CallNumber);
            Console.WriteLine("CustomerName:\t\t" + viewModel.CustomerName);
            Console.WriteLine("OperationTimeFrom:\t" + viewModel.OperationTimeFrom);
            Console.ReadLine();
        }
Example #14
0
        //accept an object and return a result to represent if the update is successful
        public IHttpActionResult Put(CallViewModel cal)
        {
            try
            {
                int retVal = cal.Update();
                switch (retVal)
                {
                case 1:
                    return(Ok("Call updated!"));

                case -1:
                    return(Ok("Call not updated"));

                case -2:
                    return(Ok("Call is stale! Call not updated"));

                default:
                    return(Ok("Call not updated!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Update failed - " + ex.Message));
            }
        }
        internal bool SwitchCall(CallViewModel pausedCallViewModel, CallViewModel activeCallViewModel)
        {
            LOG.Info(String.Format("Switching call. Main call {0}. {1}. Secondary call {2} {3}",
                                   activeCallViewModel.CallerInfo,
                                   activeCallViewModel.ActiveCall.NativeCallPtr, pausedCallViewModel.CallerInfo,
                                   pausedCallViewModel.ActiveCall.NativeCallPtr));



            if (activeCallViewModel.CallState == VATRPCallState.LocalPaused && activeCallViewModel.PauseRequest)
            {
                if (pausedCallViewModel.CallState == VATRPCallState.LocalPaused && pausedCallViewModel.PauseRequest)
                {
                    return(false);
                }
                ResumeCall(pausedCallViewModel);
            }
            else
            {
                //var textBlock =   FindChild<TextBlock>(newCallAcceptWindow.TransparentWindow, "NewCallerInfoLabel");
                //if (textBlock != null)
                //    textBlock.Text = callerInfo;
                // ShowNewCallSwapWindow(true);

                PauseCall(activeCallViewModel);
            }
            return(true);
        }
Example #16
0
        public IHttpActionResult Delete(CallViewModel call)
        {
            try
            {
                long retVal = call.Delete();
                switch (retVal)
                {
                case 1:
                    return(Ok("Call " + call.Notes + " Deleted!"));

                case -1:
                    return(Ok("Call " + call.Notes + " not deleted!"));

                case -2:
                    return(Ok("Data is stale for " + call.Notes + ", Call already deleted!"));

                default:
                    return(Ok("Call " + call.Notes + " not deleted!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Retrieve failed - " + ex.Message));
            }
        }
Example #17
0
        /*
         * protected override void OnClosing(CancelEventArgs e)
         * {
         *  if (!pleaseClose)
         *  {cvm.sck.Close();
         *      base.OnClosing(e);
         *      e.Cancel = true;
         *  }
         * }*/

        public CallWindow(string login, string password, string friendAvatar, string friendLogin, string address_ip, string call_id, string state, UdpClient udp)
        {
            InitializeComponent();
            var hwnd = new WindowInteropHelper(this).Handle;

            SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
            //audioManager = new AudioManager();
            //audioManager.Initialize(login);
            //audioManager.StartCall(address_ip);

            NotWaitToCallButton.IsEnabled = false;
            SendButton.IsEnabled          = false;

            NotReceiveButton.IsEnabled = false;
            StartCallButton.IsEnabled  = false;

            cvm = new CallViewModel(login, password, friendAvatar, friendLogin, address_ip, call_id, state, this, udp);
            cvm.RequestClose += new EventHandler(CloseWindow);
            DataContext       = cvm;

            if (!cvm.CallModel.IsNotInLocalNewtwork)
            {
                cvm.sendHi();

                System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
                dispatcherTimer.Tick    += dispatcherTimer_Tick;
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
                dispatcherTimer.Start();
            }
            else
            {
                pleaseClose = true;
                Close();
            }
        }
Example #18
0
        protected override async Task OnInitializedAsync()
        {
            await base.OnInitializedAsync();

            var connectionParameters = JsonSerializer.Deserialize <ConnectionParameters>(ConnectionParametersJson);
            await CallViewModel.OnPageAppearingAsync(connectionParameters, ReRender);
        }
        internal void AcceptCall(CallViewModel viewModel)
        {
            //**********************************************************************************************
            // Incoming Call Accepted
            //********************************************************************************************
            lock (CallsViewModelList)
            {
                if (FindCallViewModel(viewModel))
                {
                    LOG.Info(String.Format("Accepting call call for {0}. {1}", viewModel.CallerInfo,
                                           viewModel.ActiveCall.NativeCallPtr));

                    viewModel.AcceptCall();
                    bool muteMicrophone = false;
                    bool muteSpeaker    = false;
                    //bool enableVideo = true;
                    if (App.CurrentAccount != null)
                    {
                        muteMicrophone = App.CurrentAccount.MuteMicrophone;
                        muteSpeaker    = App.CurrentAccount.MuteSpeaker;
                        // enableVideo = App.CurrentAccount.EnableVideo;
                    }
                    try
                    {
                        _linphoneService.AcceptCall(viewModel.ActiveCall.NativeCallPtr,
                                                    ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                                                                                                     Configuration.ConfEntry.USE_RTT, true), muteMicrophone, muteSpeaker, true);
                    }
                    catch (Exception ex)
                    {
                        ServiceManager.LogError("AcceptCall", ex);
                    }
                }
            }
        }
        public IHttpActionResult Put(CallViewModel call)
        {
            try
            {
                //Use the EmployeeViewModel's Update method to update the employee
                int retVal = call.Update();
                switch (retVal)
                {
                case 1:
                    return(Ok("Call  updated!"));

                case -1:
                    return(Ok("Call not updated!"));

                case -2:
                    return(Ok("Data is stale, call not updated!"));

                default:
                    return(Ok("Call not updated!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Update Failed - " + ex.Message));
            }
        }
        public IActionResult Put([FromBody]  CallViewModel viewModel)
        {
            try
            {
                int retVal = viewModel.Update();
                switch (retVal)
                {
                case 1:
                    return(Ok(new { msg = "Call " + viewModel.Id + " updated!" }));

                case -1:
                    return(Ok(new { msg = "Call " + viewModel.Id + " not updated!" }));

                case -2:
                    return(Ok(new { msg = "Data is stale for " + viewModel.Id + ", Call not updated!" }));

                default:
                    return(Ok(new { msg = "Call " + viewModel.Id + " not updated!" }));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Problem in " + GetType().Name + " " +
                                 MethodBase.GetCurrentMethod().Name + " " + ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public void ShouldStartCallWithRealNumber()
        {
            var mockNotificationService  = new Mock <INotificationService>();
            var mockControllerProperties = new ControllerPropertiesMock();
            var controller = new CallCenterController(mockNotificationService.Object)
            {
                ControllerContext = mockControllerProperties.ControllerContext,
                Url = mockControllerProperties.Url(RouteConfig.RegisterRoutes)
            };

            var callViewModel = new CallViewModel {
                UserNumber = "user-number", SalesNumber = "sales-number"
            };

            controller
            .WithCallTo(c => c.Call(callViewModel))
            .ShouldReturnJson(data =>
            {
                Assert.That(data.message, Is.EqualTo("Phone call incoming!"));
            });

            const string expectedUriHandler = "http://www.example.com/Call/Connect?salesNumber=sales-number";

            mockNotificationService.Verify(
                s => s.MakePhoneCallAsync("user-number", "twilio-number", expectedUriHandler), Times.Once());
        }
        public async Task <CallViewModel> SelectAsync(Guid CallId)
        {
            CallViewModel Call = this._mapper.Map <CallViewModel>(await this._callRepository.SelectAsync(CallId));

            Call.Timeline = this._mapper.Map <IEnumerable <CallTimelineViewModel> >(await this._callTimelineRepository.SelectAllByCallIdAsync(CallId));
            return(Call);
        }
 internal int RemoveCalViewModel(CallViewModel callViewModel)
 {
     lock (CallsViewModelList)
     {
         CallsViewModelList.Remove(callViewModel);
         OnPropertyChanged("CallsViewModelList");
         return(CallsViewModelList.Count);
     }
 }
Example #25
0
        public void ComprehensiveVMTests()
        {
            CallViewModel     cvm = new CallViewModel();
            EmployeeViewModel evm = new EmployeeViewModel();
            ProblemViewModel  pvm = new ProblemViewModel();

            cvm.DateOpened = DateTime.Now;
            cvm.DateClosed = null;
            cvm.OpenStatus = true;
            evm.Lastname   = "Jarocki";
            evm.GetByLastname();
            cvm.EmployeeId = evm.Id;
            evm.Lastname   = "Burner";
            evm.GetByLastname();
            cvm.TechId      = evm.Id;
            pvm.Description = "Memory Upgrade";

            pvm.GetByDescription();
            cvm.ProblemId = pvm.Id;
            cvm.Notes     = "Kevin has bad RAM, Burner to fix it";
            cvm.Add();
            Console.WriteLine("New Call Generated - Id = " + cvm.Id);
            int id = cvm.Id;     //need id for delete later

            cvm.GetById();
            cvm.Notes += "\n Ordered new RAM!";

            if (cvm.Update() == 1)
            {
                Console.WriteLine("Call was updated " + cvm.Notes);
            }
            else
            {
                Console.WriteLine("Call was not updated!");
            }

            cvm.Notes = "Another change to comments that should not work";
            if (cvm.Update() == -2)
            {
                Console.WriteLine("Call was not updated data was stale");
            }

            cvm    = new CallViewModel();
            cvm.Id = id;
            cvm.GetById();

            if (cvm.Delete() == 1)
            {
                Console.WriteLine("Call was deleted!");
            }
            else
            {
                Console.WriteLine("Call was not deleted");
            }

            cvm.GetById();
        }
Example #26
0
        public void Dispose()
        {
            Task.Run(async() => await CallViewModel.OnPageDisappearingAsync());


            //// TODO: How to call async in Dispose??? Currently fire and forget!!!
            //Task.Run(async () => await SignallingServerService.DisposeAsync());
            //_webRtcMiddleware.Dispose();
        }
        public void Call_ComprehensiveVMTest()
        {
            CallViewModel     cvm = new CallViewModel();
            EmployeeViewModel evm = new EmployeeViewModel();
            ProblemViewModel  pvm = new ProblemViewModel();

            cvm.DateOpened = DateTime.Now;
            //cvm.DateClosed = null;
            cvm.OpenStatus = true;
            evm.Email      = "*****@*****.**";
            evm.GetByEmail();
            cvm.EmployeeId = evm.Id;
            //evm.Lastname = "Park";
            evm.Email = "*****@*****.**";
            evm.GetByEmail();
            cvm.TechId      = evm.Id;
            pvm.Description = "Memory Upgrade";
            pvm.GetByDescription();
            cvm.ProblemId = pvm.Id;
            cvm.Notes     = "Jimin has bad RAM, Burner to fix it";
            cvm.Add();
            output.WriteLine("New Call Generated - Id = " + cvm.Id);

            int id = cvm.Id;

            cvm.GetById();
            cvm.Notes += "\n Ordered new RAM!!";

            if (cvm.Update() == 1)
            {
                output.WriteLine("Call was updated " + cvm.Notes);
            }
            else
            {
                output.WriteLine("Call was not updated!");
            }

            //cvm.Notes = "Another change to comments that should not works";
            //if (cvm.Update() == -2) {
            //    output.WriteLine("Call was not updated data was stale");
            //}

            //cvm = new CallViewModel();
            //cvm.Id = id;
            //cvm.GetById();

            //if (cvm.Delete() == 1)
            //{
            //    output.WriteLine("Call was deleted!");
            //}
            //else {
            //    output.WriteLine("Call was not deleted!");
            //}

            //Exception ex = Assert.Throws<NullReferenceException>(() => cvm.GetById());
            //Assert.Equal("Object reference not set to an instance of an object.", ex.Message);
        }
        public void ComprehensiveVMTests()
        {
            CallViewModel     cvm = new CallViewModel();
            EmployeeViewModel evm = new EmployeeViewModel();
            ProblemViewModel  pvm = new ProblemViewModel();

            cvm.DateOpened = DateTime.Now;
            cvm.DateClosed = null;
            cvm.OpenStatus = true;
            evm.Lastname   = "Pollock";
            evm.GetByLastname();
            cvm.EmployeeId = evm.Id;
            evm.Lastname   = "Burner";
            evm.GetByLastname();
            cvm.TechId      = evm.Id;
            pvm.Description = "Memory Upgrade";
            pvm.GetByDescription();
            cvm.ProblemId = pvm.Id;
            cvm.Notes     = "Chris has bad RAM, Burner to fix it";
            cvm.Add();
            Console.WriteLine("New Call Generated - Id = " + cvm.Id);
            int id = cvm.Id; // need Id for delete later

            cvm.GetById();
            cvm.Notes += "\n Ordered new RAM!";

            if (cvm.Update() == 1)
            {
                Console.WriteLine("Call was updated " + cvm.Notes);
            }
            else
            {
                Console.WriteLine("Call was NOT updated!");
            }

            cvm.Notes = "Another change to comments that should not work.";
            if (cvm.Update() == -2)
            {
                Console.WriteLine("Call was NOT updated, data was stale.");
            }

            cvm    = new CallViewModel(); // need to reset because of Concurrency
            cvm.Id = id;
            cvm.GetById();

            if (cvm.Delete() == 1)
            {
                Console.WriteLine("Call was deleted!");
            }
            else
            {
                Console.WriteLine("Call was NOT deleted!");
            }

            cvm.GetById(); // should throw expected exception
        }
Example #29
0
 public ActionResult Edit([Bind(Include = "CallID,ItemID,CallDate,Number,ContractDate,DocType,RepFamilyName,RepFirstName,RepMidName,RepPosition,RepPhoneNumber,JudicialStatus,CustomerName,CustomerAddress,TaxID,BIC,CustomerPhoneNumber,OKPO,CustomerBankAccount,BankBranch,BranchAddress,BankCode,MPhoneNumber,FamilyName,FirstName,MidName,PositionDescr,AffidavitNum,AffidavitDate,ItemName,ItemProducer,ItemQty,Comments,Image,Additional,ProgramNameFull,ProgramNameShort")] CallViewModel callViewModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(callViewModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(callViewModel));
 }
Example #30
0
        public void Call_ComprehensiveVMTest()
        {
            CallViewModel     cvm = new CallViewModel();
            EmployeeViewModel evm = new EmployeeViewModel();
            ProblemViewModel  pvm = new ProblemViewModel();

            cvm.DateOpened = DateTime.Now;
            cvm.DateClosed = null;
            cvm.OpenStatus = true;
            evm.Email      = "*****@*****.**";
            evm.GetByEmail();
            cvm.EmployeeId = evm.Id;
            evm.Lastname   = "*****@*****.**";
            evm.GetByEmail();
            cvm.EmployeeName = evm.Lastname;
            cvm.TechId       = evm.Id;
            pvm.Description  = "Memory Upgrade";
            pvm.GetByDescription();
            cvm.ProblemId = pvm.Id;
            cvm.Notes     = "Sonia has bad RAM, Burner to fix it";
            cvm.Add();
            output.WriteLine("New Call Generated - Id = " + cvm.Id);
            int id = cvm.Id;

            cvm.GetById();
            cvm.Notes += "\n Ordered new RAM!";
            if (cvm.Update() == 1)
            {
                output.WriteLine("Call was updated " + cvm.Notes);
            }
            else
            {
                output.WriteLine("Call was not updated!");
            }
            cvm.Notes = "Another change to comments that should not work";
            if (cvm.Update() == -2)
            {
                output.WriteLine("Call was not updated data was stale");
            }
            cvm    = new CallViewModel();// need to reset because of concureency error
            cvm.Id = id;
            cvm.GetById();

            if (cvm.Delete() == 1)
            {
                output.WriteLine("Call was deleted");
            }
            else
            {
                output.WriteLine("Call was not deleted");
            }
            Exception ex = Assert.Throws <NullReferenceException>(() => cvm.GetById()); // should throw expected exception

            Assert.Equal("Object reference not set to an instance of an object.", ex.Message);
        }
        private void OnCallStateChanged(VATRPCall call)
        {
            if (this.Dispatcher == null)
                return;

            if (this.Dispatcher.Thread != Thread.CurrentThread)
            {
                this.Dispatcher.BeginInvoke((Action)(() => this.OnCallStateChanged(call)));
                return;
            }

            if (call == null)
                return;

            lock (deferredLock)
            {
                if (deferredHideTimer != null && deferredHideTimer.IsEnabled)
                    deferredHideTimer.Stop();
            }

            if (_mainViewModel == null)
                return;

            if (_mainViewModel.ActiveCallModel != null &&
                _mainViewModel.ActiveCallModel.CallState == VATRPCallState.Declined)
            {
                _mainViewModel.ActiveCallModel.DeclinedMessage = string.Empty;
                _mainViewModel.RemoveCalViewModel(_mainViewModel.ActiveCallModel);
            }

            CallViewModel callViewModel = _mainViewModel.FindCallViewModel(call);

            if (callViewModel == null)
            {
                callViewModel = new CallViewModel(_linphoneService, call)
                {
                    CallInfoCtrl = _callInfoView
                };

                callViewModel.CallQualityChangedEvent += OnCallQualityChanged;

                callViewModel.VideoWidth = (int)CombinedUICallViewSize.Width;
                callViewModel.VideoHeight = (int)CombinedUICallViewSize.Height;
                _mainViewModel.AddCalViewModel(callViewModel);
            }

            if ((call.CallState == VATRPCallState.InProgress) ||
                (call.CallState == VATRPCallState.StreamsRunning))
            {
                _mainViewModel.ActiveCallModel = callViewModel;
            }

            if (callViewModel.Declined)
            {
                // do not process declined call
                _mainViewModel.RemoveCalViewModel(callViewModel);
                return;
            }

            if (_mainViewModel.ActiveCallModel == null)
                _mainViewModel.ActiveCallModel = callViewModel;

            LOG.Info(string.Format("CallStateChanged: State - {0}. Call: {1}", call.CallState, call.NativeCallPtr));
            ctrlCall.SetCallViewModel(_mainViewModel.ActiveCallModel);
            VATRPContact contact = null;

            var stopPlayback = false;
            var destroycall = false;
            var callDeclined = false;
            bool isError = false;
            switch (call.CallState)
            {
                case VATRPCallState.Trying:
                    // call started,
                    call.RemoteParty = call.To;
                    callViewModel.OnTrying();
                    _mainViewModel.IsCallPanelDocked = true;

                    if (callViewModel.Contact == null)
                        callViewModel.Contact =
            ServiceManager.Instance.ContactService.FindContact(new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress), IntPtr.Zero));

                    if (callViewModel.Avatar == null && callViewModel.Contact != null)
                    {
                        callViewModel.LoadAvatar(callViewModel.Contact.Avatar);
                    }

                    if (callViewModel.Contact == null)
                    {
                        var contactID = new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress),
                            IntPtr.Zero);
                        callViewModel.Contact = new VATRPContact(contactID)
                        {
                            DisplayName = call.To.DisplayName,
                            Fullname = call.To.Username,
                            SipUsername = call.To.Username,
                            RegistrationName = contactID.ID
                        };
                    }

                    break;
                case VATRPCallState.InProgress:
                    WakeupScreenSaver();
                    this.ShowSelfPreviewItem.IsEnabled = false;
                    call.RemoteParty = call.From;
                    ServiceManager.Instance.SoundService.PlayRingTone();
                    if (callViewModel.Contact == null)
                        callViewModel.Contact =
            ServiceManager.Instance.ContactService.FindContact(new ContactID(string.Format("{0}@{1}", call.From.Username, call.From.HostAddress), IntPtr.Zero));

                    if (callViewModel.Avatar == null && callViewModel.Contact != null)
                    {
                        callViewModel.LoadAvatar(callViewModel.Contact.Avatar);
                    }

                    if (callViewModel.Contact == null)
                    {
                        var contactID = new ContactID(string.Format("{0}@{1}", call.From.Username, call.From.HostAddress),
                            IntPtr.Zero);
                        callViewModel.Contact = new VATRPContact(contactID)
                        {
                            DisplayName = call.From.DisplayName,
                            Fullname = call.From.Username,
                            SipUsername = call.From.Username,
                            RegistrationName = contactID.ID
                        };
                    }

                    callViewModel.OnIncomingCall();

                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        ShowOverlayNewCallWindow(true);
                        ctrlCall.ctrlOverlay.SetNewCallerInfo(callViewModel.CallerInfo);
                    }
                    else
                    {
                        callViewModel.ShowIncomingCallPanel = true;
                    }

                    if (WindowState != WindowState.Minimized)
                        _mainViewModel.IsCallPanelDocked = true;

                    if (_flashWindowHelper != null)
                        _flashWindowHelper.FlashWindow(this);
                    if (WindowState == WindowState.Minimized)
                        this.WindowState = WindowState.Normal;

                    Topmost = true;
                    Activate();
                    Topmost = false;
                    break;
                case VATRPCallState.Ringing:
                    this.ShowSelfPreviewItem.IsEnabled = false;
                    callViewModel.OnRinging();
                    _mainViewModel.IsCallPanelDocked = true;
                    call.RemoteParty = call.To;
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("Ringing");
                    if (callViewModel.Contact == null)
                        callViewModel.Contact =
            ServiceManager.Instance.ContactService.FindContact(new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress), IntPtr.Zero));

                    if (callViewModel.Avatar == null && callViewModel.Contact != null)
                    {
                        callViewModel.LoadAvatar(callViewModel.Contact.Avatar);
                    }

                    if (callViewModel.Contact == null)
                    {
                        var contactID = new ContactID(string.Format("{0}@{1}", call.To.Username, call.To.HostAddress),
                            IntPtr.Zero);
                        callViewModel.Contact = new VATRPContact(contactID)
                        {
                            DisplayName = call.To.DisplayName,
                            Fullname = call.To.Username,
                            SipUsername = call.To.Username,
                            RegistrationName = contactID.ID
                        };
                    }

                    ServiceManager.Instance.SoundService.PlayRingBackTone();
                    break;
                case VATRPCallState.EarlyMedia:
                    callViewModel.OnEarlyMedia();
                    break;
                case VATRPCallState.Connected:
                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                        Configuration.ConfEntry.USE_RTT, true))
                    {
                        _mainViewModel.IsRTTViewEnabled = true;
                        ctrlRTT.SetViewModel(_mainViewModel.RttMessagingModel);
                        _mainViewModel.RttMessagingModel.CreateRttConversation(call.RemoteParty.Username, call.NativeCallPtr);
                    }
                    else
                    {
                        _mainViewModel.IsRTTViewEnabled = false;
                    }

                    callViewModel.OnConnected();
                    if (_flashWindowHelper != null)
                        _flashWindowHelper.StopFlashing();
                    stopPlayback = true;
                    callViewModel.ShowOutgoingEndCall = false;
                    callViewModel.IsRTTEnabled =
                        ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                            Configuration.ConfEntry.USE_RTT, true) && callViewModel.ActiveCall != null &&
                        _linphoneService.IsRttEnabled(callViewModel.ActiveCall.NativeCallPtr);

                    ShowCallOverlayWindow(true);
                    ShowOverlayNewCallWindow(false);
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("Connected");
                    ctrlCall.ctrlOverlay.ForegroundCallDuration = callViewModel.CallDuration;

                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        CallViewModel nextVM = _mainViewModel.GetNextViewModel(callViewModel);
                        if (nextVM != null)
                        {
                            ShowOverlaySwitchCallWindow(true);
                            ctrlCall.ctrlOverlay.SetPausedCallerInfo(nextVM.CallerInfo);
                            ctrlCall.ctrlOverlay.BackgroundCallDuration = nextVM.CallDuration;
                            ctrlCall.ctrlOverlay.StartPausedCallTimer(ctrlCall.ctrlOverlay.BackgroundCallDuration);
                            ctrlCall.BackgroundCallViewModel = nextVM;
                        }
                    }
                    else
                    {
                        ShowOverlaySwitchCallWindow(false);
                    }

                    ctrlCall.ctrlOverlay.StartCallTimer(ctrlCall.ctrlOverlay.ForegroundCallDuration);
                    _callOverlayView.EndCallRequested = false;

                    if (_selfView.IsVisible)
                    {
                        _selfView.ResetNativePreviewHandle = false;
                        _selfView.Hide();
                    }

                    ctrlCall.ctrlVideo.DrawCameraImage = false;
                    ctrlCall.AddVideoControl();
                    ctrlCall.RestartInactivityDetectionTimer();
                    ctrlCall.UpdateVideoSettingsIfOpen();
                    ctrlCall.UpdateMuteSettingsIfOpen();

            //                    MuteCall(createCmd.MuteMicrophone);
            //                    MuteSpeaker(createCmd.MuteSpeaker);

                    break;
                case VATRPCallState.StreamsRunning:
                    callViewModel.OnStreamRunning();
                    ShowCallOverlayWindow(true);

                    // VATRP-1623: we are setting mute microphone true prior to initiating a call, but the call is always started
                    //   with the mic enabled. attempting to mute right after call is connected here to side step this issue -
                    //   it appears to be an initialization issue in linphone
                    if (_linphoneService.GetActiveCallsCount == 1)
                    {
                        ServiceManager.Instance.ApplyMediaSettingsChanges();
                    }
                    ctrlCall.ctrlOverlay.SetCallState("Connected");
                    ctrlCall.UpdateControls();
                    ctrlCall.ctrlOverlay.ForegroundCallDuration = _mainViewModel.ActiveCallModel.CallDuration;
                    ctrlCall.RestartInactivityDetectionTimer();
                    ctrlCall.UpdateVideoSettingsIfOpen();
                    // VATRP-1899: This is a quick and dirty solution for POC. It will be funational, but not the end implementation we will want.
                    if ((App.CurrentAccount != null) && App.CurrentAccount.UserNeedsAgentView)
                    {
                        _mainViewModel.IsMessagingDocked = true;
                    }
                    break;
                case VATRPCallState.RemotePaused:
                    callViewModel.OnRemotePaused();
                    callViewModel.CallState = VATRPCallState.RemotePaused;
                    ShowCallOverlayWindow(true);
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("On Hold");
                    ctrlCall.UpdateControls();
                    break;
                case VATRPCallState.LocalPausing:
                    callViewModel.CallState = VATRPCallState.LocalPausing;
                    break;
                case VATRPCallState.LocalPaused:
                    callViewModel.OnLocalPaused();
                    callViewModel.CallState = VATRPCallState.LocalPaused;
                    callViewModel.IsCallOnHold = true;
                    bool updateInfoView = callViewModel.PauseRequest;
                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        if (!callViewModel.PauseRequest)
                        {
                            CallViewModel nextVM = _mainViewModel.GetNextViewModel(callViewModel);

                            if (nextVM != null)
                            {
                                ShowOverlaySwitchCallWindow(true);
                                ctrlCall.ctrlOverlay.SetPausedCallerInfo(callViewModel.CallerInfo);
                                ctrlCall.ctrlOverlay.BackgroundCallDuration = callViewModel.CallDuration;
                                ctrlCall.ctrlOverlay.StartPausedCallTimer(ctrlCall.ctrlOverlay.BackgroundCallDuration);
                                ctrlCall.BackgroundCallViewModel = callViewModel;
                                ctrlCall.ctrlOverlay.ForegroundCallDuration = nextVM.CallDuration;
                                ctrlCall.SetCallViewModel(nextVM);
                                if (!nextVM.PauseRequest)
                                    _mainViewModel.ResumeCall(nextVM);
                                else
                                    updateInfoView = true;
                            }
                        }
                    }

                    if (updateInfoView)
                    {
                        ShowCallOverlayWindow(true);
                        ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                        ctrlCall.ctrlOverlay.SetCallState("On Hold");
                        ctrlCall.UpdateControls();
                    }
                    break;
                case VATRPCallState.LocalResuming:
                    callViewModel.OnResumed();
                    callViewModel.IsCallOnHold = false;
                    ShowCallOverlayWindow(true);
                    ctrlCall.ctrlOverlay.SetCallerInfo(callViewModel.CallerInfo);
                    ctrlCall.ctrlOverlay.SetCallState("Connected");
                    ctrlCall.UpdateControls();

                    if (_linphoneService.GetActiveCallsCount == 2)
                    {
                        CallViewModel nextVM = _mainViewModel.GetNextViewModel(callViewModel);
                        if (nextVM != null)
                        {
                            ShowOverlaySwitchCallWindow(true);
                            ctrlCall.ctrlOverlay.SetPausedCallerInfo(nextVM.CallerInfo);
                            ctrlCall.ctrlOverlay.BackgroundCallDuration = nextVM.CallDuration ;
                            ctrlCall.ctrlOverlay.StartPausedCallTimer(ctrlCall.ctrlOverlay.BackgroundCallDuration);
                            ctrlCall.BackgroundCallViewModel = nextVM;
                            ctrlCall.SetCallViewModel(callViewModel);
                            ctrlCall.ctrlOverlay.ForegroundCallDuration = callViewModel.CallDuration;
                            if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                        Configuration.ConfEntry.USE_RTT, true))
                            {
                                _mainViewModel.RttMessagingModel.CreateRttConversation(call.RemoteParty.Username, call.NativeCallPtr);
                            }
                        }
                        else
                        {
                            ShowOverlaySwitchCallWindow(false);
                        }
                    }
                    else
                    {
                        ShowOverlaySwitchCallWindow(false);
                    }
                    ctrlCall.ctrlVideo.DrawCameraImage = false;
                    ctrlCall.AddVideoControl();
                    break;
                case VATRPCallState.Closed:
                    if (_flashWindowHelper != null)
                        _flashWindowHelper.StopFlashing();
                    LOG.Info(string.Format("CallStateChanged: Result Code - {0}. Message: {1} Call: {2}", call.SipErrorCode, call.LinphoneMessage, call.NativeCallPtr));
                    callDeclined = call.SipErrorCode == 603;
                    callViewModel.OnClosed(ref isError, call.LinphoneMessage, call.SipErrorCode, callDeclined);
                    stopPlayback = true;
                    destroycall = true;
                    callViewModel.CallQualityChangedEvent -= OnCallQualityChanged;
                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                       Configuration.ConfEntry.USE_RTT, true))
                    {
                        _mainViewModel.RttMessagingModel.ClearRTTConversation(call.NativeCallPtr);
                        ctrlRTT.SetViewModel(null);
                    }
                    ShowOverlayNewCallWindow(false);
                    ShowOverlaySwitchCallWindow(false);
                    ctrlCall.BackgroundCallViewModel = null;

                    if (callDeclined)
                    {
                        _mainViewModel.IsRTTViewEnabled = false;
                        this.ShowSelfPreviewItem.IsEnabled = true;
                        _callInfoView.Hide();
                        ctrlCall.ctrlOverlay.StopCallTimer();
                        ShowCallOverlayWindow(false);
                        _mainViewModel.IsMessagingDocked = false;
                        if (_mainViewModel.ActiveCallModel.DeclinedMessage.NotBlank())
                            _mainViewModel.ActiveCallModel.ShowDeclinedMessage = true;
                        else
                        {
                            _mainViewModel.ActiveCallModel.WaitForDeclineMessage = true;
                        }
                        if (deferredHideTimer != null)
                        {
                            lock (deferredLock)
                            {
                                deferredHideTimer.Interval = TimeSpan.FromMilliseconds(DECLINE_WAIT_TIMEOUT);
                                deferredHideTimer.Start();
                            }
                        }
                    }
                    else
                    {
                        int callsCount = _mainViewModel.RemoveCalViewModel(callViewModel);
                        if (callsCount == 0)
                        {
                            _mainViewModel.IsRTTViewEnabled = false;
                            this.ShowSelfPreviewItem.IsEnabled = true;
                            _callInfoView.Hide();
                            ctrlCall.ctrlOverlay.StopCallTimer();

                            if (!isError)
                            {
                                this.SizeToContent = SizeToContent.WidthAndHeight;
                                ctrlCall.SetCallViewModel(null);
                                _mainViewModel.IsCallPanelDocked = false;
                            }
                            else
                            {
                                if (deferredHideTimer != null)
                                {
                                    lock (deferredLock)
                                    {
                                        deferredHideTimer.Interval = TimeSpan.FromMilliseconds(DECLINE_WAIT_TIMEOUT);
                                        deferredHideTimer.Start();
                                    }
                                }
                            }
                            ShowCallOverlayWindow(false);
                            _mainViewModel.IsMessagingDocked = false;
                            _mainViewModel.ActiveCallModel = null;
                            OnFullScreenToggled(false); // restore main window to dashboard

                            if (this.ShowSelfPreviewItem.IsChecked && !_selfView.ResetNativePreviewHandle)
                            {
                                _selfView.ResetNativePreviewHandle = true;
                                deferredShowPreviewTimer.Start();
                            }
                        }
                        else
                        {
                            var nextVM = _mainViewModel.GetNextViewModel(null);
                            if (nextVM != null)
                            {
                                // defensive coding here- do not try to operate on an errored call state object
                                if (nextVM.CallState != VATRPCallState.Error)
                                {
                                    _mainViewModel.ActiveCallModel = nextVM;
                                    nextVM.CallSwitchLastTimeVisibility = Visibility.Hidden;

                                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                                        Configuration.ConfEntry.USE_RTT, true))
                                    {
                                        _mainViewModel.IsRTTViewEnabled = true;
                                        ctrlRTT.SetViewModel(_mainViewModel.RttMessagingModel);
                                        _mainViewModel.RttMessagingModel.CreateRttConversation(
                                            nextVM.ActiveCall.RemoteParty.Username, nextVM.ActiveCall.NativeCallPtr);
                                    }
                                    else
                                    {
                                        _mainViewModel.IsRTTViewEnabled = false;
                                    }
                                    ShowCallOverlayWindow(true);
                                    ctrlCall.ctrlOverlay.SetCallerInfo(nextVM.CallerInfo);
                                    ctrlCall.ctrlOverlay.ForegroundCallDuration = _mainViewModel.ActiveCallModel.CallDuration;
                                    ctrlCall.SetCallViewModel(_mainViewModel.ActiveCallModel);
                                    ctrlCall.UpdateControls();
                                    if (nextVM.ActiveCall.CallState == VATRPCallState.LocalPaused)
                                    {
                                        if (!nextVM.PauseRequest)
                                            _mainViewModel.ResumeCall(nextVM);
                                        else
                                        {
                                            ctrlCall.ctrlOverlay.SetCallState("On Hold");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ((registerRequested || signOutRequest || defaultConfigRequest) && _linphoneService.GetActiveCallsCount == 0)
                    {
                        _linphoneService.Unregister(false);
                    }

                    break;
                case VATRPCallState.Error:
                    destroycall = true;
                    if (_flashWindowHelper != null)
                        _flashWindowHelper.StopFlashing();
                    ctrlCall.BackgroundCallViewModel = null;
                    isError = true;
                    callViewModel.OnClosed(ref isError, call.LinphoneMessage, call.SipErrorCode, false);
                    callViewModel.CallSwitchLastTimeVisibility = Visibility.Hidden;
                    stopPlayback = true;
                    if (ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                       Configuration.ConfEntry.USE_RTT, true))
                    {
                        _mainViewModel.RttMessagingModel.ClearRTTConversation(call.NativeCallPtr);
                        ctrlRTT.SetViewModel(null);
                    }

                    if (_linphoneService.GetActiveCallsCount == 0)
                    {
                        _mainViewModel.IsRTTViewEnabled = false;
                        this.ShowSelfPreviewItem.IsEnabled = true;
                        if (this.ShowSelfPreviewItem.IsChecked && !_selfView.ResetNativePreviewHandle)
                        {
                            _selfView.ResetNativePreviewHandle = true;
                            deferredShowPreviewTimer.Start();
                        }
                        if (callViewModel.CallState != VATRPCallState.Declined)
                            _mainViewModel.RemoveCalViewModel(callViewModel);
                        _callInfoView.Hide();
                        ctrlCall.ctrlOverlay.StopCallTimer();
                        ShowCallOverlayWindow(false);
                        _mainViewModel.IsMessagingDocked = false;

                        if (deferredHideTimer != null)
                        {
                            lock (deferredLock)
                            {
                                deferredHideTimer.Interval = TimeSpan.FromMilliseconds(DECLINE_WAIT_TIMEOUT);
                                deferredHideTimer.Start();
                            }
                        }

                        _mainViewModel.ActiveCallModel = null;
                        OnFullScreenToggled(false); // restore main window to dashboard
                    }
                    else
                    {
                        _mainViewModel.RemoveCalViewModel(callViewModel);
                    }

                    break;
                default:
                    break;
            }

            if (stopPlayback)
            {
                ServiceManager.Instance.SoundService.StopRingBackTone();
                ServiceManager.Instance.SoundService.StopRingTone();
            }

            if (destroycall)
            {
                if (_linphoneService.GetActiveCallsCount == 0)
                {
                    if (_mainViewModel.IsCallPanelDocked)
                    {
                        ServiceManager.Instance.LinphoneService.SetVideoCallWindowHandle(IntPtr.Zero, true);
                        if (_remoteVideoView != null)
                        {
                            _remoteVideoView.DestroyOnClosing = true; // allow window to be closed
                            _remoteVideoView.Close();
                            _remoteVideoView = null;
                        }
                        if (deferredHideTimer != null && !deferredHideTimer.IsEnabled)
                        {
                            _mainViewModel.IsMessagingDocked = false;
                            _mainViewModel.IsCallPanelDocked = false;
                        }
                    }

                    if (!callDeclined)
                        _mainViewModel.ActiveCallModel = null;
                }
            }
        }
        internal bool SwitchCall(CallViewModel pausedCallViewModel, CallViewModel activeCallViewModel)
        {
            LOG.Info(String.Format("Switching call. Main call {0}. {1}. Secondary call {2} {3}",
                activeCallViewModel.CallerInfo,
                activeCallViewModel.ActiveCall.NativeCallPtr, pausedCallViewModel.CallerInfo,
                pausedCallViewModel.ActiveCall.NativeCallPtr));

            if (activeCallViewModel.CallState == VATRPCallState.LocalPaused && activeCallViewModel.PauseRequest)
            {
                if (pausedCallViewModel.CallState == VATRPCallState.LocalPaused && pausedCallViewModel.PauseRequest)
                    return false;
                ResumeCall(pausedCallViewModel);
            }
            else
            {
                PauseCall(activeCallViewModel);
            }
            return true;
        }
 public CallProcessingBox()
     : base(VATRPWindowType.CALL_VIEW)
 {
     DataContext = new CallViewModel();
     InitializeComponent();
 }
        internal void AcceptCall(CallViewModel viewModel)
        {
            lock (CallsViewModelList)
            {
                if (FindCallViewModel(viewModel))
                {
                    LOG.Info(String.Format("Accepting call call for {0}. {1}", viewModel.CallerInfo,
                        viewModel.ActiveCall.NativeCallPtr));

                    viewModel.AcceptCall();
                    bool muteMicrophone = false;
                    bool muteSpeaker = false;
                    //bool enableVideo = true;
                    if (App.CurrentAccount != null)
                    {
                        muteMicrophone = App.CurrentAccount.MuteMicrophone;
                        muteSpeaker = App.CurrentAccount.MuteSpeaker;
                       // enableVideo = App.CurrentAccount.EnableVideo;
                    }
                    try
                    {
                        _linphoneService.AcceptCall(viewModel.ActiveCall.NativeCallPtr,
                            ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                                Configuration.ConfEntry.USE_RTT, true), muteMicrophone, muteSpeaker, true);
                    }
                    catch (Exception ex)
                    {
                        ServiceManager.LogError("AcceptCall", ex);
                    }
                }
            }
        }
        internal void DeclineCall(CallViewModel viewModel, string message)
        {
            lock (CallsViewModelList)
            {
                if (FindCallViewModel(viewModel))
                {
                    LOG.Info(String.Format("Declining call for {0}. {1}", viewModel.CallerInfo,
                        viewModel.ActiveCall.NativeCallPtr));
                    var contactID = new ContactID(
                            string.Format("{0}@{1}", viewModel.ActiveCall.RemoteParty.Username,
                                viewModel.ActiveCall.RemoteParty.HostAddress), IntPtr.Zero);
                    var contact = ServiceManager.Instance.ContactService.FindContact(contactID);
                    if (contact == null)
                    {
                        contact = new VATRPContact(contactID)
                        {
                            Fullname = viewModel.ActiveCall.RemoteParty.Username,
                            DisplayName = viewModel.ActiveCall.RemoteParty.Username,
                            SipUsername = viewModel.ActiveCall.RemoteParty.Username,
                            RegistrationName = contactID.ID
                        };
                        ServiceManager.Instance.ContactService.AddContact(contact, string.Empty);
                    }
                    viewModel.DeclineCall(false);
                    try
                    {
                        _linphoneService.DeclineCall(viewModel.ActiveCall.NativeCallPtr);
                    }
                    catch (Exception ex)
                    {
                        ServiceManager.LogError("DeclineCall", ex);
                    }

                    if (message.NotBlank())
                    {
                        if (_simpleMessageViewModel != null)
                        {
                            _simpleMessageViewModel.SetActiveChatContact(contact, IntPtr.Zero);
                            _simpleMessageViewModel.SendMessage(string.Format("{0}{1}", VATRPChatMessage.DECLINE_PREFIX, message));
                        }
                    }
                }
            }
        }
        internal void AddCalViewModel(CallViewModel callViewModel)
        {
            if (FindCallViewModel(callViewModel))
                return;

            lock (CallsViewModelList)
            {
                CallsViewModelList.Add(callViewModel);
                OnPropertyChanged("CallsViewModelList");
            }
        }
        internal void EndAndAcceptCall(CallViewModel viewModel)
        {
            lock (CallsViewModelList)
            {
                CallViewModel nextCall = GetNextViewModel(viewModel);
                if (nextCall != null)
                {
                    TerminateCall(nextCall);

                    AcceptCall(viewModel);
                }
            }
        }
 internal bool FindCallViewModel(CallViewModel callViewModel)
 {
     lock (CallsViewModelList)
     {
         foreach (var callVM in CallsViewModelList)
         {
             if (callVM.Equals(callViewModel))
                 return true;
         }
     }
     return false;
 }
 internal CallViewModel GetNextViewModel(CallViewModel skipVM)
 {
     lock (CallsViewModelList)
     {
         foreach (var callVM in CallsViewModelList)
         {
             if (!callVM.Equals(skipVM))
                 return callVM;
         }
     }
     return null;
 }
 internal int RemoveCalViewModel(CallViewModel callViewModel)
 {
     lock (CallsViewModelList)
     {
         CallsViewModelList.Remove(callViewModel);
         OnPropertyChanged("CallsViewModelList");
         return CallsViewModelList.Count;
     }
 }
        internal void TerminateCall(CallViewModel viewModel)
        {
            lock (CallsViewModelList)
            {
                if (FindCallViewModel(viewModel))
                {
                    if (viewModel.CallState == VATRPCallState.Declined)
                    {

                    }
                    else
                    {
                        LOG.Info(String.Format("Terminating call call for {0}. {1}", viewModel.CallerInfo,
                            viewModel.ActiveCall.NativeCallPtr));

                        try
                        {
                            _linphoneService.TerminateCall(viewModel.ActiveCall.NativeCallPtr);
                        }
                        catch (Exception ex)
                        {
                            ServiceManager.LogError("TerminateCall", ex);
                        }
                    }
                }
            }
        }
        internal void ResumeCall(CallViewModel viewModel)
        {
            lock (CallsViewModelList)
            {
                if (FindCallViewModel(viewModel))
                {
                    LOG.Info(String.Format("Resuming call for {0}. {1}", viewModel.CallerInfo,
                        viewModel.ActiveCall.NativeCallPtr));

                    viewModel.ResumeCall();
                }
            }
        }
 public void SetCallViewModel(CallViewModel viewModel)
 {
     lock (_viewLock)
     {
         if (_viewModel == viewModel)
             return;
         DataContext = viewModel;
         _viewModel = viewModel;
     }
     UpdateControls();
 }