public void Task_Assign_To_New_Node_Delete_Node_And_Ensure_Tasks_Removed() { //create a new document in the root var dt = DocumentType.GetAllAsList().First(); Document d = Document.MakeNew(Guid.NewGuid().ToString("N"), dt, m_User, -1); //create a new task assigned to the new document Task t = new Task(); t.Comment = Guid.NewGuid().ToString("N"); t.Node = d; t.ParentUser = m_User; t.User = m_User; t.Type = TaskType.GetAll().First(); t.Save(); //delete the document permanently d.delete(true); //ensure the task is gone var isFound = true; try { var gone = new Task(t.Id); } catch (ArgumentException) { isFound = false; } Assert.IsFalse(isFound); //ensure it's gone Assert.IsFalse(Document.IsNode(d.Id)); }
public void Task_Make_New_And_Close() { //create the task Task t = new Task(); t.Comment = Guid.NewGuid().ToString("N"); t.Node = Document.GetRootDocuments().First(); t.ParentUser = m_User; t.User = m_User; t.Type = TaskType.GetAll().First(); t.Save(); Assert.IsTrue(t.Id > 0); t.Closed = true; t.Save(); Assert.IsTrue(t.Closed); //re-get the task and make sure the props have been persisted to the db var reGet = new Task(t.Id); Assert.IsTrue(reGet.Closed); reGet.Delete(); //re-get the task and make sure it is gone var isFound = true; try { var gone = new Task(t.Id); } catch (ArgumentException) { isFound = false; } Assert.IsFalse(isFound); }
public void TaskType_Make_New_Assign_Tasks_And_Remove() { TaskType tt = new TaskType(); tt.Alias = Guid.NewGuid().ToString("N"); tt.Save(); Assert.IsTrue(tt.Id > 0); Task t = new Task(); t.Comment = Guid.NewGuid().ToString("N"); t.Node = Document.GetRootDocuments().First(); t.ParentUser = m_User; t.User = m_User; t.Type = TaskType.GetAll().First(); t.Save(); //delete the task type tt.Delete(); //ensure they're gone Assert.AreEqual(0, Task.GetTasksByType(tt.Id).Count); //ensure the type is gone Assert.AreEqual(0, TaskType.GetAll().Where(x => x.Id == tt.Id).Count()); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; int pageId; XmlNode root = _xd.CreateElement("tasks"); if (int.TryParse(Request["id"], out pageId)) { var t = new Task(pageId); if (t.User.Id == base.getUser().Id || t.ParentUser.Id == base.getUser().Id) { XmlNode x = CreateTaskNode(t, _xd); root.AppendChild(x); xmlContents.Text = root.OuterXml; Response.AddHeader("Content-Disposition", "attachment; filename=" + t.Node.Text.Replace(" ", "_") + ".xml"); } } else { var nodes = new SortedList(); int totalWords = 0; foreach (Task t in Task.GetTasks(base.getUser(), false)) { if (!nodes.ContainsKey(t.Node.Path)) { var xTask = CreateTaskNode(t, _xd); totalWords += int.Parse(xTask.Attributes.GetNamedItem("TotalWords").Value); nodes.Add(t.Node.Path, xTask); } } // Arrange nodes in tree var ide = nodes.GetEnumerator(); while (ide.MoveNext()) { var x = (XmlElement)ide.Value; var parentXpath = UmbracoSettings.UseLegacyXmlSchema ? "//node [@id = '" + x.SelectSingleNode("//node").Attributes.GetNamedItem("parentID").Value + "']" : "//* [@isDoc and @id = '" + x.SelectSingleNode("//* [@isDoc]").Attributes.GetNamedItem("parentID").Value + "']"; var parent = _xd.SelectSingleNode(parentXpath); if (parent == null) parent = root; else parent = parent.ParentNode; parent.AppendChild((XmlElement)ide.Value); } root.Attributes.Append(XmlHelper.AddAttribute(_xd, "TotalWords", totalWords.ToString())); xmlContents.Text = root.OuterXml; Response.AddHeader("Content-Disposition", "attachment; filename=all.xml"); } }
protected void closeTask(object sender, EventArgs e) { int translationId = int.Parse(Request["id"]); Task t = new Task(translationId); if (t != null && (t.ParentUser.Id == base.getUser().Id || t.User.Id == base.getUser().Id)) { t.Closed = true; t.Save(); Response.Redirect("default.aspx"); } }
private XmlElement CreateTaskNode(Task t, XmlDocument xd) { Document d = new Document(t.Node.Id); XmlNode x = d.ToPreviewXml(xd);// xd.CreateNode(XmlNodeType.Element, "node", ""); XmlElement xTask = xd.CreateElement("task"); xTask.SetAttributeNode(xmlHelper.addAttribute(xd, "Id", t.Id.ToString())); xTask.SetAttributeNode(xmlHelper.addAttribute(xd, "Date", t.Date.ToString("s"))); xTask.SetAttributeNode(xmlHelper.addAttribute(xd, "NodeId", t.Node.Id.ToString())); xTask.SetAttributeNode(xmlHelper.addAttribute(xd, "TotalWords", cms.businesslogic.translation.Translation.CountWords(d.Id).ToString())); xTask.AppendChild(xmlHelper.addCDataNode(xd, "Comment", t.Comment)); string protocol = GlobalSettings.UseSSL ? "https" : "http"; xTask.AppendChild(xmlHelper.addTextNode(xd, "PreviewUrl", protocol + "://" + Request.ServerVariables["SERVER_NAME"] + SystemDirectories.Umbraco + "/translation/preview.aspx?id=" + t.Id.ToString())); // d.XmlPopulate(xd, ref x, false); xTask.AppendChild(x); return xTask; }
protected void Page_Load(object sender, EventArgs e) { int taskId = int.Parse(helper.Request("id")); Task t = new Task(taskId); Document translated = new Document(t.Node.Id); translatedUrl = String.Format("../dialogs/preview.aspx?id={0}", translated.Id.ToString(), translated.Version.ToString()); Relation[] orgRel = Relation.GetRelations(t.Node.Id, RelationType.GetByAlias("relateDocumentOnCopy")); if (orgRel.Length > 0) { Document original = new Document(orgRel[0].Parent.Id); originalUrl = String.Format("../dialogs/preview.aspx?id={0}", original.Id.ToString(), original.Version.ToString()); } else { Response.Redirect(translatedUrl); } }
private List<Task> ImportTranslatationFile(string tempFileName) { try { List<Task> tl = new List<Task>(); // open file XmlDocument tf = new XmlDocument(); tf.XmlResolver = null; tf.Load(tempFileName); // Get task xml node XmlNodeList tasks = tf.SelectNodes("//task"); foreach (XmlNode taskXml in tasks) { string xpath = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema ? "node" : "* [@isDoc]"; XmlNode taskNode = taskXml.SelectSingleNode(xpath); // validate file Task t = new Task(int.Parse(taskXml.Attributes.GetNamedItem("Id").Value)); if (t != null) { //user auth and content node validation if (t.Node.Id == int.Parse(taskNode.Attributes.GetNamedItem("id").Value) && (t.User.Id == base.getUser().Id || t.ParentUser.Id == base.getUser().Id)) { // update node contents var d = new Document(t.Node.Id); Document.Import(d.ParentId, getUser(), (XmlElement)taskNode); /* d.Text = taskNode.Attributes.GetNamedItem("nodeName").Value.Trim(); // update data elements foreach (XmlNode data in taskNode.SelectNodes("data")) if (data.FirstChild != null) d.getProperty(data.Attributes.GetNamedItem("alias").Value).Value = data.FirstChild.Value; else d.getProperty(data.Attributes.GetNamedItem("alias").Value).Value = ""; */ t.Closed = true; t.Save(); tl.Add(t); } } } return tl; } catch (Exception ee) { throw new Exception("Error importing translation file '" + tempFileName + "': " + ee.ToString()); } }
public void Task_Not_Found_Constructor() { Task u = new Task(-1111); }
/// <summary> /// Adds the specified new task. /// </summary> /// <param name="NewTask">The new task.</param> public virtual void Add(Task NewTask) { this.List.Add(NewTask); }
protected void Page_Load(object sender, EventArgs e) { int translationId = int.Parse(Request["id"]); Task t = new Task(translationId); Document page = new Document(t.Node.Id); //Bind meta data and language... Literal lt = new Literal(); lt.Text = t.Date.ToLongDateString() + " " + t.Date.ToLongTimeString(); pp_date.Controls.Add(lt); pp_date.Text = ui.Text("translation","taskOpened"); lt = new Literal(); lt.Text = t.ParentUser.Name; pp_owner.Controls.Add(lt); pp_owner.Text = ui.Text("translation", "taskAssignedBy"); lt = new Literal(); lt.Text = Translation.CountWords(t.Node.Id).ToString(); pp_totalWords.Controls.Add(lt); pp_totalWords.Text = ui.Text("translation", "totalWords"); lt = new Literal(); lt.Text = library.ReplaceLineBreaks(t.Comment); pp_comment.Controls.Add(lt); pp_comment.Text = ui.Text("comment"); lt = new Literal(); lt.Text = "<a target=\"_blank\" href=\"xml.aspx?id=" + t.Id + "\">" + ui.Text("download") + "</a>"; pp_xml.Controls.Add(lt); pp_xml.Text = ui.Text("translation", "downloadTaskAsXml"); pane_details.Text = ui.Text("translation", "details"); panel1.Text = ui.Text("translation", "details"); pane_fields.Text = ui.Text("translation", "fields"); pane_tasks.Text = ui.Text("translation", "translationOptions"); lt = new Literal(); lt.Text = "<a href=\"default.aspx?id=" + t.Id + "\">" + ui.Text("upload") + "</a>"; pp_upload.Controls.Add(lt); pp_upload.Text = ui.Text("translation", "uploadTranslationXml"); if (t.Closed) pp_closeTask.Visible = false; else { pp_closeTask.Text = ui.Text("translation", "closeTask"); bt_close.Text = ui.Text("close"); } //Bind page fields DataTable pageTable = new DataTable(); pageTable.Columns.Add(ui.Text("name")); pageTable.Columns.Add(ui.Text("value")); DataRow pageRow = pageTable.NewRow(); pageRow[ui.Text("name")] = ui.Text("nodeName"); pageRow[ui.Text("value")] = page.Text; pageTable.Rows.Add(pageRow); foreach (PropertyType pt in page.ContentType.PropertyTypes) { pageRow = pageTable.NewRow(); pageRow[ui.Text("name")] = pt.Name; pageRow[ui.Text("value")] = page.getProperty(pt.Alias).Value; pageTable.Rows.Add(pageRow); } dg_fields.DataSource = pageTable; dg_fields.DataBind(); }
public static void MakeNew(CMSNode Node, User User, User Translator, Language Language, string Comment, bool IncludeSubpages, bool SendEmail) { // Create pending task Task t = new Task(); t.Comment = Comment; t.Node = Node; t.ParentUser = User; t.User = Translator; t.Type = new TaskType("toTranslate"); t.Save(); // Add log entry Log.Add(LogTypes.SendToTranslate, User, Node.Id, "Translator: " + Translator.Name + ", Language: " + Language.FriendlyName); // send it if (SendEmail) { string serverName = HttpContext.Current.Request.ServerVariables["SERVER_NAME"]; int port = HttpContext.Current.Request.Url.Port; if(port != 80) serverName += ":" + port.ToString(); serverName += IOHelper.ResolveUrl(SystemDirectories.Umbraco); // Send mail string[] subjectVars = {serverName, Node.Text}; string[] bodyVars = { Translator.Name, Node.Text, User.Name, serverName, t.Id.ToString(), Language.FriendlyName }; if (User.Email != "" && User.Email.Contains("@") && Translator.Email != "" && Translator.Email.Contains("@")) { // create the mail message MailMessage mail = new MailMessage(User.Email, Translator.Email); // populate the message mail.Subject = ui.Text("translation", "mailSubject", subjectVars, Translator); mail.IsBodyHtml = false; mail.Body = ui.Text("translation", "mailBody", bodyVars, Translator); try { SmtpClient sender = new SmtpClient(); sender.Send(mail); } catch (Exception ex) { LogHelper.Error<Translation>("Error sending translation e-mail", ex); } } else { LogHelper.Warn<Translation>("Could not send translation e-mail because either user or translator lacks e-mail in settings"); } } if (IncludeSubpages) { //store children array here because iterating over an Array property object is very inneficient. var c = Node.Children; foreach (CMSNode n in c) { MakeNew(n, User, Translator, Language, Comment, true, false); } } }
/// <summary> /// Retrieves a collection of open tasks assigned to the user /// </summary> /// <param name="User">The User who have the tasks assigned</param> /// <param name="IncludeClosed">If true both open and closed tasks will be returned</param> /// <returns>A collections of tasks</returns> public static Tasks GetOwnedTasks(User User, bool IncludeClosed) { string sql = "select id, taskTypeId, nodeId, parentUserId, userId, DateTime, comment, closed from cmsTask where parentUserId = @userId"; if (!IncludeClosed) sql += " and closed = 0"; sql += " order by DateTime desc"; Tasks tasks = new Tasks(); using (IRecordsReader dr = SqlHelper.ExecuteReader( sql, SqlHelper.CreateParameter("@userId", User.Id))) { while (dr.Read()) { var t = new Task(); t.PopulateTaskFromReader(dr); tasks.Add(t); } } return tasks; }
/// <summary> /// Get all tasks assigned to a node /// </summary> /// <param name="nodeId"></param> /// <returns></returns> public static Tasks GetTasks(int nodeId) { var sql = "select id, taskTypeId, nodeId, parentUserId, userId, DateTime, comment, closed from cmsTask where nodeId = @nodeId"; Tasks tasks = new Tasks(); using (IRecordsReader dr = SqlHelper.ExecuteReader(sql, SqlHelper.CreateParameter("@nodeId", nodeId))) { while (dr.Read()) { var t = new Task(); t.PopulateTaskFromReader(dr); tasks.Add(t); } } return tasks; }