private async void BtnDeleteFile_Click(object sender, EventArgs e) { //using (var db = new ICMDBContext()) { foreach (DataGridViewRow row in upgradeDataGridView.SelectedRows) { upgrade upgradeInfo = (upgrade)row.DataBoundItem; // delete file and directory string filepath = Config.Instance.FTPServerRootDir + @"\" + upgradeInfo.filepath; try { System.IO.File.Delete(filepath); string dirpath = System.IO.Path.GetDirectoryName(filepath); System.IO.Directory.Delete(dirpath); } catch (Exception) { } db.Upgrades.Remove(upgradeInfo); } await db.SaveChangesAsync(); RefreshUgradeFileList(); } }
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 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 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(); //} } }
public ModuleAnnouncements() : base("/") { Get["/doorbell/message_text_list"] = parameters => { string responseText = ""; string DeviceId = this.Request.Query["ro"]; //Match m = Regex.Match(DeviceId, @"(?<a1>^\w{2})-(?<a2>\w{2})-(?<a3>\w{2})-(?<a4>\w{2})-(?<a5>\w{2})"); Match m = Regex.Match(DeviceId, @"^\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 announcements = from publishinfo in db.Publishinfoes where publishinfo.dstaddr.StartsWith(DeviceId) select publishinfo; responseText += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; responseText += "<MessageTextList>\n"; string pattern = @"<message>" + "\n" + @" <id>{0}</id>"+ "\n" + @" <topic>{1}</topic>"+ "\n" + @" <time>{2}</time>"+ "\n" + @" <image>{3}</image>"+ "\n" + @" <read>{4}</read>"+ "\n" + @"</message>" + "\n"; foreach (var announcement in announcements) { string imagePath = string.Format("http://{0}/{1}?type=publish&id={2}", this.Request.Url.HostName, announcement.filepath.Replace(@"\", "/"), announcement.id); responseText += string.Format(pattern, announcement.id, announcement.title, ((DateTime)announcement.time).ToString("yyyy-MM-dd HH:mm:ss"), imagePath, announcement.isread != 0 ? "true" : "false"); } responseText += "</MessageTextList>\r\n"; } return(responseText); }; Get["/doorbell/message_text_delete"] = parameters => { string DeviceId = this.Request.Query["ro"]; int msgId = int.Parse(this.Request.Query["id"]); Match m = Regex.Match(DeviceId, @"^\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 announcement = (from announce in db.Publishinfoes where announce.dstaddr.StartsWith(DeviceId) && announce.id == msgId select announce).FirstOrDefault(); if (announcement != null) { db.Publishinfoes.Remove(announcement); db.SaveChangesAsync(); } } return("OK"); }; Get["/data/publish_informations/{imgFileName}"] = parameters => { string imgFilePath = Path.GetPublishInfoFolderPath() + @"\" + parameters.imgFileName; var response = new Response(); try { int id = int.Parse(this.Request.Query["id"]); using (var db = new ICMDBContext()) { var announcement = (from announce in db.Publishinfoes where announce.id == id select announce).FirstOrDefault(); if (announcement == null) { return(HttpStatusCode.NotFound); } announcement.isread = 1; db.SaveChanges(); // Refresh Msgs has read HttpServer.Instance.RaiseReceivedGetMsgsEvent(); //get unread message count var count = (from announce in db.Publishinfoes where announce.dstaddr == announcement.dstaddr && announce.isread == 0 select announce).Count(); Task.Factory.StartNew(async() => { await ICMServer.Net.HttpClient.SendNewTextMsgCount(this.Request.UserHostAddress, count); }, TaskCreationOptions.LongRunning); } byte[] imageData = System.IO.File.ReadAllBytes(imgFilePath); response.ContentType = "image/jpg"; response.Contents = s => s.Write(imageData, 0, imageData.Count()); } catch (Exception) { return(HttpStatusCode.NotFound); } return(response); }; }
public ModuleVideoMsgs() : base("/doorbell") { Get["/message_video_list"] = parameters => { string responseText = ""; string DeviceId = this.Request.Query["ro"]; Match m = Regex.Match(DeviceId, @"^\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 videoMsgs = from leaveword in db.Leavewords where leaveword.dst_addr.StartsWith(DeviceId) // && leaveword.readflag == 0 select leaveword; responseText += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; responseText += "<MessageVideoList>\n"; string pattern = @"<message>" + "\n" + @" <id>{0}</id>"+ "\n" + @" <topic>{1}</topic>"+ "\n" + @" <time>{2}</time>"+ "\n" + @" <read>{3}</read>"+ "\n" + @"</message>" + "\n"; foreach (var videoMsg in videoMsgs) { if (File.Exists(videoMsg.filenames + ".sdp")) { responseText += string.Format(pattern, videoMsg.id, videoMsg.src_addr, videoMsg.time, videoMsg.readflag != 0 ? "true" : "false"); } else { db.Leavewords.Remove(videoMsg); } } db.SaveChanges(); responseText += "</MessageVideoList>\r\n"; } return(responseText); }; Get["/message_video_delete"] = parameters => { string DeviceId = this.Request.Query["ro"]; int msgId = int.Parse(this.Request.Query["id"]); Match m = Regex.Match(DeviceId, @"^\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 videoMsg = (from leaveword in db.Leavewords where leaveword.dst_addr.StartsWith(DeviceId) && leaveword.id == msgId select leaveword).FirstOrDefault(); if (videoMsg != null) { db.Leavewords.Remove(videoMsg); db.SaveChangesAsync(); } } return("OK"); }; }