예제 #1
0
파일: HttpMime.cs 프로젝트: tomaspsenak/hmc
        public override bool Equals(object obj)
        {
            HttpMime mime = obj as HttpMime;

            if (mime == null)
            {
                return(false);
            }

            return(this.extension == mime.extension);
        }
예제 #2
0
        public override void RefreshMe(DataContext context, ItemManager manager, bool recursive)
        {
            if (manager.UpnpDevice.Stopping)
            {
                return;
            }

            try
            {
                //Rozdielova obnova adresarov
                IEnumerable <string> directories = new DirectoryInfo(this.Path).GetDirectories().Where(
                    a => manager.ShowHiddenFiles || (a.Attributes & FileAttributes.Hidden) == 0).Select(a => a.FullName).ToArray();

                Item[] toRemove = this.Items.Where(a => a.GetType() == typeof(ItemContainer)).Except(
                    directories, new PathItemEqualityComparer()).Cast <Item>().ToArray();
                string[] toAdd = directories.Except(this.Items.Where(a => a.GetType() == typeof(ItemContainer)).Select(a => a.Path)).ToArray();

                RemoveRange(context, manager, toRemove);

                foreach (string path in toAdd)
                {
                    Item item = new ItemContainer(System.IO.Path.GetFileName(path), path, this);
                    //Ak nie je rekurzia - obnovia sa iba nove adresare
                    if (!recursive)
                    {
                        item.RefreshMe(context, manager, false);
                    }
                }

                //Rozdielova obnova suborov
                IEnumerable <PathMime> files = new DirectoryInfo(this.Path).GetFiles().Where(
                    a => manager.ShowHiddenFiles || (a.Attributes& FileAttributes.Hidden) == 0).Select(
                    delegate(FileInfo a) {
                    HttpMime mime = manager.GetMimeType(a.Extension);
                    if (mime == null || mime.MediaType == MediaType.Other)
                    {
                        return(null);
                    }
                    return(new PathMime()
                    {
                        Path = a.Name, Mime = mime
                    });
                }).Where(a => a != null).ToArray();

                toRemove = this.Items.Where(a => a.GetType() != typeof(ItemContainer)).Except(
                    files.Select(a => a.Path), new PathItemEqualityComparer()).Cast <Item>().ToArray();
                PathMime[] toAddFile = files.Cast <object>().Except(this.Items.Where(a => a.GetType() != typeof(ItemContainer)).Select(
                                                                        a => a.Path), new PathMimeEqualityComparer()).Cast <PathMime>().ToArray();

                RemoveRange(context, manager, toRemove);

                foreach (PathMime pathMime in toAddFile)
                {
                    try
                    {
                        FileInfo fi = new FileInfo(System.IO.Path.Combine(this.Path, pathMime.Path));

                        switch (pathMime.Mime.MediaType)
                        {
                        case MediaType.Audio: new ItemAudio(fi, pathMime.Mime.ToString(), this); break;

                        case MediaType.Image: new ItemImage(fi, pathMime.Mime.ToString(), this); break;

                        case MediaType.Video: new ItemContainerVideo(fi, pathMime.Mime.ToString(), this); break;
                        }
                    }
                    catch { }
                }

                if (recursive)
                {
                    //Volanie obnovy do adresarov a prvkov
                    foreach (Item item in this.Items)
                    {
                        item.RefreshMe(context, manager, true);
                    }
                }
                else
                {
                    //Volanie obnovy pre subory vratane ItemContainerVideo - overenie ci sa nezmenil titulkovy subor
                    foreach (Item item in this.items.Where(a => a.GetType() != typeof(ItemContainer)))
                    {
                        item.RefreshMe(context, manager, false);
                    }
                }
            }
            catch { }
        }
예제 #3
0
 public void Add(HttpMime mime)
 {
     this.mime.Add(mime.Extension, mime);
 }