Exemplo n.º 1
0
 public void Save(SIPAccount account)
 {
     if (_accounts.Any(d => d.SIPUsername == account.SIPUsername || d.SIPDomain == account.SIPDomain))
     {
         SipAccount.Update(account);
     }
     else
     {
         SipAccount.Add(account);
         _accounts.Add(account);
     }
 }
Exemplo n.º 2
0
 public void Update(SipAccount ccmUser)
 {
     using (var db = GetDbContext())
     {
         SipAccountEntity dbUser = db.SipAccounts.SingleOrDefault(u => u.Id == ccmUser.Id);
         if (dbUser != null)
         {
             SetEntityFromSipAccount(db, ccmUser, dbUser);
             db.SaveChanges();
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 注册SIP服务器
        /// </summary>
        private void RegisterSip()
        {
            SipAccount MySipAccount = new SipAccount(frmMain.m_SqlHelper);
            string     strError     = "";

            m_SipAccount = MySipAccount.GetDefaultSipAccount(ref strError);
            if (m_SipAccount.ID > 0)
            {
                m_Phone.RegisterSipServer(m_SipAccount.Server, m_SipAccount.Port, m_SipAccount.Name, m_SipAccount.Pwd, 0, m_SipAccount.Domain, false, "", false, "");
            }
            m_Dialer.UpdateSipAccount(m_SipAccount);
            //m_Phone.RegisterSipServer("192.168.0.247", 5060, "1019", "123456", 0, "192.168.0.247", false, "", false, "");
        }
Exemplo n.º 4
0
        public SIP(Core core, ISynchronizeInvoke syncInvoke)
        {
            Logger.LogNotice("Initializing SIP core");
            _core = core;

            _deferredSetAudioDevicesTimer = new System.Timers.Timer()
            {
                Interval = 200, SynchronizingObject = syncInvoke
            };
            _deferredSetAudioDevicesTimer.Elapsed += new System.Timers.ElapsedEventHandler(_deferredSetAudioDevicesTimer_Elapsed);
            _deferredSetAudioDevicesTimer.Stop();

            // Initialize PjSIP
            SipekResources = new SipekResources(core);

            if (!CheckUdpPort(SipekResources.Configurator.SIPPort))
            {
                if (CheckUdpPort(5060))
                {
                    SipekResources.Configurator.SIPPort = 5060;
                }
                else if (CheckUdpPort(5061))
                {
                    SipekResources.Configurator.SIPPort = 5061;
                }
                else
                {
                    throw new InvalidOperationException("SIP port is in use");
                }
            }

            if (SipekResources.StackProxy.initialize() != 0)
            {
                throw new InvalidOperationException("Can't initialize PjSIP proxy stack!");
            }

            if (SipekResources.CallManager.Initialize(SipekResources.StackProxy) != 0)
            {
                throw new InvalidOperationException("Can't initialize PjSIP call manager!");
            }

            Codecs = LoadCodecs();

            // Initialize account
            Account   = new SipAccount(this);
            Messenger = new SipMessenger(this);

            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
        }
Exemplo n.º 5
0
        public void Create(SipAccount account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            using (var db = GetDbContext())
            {
                var dbAccount = new SipAccountEntity();
                SetEntityFromSipAccount(db, account, dbAccount);
                db.SipAccounts.Add(dbAccount);
                db.SaveChanges();
            }
        }
Exemplo n.º 6
0
        public ActionResult Edit(SipAccountEditFormViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new SipAccount
                {
                    Id              = model.Id,
                    UserName        = model.UserName.Trim(),
                    DisplayName     = model.DisplayName,
                    Comment         = model.Comment,
                    ExtensionNumber = model.ExtensionNumber,
                    AccountType     = model.AccountType,
                    AccountLocked   = model.AccountLocked,
                    Password        = model.Password,
                    Owner           = _ownersRepository.GetById(model.OwnerId),
                    CodecType       = _codecTypeRepository.GetById(model.CodecTypeId),
                };

                try
                {
                    if (model.ChangePassword)
                    {
                        _sipAccountManager.UpdatePassword(user.Id, model.Password);
                    }

                    _sipAccountManager.Update(user);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    log.Error(ex, "Could not edit SIP account");
                    if (ex is ApplicationException)
                    {
                        ModelState.AddModelError("EditUser", ex.Message);
                    }
                    else
                    {
                        ModelState.AddModelError("EditUser", Resources.Sip_Account_Could_Not_Be_Saved);
                    }
                }
            }

            SetListData(model);
            return(View("Edit", model));
        }
Exemplo n.º 7
0
        public IHttpActionResult Get(string username)
        {
            log.Debug("Call to ExternalAccountController.Get");

            SipAccount user = _sipAccountManager.GetByUserName(username);

            if (user == null)
            {
                return(NotFound());
            }

            return(Ok(new UserModel()
            {
                UserName = user.UserName,
                DisplayName = user.DisplayName,
                Comment = user.Comment
            }));
        }
Exemplo n.º 8
0
        public ActionResult Delete(Guid id)
        {
            SipAccount user = _sipAccountManager.GetById(id);

            if (user == null)
            {
                return(RedirectToAction("Index"));
            }

            var model = new DeleteUserViewModel
            {
                Id       = user.Id,
                UserName = user.UserName
            };

            ViewBag.Title = Resources.New_User;
            return(View(model));
        }
Exemplo n.º 9
0
        private void SetEntityFromSipAccount(CcmDbContext cxt, SipAccount account, SipAccountEntity dbAccount)
        {
            dbAccount.Id              = account.Id;
            dbAccount.UserName        = account.UserName;
            dbAccount.Comment         = account.Comment;
            dbAccount.ExtensionNumber = account.ExtensionNumber;
            dbAccount.DisplayName     = account.DisplayName;
            dbAccount.Owner           = account.Owner != null?cxt.Owners.SingleOrDefault(o => o.Id == account.Owner.Id) : null;

            dbAccount.CodecType = account.CodecType != null?cxt.CodecTypes.SingleOrDefault(c => c.Id == account.CodecType.Id) : null;

            dbAccount.AccountLocked = account.AccountLocked;
            dbAccount.AccountType   = account.AccountType;

            if (!string.IsNullOrEmpty(account.Password))
            {
                dbAccount.Password = account.Password;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 更新控件值
        /// </summary>
        public void UpdateCtrlValue()
        {
            lbStatus.Text = "";
            SipAccount MySipAccount = new SipAccount(frmMain.m_SqlHelper);
            string     strError     = "";

            m_sttSipAccount = MySipAccount.GetDefaultSipAccount(ref strError);
            if (strError.Trim().Length > 0)
            {
                lbStatus.Text      = strError;
                lbStatus.ForeColor = Color.Red;
                //MessageBox.Show(strError, "错误");
                return;
            }
            if (m_sttSipAccount.ID > 0)
            {
                txtUserName.Text = m_sttSipAccount.Name;
                txtUserPwd.Text  = m_sttSipAccount.Pwd;
                txtServer.Text   = m_sttSipAccount.Server + ":" + m_sttSipAccount.Port.ToString();
                txtDomain.Text   = m_sttSipAccount.Domain;
            }
        }
Exemplo n.º 11
0
        public IHttpActionResult Add(AddUserModel model)
        {
            log.Debug("Call to ExternalAccountController.AddUser");

            if (model == null)
            {
                return(BadRequest("Parameters missing."));
            }

            var user = new SipAccount
            {
                Id          = Guid.NewGuid(),
                UserName    = model.UserName.Trim(),
                DisplayName = model.DisplayName,
                Comment     = model.Comment,
                Owner       = _ownersRepository.GetByName(Owners.SrOwnerName),
                CodecType   = _codecTypeRepository.Find(CodecTypes.Personliga).FirstOrDefault(),
                Password    = model.Password
            };

            try
            {
                var existingUser = _sipAccountManager.GetByUserName(user.UserName);
                if (existingUser != null)
                {
                    return(Conflict());
                }

                _sipAccountManager.Create(user);
                return(Created(Url.Content("get?username="******"User created"));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Could not create user");
                return(InternalServerError());
            }
        }
Exemplo n.º 12
0
 public void Update(SipAccount account)
 {
     _sipAccountRepository.Update(account);
 }
Exemplo n.º 13
0
 public void Update(SipAccount ccmUser)
 {
     _internalRepository.Update(ccmUser);
     _lazyCache.ClearSipAccounts();
 }
Exemplo n.º 14
0
 public void Create(SipAccount ccmUser)
 {
     _internalRepository.Create(ccmUser);
 }