private async Task SyncSipAccounts( CancellationToken cancelToken = new CancellationToken()) { bool result = false; string sipServerIP = Config.Instance.SIPServerIP; int sipServerPort = Config.Instance.SIPServerPort; if (string.IsNullOrWhiteSpace(sipServerIP) || sipServerPort == 0) { throw new Exception(CulturesHelper.GetTextValue("PleaseSetTheIPAndPortNumberOfSIPServerFirst")); } // http://172.29.1.21:5050/AddSipAccount?sip_account=account1&sip_pwd=BqVXrqD0YS&apply=1 // ring group // account1-account2-account3 // http://172.29.1.21:5050/AddRingGroup?group_num=0000000000&group_list=account1-account2-account3 //var unsyncedAccounts = this.SipAccounts.Cast<sipaccount>(); var groups = this.SipAccounts.Groups.ToList(); foreach (var group in groups) { result = false; string roomAddress = (string)((CollectionViewGroup)group).Name; List <string> accountNames = new List <string>(); var accounts = (from a in this._dataModel.Data where a.C_room == roomAddress select a).ToList(); foreach (var account in accounts) { accountNames.Add(account.C_user); if (account.C_sync == null || account.C_sync == 0) { result = await HttpClient.AddSipAccountAsync(sipServerIP, sipServerPort, account.C_user, account.C_password, cancelToken).ConfigureAwait(false); if (result == false) { break; } } } if (!result || false == (result = await HttpClient.AddRingGroupAsync(sipServerIP, sipServerPort, roomAddress.Replace("-", ""), string.Join("-", accountNames), cancelToken).ConfigureAwait(false))) { continue; } foreach (var account in accounts) { if (account.C_sync == null || account.C_sync == 0) { account.C_sync = 1; await this._dataModel.UpdateAsync(account).ConfigureAwait(false); } } } }