/// <summary> /// 移动一个节点 /// </summary> /// <param name="nodeIdStr"></param> /// <param name="sourceParentIDStr"></param> /// <param name="targetParentNodeIDStr"></param> /// <returns></returns> public RES MoveNode(string nodeIdStr, string sourceParentIDStr, string targetParentNodeIDStr) { try { if (GUID.IsGuid(nodeIdStr) && GUID.IsGuid(sourceParentIDStr) && GUID.IsGuid(targetParentNodeIDStr)) { var currentNodeID = Guid.Parse(nodeIdStr); var sourceParentNodeID = Guid.Parse(sourceParentIDStr); var targetParentNodeID = Guid.Parse(targetParentNodeIDStr); var db = ModelEF.GetInst(); var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == currentNodeID); if (null != currentEntity) { currentEntity.ParentID = targetParentNodeID; } db.SaveChangesAsync(); return(RES.OK()); } return(RES.FAIL()); } catch (Exception ex) { return(RES.FAIL()); } }
/// <summary> /// 保存一个实体 /// </summary> /// <returns></returns> public RES Save() { try { var db = ModelEF.GetInst(); if (this.ID == Guid.Empty) { this.ID = Guid.NewGuid(); db.YunRelations.Add(this); } else { var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == this.ID); if (null != currentEntity) { currentEntity.Name = this.Name; } } db.SaveChangesAsync(); return(RES.OK()); } catch (Exception ex) { return(RES.FAIL()); } }
public RES StopJob(string jobName) { try { var scheduler = this.factory.GetScheduler(); scheduler.Result.DeleteJob(new JobKey(jobName)); return(RES.OK()); } catch (Exception ex) { return(RES.FAIL(ex.Message, ex.Message)); } }
public RES LoadList(string filter) { try { var db = ModelEF.GetInst(); var titleId = GUID.FromStringToGuid("Title"); var list = db.YunFormInsts.Where(p => p.CreateTime <= DateTime.Now && p.PropertyID == titleId).ToList(); return(RES.OK(list)); } catch (Exception ex) { return(RES.FAIL()); } }
public RES Save(string json) { try { var logItem = JSON.ToObject <ALog>(json); var db = ModelEF.GetInst(); db.ALogs.Add(logItem); db.SaveChangesAsync(); return(RES.OK()); } catch (Exception e) { return(RES.FAIL(e.Message)); } }
/// <summary> /// /// </summary> /// <returns></returns> public RES StopJob(string jobName) { try { var factory = new StdSchedulerFactory(); var scheduler = factory.GetScheduler(); scheduler.Result.DeleteJob(new JobKey(jobName)); scheduler.Result.Start(); return(RES.OK()); } catch (Exception ex) { return(RES.FAIL()); } }
public RES SendMail() { MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(new MailAddress("*****@*****.**")); mail.Subject = "定时测试"; mail.Body = "定时测试"; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("smtp.163.com", 25); //smtp.EnableSsl = true; smtp.Credentials = new NetworkCredential("tushu2019", "7573Wj7573"); smtp.Send(mail); return(RES.OK()); }
public RES Traverse(string rootPath, EventHandler <CallbackEventAgrs> fileCallback, EventHandler <CallbackEventAgrs> foldlerCallback) { if (!string.IsNullOrWhiteSpace(rootPath)) { if (Directory.Exists(rootPath)) { this.AddFolder(rootPath); while (0 < this.folderStack.Count) { try { var cur = this.folderStack.Pop(); var files = Directory.EnumerateFiles(cur); foreach (var file in files) { if (null != fileCallback) { fileCallback(this, new CallbackEventAgrs { DATA = file }); } } var subFolders = Directory.EnumerateDirectories(cur); foreach (var folder in subFolders) { if (null != foldlerCallback) { foldlerCallback(this, new CallbackEventAgrs { DATA = folder }); } } } catch (Exception ex) { Console.WriteLine($"{ex.Message}"); } } } } return(RES.OK()); }
public RES StartJob <T>(string jobName, string triggerName, int interval, int repeatCount) where T : IJob { try { var scheduler = this.factory.GetScheduler(); var jobDetail = JobBuilder.Create <T>().WithIdentity(jobName).Build(); var trigger = TriggerBuilder.Create().WithIdentity(triggerName).WithSimpleSchedule(p => p.WithIntervalInSeconds(interval).WithRepeatCount(repeatCount)).Build(); scheduler.Result.ScheduleJob(jobDetail, trigger); scheduler.Result.Start(); return(RES.OK()); } catch (Exception ex) { return(RES.FAIL(ex.Message, ex.Message)); } }
public RES Send(string sourceAddress, string targetAddress, string title, string content) { try { MailMessage mail = new MailMessage(); mail.From = new MailAddress(sourceAddress); mail.To.Add(new MailAddress(targetAddress)); mail.Subject = title; mail.Body = content; mail.IsBodyHtml = true; this.smtp.Send(mail); return(RES.OK()); } catch (Exception ex) { return(RES.FAIL(ex.Message, ex.Message)); } }
public RES Query(string folderPath, string fileName) { var filePath = $"{this.rootPath}\\{folderPath}\\{fileName}"; try { if (File.Exists(filePath)) { var fileInfo = new FileInfo(filePath); return(RES.OK(fileInfo)); } return(RES.FAIL("文件不存在")); } catch (Exception ex) { return(RES.FAIL($"{ex.Message}\t{((null != ex.InnerException) ? ex.InnerException.Message : string.Empty)}\t{filePath}")); } }
/// <summary> /// 获取子节点集合 /// </summary> /// <param name="nodeId"></param> /// <returns></returns> public RES GetChildNodes(string nodeId) { if (GUID.IsGuid(nodeId)) { try { var nId = Guid.Parse(nodeId); var db = ModelEF.GetInst(); var childNodes = db.YunRelations.Where(p => p.ParentID == nId); return(RES.OK(childNodes)); } catch (Exception ex) { return(RES.FAIL()); } } return(RES.FAIL()); }
/// <summary> /// 获取当前节点信息 /// </summary> /// <param name="nodeId"></param> /// <returns></returns> public RES GetCurrentNode(string nodeId) { if (GUID.IsGuid(nodeId)) { try { var nId = Guid.Parse(nodeId); var db = ModelEF.GetInst(); var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == nId); return(RES.OK(currentEntity)); } catch (Exception ex) { return(RES.FAIL()); } } return(RES.FAIL()); }
public RES LoadDetail(string idStr) { try { if (GUID.IsGuid(idStr)) { var id = Guid.Parse(idStr); var db = ModelEF.GetInst(); var entity = db.YunFormInsts.FirstOrDefault(p => p.ID == id); return(RES.OK(entity)); } return(RES.FAIL()); } catch (Exception ex) { return(RES.FAIL()); } }
public RES SaveTo(string folderPath, string fileName, byte[] data) { try { this.CreateFolder(folderPath); var filePath = $"{this.rootPath}\\{folderPath}\\{fileName}"; File.WriteAllBytes(filePath, data); var fileInfo = new FileInfo(filePath); var fs = fileInfo.OpenWrite(); fs.Write(data, 0, data.Length); fs.Close(); return(RES.OK($"{folderPath}\\{fileName}")); } catch (Exception ex) { return(RES.FAIL($"{ex.Message}\t{((null != ex.InnerException) ? ex.InnerException.Message : string.Empty)}\t{folderPath}\\{fileName}")); } }
/// <summary> /// 保存一个ToDo /// </summary> /// <param name="id"></param> /// <param name="title"></param> /// <param name="content"></param> /// <returns></returns> public RES SaveToDo(string idStr, string title, string content) { try { var db = ModelEF.GetInst(); var titleId = GUID.FromStringToGuid("Title"); var contentId = GUID.FromStringToGuid("Content"); YunFormInst titleInst = null; YunFormInst contentInst = null; if (GUID.IsGuid(idStr)) { var id = Guid.Parse(idStr); var oldInst = db.YunFormInsts.Where(p => p.ID == id); if (null != oldInst) { titleInst = oldInst.FirstOrDefault(p => p.PropertyID == titleId); titleInst.PropertyValueString = title; titleInst.UpdateTime = DateTime.Now; contentInst = oldInst.FirstOrDefault(p => p.PropertyID == contentId); contentInst.PropertyValueString = title; contentInst.UpdateTime = DateTime.Now; } } else { titleInst = new YunFormInst { ID = Guid.NewGuid(), CreateTime = DateTime.Now, PropertyID = titleId, PropertyValueString = title }; contentInst = new YunFormInst { ID = Guid.NewGuid(), CreateTime = DateTime.Now, PropertyID = contentId, PropertyValueString = content }; db.YunFormInsts.Add(titleInst); db.YunFormInsts.Add(contentInst); } var rInt = db.SaveChanges(); return(RES.OK(rInt)); } catch (Exception ex) { return(RES.FAIL(ex.Message)); } }
/// <summary> /// 保存一个文档 /// </summary> /// <param name="title"></param> /// <param name="content"></param> /// <returns></returns> public RES SaveArticle(string title, string content, int status = 0) { try { var inst = new YunArticle(); inst.ID = Guid.NewGuid(); inst.Status = status; inst.Title = title; inst.Content = content; var db = ModelEF.GetInst(); db.YunArticles.Add(inst); db.SaveChangesAsync(); return(RES.OK(inst)); } catch (Exception ex) { return(RES.FAIL()); } }
/// <summary> /// 写入云日志 /// </summary> /// <param name="position"></param> /// <param name="msg"></param> /// <param name="param"></param> /// <param name="remark"></param> /// <param name="summary"></param> /// <param name="typeID"></param> /// <param name="typeName"></param> /// <returns></returns> public RES SaveLog(string position, string msg, string param, string remark, string summary, int typeID, string typeName) { try { var log = new { CreateTime = DateTime.Now, Position = position, Msg = msg, Param = param, Remark = remark, Summary = summary, TypeID = typeID, TypeName = typeName, AppID = this.appId }; var res = HTTP.POST("http://localhost:6003/LogAPI.ashx", null, JSON.ToJson(new { TargetClass = "YunLog", Method = "Save", Param = new { }, InputParamArray = new string[] { JSON.ToJson(log) } })); return(RES.OK(res)); } catch (Exception ex) { return(RES.FAIL(ex.Message)); } }
/// <summary> /// 获取整棵树 /// </summary> /// <returns></returns> public RES GetWholeTree(string rootID) { if (GUID.IsGuid(rootID)) { try { var nId = Guid.Parse(rootID); var db = ModelEF.GetInst(); var nodes = db.YunRelations.Where(p => p.RootID == nId).ToList(); var rootNode = db.YunRelations.FirstOrDefault(p => p.ID == nId); nodes.Add(rootNode); return(RES.OK(nodes)); } catch (Exception ex) { return(RES.FAIL()); } } return(RES.FAIL()); }
public RES QueryDirectory(string folderPath) { var dirPath = $"{this.rootPath}\\{folderPath}"; try { if (Directory.Exists(dirPath)) { var files = Directory.GetFiles(dirPath); var folders = Directory.GetDirectories(dirPath); var res = new List <string>(files); res.AddRange(folders); return(RES.OK(res)); } return(RES.FAIL("目录不存在")); } catch (Exception ex) { return(RES.FAIL($"{ex.Message}\t{((null != ex.InnerException) ? ex.InnerException.Message : string.Empty)}\t{dirPath}")); } }
public RES StartJob(string jobName, string param) { try { var factory = new StdSchedulerFactory(); var scheduler = factory.GetScheduler(); IJobDetail job = JobBuilder.Create <YunJob>().WithIdentity("job1", "group1").Build(); job.JobDataMap.Put("param", param); job.JobDataMap.Put("name", jobName); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1", "group1") .WithCronSchedule("0/5 * * * * ?") //5秒执行一次 .Build(); scheduler.Result.ScheduleJob(job, trigger); scheduler.Result.Start(); return(RES.OK()); } catch (Exception ex) { return(RES.FAIL()); } }
public RES Download(string folderPath, string fileName) { var filePath = $"{this.rootPath}\\{folderPath}\\{fileName}"; try { if (File.Exists(filePath)) { var fileInfo = new FileInfo(filePath); var fs = fileInfo.OpenRead(); byte[] buffer = new byte[(int)fs.Length]; fs.Read(buffer, 0, buffer.Length); return(RES.OK(buffer)); } return(RES.FAIL("文件不存在")); } catch (Exception ex) { return(RES.FAIL($"{ex.Message}\t{((null != ex.InnerException) ? ex.InnerException.Message : string.Empty)}\t{filePath}")); } }
/// <summary> /// 移除一个子节点 /// </summary> /// <param name="nodeId"></param> /// <returns></returns> public RES RemoveNode(string nodeId) { if (GUID.IsGuid(nodeId)) { try { var nId = Guid.Parse(nodeId); var db = ModelEF.GetInst(); var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == nId); if (null != currentEntity) { currentEntity.Status = (int)ENUM.实体状态.已删除; } db.SaveChangesAsync(); return(RES.OK()); } catch (Exception ex) { return(RES.FAIL()); } } return(RES.FAIL()); }
/// <summary> /// 修改一个子节点的信息 /// </summary> /// <param name="nodeId"></param> /// <returns></returns> public RES RenameNode(string nodeId, string newName) { if (GUID.IsGuid(nodeId) && !string.IsNullOrWhiteSpace(newName)) { try { var nId = Guid.Parse(nodeId); var db = ModelEF.GetInst(); var currentEntity = db.YunRelations.FirstOrDefault(p => p.ID == nId); if (null != currentEntity) { currentEntity.Name = newName; } db.SaveChangesAsync(); return(RES.OK()); } catch (Exception ex) { return(RES.FAIL()); } } return(RES.FAIL()); }
/// <summary> /// 从url中保存一个原始文章 /// </summary> /// <param name="url"></param> /// <param name="headers"></param> /// <returns></returns> public RES SaveArticleFromUrl(string url, string headers) { try { var content = HTTP.Get(url, string.IsNullOrWhiteSpace(headers) ? null: JSON.ToObject <Dictionary <string, string> >(headers)); var inst = new YunArticle(); inst.ID = Guid.NewGuid(); inst.Status = (int)ENUM.实体状态.可用; inst.Title = null; inst.Url = url; inst.Content = content; inst.CreateTime = DateTime.Now; inst.UpdateTime = DateTime.Now; var db = ModelEF.GetInst(); db.YunArticles.Add(inst); db.SaveChangesAsync(); return(RES.OK(inst)); } catch (Exception ex) { return(RES.FAIL(ex.Message)); } }