public async Task <ActionResult> Create([Bind(Include = "City,Created,Description,FirstName,ImageUri,IsEmergency,LastModified,LastName,OutageType,PhoneNumber,Resolved,State,Street,ZipCode")] IncidentViewModel incident, HttpPostedFileBase imageFile) { try { if (ModelState.IsValid) { Incident incidentToSave = IncidentMapper.MapIncidentViewModel(incident); using (IncidentAPIClient client = IncidentApiHelper.GetIncidentAPIClient()) { var result = client.IncidentOperations.CreateIncident(incidentToSave); Newtonsoft.Json.Linq.JObject jobj = (Newtonsoft.Json.Linq.JObject)result; incidentToSave = jobj.ToObject <Incident>(); } //TODO: ADD CODE TO UPLOAD THE BLOB //Now upload the file if there is one if (imageFile != null && imageFile.ContentLength > 0) { //### Add Blob Upload code here ##### //Give the image a unique name based on the incident id var imageUrl = await StorageHelper.UploadFileToBlobStorage(incidentToSave.Id, imageFile); //### Add Blob Upload code here ##### //### Add Queue code here ##### //Add a message to the queue to process this image await StorageHelper.AddMessageToQueue(incidentToSave.Id, imageFile.FileName); //### Add Queue code here ##### } ////##### CLEAR CACHE #### //RedisCacheHelper.ClearCache(Settings.REDISCCACHE_KEY_INCIDENTDATA); //##### CLEAR CACHE #### //##### SEND EMAIL ##### await SendIncidentEmail(incidentToSave); //##### SEND EMAIL ##### await CreateEvent(incidentToSave); return(RedirectToAction("Index", "Dashboard")); } } catch { return(View()); } return(View(incident)); }
public static IncidentBean GetBean() { IncidentBean bean = IncidentMapper.GetLastBean(); if (bean == null) { bean = new IncidentBean(); } bean.Title = string.Empty; bean.Explain = string.Empty; return(bean); }
public ActionResult Details(string Id) { IncidentViewModel incidentView = null; using (IncidentAPIClient client = IncidentApiHelper.GetIncidentAPIClient()) { var result = client.IncidentOperations.GetById(Id); Newtonsoft.Json.Linq.JObject jobj = (Newtonsoft.Json.Linq.JObject)result; Incident incident = jobj.ToObject <Incident>(); incidentView = IncidentMapper.MapIncidentModelToView(incident); } return(View(incidentView)); }
/// <summary> /// 获取事件选择列表 /// </summary> public static IncidentBean[] GetComboBoxResource() { IncidentBean[] beans = IncidentMapper.GetSuccessIncident(); IncidentBean[] items = new IncidentBean[beans.Length + 1]; items[0] = new IncidentBean { Id = 0, Title = "请选择事件", }; for (int i = 1; i < items.Length; i++) { items[i] = beans[i - 1]; } return(items); }
public async Task <ActionResult> Create([Bind(Include = "City,Created,Description,FirstName,ImageUri,IsEmergency,LastModified,LastName,OutageType,PhoneNumber,Resolved,State,Street,ZipCode")] IncidentViewModel incident, HttpPostedFileBase imageFile) { try { if (ModelState.IsValid) { Incident incidentToSave = IncidentMapper.MapIncidentViewModel(incident); using (IncidentAPIClient client = IncidentApiHelper.GetIncidentAPIClient()) { var result = client.Incident.CreateIncident(incidentToSave); if (!string.IsNullOrEmpty(result)) { incidentToSave = JsonConvert.DeserializeObject <Incident>(result); } } //Now upload the file if there is one if (imageFile != null && imageFile.ContentLength > 0) { //### Add Blob Upload code here ##### //Give the image a unique name based on the incident id var imageUrl = await StorageHelper.UploadFileToBlobStorage(incidentToSave.ID, imageFile); //### Add Blob Upload code here ##### //### Add Queue code here ##### //Add a message to the queue to process this image await StorageHelper.AddMessageToQueue(incidentToSave.ID, imageFile.FileName); //### Add Queue code here ##### } //##### CLEAR CACHE #### RedisCacheHelper.ClearCache(Settings.REDISCCACHE_KEY_INCIDENTDATA); //##### CLEAR CACHE #### return(RedirectToAction("Index", "Dashboard")); } } catch { return(View()); } return(View(incident)); }
public ActionResult Details(string Id) { IncidentViewModel incidentView = null; using (IncidentAPIClient client = IncidentApiHelper.GetIncidentAPIClient()) { var result = client.Incident.GetById(Id); if (!string.IsNullOrEmpty(result)) { Incident incident = JsonConvert.DeserializeObject <Incident>(result); incidentView = IncidentMapper.MapIncidentModelToView(incident); } } return(View(incidentView)); }
public void AddOne(object obj) { DateTime startTime = DateTime.Now; Thread.Sleep(1000); object[] objs = (object[])obj; ProgramWindow programWindow = (ProgramWindow)objs[0]; IncidentBean bean = (IncidentBean)objs[1]; programWindow.WriteLine("初始化..."); try { //处理事件 bean.CreateTime = DateTime.Now; bean.State = 1; incidentId = IncidentMapper.AddOne(bean); isFirst = IncidentMapper.IsFirstRecord(); //第一次记录必须保证索引表为空 if (isFirst) { DirIndexMapper.CleanAll(); } //新建记录表 Extend.BuildTable(incidentId, isFirst); programWindow.WriteLine("开始记录硬盘使用空间..."); programWindow.WriteLine("(建议此时不要修改硬盘上的文件,以免影响最终的分析结果)"); programWindow.Freeze(); isRunning = true; Thread showProgress = new Thread(ShowProgress) { Name = "showProgress" }; showProgress.Start(programWindow); DriveInfo[] drives = DriveInfo.GetDrives(); //遍历分区 foreach (DriveInfo drive in drives) { DirectoryInfo rootDir = new DirectoryInfo(drive.Name); SeeDirectory(rootDir, 0); } isRunning = false; programWindow.WriteAll("记录完成,建立索引...\n"); Extend.BuildIndex(incidentId); //收尾工作 long count = RecordMapper.Count(incidentId); IncidentMapper.SetStateById(incidentId, 0); if (isFirst) { //删除以前记录失败的作废表格 Extend.DeleteErrorTable(incidentId); } TimeSpan consumption = DateTime.Now - startTime; Log.Info(string.Format("数据记录完成, 记录:{0}({1}), 耗时:{2}", count, beanCount, consumption)); programWindow.WriteLine(string.Format("数据记录完成,耗时:{0}小时{1}分。", consumption.Days * 24 + consumption.Hours, consumption.Minutes)); programWindow.RunOver(); } catch (Exception e) { Log.Add(e); isRunning = false; programWindow.WriteLine("\n错误:"); programWindow.WriteLine(e.Message); programWindow.RunOver(); //throw e; } }