From 17106ea5c72511f5871178c7f1def629c20191ac Mon Sep 17 00:00:00 2001 From: ebr11 Eric Reed spam Date: Mon, 17 Sep 2012 11:12:43 -0400 Subject: Initial commit changing to on-demand child loading and validations --- MediaBrowser.Controller/Kernel.cs | 66 ++++++++++++++------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) (limited to 'MediaBrowser.Controller/Kernel.cs') diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 47a3773b34..13010ad8ec 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -10,6 +10,7 @@ using MediaBrowser.Controller.Weather; using MediaBrowser.Model.Authentication; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Progress; +using MediaBrowser.Common.Extensions; using System; using System.Collections.Generic; using System.ComponentModel.Composition; @@ -83,8 +84,6 @@ namespace MediaBrowser.Controller DirectoryWatchers = new DirectoryWatchers(); WeatherClient = new WeatherClient(); - ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath; - ItemController.BeginResolvePath += ItemController_BeginResolvePath; } public async override Task Init(IProgress progress) @@ -100,6 +99,13 @@ namespace MediaBrowser.Controller await ReloadRoot(allowInternetProviders: false).ConfigureAwait(false); progress.Report(new TaskProgress() { Description = "Loading Complete", PercentComplete = 100 }); + + //watch the root folder children for changes + RootFolder.ChildrenChanged += RootFolder_ChildrenChanged; + + System.Threading.Thread.Sleep(25000); + var allChildren = RootFolder.RecursiveChildren; + Logger.LogInfo(string.Format("Loading complete. Movies: {0} Episodes: {1}", allChildren.OfType().Count(), allChildren.OfType().Count())); } protected override void OnComposablePartsLoaded() @@ -114,46 +120,20 @@ namespace MediaBrowser.Controller MetadataProviders = MetadataProvidersEnumerable.OrderBy(e => e.Priority).ToArray(); } - /// - /// Fires when a path is about to be resolved, but before child folders and files - /// have been collected from the file system. - /// This gives us a chance to cancel it if needed, resulting in the path being ignored - /// - void ItemController_PreBeginResolvePath(object sender, PreBeginResolveEventArgs e) + public BaseItem ResolveItem(ItemResolveEventArgs args) { - // Ignore hidden files and folders - if (e.IsHidden || e.IsSystemFile) - { - e.Cancel = true; - } - - // Ignore any folders named "trailers" - else if (Path.GetFileName(e.Path).Equals("trailers", StringComparison.OrdinalIgnoreCase)) + // Try first priority resolvers + for (int i = 0; i < EntityResolvers.Length; i++) { - e.Cancel = true; - } + var item = EntityResolvers[i].ResolvePath(args); - // Don't try and resolve files within the season metadata folder - else if (Path.GetFileName(e.Path).Equals("metadata", StringComparison.OrdinalIgnoreCase) && e.IsDirectory) - { - if (e.Parent is Season || e.Parent is Series) + if (item != null) { - e.Cancel = true; + return item; } } - } - /// - /// Fires when a path is about to be resolved, but after child folders and files - /// This gives us a chance to cancel it if needed, resulting in the path being ignored - /// - void ItemController_BeginResolvePath(object sender, ItemResolveEventArgs e) - { - if (e.ContainsFile(".ignore")) - { - // Ignore any folders containing a file called .ignore - e.Cancel = true; - } + return null; } private void ReloadUsers() @@ -178,12 +158,11 @@ namespace MediaBrowser.Controller DirectoryWatchers.Start(); } - public static Guid GetMD5(string str) + void RootFolder_ChildrenChanged(object sender, ChildrenChangedEventArgs e) { - using (var provider = new MD5CryptoServiceProvider()) - { - return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str))); - } + //re-start the directory watchers + DirectoryWatchers.Stop(); + DirectoryWatchers.Start(); } /// @@ -222,7 +201,8 @@ namespace MediaBrowser.Controller } else { - result.Success = GetMD5((password ?? string.Empty)).ToString().Equals(user.Password); + password = password ?? string.Empty; + result.Success = password.GetMD5().ToString().Equals(user.Password); } // Update LastActivityDate and LastLoginDate, then save @@ -261,7 +241,7 @@ namespace MediaBrowser.Controller children.Insert(index, newItem); - item.Parent.Children = children.ToArray(); + //item.Parent.ActualChildren = children.ToArray(); } } @@ -297,7 +277,7 @@ namespace MediaBrowser.Controller user.Id = Guid.NewGuid(); user.LastLoginDate = DateTime.UtcNow.AddDays(-1); user.LastActivityDate = DateTime.UtcNow.AddHours(-3); - user.Password = GetMD5("1234").ToString(); + user.Password = ("1234").GetMD5().ToString(); list.Add(user); user = new User(); -- cgit v1.2.3