/// <summary> /// Validates state of the specified handler. /// </summary> /// <param name="expected">The expected initialize state.</param> /// <param name="handler">The initialize state handler to validate.</param> /// <param name="throws">The value that determines whether to throw exception on invalid validate result.</param> public static bool ValidateState(bool expected, IInitialize handler, bool throws = true) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } return(ValidateState(expected, handler.IsInitialized, handler.ToString(), throws)); }
public InitializeScope(IInitialize target) { m_target = target ?? throw new ArgumentNullException(nameof(target)); if (!m_target.IsInitialized) { m_target.Initialize(); } }
public void Execute(object command, IInitialize executor) { try { executor.Init(command); } finally { _container.Release(executor); } }
protected override void Awake() { base.Awake(); m_initializer = GetComponentInChildren <IInitialize>(); if (!GameManager.Exists) { Instantiate(m_gameManagerPrefab); } Gameplay.TimeManager.Instance.ClearLevelTimer(); Gameplay.TimeManager.Instance.SetTimeScale(1, 0); StartCoroutine(Initialize_Coroutine()); }
protected virtual void CreateManagersInstance() { for (int i = 0; i < managersList.Length; i++) { var instance = GameObject.Instantiate(managersList[i], transform); IInitialize initialize = instance.GetComponentInChildren <IInitialize>(); if (initialize != null) { ObjectInitializationCallBack.AddListener(initialize.Initialize); } if (_timeManager == null) { _timeManager = instance.GetComponentInChildren <ITimeManager>(); } } }
public void Initialize(IProgressMonitor monitor) { if (this.type == "Flash") { this.ConvertFlashSolution(monitor); this.type = "CocosStudio"; } foreach (SolutionEntityItem current in this.RootFolder.Items) { IInitialize initialize = current as IInitialize; if (initialize != null) { initialize.Initialize(monitor); } } this.SetPublishDirectory(); }
public bool TryGet(Type type, out IInitialize item) { if (type == null) { throw new ArgumentNullException(nameof(type)); } for (int i = 0; i < m_collection.Count; i++) { item = m_collection[i]; if (type.IsInstanceOfType(item)) { return(true); } } item = null; return(false); }
public void LoaderMustCallCustomLoaderActions() { var mockContainer = new Mock <IServiceContainer>(); var mockListing = new Mock <IDirectoryListing>(); var loader = new Loader <IServiceContainer>(); loader.DirectoryLister = mockListing.Object; // Return an empty file listing mockListing.Expect(listing => listing.GetFiles(It.IsAny <string>(), It.IsAny <string>())) .Returns(new string[0]); // Use the initializer mock to verify // that the custom action was called var mockInitializer = new Mock <IInitialize>(); mockInitializer.Expect(initializer => initializer.Initialize(mockContainer.Object)); // HACK: In order to verify the call, // we need to adapt the mock to an // Action<ILoader<IServiceContainer>> instance Action <ILoader <IServiceContainer> > customAction = targetLoader => { IInitialize initializer = mockInitializer.Object; IServiceContainer container = mockContainer.Object; // The test will only succeed if // the following line of code // is invoked: initializer.Initialize(container); }; loader.CustomLoaderActions.Add(customAction); loader.LoadInto(mockContainer.Object); mockInitializer.VerifyAll(); }
/// <summary> /// Initializes the <paramref name="target"/> with the given <paramref name="source"/> instance. /// </summary> /// <param name="target">The target to initialize.</param> /// <param name="source">The instance that will be introduced to the <see cref="IInitialize{T}"/> instance.</param> private static void Initialize(IInitialize <T> target, T source) { if (target == null) { return; } if ((_initializeCallCount = ++_initializeCallCount % 100) == 0) { _instances.RemoveWhere(w => !w.IsAlive); } // Make sure that the target is initialized only once var weakReference = new HashableWeakReference(target); if (_instances.Contains(weakReference)) { return; } // Initialize the target target.Initialize(source); _instances.Add(weakReference); }
bool IInitializeCollection.Remove(IInitialize item) { return(Remove((TItem)item)); }
void IInitializeCollection.Add(IInitialize item) { Add((TItem)item); }
bool IInitializeCollection.Contains(IInitialize item) { return(Contains((TItem)item)); }
/// <summary> /// Validates state of the specified handler. /// </summary> /// <param name="handler">The initialize state handler to validate.</param> /// <param name="expected">The expected initialize state.</param> /// <param name="throws">The value that determines whether to throw exception on invalid validate result.</param> public static bool ValidateState(this IInitialize handler, bool expected, bool throws = true) { return(InitializeUtility.ValidateState(expected, handler, throws)); }