public void DefaultCatalogTest() { StringBuilder expectedOutput = new StringBuilder(); StringBuilder actualOutput = new StringBuilder(); actualOutput.AppendLine("No items found"); actualOutput.AppendLine("Application added"); actualOutput.AppendLine("Book added"); actualOutput.AppendLine("Song added"); actualOutput.AppendLine("Movie added"); actualOutput.AppendLine("Song: One; Metallica; 8771120; http://goo.gl/dIkth7gs"); actualOutput.AppendLine("Movie added"); actualOutput.AppendLine("Movie: One; James Wong (2001); 969763002; http://www.imdb.com/title/tt0267804/"); actualOutput.AppendLine("Song: One; Metallica; 8771120; http://goo.gl/dIkth7gs"); actualOutput.AppendLine("1 items updated"); actualOutput.AppendLine("Book: Intro C#; S.Nakov; 12763892; http://introprograming.info/en/"); actualOutput.AppendLine("0 items updated"); StringBuilder input = new StringBuilder(); input.AppendLine("Find: One; 3"); input.AppendLine("Add application: Firefox v.11.0; Mozilla; 16148072; http://www.mozilla.org "); input.AppendLine("Add book: Intro C#; S.Nakov; 12763892; http://www.introprogramming.info"); input.AppendLine("Add song: One; Metallica; 8771120; http://goo.gl/dIkth7gs"); input.AppendLine("Add movie: The Secret; Drew Heriot, Sean Byrne & others (2006); 832763834; http://t.co/dNV4d"); input.AppendLine("Find: One; 1"); input.AppendLine("Add movie: One; James Wong (2001); 969763002; http://www.imdb.com/title/tt0267804/"); input.AppendLine("Find: One; 10"); input.AppendLine("Update: http://www.introprogramming.info; http://introprograming.info/en/"); input.AppendLine("Find: Intro C#; 1"); input.AppendLine("Update: http://nakov.com; sftp://www.nakov.com"); input.AppendLine("End"); input.AppendLine(string.Empty); sr = new StringReader(input.ToString()); Console.SetIn(sr); using (sr) { StringBuilder output = new StringBuilder(); ContentCatalog catalog = new ContentCatalog(); ICommandExecutor executor = new CommandExecutor(); List <ICommand> commands = catalog.Parse(); foreach (ICommand command in commands) { executor.ExecuteCommand(catalog, command, expectedOutput); } } Assert.AreEqual(expectedOutput.ToString(), actualOutput.ToString(), "Incorrect result"); }
/// <summary> /// Get the ContentCatalog stored in `catalog.json`. /// </summary> /// <returns></returns> public static ContentCatalog GetCatalog() { if (catalog == null) { if (!File.Exists("./catalog.json")) { throw new Exception("Catalog not found. To use this class, make sure you have a content catalog stored at catalog.json in the build directory."); } var json = File.ReadAllText("./catalog.json"); catalog = JsonConvert.DeserializeObject <ContentCatalog>(json); // Mutate IDs, otherwise we run into a bug with the export server, collisions with shared catalogs, big messy mess. foreach (var element in catalog.Content) { element.Id = Guid.NewGuid(); } } return(catalog); }
public void CatalogSerialization() { ContentElement boxType = new ContentElement("../../../models/MergeGlTF/Workstation_Pod_SemiPrivate_Harbour - Semi 1600w x 1300d 3.glb", new BBox3(new Vector3(-0.5, -0.5, 0), new Vector3(0.5, 0.5, 3)), 1, new Vector3(), new Transform(new Vector3(), Vector3.ZAxis), BuiltInMaterials.Default, null, true, Guid.NewGuid(), "BoxyType"); ContentElement boxType2 = new ContentElement("../../../models/MergeGlTF/Box.glb", new BBox3(new Vector3(-1, -1, 0), new Vector3(1, 1, 2)), 1, new Vector3(), new Transform(new Vector3(), Vector3.YAxis), BuiltInMaterials.Default, null, true, Guid.NewGuid(), "BoxyType"); var str = boxType2.ToString(); boxType.AdditionalProperties["ImportantParameter"] = "The Value"; var testCatalog = new ContentCatalog(new List <ContentElement> { boxType, boxType2 }, Guid.NewGuid(), "test"); var savePath = "../../../models/ContentCatalog.json"; var json = testCatalog.ToJson(); File.WriteAllText(savePath, json); var loadedCatalog = ContentCatalog.FromJson(File.ReadAllText(savePath)); File.Delete(savePath); Assert.Equal(testCatalog.Id, loadedCatalog.Id); Assert.Equal(testCatalog.Content.Count, loadedCatalog.Content.Count); Assert.Equal("The Value", loadedCatalog.Content[0].AdditionalProperties["ImportantParameter"]); }
/// <summary> /// Get the ContentCatalog stored in `catalog.json`. /// </summary> /// <returns></returns> public static ContentCatalog GetCatalog() { if (catalog == null) { var catalogPath = catalogFilePath ?? Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "catalog.json"); if (!File.Exists(catalogPath)) { throw new Exception("Catalog not found. To use this class, make sure you have a content catalog stored at catalog.json in the build directory."); } var json = File.ReadAllText(catalogPath); catalog = ContentCatalog.FromJson(json); // Mutate IDs, otherwise we run into a bug with the export server, collisions with shared catalogs, big messy mess. foreach (var element in catalog.Content) { element.Id = Guid.NewGuid(); } } return(catalog); }
public MainPageVm(ContentCatalog catalog) { Helpers.Argument.ValidateIsNotNull(catalog, nameof(catalog)); ToggleAutoResume = new DelegateCommand { Execute = delegate { App.Current.Settings.IsAutoResumeEnabled = !App.Current.Settings.IsAutoResumeEnabled; } }; ToggleBackgroundDownload = new DelegateCommand { Execute = async delegate { await BackgroundTaskManager.ToggleIsBackgroundDownloadEnabled(); } }; UpdateSettings(); #region WeakEventListener: App.Current.Settings.PropertyChanged += OnSettingsChanged var settingsListener = new WeakEventListener<MainPageVm, object, PropertyChangedEventArgs>(this); settingsListener.OnEventAction = (instance, source, args) => instance.OnSettingsChanged(source, args); settingsListener.OnDetachAction = (wel) => App.Current.Settings.PropertyChanged -= wel.OnEvent; App.Current.Settings.PropertyChanged += settingsListener.OnEvent; #endregion _catalogItems = catalog.Items.Select(i => new CatalogItemOverviewVm(i)).ToArray(); }
protected override async void OnLaunched(LaunchActivatedEventArgs e) { // This method runs on UI thread, so starting from here we can work with UI-thread-related things. _log.Debug("Launched. {0}", Helpers.Debug.ToDebugString(e)); // If the app was already running, we skip just about all of this and get to the UI immediately. if (e.PreviousExecutionState != ApplicationExecutionState.Running) { // The startup lifetime seems pretty complicated in UWP. // Unclear when this can happen; let's just throw if it does, to find out! if (MediaStorageSession != null) throw new Exception("WTF just happened? Tell Sander when you encounter this situation and describe how it happened, please!"); MediaStorageSession = new TransientMediaStorageSession(); ContentCatalog = new ContentCatalog(MediaStorageSession); EnsureRootFrame(); UpdateBackButtonVisibility(); // Always go to main page on launch, to keep the implementation of this sample app very simple. _rootFrame.Navigate(typeof(MainPage), new MainPageVm(ContentCatalog)); } _log.Debug("Displaying UI now."); // This displays our window to the user and thus we want to get here ASAP. Window.Current.Activate(); if (e.PreviousExecutionState != ApplicationExecutionState.Running) { _log.Debug("Executing post-launch initialization."); var uiThreadTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); // Kick off some initialization on a background thread, to not hog the UI thread so much. Helpers.Async.BackgroundThreadInvoke(async delegate { // Note that this may not immediately terminate the task if it is running! // Resources may remain locked for some seconds, still, and we need to account for this. BackgroundTaskManager.UnregisterAndTerminateBackgroundDownloadTask(); try { // Activate PlayReady if required. await Helpers.PlayReady.EnsureActivatedAsync().IgnoreContext(); } catch (Exception ex) { _log.Error("PlayReady activation startup logic failed: " + ex.Message); } // Now we allow access to PlayReady. This may have deferred some license status refreshes already. PlayReadyInitialized = true; // Kick off an update of the license acquisition statuses, now that PlayReady is known to be activated. // We need to do this on the UI thread, so the changed events are raised on the UI thread. Task.Factory.StartNew(async delegate { await ContentCatalog.RefreshLicenseStatusesAsync(); }, CancellationToken.None, TaskCreationOptions.None, uiThreadTaskScheduler).Forget(); }); // This will acquire the storage session soon, waiting for the background task to finish if it is running. // This must be done on the UI thread, to ensure that the MediaAgents also get created on the UI thread. await MediaStorageSession.StartAcquireAsync(); } _log.Debug("Post-launch logic complete."); }