示例#1
0
        private TreeItem[] getItems(string path)
        {
            if (!Directory.Exists(path))
                path = _sharedRoot;

            var subdirs = Directory.GetDirectories(path);
            var files = Directory.GetFiles(path);

            var result = new List<TreeItem>();

            foreach (var subdir in subdirs)
            {
                var item = new TreeItem();
                item.Type = ItemType.folder;
                item.Path = subdir;
                item.Children = Directory.GetDirectories(subdir).Length;

                result.Add(item);
            }

            foreach (var file in files)
            {
                var item = new TreeItem();
                item.Type = ItemType.file;
                item.Path = file;
                item.Children = 0;

                result.Add(item);
            }

            return result.ToArray();
        }
示例#2
0
        private string ToDIDL_Lite(TreeItem item)
        {
            //0-path, 1-parentFolderPath, 2-item name, 3-children count,4-item type,5-shared path,6-upnp object type
            string formatPattern = "";
            switch (item.Type)
            {
                case ItemType.folder:
                    formatPattern =
            @"<container id=""{0}"" parentID=""{1}"" restricted=""1"">
            <dc:title>{2}</dc:title>
            <upnp:class>object.container</upnp:class>
            </container>";
                    break;
                case ItemType.file:
                    formatPattern =
            @"<item id=""{0}"" parentID=""{1}"" restricted=""1"">
              <dc:title>{2}</dc:title>
              <dc:creator>Jmeno autora - nezname</dc:creator>
              <upnp:class>{6}</upnp:class>
              <upnp:genre>Nazev zanru - neznamy</upnp:genre>
              <upnp:artist role=""Performer"">Jmeno umelce - nezname</upnp:artist>
              <upnp:album>Nazev alba/serie - nezname</upnp:album>
              <dc:date>2012-06-23</dc:date>
              <upnp:actor>Jmeno herce - nezname</upnp:actor>
              <res protocolInfo=""http-get:*:video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=AVC_TS_HD_50_AC3_T;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01500000000000000000000000000000"">{5}</res>
               </item>";
                    break;
            }

            var info=Directory.GetParent(item.Path);
            var parentPath =info.FullName ;
            if (parentPath == _sharedRoot)
                parentPath = "0";

            var itemName = Path.GetFileName(item.Path);
            var networkPath = _networkRoot + "/" + item.Path.Substring(_sharedRoot.Length);
            var upnpType = upnpObjectType(item.Path);

            return string.Format(formatPattern, item.Path, parentPath, itemName, item.Children, item.Type, networkPath.Replace(" ","%20"),upnpType);
        }
示例#3
0
        /// <summary>
        /// Returns didl formated metadata from object with id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        internal DIDLResult ToDIDL_Lite_Meta(string id)
        {
            if (!id.Contains(_sharedRoot))
                id = _sharedRoot + @"\" + id;

            var isFolder = Directory.Exists(id);

            var item = new TreeItem();
            item.Type =isFolder?ItemType.folder:ItemType.file;
            item.Path = id;
            item.Children = isFolder?Directory.GetDirectories(id).Length:0;

            var didl = encapsulateWithDIDL(item);
            return new DIDLResult(didl, 1, 1);
        }