public LibraryGeneratorStatus GetStatus() { if (this.Status == null) { var status = new LibraryGeneratorStatus(); return(status); } else { return(this.Status.Clone()); } }
/// <summary> /// /// </summary> /// <param name="baseUrl">We need the baseUrl to handle metadata fetching for certain media items</param> /// <returns></returns> public async Task Generate(string baseUrl) { try { if (IsGenerating == true) { throw new Exception("Library generation is already in process"); } IsGenerating = true; var oldStatus = this.Status; this.Status = new LibraryGeneratorStatus(); this.Status.StartTime = DateTime.UtcNow; this.Status.IsProcessing = true; this.Status.LastGeneratedDate = oldStatus?.LastGeneratedDate; this.Status.State = "processing movies"; await this.ProcessMovies(); this.Status.State = "processing tv shows"; await this.ProcessSeries(); this.Status.State = "generating search indexes"; this.SearchCatalog.GenerateIndexes(); this.Status.State = "completed"; this.Status.LastGeneratedDate = DateTime.UtcNow; } catch (Exception e) { //find the deepest exception and only keep that while (e.InnerException != null) { e = e.InnerException; } this.Status.State = "failed"; this.Status.Exception = e; } finally { this.Status.IsProcessing = false; } try { var json = JsonConvert.SerializeObject(this.Status); File.WriteAllText(LibraryGenerator.StatusFilePath, json); } catch (Exception) { } IsGenerating = false; }