/// <summary> /// Initialize the specified instance. All exceptions from the invocation of instance.Initialize() will be swallowed. /// </summary> /// <param name="instance">Instance to intialize.</param> private bool Initialize(IInitializable instance) { string instanceName = instance.GetType().Name; try { this.LogTrace("Initializing " + instanceName, LogCategory.INITIALIZATION); #if METRICS_ENABLED && INCLUDE_DEV_METRICS Metrics.Start("Initialize:" + instanceName); #endif instance.Initialize(InstanceInitialized); } catch (Exception e) { #if METRICS_ENABLED && INCLUDE_DEV_METRICS Metrics.End("Initialize:" + instanceName); #endif // An exception was thrown, so we will never complete. Invoke failedCallback. this.LogError("Exception initializing " + (instance != null ? instance.ToString() : "null instance") + ": " + e.ToString()); Failure(e.ToString()); // Stop initialization of any future instances return(false); } // Continue initialization return(true); }
/// <summary> /// Callback invoked internally by an instance when it has completed initialization. /// </summary> /// <param name="instance">Instance that completed.</param> private void InstanceInitialized(IInitializable instance) { #if METRICS_ENABLED && INCLUDE_DEV_METRICS Metrics.End("Initialize:" + instance.GetType().Name); #endif try { if (_progressCallback != null) { _progressCallback(_instances[_instanceIdx], _instanceCount, _instanceIdx); } ++_instanceIdx; if (Debug.isDebugBuild) { LogProgress(); } if (_remainingCount <= 0) { Success(); } else if (_chained) { Initialize(_instances[_instanceIdx]); } // Swallow exception to prevent firing _failedCallback as a result of exception in InstanceInitialized/_successCallback } catch (Exception e) { this.LogError("Exception in InstanceInitialized() at index " + _instanceIdx + ": " + e.ToString()); } }
private void OnStepComplete(IInitializable initializable) { if (_steps.Peek() != initializable) { return; } _steps.Dequeue(); Debug.Log($"[{nameof(GameStateController)}] {nameof(OnStepComplete)} Completed {initializable.GetType().Name}"); new EventCommand(GameEvents.StateMachineEvents.End, initializable.GetType().Name).Execute(); NextState(); }
private static AssemblyModel ConvertAssembly(IInitializable service) { var assembly = service.GetType().Assembly; var assemblyName = assembly.GetName(); var bundleAtt = assembly.GetCustomAttribute <BundleAttribute>(); var model = new AssemblyModel { Name = assemblyName.Name + ".dll", Version = assemblyName.Version.ToString(), Bundle = bundleAtt == null ? "Unknown" : bundleAtt.Bundle }; return(model); }
private void OnStepComplete(IInitializable completedStep) { if (_steps.Peek() != completedStep) { return; } Debug.Log($"[{GetType()}] {nameof(OnStepComplete)} {completedStep.GetType()}"); _steps.Dequeue(); if (!TryCompleteQueue()) { InitializeStep(); } }
private static AssemblyModel ConvertAssembly(IInitializable service) { var assembly = service.GetType().Assembly; var assemblyName = assembly.GetName(); var assemblyVersion = assemblyName.Version; var fileVersionAttr = assembly.GetCustomAttribute <AssemblyFileVersionAttribute>(); var informationalVersionAttr = assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>(); var model = new AssemblyModel { Name = assemblyName.Name + ".dll", Version = assemblyVersion.Major + "." + assemblyVersion.Minor + "." + assemblyVersion.Build, FileVersion = fileVersionAttr?.Version, InformationalVersion = informationalVersionAttr?.InformationalVersion }; return(model); }
public InitializableManager( [Inject(Optional = true, Source = InjectSources.Local)] List <IInitializable> initializables, [Inject(Optional = true, Source = InjectSources.Local)] List <ModestTree.Util.ValuePair <Type, int> > priorities) { _initializables = new List <InitializableInfo>(); for (int i = 0; i < initializables.Count; i++) { IInitializable initializable = initializables[i]; // Note that we use zero for unspecified priority // This is nice because you can use negative or positive for before/after unspecified List <int> matches = priorities.Where(x => initializable.GetType().DerivesFromOrEqual(x.First)).Select(x => x.Second).ToList(); int priority = matches.IsEmpty() ? 0 : matches.Distinct().Single(); _initializables.Add(new InitializableInfo(initializable, priority)); } }
private void ProcessState(IInitializable step) { Debug.Log($"[{nameof(GameStateController)}] {nameof(ProcessState)} {step.GetType().Name}"); new EventCommand(GameEvents.StateMachineEvents.Start, step.GetType().Name).Execute(); step.Initialize(OnStepComplete); }
private void OnInitializingComponent(object sender, IInitializable initializable) { RaiseChangeValueWithMessage(string.Format(Strings.ComponentInitializerLoaderAdapter_InitializingComponent, initializable.GetType().Name)); }