public void HasPolled() { if (LastPollingTime > LastResponseTime && (LastPollingTime - LastResponseTime).TotalSeconds >= 3) { if (DeviceEntity.online != 0) { Task.Run(() => { using (var db = new ICMDBContext()) { try { db.Devices.Attach(DeviceEntity); DeviceEntity.online = 0; db.SaveChanges(); } catch (Exception) { } } }); } } LastPollingTime = DateTime.Now; PollingCount++; }
private void listViewRefresh() { ICMDBContext db = new ICMDBContext(); listViewAdmin.Items.Clear(); listViewAutho.Items.Clear(); foreach (var user in db.Users) { List <string> sublist = new List <string>(); sublist.Add(user.C_userno); sublist.Add(user.C_username); sublist.Add(user.C_id.ToString()); sublist.Add(user.C_powerid.ToString()); listViewAdmin.Items.Add(new ListViewItem(sublist.ToArray())); } foreach (var us in db.Authorities) { List <string> sublist = new List <string>(); sublist.Add(us.C_name); sublist.Add(""); sublist.Add(us.C_id.ToString()); listViewAutho.Items.Add(new ListViewItem(sublist.ToArray())); } }
public ModuleSafeties() : base("/doorbell") { // 转發安防設定 Get["/guard", true] = async(parameters, ct) => { string DeviceId = this.Request.Query["ro"]; string mode = this.Request.Query["mode"]; Match m = Regex.Match(DeviceId, @"^\w{2}-\w{2}-\w{2}-\w{2}-\w{2}-\w{2}$"); if (m.Length == 0) { return(HttpStatusCode.BadRequest); // illigal Device address format } DeviceId = m.Value; using (var db = new ICMDBContext()) { var Device = (from d in db.Devices where d.roomid == DeviceId select d).FirstOrDefault(); if (Device != null) { string uri = string.Format("http://{0}/guard?ro={1}&mode={2}", Device.ip, DeviceId, mode); System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); try { var response = await client.GetStringAsync(uri); return(response); } catch (Exception) { } } } return("FAIL"); }; }
void FtpServer_SentData(object sender, FtpSentDataEventArgs e) { using (var db = new ICMDBContext()) { lock (m_FtpTransferStatus) { var status = (from s in m_FtpTransferStatus where s.Device.ip == e.Remote.Address.ToString() select s).FirstOrDefault(); if (status != null && status.Status == FtpTransferStatus.STATUS.LOAD_ING) { status.FileSize = e.FileSize; status.SentBytes = e.SentBytes; if (status.FileSize != 0) { int percentage = (int)(status.SentBytes * 100 / status.FileSize); if (status.SentPercentage != percentage) { status.SentPercentage = percentage; SetStatusColumnText(status.DeviceIndex, status.SentPercentage + "%", Color.Black); // TODO: Progress bar } } AddLog(string.Format("FTP ({0}): Data Transfer Send ({1} / {2}) bytes", e.Remote.Address, e.SentBytes, e.FileSize)); } } } }
private void BtnDel_Click(object sender, EventArgs e) { using (var db = new ICMDBContext()) { int nCount = listViewSIPAccount.Items.Count; for (int i = 0; i < nCount; i++) { if (listViewSIPAccount.Items[i].Checked) { string queryAccount = listViewSIPAccount.Items[i].SubItems[0].Text; if (db != null) { var QueryDel = from aa in db.Sipaccounts where aa.C_user == queryAccount select aa; foreach (var del in QueryDel) { db.Sipaccounts.Remove(del); } db.SaveChanges(); } } } } BtnQuery_Click(this, e); }
// 云服務管理 - 查询 // 查询该房号下的 SIP Accounts private void BtnQuery_Click(object sender, EventArgs e) { listViewSIPAccount.Items.Clear(); using (var db = new ICMDBContext()) { string Address = ""; string room = ""; { Address = DevicesAddressConverter.ChStrToRo(maskedTextBoxRoom.Text); if (Address == "") { return; } var SIPQuery = from sip in db.Sipaccounts where sip.C_room == Address select sip; foreach (var sip in SIPQuery) { room = sip.C_room;//DevicesAddressConverter.RoToChStr(sip.C_room);//sip.room; List <string> sublist = new List <string>(); sublist.Add(sip.C_user); sublist.Add(DevicesAddressConverter.RoToChStr(room)); sublist.Add(sip.C_usergroup); listViewSIPAccount.Items.Add(new ListViewItem(sublist.ToArray())); } } } }
private void BtnDelAdmin_Click(object sender, EventArgs e) { int ID = 0; int nCount = listViewAdmin.Items.Count; for (int i = 0; i < nCount; i++) { if (listViewAdmin.Items[i].Checked) { ID = int.Parse(listViewAdmin.Items[i].SubItems[2].Text); } } if (ID != 0) { ICMDBContext db = new ICMDBContext(); var queryDel = from user in db.Users where user.C_id == ID select user; foreach (var user in queryDel) { db.Users.Remove(user); } db.SaveChanges(); listViewRefresh(); } else { MessageBox.Show("Choose the item you want to delete"); } }
private void BtnDown_Click(object sender, EventArgs e) { ICMDBContext db = new ICMDBContext(); foreach (ListViewItem tmp in listViewOrder.Items) { if (tmp.Selected == true) { int seq = int.Parse(tmp.SubItems[0].Text); if (seq < last) { var query = from zz in db.Advertisements where zz.C_no == seq || zz.C_no == seq + 1 select zz; foreach (var swap in query) { if (swap.C_no == seq) { swap.C_no += 1; } else { swap.C_no -= 1; } } db.SaveChanges(); } } } listRefresh(); }
private void BtnOK_Click(object sender, EventArgs e) { if (textBoxAccount.Text == "") { MessageBox.Show(strings.UserCannotBeNull);//"用户名不得为空"); return; } using (var db = new ICMDBContext()) { sipaccount SIP = new sipaccount(); string account = textBoxAccount.Text; var checkNameExist = (from check in db.Sipaccounts where check.C_user == account select check).FirstOrDefault(); if (checkNameExist != null) { MessageBox.Show("Account already exitst!\nPlease choose another name."); return; } SIP.C_user = textBoxAccount.Text; SIP.C_password = textBoxPasswd.Text; SIP.C_room = DevicesAddressConverter.ChStrToRo(textBoxRoomID.Text); SIP.C_usergroup = textBoxGroup.Text; SIP.C_updatetime = DateTime.Now; SIP.C_sync = 0; SIP.C_registerstatus = 0; SIP.C_randomcode = randomcode.ToString(); db.Sipaccounts.Add(SIP); db.SaveChanges(); } this.Close(); }
private AddrList DeviceToAddrList() { AddrList addrList = new AddrList(); using (var db = new ICMDBContext()) { var Devices = db.Devices.ToList(); AddLog("总共有 {0} 笔资料需要输出", Devices.Count); foreach (var d in Devices) { AddrList.devRow dev = addrList.dev.NewdevRow(); dev.ip = d.ip; dev.ro = d.roomid; dev.alias = d.Alias; dev.group = d.group; dev.mc = d.mac; dev.ty = (byte)d.type; dev.sm = d.sm; dev.gw = d.gw; dev.id = d.cameraid; dev.pw = d.camerapw; addrList.dev.AdddevRow(dev); } addrList.AcceptChanges(); } return(addrList); }
private void RefreshSIPAccountsList()// async void RefreshSIPAccountsList() { listViewSIPAccount.Items.Clear(); using (var db = new ICMDBContext()) { foreach (var dev in db.Sipaccounts) { string room = DevicesAddressConverter.RoToChStr(dev.C_room); List <string> sublist = new List <string>(); int online = (int)(dev.C_registerstatus ?? 0); if (online == 0) { sublist.Add(strings.offline);//"離線"); } else { sublist.Add(strings.online);//"在線"); } sublist.Add(dev.C_user); sublist.Add(room); sublist.Add(dev.C_usergroup); listViewSIPAccount.Items.Add(new ListViewItem(sublist.ToArray())); } } //bindingSourceSIPAccounts.DataSource = await GetSIPAccountsAsync(); //this.dataGridViewSIPAccounts.Invalidate(); }
// 查看公告信息 private void BtnCheck_Click(object sender, EventArgs e) { if (dataGridViewPublishInfo.SelectedRows.Count > 0) { using (var db = new ICMDBContext()) { bool NeedRefresh = false; var PublishInfo = (from DataGridViewRow row in dataGridViewPublishInfo.SelectedRows select(db.Publishinfoes.Attach(row.DataBoundItem as publishinfo))).ToList(); foreach (var filepath in PublishInfo) { string curPth = System.IO.Path.GetDirectoryName(Application.ExecutablePath); if (File.Exists(curPth + "\\" + filepath.filepath)) { DialogMsgView CheckForm = new DialogMsgView(filepath.id); CheckForm.ShowDialog(); } else { MessageBox.Show(strings.FilePathNotExist); db.Publishinfoes.Remove(filepath); NeedRefresh = true; } } if (NeedRefresh) { db.SaveChanges(); RefreshPublishInfoGridView(); } } } }
private void UpdateDevice(string DeviceId, int DeviceType, XElement DeviceInfo) { using (var db = new ICMDBContext()) { var Device = (from d in db.Devices where d.roomid == DeviceId select d).FirstOrDefault(); if (Device != null) { if (DeviceInfo.Attribute("ip") != null) // TODO: error check { Device.ip = DeviceInfo.Attribute("ip").Value; } if (DeviceInfo.Attribute("mc") != null) // TODO: error check { Device.mac = DeviceInfo.Attribute("mc").Value; } Device.type = DeviceType; Device.online = 1; try { db.SaveChanges(); } catch (Exception) { } } // TODO: Send message to UI. } }
private void AddCalls(string DeviceId, IEnumerable <XElement> events) { if (events.Count() == 0) { return; } using (var db = new ICMDBContext()) { foreach (var e in events) { eventcallout call = new eventcallout { from = DeviceId, to = e.Attribute("to").Value, type = 2, time = DateTime.Parse(e.Attribute("time").Value), action = e.Attribute("action").Value }; try { db.Eventcallouts.Add(call); db.SaveChangesAsync(); } catch (Exception) { } } } }
private void AddRepairs(string DeviceId, IEnumerable <XElement> events) { if (events.Count() == 0) { return; } using (var db = new ICMDBContext()) { foreach (var e in events) { eventcommon repair = new eventcommon { action = e.Attribute("action").Value, srcaddr = DeviceId, time = DateTime.Parse(e.Attribute("time").Value), content = e.Attribute("text").Value, type = int.Parse(e.Attribute("type").Value) }; try { db.Eventcommons.Add(repair); db.SaveChangesAsync(); } catch (Exception) { } } } }
private void AddPasswords(string DeviceId, IEnumerable <XElement> events) { if (events.Count() == 0) { return; } using (var db = new ICMDBContext()) { foreach (var e in events) { doorbellpassword password = new doorbellpassword { C_roomid = DeviceId, C_password = e.Attribute("password").Value, C_time = DateTime.Parse(e.Attribute("time").Value) }; db.Doorbellpasswords.Add(password); } try { db.SaveChanges(); } catch (Exception) { } } }
private void BtnDel_Click(object sender, EventArgs e) { if (dataGridViewLeaveMsgs.SelectedRows.Count > 0) { using (var db = new ICMDBContext()) { var LeaveMsgs = (from DataGridViewRow row in dataGridViewLeaveMsgs.SelectedRows select(db.Leavewords.Attach(row.DataBoundItem as leaveword))).ToList(); db.Leavewords.RemoveRange(LeaveMsgs); db.SaveChanges(); } System.IO.FileInfo fiSdp = new System.IO.FileInfo(m_filename + ".sdp"); System.IO.FileInfo fiRtpaD = new System.IO.FileInfo(m_filename + ".rtpa.data"); System.IO.FileInfo fiRtpaI = new System.IO.FileInfo(m_filename + ".rtpa.index"); System.IO.FileInfo fiRtpvD = new System.IO.FileInfo(m_filename + ".rtpv.data"); System.IO.FileInfo fiRtpvI = new System.IO.FileInfo(m_filename + ".rtpv.index"); try { fiSdp.Delete(); fiRtpaD.Delete(); fiRtpaI.Delete(); fiRtpvD.Delete(); fiRtpvI.Delete(); } catch { } RefreshLeaveMsgsGridView(); } }
private void MainTask(CancellationToken CancelToken) { List <DeviceStatus> DeviceStatus = new List <DeviceStatus>(); CancellationTokenSource tokenSourceForChild = StartChildTasks(out ConcurrentBag <Task> tasks, DeviceStatus); try { while (true) { if (CancelToken.IsCancellationRequested == true) { StopChildTasks(tasks, tokenSourceForChild); CancelToken.ThrowIfCancellationRequested(); } using (var db = new ICMDBContext()) { var DevicesInDB = (from d in db.Devices where d.type != 0 select d).ToList(); if (DeviceStatus.Count() != DevicesInDB.Count()) { StopChildTasks(tasks, tokenSourceForChild); DeviceStatus = (from d in DevicesInDB select new DeviceStatus(d)).ToList(); tokenSourceForChild = StartChildTasks(out tasks, DeviceStatus); } Thread.Sleep(2000); } } } catch (Exception) { } }
private async void BtnStart_Click(object sender, EventArgs e) { Button thisButton = sender as Button; thisButton.Enabled = false; BtnClose.Enabled = false; BtnSelecFile.Enabled = false; try { Stopwatch stopwatch = Stopwatch.StartNew(); addrList.Clear(); addrList.dev.BeginLoadData(); addrList.dev.ReadXml(textBoxPath.Text); addrList.dev.EndLoadData(); stopwatch.Stop(); //DebugLog.TraceMessage(string.Format("done: {0}", stopwatch.Elapsed)); var progressIndicator = new Progress <int>(ReportProgress); await ICMDBContext.AddDevicesAsync(addrList, progressIndicator); } catch (Exception ex) { MessageBox.Show(ex.Message, "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } thisButton.Enabled = true; BtnClose.Enabled = true; BtnSelecFile.Enabled = true; this.Close(); }
private void BtnPlay_Click(object sender, EventArgs e) { if (dataGridViewLeaveMsgs.SelectedRows.Count > 0) { using (var db = new ICMDBContext()) { bool NeedRefresh = false; var LeaveMsgs = (from DataGridViewRow row in dataGridViewLeaveMsgs.SelectedRows select(db.Leavewords.Attach(row.DataBoundItem as leaveword))).ToList(); foreach (var filepath in LeaveMsgs) { if (File.Exists(filepath.filenames + ".sdp")) { (new DialogLeaveMsgPlayer(filepath.filenames)).ShowDialog(); } else { MessageBox.Show(strings.FilePathNotExist); db.Leavewords.Remove(filepath); NeedRefresh = true; } } if (NeedRefresh) { db.SaveChanges(); RefreshLeaveMsgsGridView(); } } } }
public DbTableRepository(ICMDBContext db) { _db = db; _db.Configuration.LazyLoadingEnabled = false; _db.Configuration.ProxyCreationEnabled = false; _table = _db.Set <T>(); }
public static sipaccount GetSipAccount( ICMDBContext db, string account) { var sipAccount = (from a in db.sipaccounts where a.C_user == account select a).FirstOrDefault(); return(sipAccount); }
private void DialogSelectEntranceDevices_Load(object sender, EventArgs e) { using (var db = new ICMDBContext()) { var entranceDevices = (from d in db.Devices where 1 <= d.type && d.type <= 4 select d).ToList(); this.DeviceBindingSource.DataSource = entranceDevices; } }
private void AddAlarms(string DeviceId, IEnumerable <XElement> events, List <eventwarn> newAlarms) { //int trig = 0; if (events.Count() == 0) { return; } using (var db = new ICMDBContext()) { foreach (var e in events) { eventwarn alarm = new eventwarn { channel = int.Parse(e.Attribute("chanel").Value), type = e.Attribute("type").Value, handlestatus = 0, Action = e.Attribute("action").Value, time = DateTime.Parse(e.Attribute("time").Value), srcaddr = DeviceId }; eventwarn alarmInDB = (from a in db.Eventwarns where a.srcaddr == alarm.srcaddr && a.channel == alarm.channel && a.Action == alarm.Action && a.time == alarm.time select a).FirstOrDefault(); if (alarmInDB != null) { continue; // redudency data } if (alarm.Action == "trig") { newAlarms.Add(alarm); } db.Eventwarns.Add(alarm); //DebugLog.TraceMessage(string.Format("{0}: {1} - {2}", // alarm.srcaddr, alarm.type, alarm.action)); } try { db.SaveChangesAsync(); } catch (Exception) { } // TODO: Send message to UI. //if (trig > 0) //{ // //DialogEventWarn dlgWarn = new DialogEventWarn(); // //dlgWarn.ShowDialog(); //} } }
private async void BtnQueryOpen_Click(object sender, EventArgs e) { using (var db = new ICMDBContext()) { var opendoor = from a in db.Eventopendoors where a.C_from.StartsWith(textBoxLobby.Text) orderby a.C_time descending select a; eventopendoorbindingSource.DataSource = await Task.Run(() => { return(opendoor.ToList()); }); } }
public static BindingListView <sipaccount> GetSIPAccounts() { BindingListView <sipaccount> sipaccounts = null; using (var db = new ICMDBContext()) { sipaccounts = new BindingListView <sipaccount>(db.Sipaccounts.ToList()); } return(sipaccounts); }
private async void BtnSearch_Click(object sender, EventArgs e) { using (var db = new ICMDBContext()) { int DeviceType = ComboBoxDevTypeForPageDevInfo.SelectedIndex - 1; int onlineStatus = ComboBoxDevStatus.SelectedIndex - 1; //bindingSourceDevices.DataSource = await Task.Run(() => { return new BindingListView<Device>(db.Devices.ToList()); }); //BindingListView<Device> Devices = (BindingListView<Device>)bindingSourceDevices.DataSource; if (DeviceType > -1 && onlineStatus == -1) { bindingSourceDevices.DataSource = await Task.Run(() => { return(new BindingListView <Device>((from d in db.Devices where d.type == DeviceType select d).ToList())); }); //Devices.Filter = new PredicateItemFilter<Device>(Device => Device.type == DeviceType); } else if (DeviceType == -1 && onlineStatus > -1) { bindingSourceDevices.DataSource = await Task.Run(() => { return(new BindingListView <Device>((from d in db.Devices where d.online == (onlineStatus == 0 ? 0 : 1) select d).ToList())); }); //Devices.Filter = new PredicateItemFilter<Device>(Device => Device.online == (onlineStatus == 0 ? 0 : 1)); } else if (DeviceType > -1 && onlineStatus > -1) { bindingSourceDevices.DataSource = await Task.Run(() => { return(new BindingListView <Device>( (from d in db.Devices where (d.type == DeviceType) && (d.online == (onlineStatus == 0 ? 0 : 1)) select d).ToList())); }); //Devices.Filter = new PredicateItemFilter<Device>(Device => (Device.type == DeviceType) && (Device.online == (onlineStatus == 0 ? 0 : 1))); } else { bindingSourceDevices.DataSource = await Task.Run(() => { return(new BindingListView <Device>(db.Devices.ToList())); }); //Devices.Filter = null; } } }
private void ExportXmlAddressBook() { using (var db = new ICMDBContext()) { AddrList addrList = DeviceToAddrList(); string filePath = Path.GetAddressBookTempXmlFilePath(); ExportXml(filePath, addrList.dev); AddLog("已输出至 {0}", Path.GetAddressBookTempXmlFilePath()); } }
internal async void RefreshAlarmsList() { using (var db = new ICMDBContext()) { var alarms = from a in db.Eventwarns where a.handlestatus == 0 && a.Action == "trig" orderby a.time descending select a; eventwarnBindingSource.DataSource = await alarms.ToListAsync(); } }
private async void BtnQuery_Click(object sender, EventArgs e) { string DeviceId = textBoxDeviceId.Text; using (var db = new ICMDBContext()) { var sipAccounts = from account in db.Sipaccounts where account.C_room == DeviceId select account; this.sipaccountBindingSource.DataSource = await sipAccounts.ToListAsync(); } }