Beispiel #1
0
        public void AssetLibrary_UnitTest_CreateNewAsset()
        {
            // Get root node first
            TreeNode[] treeNodes = TreeManager.GetRootNodes(Folder.GetAssignedMetaClass());

            if (treeNodes.Length == 0)
            {
                Assert.Fail("Asset library must have atleast one root node defined");
            }

            int rootNodeId = treeNodes[0].ObjectId;

            // Create new Folder
            Guid   folderName = Guid.NewGuid();
            Folder folder     = new Folder();

            folder.Name = folderName.ToString();
            folder.Save();
            TreeNode currenFolder = TreeManager.AppendNode(Folder.GetAssignedMetaClass(), rootNodeId, true, folder);

            // Read file
            FileStream    fileStream = File.Open("winter.jpg", FileMode.Open);
            FolderElement newFile    = FolderElement.Create(currenFolder.ObjectId, fileStream.Name, fileStream);

            // Now create a business object that will store meta data
            BusinessObject businessObject = MetaObjectActivator.CreateInstance <BusinessObject>("FolderElement", newFile.PrimaryKeyId.Value);

            // Now set business object fields
            businessObject.Properties["Description"].Value = "Some description goes here";

            // Save business object
            businessObject.Save();

            FolderElement[] myElements = FolderElement.List <FolderElement>(FolderElement.GetAssignedMetaClass(), new FilterElement[] { new FilterElement("FolderElementId", FilterElementType.Equal, newFile.PrimaryKeyId.Value.ToString()) });
            Assert.IsTrue(myElements.Length > 0, "No File FolderElement found. File must have not been created");
            myElements[0].Delete();

            Folder[] myFolders = Folder.List <Folder>(Folder.GetAssignedMetaClass(), new FilterElement[] { new FilterElement("FolderId", FilterElementType.Equal, currenFolder.ObjectId.ToString()) });
            Assert.IsTrue(myFolders.Length > 0, "No Folder found. Folder must have not been created");
            myFolders[0].Delete();

            /*
             * // Assign asset to an entry
             * CatalogEntryDto entryDto = CatalogContext.Current.GetCatalogEntryDto("samplecode", new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Assets));
             *
             * if(entryDto.CatalogEntry.Count == 0)
             *  Assert.Fail("specified entry could not be located");
             *
             * // Associate file with an entry
             * CatalogEntryDto.CatalogItemAssetRow row = entryDto.CatalogItemAsset.NewCatalogItemAssetRow();
             * row.AssetType = "file"; // specify "folder", if type is folder
             * row.AssetKey = newFile.PrimaryKeyId.ToString();
             * row.CatalogEntryId = entryDto.CatalogEntry[0].CatalogEntryId; // specify CatalogNodeId if associated with a category
             * row.GroupName = "images";
             * row.SortOrder = 0;
             *
             * entryDto.CatalogEntry.Rows.Add(row);
             *
             * // Save the new data
             * CatalogContext.Current.SaveCatalogEntry(entryDto);
             * */
        }
Beispiel #2
0
 /// <summary>
 /// Moves the specified folder.
 /// </summary>
 /// <param name="folder">The folder.</param>
 /// <param name="newParentId">The new parent id.</param>
 public static void Move(Folder folder, int newParentId)
 {
     TreeManager.AppendNode(GetAssignedMetaClass(), newParentId, folder);
 }