public InitializeScope(IInitialize target)
        {
            m_target = target ?? throw new ArgumentNullException(nameof(target));

            if (!m_target.IsInitialized)
            {
                m_target.Initialize();
            }
        }
Exemple #2
0
 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();
 }
Exemple #3
0
        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();
        }
Exemple #4
0
        /// <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);
        }