/// <summary> /// Initializes a new instance of the <see cref="ModuleTracker"/> class. /// </summary> /// <param name="logger"> /// The logger. /// </param> /// <exception cref="System.ArgumentNullException">The <paramref name="logger"/> is <c>null</c>.</exception> public ModuleTracker(ILoggerFacade logger) { Argument.IsNotNull("logger", logger); this.logger = logger; // These states are defined specifically for the Silverlight version of the quickstart. moduleATrackingState = new ModuleTrackingState { ModuleName = WellKnownModuleNames.ModuleA, ExpectedDiscoveryMethod = DiscoveryMethod.ApplicationReference, ExpectedInitializationMode = InitializationMode.WhenAvailable, ExpectedDownloadTiming = DownloadTiming.WithApplication, ConfiguredDependencies = WellKnownModuleNames.ModuleD, }; moduleBTrackingState = new ModuleTrackingState { ModuleName = WellKnownModuleNames.ModuleB, ExpectedDiscoveryMethod = DiscoveryMethod.XamlManifest, ExpectedInitializationMode = InitializationMode.WhenAvailable, ExpectedDownloadTiming = DownloadTiming.InBackground, }; moduleCTrackingState = new ModuleTrackingState { ModuleName = WellKnownModuleNames.ModuleC, ExpectedDiscoveryMethod = DiscoveryMethod.ApplicationReference, ExpectedInitializationMode = InitializationMode.OnDemand, ExpectedDownloadTiming = DownloadTiming.WithApplication, }; moduleDTrackingState = new ModuleTrackingState { ModuleName = WellKnownModuleNames.ModuleD, ExpectedDiscoveryMethod = DiscoveryMethod.XamlManifest, ExpectedInitializationMode = InitializationMode.WhenAvailable, ExpectedDownloadTiming = DownloadTiming.InBackground, }; moduleETrackingState = new ModuleTrackingState { ModuleName = WellKnownModuleNames.ModuleE, ExpectedDiscoveryMethod = DiscoveryMethod.XamlManifest, ExpectedInitializationMode = InitializationMode.OnDemand, ExpectedDownloadTiming = DownloadTiming.InBackground, }; moduleFTrackingState = new ModuleTrackingState { ModuleName = WellKnownModuleNames.ModuleF, ExpectedDiscoveryMethod = DiscoveryMethod.XamlManifest, ExpectedInitializationMode = InitializationMode.OnDemand, ExpectedDownloadTiming = DownloadTiming.InBackground, ConfiguredDependencies = WellKnownModuleNames.ModuleE, }; }
/// <summary> /// Records the module has been initialized. /// </summary> /// <param name="moduleName"> /// The <see cref="WellKnownModuleNames">well-known name</see> of the module. /// </param> public void RecordModuleInitialized(string moduleName) { ModuleTrackingState moduleTrackingState = GetModuleTrackingState(moduleName); if (moduleTrackingState != null) { moduleTrackingState.ModuleInitializationStatus = ModuleInitializationStatus.Initialized; } logger.Log(string.Format("{0} module initialized.", moduleName), Category.Debug, Priority.Low); }
private void ContentControl_Loaded(object sender, RoutedEventArgs e) { this.UpdateClickToLoadTextBlockVisibility(); this.UpdateLoadProgressTextBlockVisibility(); ModuleTrackingState moduleTrackingState = this.DataContext as ModuleTrackingState; if (moduleTrackingState != null) { moduleTrackingState.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(ModuleTrackingState_PropertyChanged); } }
/// <summary> /// Called before the <see cref="E:System.Windows.UIElement.MouseLeftButtonUp"/> event occurs. /// </summary> /// <param name="e">The data for the event.</param> protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { base.OnMouseLeftButtonUp(e); if (!e.Handled) { ModuleTrackingState moduleTrackingState = this.DataContext as ModuleTrackingState; if ((moduleTrackingState != null) && (moduleTrackingState.ExpectedInitializationMode == InitializationMode.OnDemand) && (moduleTrackingState.ModuleInitializationStatus == ModuleInitializationStatus.NotStarted)) { this.RaiseRequestModuleLoad(); e.Handled = true; } } }
private void UpdateLoadProgressTextBlockVisibility() { ModuleTrackingState moduleTrackingState = this.DataContext as ModuleTrackingState; if ((moduleTrackingState != null) && (moduleTrackingState.ExpectedDownloadTiming == DownloadTiming.InBackground) && (moduleTrackingState.ModuleInitializationStatus == ModuleInitializationStatus.Downloading)) { this.LoadProgressPanel.Visibility = Visibility.Visible; } else { this.LoadProgressPanel.Visibility = Visibility.Collapsed; } }
private void UpdateClickToLoadTextBlockVisibility() { ModuleTrackingState moduleTrackingState = this.DataContext as ModuleTrackingState; if ((moduleTrackingState != null) && (moduleTrackingState.ExpectedInitializationMode == InitializationMode.OnDemand) && (moduleTrackingState.ModuleInitializationStatus == ModuleInitializationStatus.NotStarted)) { this.ClickToLoadTextBlock.Visibility = Visibility.Visible; } else { this.ClickToLoadTextBlock.Visibility = Visibility.Collapsed; } }
/// <summary> /// Records the module is loading. /// </summary> /// <param name="moduleName"> /// The <see cref="WellKnownModuleNames">well-known name</see> of the module. /// </param> /// <param name="bytesReceived"> /// The number of bytes downloaded. /// </param> /// <param name="totalBytesToReceive"> /// The total Bytes To Receive. /// </param> public void RecordModuleDownloading(string moduleName, long bytesReceived, long totalBytesToReceive) { ModuleTrackingState moduleTrackingState = GetModuleTrackingState(moduleName); if (moduleTrackingState != null) { moduleTrackingState.BytesReceived = bytesReceived; moduleTrackingState.TotalBytesToReceive = totalBytesToReceive; if (bytesReceived < totalBytesToReceive) { moduleTrackingState.ModuleInitializationStatus = ModuleInitializationStatus.Downloading; } else { moduleTrackingState.ModuleInitializationStatus = ModuleInitializationStatus.Downloaded; } } logger.Log(string.Format("'{0}' module is loading {1}/{2} bytes.", moduleName, bytesReceived, totalBytesToReceive), Category.Debug, Priority.Low); }