/// <summary> /// 导入Excel /// </summary> /// <returns></returns> public ActionResult ImportCommentsFile() { var ptcp = new BaseResponse { DoFlag = true, DoResult = "" }; try { FileUploader uploader = new FileUploader("~/Upload"); uploader.SetExtensionLimit(".xls|.xlsx"); string error; List <string> filenames = uploader.Process(this.Request, out error); string fileName = filenames.FirstOrDefault(); if (!string.IsNullOrEmpty(error)) { ptcp.DoFlag = false; ptcp.DoResult = error; } else { fileName = Path.GetFileName(fileName); string fullPath = Path.Combine(Server.MapPath("~/Upload"), fileName); //将excel数据导入到列表中 ImportExcelToList import = new ImportExcelToList(); MessageList errors = new MessageList(); //获取表数据 ImportToListResult importedResult = import.DoImport(fullPath); if (importedResult.Result.IsSuccess) { //获取验证返回的错误信息 errors.Merge(DoValidData(importedResult.Data.ImportedBody)); if (errors.Messages != null && errors.Messages.Any()) { ptcp.DoFlag = false; ViewBag.ErrorMsgs = errors.Messages.Select(s => s.Message).ToList(); } else { //执行导入 Stopwatch during = new Stopwatch(); during.Start(); int success = DoImport(importedResult.Data.ImportedHeader, importedResult.Data.ImportedBody); during.Stop(); string info = success > 0?string.Format("导入成功!一共导入:{0}条记录,耗时{1}秒", success, during.Elapsed.TotalSeconds):"导入错误;插入失败"; ptcp.DoFlag = success > 0; ptcp.DoResult = info; } } else { ptcp.DoFlag = false; ptcp.DoResult = importedResult.Result.Error; } } } catch (Exception ex) { ptcp.DoFlag = false; ptcp.DoResult = "导入异常"; } ViewBag.Result = ptcp; return(View("ImportCommnets")); }
private void MainProcess(bool restarting = false) { try { ThreadHelper.SafeSleep(4000); if (!restarting) { LoadDb().Wait(); } SetConnectToYouTubeButtonEnabled(true); CheckForLatestVersion(); Logger.LogInfo("MainProcess", "File scanner starting"); FileScanner.Process(); Logger.LogInfo("MainProcess", "File scan complete"); YTMAuthenticationCheckWait(); RepopulateAmountLables(); Logger.LogInfo("MainProcess", "Starting upload check and upload process"); FileUploader.Process().Wait(); Logger.LogInfo("MainProcess", "Upload check and process upload process complete"); YTMAuthenticationCheckWait(); RepopulateAmountLables(); if (Settings.UploadPlaylists) { if (!Settings.LastPlaylistUpload.HasValue) { Settings.LastPlaylistUpload = DateTime.Now.AddHours(Global.SessionRestartHours * -1).AddHours(-2); } if (DateTime.Now > ((DateTime)Settings.LastPlaylistUpload).AddHours(Global.SessionRestartHours)) { Logger.LogInfo("MainProcess", "Starting playlist processing"); PlaylistProcessor.Process(); Logger.LogInfo("MainProcess", "Playlist processing complete"); } } if (ManagingYTMusicStatus != ManagingYTMusicStatusEnum.Showing) { SetStatusMessage("Idle", "Idle"); SetUploadingMessage("Idle", null, "Idle", null, true); } if (WatchFolders.Count == 0) { SetAmountLabelsToZero(); } else { RepopulateAmountLables(true); } ThreadHelper.SafeSleep(10000); } catch (Exception e) { string _ = e.Message; #if DEBUG Console.Out.WriteLine("Main Process Thread Error: " + e.Message); #endif if (e.Message.ToLower().Contains("thread was being aborted") || (e.InnerException != null && e.InnerException.Message.ToLower().Contains("thread was being aborted"))) { // Non-detrimental - Ignore to not clog up the application log // Logger.Log(e, "Main Process thread error", Log.LogTypeEnum.Warning); } else { Logger.Log(e, "Main Process thread error", Log.LogTypeEnum.Critical); } } IdleProcessor.Paused = false; GCCollect(); }
public void StartMainProcess() { IdleProcessor.Paused = true; DataAccess.CheckAndCopyDatabaseFile(); _scanAndUploadThread = new Thread((ThreadStart) delegate { try { LoadDb().Wait(); while (InstallingEdge) { ThreadHelper.SafeSleep(200); } if (Aborting) { SetStatusMessage("Idle", "Idle"); return; } FileScanner.Process(); while (!ConnectedToYTMusic) { if (Aborting) { SetStatusMessage("Idle", "Idle"); return; } ThreadHelper.SafeSleep(1000); } while (!NetworkHelper.InternetConnectionIsUp()) { SetStatusMessage("No internet connection", "No internet connection"); ThreadHelper.SafeSleep(5000); } while (!Requests.IsAuthenticated(Settings.AuthenticationCookie)) { try { SetConnectedToYouTubeMusic(false); ThreadHelper.SafeSleep(1000); Settings = SettingsRepo.Load().Result; } catch { } } SetConnectedToYouTubeMusic(true); SetStatusMessage("Uploading", "Uploading"); RepopulateAmountLables(); FileUploader.Process().Wait(); SetStatusMessage("Idle", "Idle"); SetUploadingMessage("Idle", "Idle", null, true); RepopulateAmountLables(true); } catch (Exception e) { string _ = e.Message; #if DEBUG Console.Out.WriteLine("Main Process Thread Error: " + e.Message); #endif } IdleProcessor.Paused = false; }) { IsBackground = true }; _scanAndUploadThread.Start(); }
private void MainProcess(bool restarting = false) { try { ThreadHelper.SafeSleep(4000); if (!restarting) { LoadDb().Wait(); } while (InstallingEdge) { ThreadHelper.SafeSleep(200); } CheckForLatestVersion(); Logger.LogInfo("MainProcess", "File scanner starting"); FileScanner.Process(); Logger.LogInfo("MainProcess", "File scan complete"); YTMAuthenticationCheckWait(); RepopulateAmountLables(); Logger.LogInfo("MainProcess", "Starting upload check and upload process"); FileUploader.Process().Wait(); Logger.LogInfo("MainProcess", "Upload check and process upload process complete"); YTMAuthenticationCheckWait(); RepopulateAmountLables(); Logger.LogInfo("MainProcess", "Starting playlist processing"); PlaylistProcessor.Process(); Logger.LogInfo("MainProcess", "Playlist processing complete"); if (ManagingYTMusicStatus != ManagingYTMusicStatusEnum.Showing) { SetStatusMessage("Idle", "Idle"); SetUploadingMessage("Idle", "Idle", null, true); } if (WatchFolders.Count == 0) { SetAmountLabelsToZero(); } else { RepopulateAmountLables(true); } ThreadHelper.SafeSleep(10000); } catch (Exception e) { string _ = e.Message; #if DEBUG Console.Out.WriteLine("Main Process Thread Error: " + e.Message); #endif if (e.Message.ToLower().Contains("thread was being aborted") || (e.InnerException != null && e.InnerException.Message.ToLower().Contains("thread was being aborted"))) { // Non-detrimental - Ignore to not clog up the application log // Logger.Log(e, "Main Process thread error", Log.LogTypeEnum.Warning); } else { Logger.Log(e, "Main Process thread error", Log.LogTypeEnum.Critical); } } IdleProcessor.Paused = false; }