public void Media_Delete_Heirarchy_Permanently() { var mediaList = new List<Media>(); var total = 20; var mt = new MediaType(GetExistingMediaTypeId()); //allow the doc type to be created underneath itself mt.AllowedChildContentTypeIDs = new int[] { mt.Id }; mt.Save(); //create 20 content nodes underneath each other, this will test deleting with heirarchy as well var lastParentId = -1; for (var i = 0; i < total; i++) { var newDoc = Media.MakeNew(i.ToString() + Guid.NewGuid().ToString("N"), mt, m_User, lastParentId); mediaList.Add(newDoc); Assert.IsTrue(mediaList[mediaList.Count - 1].Id > 0); lastParentId = newDoc.Id; } //now delete all of them permanently, since they are nested, we only need to delete one mediaList.First().delete(true); //make sure they are all gone foreach (var d in mediaList) { Assert.IsFalse(Media.IsNode(d.Id)); } }
public int create(mediaCarrier carrier, string username, string password) { Authenticate(username, password); if (carrier == null) throw new Exception("No carrier specified"); if (carrier.ParentId == 0) throw new Exception("Media needs a parent"); if (carrier.TypeId == 0) throw new Exception("Type must be specified"); if (carrier.Text == null || carrier.Text.Length == 0) carrier.Text = "unnamed"; BusinessLogic.User user = GetUser(username, password); var mt = new MediaType(carrier.TypeId); var m = Media.MakeNew(carrier.Text, mt, user, carrier.ParentId); if (carrier.MediaProperties != null) { foreach (mediaProperty updatedproperty in carrier.MediaProperties) { if (!(updatedproperty.Key.ToLower().Equals("umbracofile"))) { Property property = m.getProperty(updatedproperty.Key); if (property == null) throw new Exception("property " + updatedproperty.Key + " was not found"); property.Value = updatedproperty.PropertyValue; } } } return m.Id; }
public bool Save() { cms.businesslogic.media.MediaType dt = new cms.businesslogic.media.MediaType(TypeID); cms.businesslogic.media.Media m = cms.businesslogic.media.Media.MakeNew(Alias, dt, BusinessLogic.User.GetUser(_userID), ParentID); _returnUrl = "editMedia.aspx?id=" + m.Id.ToString() + "&isNew=true"; return(true); }
public bool Save() { cms.businesslogic.media.MediaType dt = new cms.businesslogic.media.MediaType(TypeID); cms.businesslogic.media.Media m = cms.businesslogic.media.Media.MakeNew(Alias, dt, BusinessLogic.User.GetUser(_userID), ParentID); _returnUrl = "editMedia.aspx?id=" + m.Id.ToString() + "&isNew=true"; return true; }
public static void SaveToDisk(MediaType item) { if (item != null) { try { XmlDocument xmlDoc = helpers.XmlDoc.CreateDoc(); xmlDoc.AppendChild(MediaTypeHelper.ToXml(xmlDoc, item)); helpers.XmlDoc.SaveXmlDoc(item.GetType().ToString(), GetMediaPath(item), "def", xmlDoc); } catch (Exception ex) { helpers.uSyncLog.DebugLog("uSync: Error Saving Media Type {0}, {1}", item.Text, ex.ToString()); } } }
/// <summary> /// Creates a new Media /// </summary> /// <param name="Name">The name of the media</param> /// <param name="dct">The type of the media</param> /// <param name="u">The user creating the media</param> /// <param name="ParentId">The id of the folder under which the media is created</param> /// <returns></returns> public static Media MakeNew(string Name, MediaType dct, BusinessLogic.User u, int ParentId) { Guid newId = Guid.NewGuid(); // Updated to match level from base node CMSNode n = new CMSNode(ParentId); int newLevel = n.Level; newLevel++; CMSNode.MakeNew(ParentId, _objectType, u.Id, newLevel, Name, newId); Media tmp = new Media(newId); tmp.CreateContent(dct); NewEventArgs e = new NewEventArgs(); tmp.OnNew(e); return tmp; }
private static string GetMediaPath(MediaType item) { string path = ""; if (item != null) { // does this documentType have a parent if (item.MasterContentType != 0) { // recurse in to the parent to build the path path = GetMediaPath(new MediaType(item.MasterContentType)); } // buld the final path (as path is "" to start with we always get // a preceeding '/' on the path, which is nice path = string.Format(@"{0}\{1}", path, helpers.XmlDoc.ScrubFile(item.Alias)); } return path; }
public void Can_Set_Tab_On_PropertyType() { var UPLOAD_DATATYPE_ID = -90; var CROP_DATATYPE_ID = 1043; var LABEL_DATATYPE_ID = -92; var mediaTypeName = "ImageWide"; MediaType mediaType = MediaType.MakeNew(new User(0), mediaTypeName); int imageTab = mediaType.AddVirtualTab("Image"); int cropTab = mediaType.AddVirtualTab("Crop"); mediaType.AddPropertyType(new DataTypeDefinition(UPLOAD_DATATYPE_ID), "umbracoFile", "Upload image"); mediaType.AddPropertyType(new DataTypeDefinition(LABEL_DATATYPE_ID), "umbracoWidth", "Width"); mediaType.AddPropertyType(new DataTypeDefinition(LABEL_DATATYPE_ID), "umbracoHeight", "Height"); mediaType.AddPropertyType(new DataTypeDefinition(LABEL_DATATYPE_ID), "umbracoBytes", "Size"); mediaType.AddPropertyType(new DataTypeDefinition(LABEL_DATATYPE_ID), "umbracoExtension", "Type"); mediaType.AddPropertyType(new DataTypeDefinition(CROP_DATATYPE_ID), "wideImage", "Wide image"); mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoFile"), imageTab); mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoWidth"), imageTab); mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoHeight"), imageTab); mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoBytes"), imageTab); mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoExtension"), imageTab); mediaType.SetTabOnPropertyType(mediaType.getPropertyType("wideImage"), cropTab); mediaType.Text = mediaTypeName; mediaType.IconUrl = "mediaPhoto.gif"; mediaType.Save(); Assert.That(mediaType.getVirtualTabs.Count(), Is.EqualTo(2)); Assert.That(mediaType.getVirtualTabs.Any(x => x.Caption.Equals("Image")), Is.True); Assert.That(mediaType.getVirtualTabs.Any(x => x.Caption.Equals("Crop")), Is.True); var updated = new MediaType(mediaType.Id); Assert.That(updated.getVirtualTabs.Count(), Is.EqualTo(2)); Assert.That(updated.getVirtualTabs.Any(x => x.Caption.Equals("Image")), Is.True); Assert.That(updated.getVirtualTabs.Any(x => x.Caption.Equals("Crop")), Is.True); Assert.That(updated.ContentTypeItem.PropertyGroups.Count(), Is.EqualTo(2)); Assert.That(updated.ContentTypeItem.PropertyTypes.Count(), Is.EqualTo(6)); }
public static void DeleteFromType(MediaType dt) { ApplicationContext.Current.Services.MediaService.DeleteMediaOfType(dt.Id); }
private void DeleteMediaType(MediaType mt) { var id = mt.Id; mt.delete(); //check with sql that it is gone var count = Application.SqlHelper.ExecuteScalar<int>("SELECT COUNT(*) FROM umbracoNode WHERE id=@id", Application.SqlHelper.CreateParameter("@id", id)); Assert.AreEqual(0, count); }
public virtual bool CanHandleMedia(int parentNodeId, PostedMediaFile postedFile, User user) { try { var parentNode = new Media(parentNodeId); return(parentNodeId <= -1 || user.Applications.Any(app => app.alias.ToLower() == "media") && (user.StartMediaId <= 0 || ("," + parentNode.Path + ",").Contains("," + user.StartMediaId + ",")) && parentNode.ContentType.AllowedChildContentTypeIDs.Contains(MediaType.GetByAlias(MediaTypeAlias).Id)); } catch { return(false); } }
public void Media_Undelete() { //find existing content var media = new Media(GetExistingNodeId()); //create new content based on the existing content in the same heirarchy var mt = new MediaType(media.ContentType.Id); var parentId = media.ParentId; var newMedia = Media.MakeNew("NewMedia" + Guid.NewGuid().ToString("N"), mt, m_User, parentId); Assert.IsTrue(newMedia.Id > 0); //this will recycle the node newMedia.delete(); Assert.IsTrue(newMedia.IsTrashed); Assert.IsTrue(newMedia.Path.Contains("," + (int)RecycleBin.RecycleBinType.Media + ",")); //undelete the node (move it) newMedia.Move(parentId); Assert.IsFalse(newMedia.IsTrashed); Assert.IsFalse(newMedia.Path.Contains("," + (int)RecycleBin.RecycleBinType.Media + ",")); //remove it completely RecycleAndDelete(newMedia); }
private Property GetUploadProperty(MediaType mt, Media m) { DataTypeNoEdit lblField = new DataTypeNoEdit(); var prop = mt.PropertyTypes .Where(x => x.DataTypeDefinition.DataType.Id == lblField.Id).First(); return m.GenericProperties.Where(x => x.PropertyType.Id == prop.Id).First(); }
public void MyTestInitialize() { m_ExistingMediaType = GetExistingMediaType(); m_NewRootMedia = CreateNewUnderRoot(m_ExistingMediaType); }
public XmlElement ToXml(XmlDocument xd, MediaType mt) { XmlElement doc = xd.CreateElement("MediaType"); // info section XmlElement info = xd.CreateElement("Info"); doc.AppendChild(info); info.AppendChild(xmlHelper.addTextNode(xd, "Name", mt.Text)); info.AppendChild(xmlHelper.addTextNode(xd, "Alias", mt.Alias)); info.AppendChild(xmlHelper.addTextNode(xd, "Icon", mt.IconUrl)); info.AppendChild(xmlHelper.addTextNode(xd, "Thumbnail", mt.Thumbnail)); info.AppendChild(xmlHelper.addTextNode(xd, "Description", mt.Description)); if (mt.MasterContentType > 0) { DocumentType dt = new DocumentType(mt.MasterContentType); if (dt != null) info.AppendChild(xmlHelper.addTextNode(xd, "Master", dt.Alias)); } // structure XmlElement structure = xd.CreateElement("Structure"); doc.AppendChild(structure); foreach (int cc in mt.AllowedChildContentTypeIDs.ToList()) structure.AppendChild(xmlHelper.addTextNode(xd, "MediaType", new DocumentType(cc).Alias)); // generic properties XmlElement pts = xd.CreateElement("GenericProperties"); foreach (PropertyType pt in mt.PropertyTypes) { //only add properties that aren't from master doctype if (pt.ContentTypeId == mt.Id) { XmlElement ptx = xd.CreateElement("GenericProperty"); ptx.AppendChild(xmlHelper.addTextNode(xd, "Name", pt.Name)); ptx.AppendChild(xmlHelper.addTextNode(xd, "Alias", pt.Alias)); ptx.AppendChild(xmlHelper.addTextNode(xd, "Type", pt.DataTypeDefinition.DataType.Id.ToString())); //Datatype definition guid was added in v4 to enable datatype imports ptx.AppendChild(xmlHelper.addTextNode(xd, "Definition", pt.DataTypeDefinition.UniqueId.ToString())); ptx.AppendChild(xmlHelper.addTextNode(xd, "Tab", umbraco.cms.businesslogic.ContentType.Tab.GetCaptionById(pt.TabId))); ptx.AppendChild(xmlHelper.addTextNode(xd, "Mandatory", pt.Mandatory.ToString())); ptx.AppendChild(xmlHelper.addTextNode(xd, "Validation", pt.ValidationRegExp)); ptx.AppendChild(xmlHelper.addCDataNode(xd, "Description", pt.Description)); pts.AppendChild(ptx); } } doc.AppendChild(pts); // tabs XmlElement tabs = xd.CreateElement("Tabs"); foreach (umbraco.cms.businesslogic.ContentType.TabI t in mt.getVirtualTabs.ToList()) { //only add tabs that aren't from a master doctype if (t.ContentType == mt.Id) { XmlElement tabx = xd.CreateElement("Tab"); tabx.AppendChild(xmlHelper.addTextNode(xd, "Id", t.Id.ToString())); tabx.AppendChild(xmlHelper.addTextNode(xd, "Caption", t.Caption)); tabs.AppendChild(tabx); } } doc.AppendChild(tabs); return doc; }
/// <summary> /// Create a new Mediatype /// </summary> /// <param name="u">The Umbraco user context</param> /// <param name="Text">The name of the MediaType</param> /// <returns>The new MediaType</returns> public static MediaType MakeNew(BusinessLogic.User u, string Text) { int ParentId = -1; int level = 1; Guid uniqueId = Guid.NewGuid(); CMSNode n = CMSNode.MakeNew(ParentId, _objectType, u.Id, level, Text, uniqueId); ContentType.Create(n.Id, Text, ""); MediaType mt = new MediaType(n.Id); NewEventArgs e = new NewEventArgs(); mt.OnNew(e); return mt; }
/// <summary> /// Returns an XPathNodeIterator of the specified media-type. /// </summary> /// <param name="mediaTypeId">The media-type id.</param> /// <param name="includeTabs">if set to <c>true</c> [include tabs].</param> /// <param name="includePropertyTypes">if set to <c>true</c> [include property types].</param> /// <returns>A node-set of the specified media-type.</returns> public static XPathNodeIterator GetMediaType(int mediaTypeId, bool includeTabs, bool includePropertyTypes) { try { var xd = new XmlDocument(); var mediaType = new MediaType(mediaTypeId); if (mediaType != null) { AppendMediaType(xd, mediaType, includeTabs, includePropertyTypes); } return xd.CreateNavigator().Select("/MediaType"); } catch (Exception ex) { return ex.ToXPathNodeIterator(); } }
void UpdateProperties(XDocument xmlDoc, MediaType docType) { var updatedProperties = xmlDoc.Descendants("GenericProperty"); var updatedPropertiesNames = updatedProperties.Select(x => x.Element("Alias").Value); var props = PropertyType.GetAll().Where(x => x.ContentTypeId == docType.Id); var matchingProps = props.Where(x => updatedPropertiesNames.Contains(x.Alias)); var toDelete = props.Where(x => !matchingProps.Contains(x)); var newProperties = updatedProperties.Where(x => !matchingProps.Select(y => y.Alias).Contains(x.Element("Alias").Value)); foreach (var p in toDelete) p.delete(); var allDtd = DataTypeDefinition.GetAll(); var tabs = docType.getVirtualTabs; foreach (var p in matchingProps) { var match = updatedProperties.Where(x => x.Element("Alias").Value == p.Alias).Single(); var dtd = allDtd.Where(x => x.UniqueId == new Guid(match.Element("Definition").Value)).Single(); p.DataTypeDefinition = dtd; p.Description = match.Element("Description").Value; var t = tabs.Where(x => x.Caption == match.Element("Tab").Value).FirstOrDefault(); if (t != null) p.TabId = t.Id; p.Mandatory = bool.Parse(match.Element("Mandatory").Value); p.ValidationRegExp = match.Element("Validation").Value; p.Name = match.Element("Name").Value; p.Save(); } foreach (var m in newProperties) { var dtd = allDtd.Where(x => x.UniqueId == new Guid(m.Element("Definition").Value)).Single(); var p = PropertyType.MakeNew(dtd, docType, m.Element("Name").Value, m.Element("Alias").Value); p.Description = m.Element("Description").Value; p.TabId = tabs.Where(x => x.Caption == m.Element("Tab").Value).First().Id; p.Mandatory = bool.Parse(m.Element("Mandatory").Value); p.ValidationRegExp = m.Element("Validation").Value; p.Save(); } }
public static void DeleteFromType(MediaType dt);
public static Media MakeNew(string Name, MediaType dct, User u, int ParentId);
public static IEnumerable<MediaType> GetAllAsList() { var mediaTypes = new List<MediaType>(); using (IRecordsReader dr = SqlHelper.ExecuteReader(m_SQLOptimizedGetAll.Trim(), SqlHelper.CreateParameter("@nodeObjectType", MediaType._objectType))) { while (dr.Read()) { //check if the document id has already been added if (mediaTypes.Where(x => x.Id == dr.Get<int>("id")).Count() == 0) { //create the DocumentType object without setting up MediaType dt = new MediaType(dr.Get<int>("id"), true); //populate it's CMSNode properties dt.PopulateCMSNodeFromReader(dr); //populate it's ContentType properties dt.PopulateContentTypeNodeFromReader(dr); mediaTypes.Add(dt); } else { //we've already created the document type with this id, so we'll add the rest of it's templates to itself var dt = mediaTypes.Where(x => x.Id == dr.Get<int>("id")).Single(); } } } return mediaTypes.OrderBy(x => x.Text).ToList(); }
public void MyTestInitialize() { m_NewMediaType = CreateNewMediaType(); }
private MediaType GetExistingMediaType() { MediaType dct = new MediaType(GetExistingMediaTypeId()); Assert.IsTrue(dct.Id > 0); return dct; }
protected void Page_PreRender(object sender, EventArgs e) { int parentNodeID = Convert.ToInt32(HttpContext.Current.Request.QueryString["nodeid"]); if (IsPostBack) { Media media = Media.MakeNew(name.Value, new MediaType(Convert.ToInt32(mediaTypeID.Value)), User.GetCurrent(), parentNodeID); string returnUrl = "editMedia.aspx?id=" + media.Id + "&isNew=true"; BasePage.Current.ClientTools.ChangeContentFrameUrl(returnUrl).CloseModalWindow(); } else { List<MediaType> MediaTypes = new List<MediaType>() { }; if (parentNodeID == -1) { foreach (MediaType mt in MediaType.GetAllAsList()) { MediaTypes.Add(mt); } } else { Media parentMedia = new Media(parentNodeID); foreach (int mediaTypeID in parentMedia.ContentType.AllowedChildContentTypeIDs) { MediaType mt = new MediaType(Convert.ToInt32(mediaTypeID)); MediaTypes.Add(mt); } } if (MediaTypes.Count == 0) { header.Visible = false; createButton.Visible = false; HtmlGenericControl div = new HtmlGenericControl("div"); div.InnerHtml = "There are no media types available to be made under this media item."; mediaTypeWrapper.Controls.Add(div); return; } MediaTypes = MediaTypes.OrderBy(o => o.Text).ToList(); foreach (MediaType mt in MediaTypes) { HtmlGenericControl mtDiv; HtmlGenericControl div; HtmlGenericControl img; mtDiv = new HtmlGenericControl("div"); mtDiv.Attributes["class"] = "mediaType"; mtDiv.Attributes["rel"] = mt.Id.ToString(); mediaTypeWrapper.Controls.Add(mtDiv); img = new HtmlGenericControl("img"); img.Attributes["src"] = "/umbraco/images/thumbnails/" + mt.Thumbnail; img.Attributes["class"] = "large"; mtDiv.Controls.Add(img); img = new HtmlGenericControl("img"); img.Attributes["src"] = "/umbraco/images/umbraco/" + mt.IconUrl; img.Attributes["class"] = "small"; mtDiv.Controls.Add(img); div = new HtmlGenericControl("div"); div.Attributes["class"] = "mediaTypeTitle"; div.InnerHtml = mt.Text; mtDiv.Controls.Add(div); div = new HtmlGenericControl("div"); div.Attributes["class"] = "mediaTypeDescription"; div.InnerHtml = mt.Description; mtDiv.Controls.Add(div); } } }
public void Media_Move() { //first need to document type that allows other types of document types to exist underneath it MediaType parent = null; MediaType child = null; var ids = MediaType.getAllUniqueNodeIdsFromObjectType(MediaType._objectType); foreach (var id in ids) { var dt = new MediaType(id); var allowed = dt.AllowedChildContentTypeIDs.ToList(); if (allowed.Count() > 0) { parent = dt; child = new MediaType(allowed[0]); break; } } if (parent == null || child == null) { throw new NotImplementedException("The umbraco install doesn't have document types that support a heirarchy"); } //now that we have a parent and a child, we need to create some documents var node1 = Media.MakeNew("FromCopy" + Guid.NewGuid().ToString("N"), parent, m_User, -1); Assert.IsTrue(node1.Id > 0); var node2 = Media.MakeNew("ToCopy" + Guid.NewGuid().ToString("N"), parent, m_User, -1); Assert.IsTrue(node2.Id > 0); //we now have 2 nodes in the root of the same type, we'll create a child node under node1 and move it to node2 var childNode = Media.MakeNew("ChildCopy" + Guid.NewGuid().ToString("N"), child, m_User, node2.Id); Assert.IsTrue(childNode.Id > 0); childNode.Move(node2.Id); Assert.AreEqual(node2.Id, childNode.Parent.Id); RecycleAndDelete(childNode); RecycleAndDelete(node2); RecycleAndDelete(node1); }
void UpdateTabs(XDocument xmlDoc, MediaType docType) { var tabs = docType.getVirtualTabs; var updatedTabs = xmlDoc.Descendants("Tabs").Descendants("Tab").Select(x => x.Element("Caption").Value); var currentNames = tabs.Select(x => x.Caption); var toDelete = tabs.Where(x => !updatedTabs.Contains(x.Caption)); var toAdd = updatedTabs.Where(x => !currentNames.Contains(x)); foreach (var t in toDelete) docType.DeleteVirtualTab(t.Id); foreach (var t in toAdd) docType.AddVirtualTab(t); }
public static XmlElement ToXml(XmlDocument xd, MediaType mt) { if (mt == null) throw new ArgumentNullException("Mediatype cannot be null"); if (xd == null) throw new ArgumentNullException("XmlDocument cannot be null"); XmlElement doc = xd.CreateElement("MediaType"); // build the info section (name and stuff) XmlElement info = xd.CreateElement("Info"); doc.AppendChild(info); info.AppendChild(XmlHelper.AddTextNode(xd, "Name", mt.Text)); info.AppendChild(XmlHelper.AddTextNode(xd, "Alias", mt.Alias)); info.AppendChild(XmlHelper.AddTextNode(xd, "Icon", mt.IconUrl)); info.AppendChild(XmlHelper.AddTextNode(xd, "Thumbnail", mt.Thumbnail)); info.AppendChild(XmlHelper.AddTextNode(xd, "Description", mt.Description)); // v6 property #if UMBRACO6 info.AppendChild(XmlHelper.AddTextNode(xd, "AllowAtRoot", mt.AllowAtRoot.ToString())); #endif XmlElement structure = xd.CreateElement("Structure"); foreach (int child in mt.AllowedChildContentTypeIDs.ToList()) { structure.AppendChild(XmlHelper.AddTextNode(xd, "MediaType", new MediaType(child).Alias)); } doc.AppendChild(structure); #if UMBRACO6 // // in v6 - media types can be nested. // if (mt.MasterContentType > 0) { MediaType pmt = new MediaType(mt.MasterContentType); if (pmt != null) info.AppendChild(XmlHelper.AddTextNode(xd, "Master", pmt.Alias)); } #endif // stuff in the generic properties tab XmlElement props = xd.CreateElement("GenericProperties"); foreach (PropertyType pt in mt.PropertyTypes) { // we only add properties that arn't in a parent (although media types are flat at the mo) if (pt.ContentTypeId == mt.Id) { XmlElement prop = xd.CreateElement("GenericProperty"); prop.AppendChild(XmlHelper.AddTextNode(xd, "Name", pt.Name)); prop.AppendChild(XmlHelper.AddTextNode(xd, "Alias", pt.Alias)); prop.AppendChild(XmlHelper.AddTextNode(xd, "Type", pt.DataTypeDefinition.DataType.Id.ToString())); prop.AppendChild(XmlHelper.AddTextNode(xd, "Definition", pt.DataTypeDefinition.UniqueId.ToString())); prop.AppendChild(XmlHelper.AddTextNode(xd, "Tab", ContentType.Tab.GetCaptionById(pt.TabId))); prop.AppendChild(XmlHelper.AddTextNode(xd, "Mandatory", pt.Mandatory.ToString())); prop.AppendChild(XmlHelper.AddTextNode(xd, "Validation", pt.ValidationRegExp)); prop.AppendChild(XmlHelper.AddCDataNode(xd, "Description", pt.Description)); // add this property to the tree props.AppendChild(prop); } } // add properties to the doc doc.AppendChild(props); // tabs XmlElement tabs = xd.CreateElement("Tabs"); foreach (ContentType.TabI t in mt.getVirtualTabs.ToList()) { //only add tabs that aren't from a master doctype if (t.ContentType == mt.Id) { XmlElement tabx = xd.CreateElement("Tab"); tabx.AppendChild(xmlHelper.addTextNode(xd, "Id", t.Id.ToString())); tabx.AppendChild(xmlHelper.addTextNode(xd, "Caption", t.Caption)); tabx.AppendChild(xmlHelper.addTextNode(xd, "Sort", t.SortOrder.ToString())); tabs.AppendChild(tabx); } } doc.AppendChild(tabs); return doc; }
static void MediaType_BeforeDelete(MediaType sender, DeleteEventArgs e) { helpers.XmlDoc.ArchiveFile(sender.GetType().ToString(), GetMediaPath(sender), "def"); e.Cancel = false; }
private Media CreateNewUnderRoot(MediaType mt) { string Name = "TEST-" + Guid.NewGuid().ToString("N"); int ParentId = -1; Media actual = Media.MakeNew(Name, mt, m_User, ParentId); var id = actual.Id; Assert.IsTrue(actual.Id > 0); return actual; }
static void MediaType_AfterSave(MediaType sender, SaveEventArgs e) { SaveToDisk(sender); }
/// <summary> /// Deletes all medias of the given type, used when deleting a mediatype /// /// Use with care. /// </summary> /// <param name="dt"></param> public static void DeleteFromType(MediaType dt) { //get all document for the document type and order by level (top level first) var medias = Media.GetMediaOfMediaType(dt.Id) .OrderByDescending(x => x.Level); foreach (Media media in medias) { //before we delete this document, we need to make sure we don't end up deleting other documents that //are not of this document type that are children. So we'll move all of it's children to the trash first. foreach (Media m in media.GetDescendants()) { if (m.ContentType.Id != dt.Id) { m.MoveToTrash(); } } media.DeletePermanently(); } }