Esempio n. 1
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Microsoft.Practices.RecipeFramework.GuidancePackage package = (Microsoft.Practices.RecipeFramework.GuidancePackage)provider.GetService(typeof(IExecutionService));
            string basepath = @"c:\";
            string temp     = package.BasePath;

            if (Directory.Exists(temp))
            {
                basepath = temp;
                temp     = string.Format(CultureInfo.InvariantCulture, @"{0}\Templates", basepath);
                if (Directory.Exists(temp))
                {
                    basepath = temp;
                    if (!string.IsNullOrEmpty(AdditionalSubPath))
                    {
                        temp = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}", basepath, AdditionalSubPath);
                        if (Directory.Exists(temp))
                        {
                            basepath = temp;
                        }
                    }
                }
            }
            initialDirectory = basepath;
            return(base.EditValue(context, provider, value));
        }
Esempio n. 2
0
        public void EnableDisablePackage()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(Utils.MakeTestRelativePath("RecipeTest.xml")));

            Manager.EnablePackage(package);
            package.Disposed += new EventHandler(OnPackageDisposed);
            Manager.DisablePackage(package.Configuration.Name);

            Assert.IsTrue(Flags[0], "Package was not disposed");
        }
Esempio n. 3
0
        public void WizardChangeMonitoring()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("ValueProviderTests.xml"));

            EnablePackage(package);

            package.Execute(new MockObjects.MockReference("TestChangeNotification", ""));

            Assert.IsTrue(Flags[0]);
            Assert.AreEqual("A new value-B", Values["B"]);
        }
Esempio n. 4
0
 private void EnablePackage(GuidancePackage guidancePackage, bool UseMock)
 {
     Manager.EnablePackage(guidancePackage);
     if (UseMock)
     {
         guidancePackage.AddService(typeof(IValueGatheringService), new MockServices.MockArgumentGatheringService());
     }
     else
     {
         guidancePackage.AddService(typeof(IValueGatheringService), new WizardFramework.WizardGatheringService());
     }
 }
Esempio n. 5
0
        public void SuccessfullAction()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(Utils.MakeTestRelativePath("ActionExecutionTests.xml")));

            Manager.EnablePackage(package);

            package.Execute(new MockObjects.MockReference("SuccessfullAction", ""));

            // Check the "SuccessAction" action was executed.
            Assert.IsNotNull(Tracker.Executed[typeof(SuccessAction)]);
        }
Esempio n. 6
0
        public void EnableCancel()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("RecipeTest.xml"));

            Manager.AddService(typeof(Services.IHostService),
                               new TestHost(Manager, true, false, false));

            Manager.EnablePackage(package);
            Assert.IsNull(Manager.GetPackage(package.Configuration.Name),
                          "Host shouldn't have let package to get enabled");
        }
Esempio n. 7
0
        public void ValueProviderLifeCycle()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("ValueProviderTests.xml"));

            EnablePackage(package);

            package.Execute(new MockObjects.MockReference("TestLifeCycle", ""));

            Assert.IsTrue(Flags[0]);
            Assert.IsTrue(Flags[1]);
        }
Esempio n. 8
0
        public void CanReplaceExecutionService()
        {
            MockActionExecutionService exec = new MockActionExecutionService();
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("RecipeTest.xml"));

            EnablePackage(package);
            package.AddService(typeof(IActionExecutionService), exec);

            package.Execute(new MockObjects.MockReference("TestRecipe", ""));

            Assert.IsTrue(exec.ExecuteCalled, "Custom execution service was not called");
        }
Esempio n. 9
0
        public void ExecuteHost()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(Utils.MakeTestRelativePath("RecipeTest.xml")));

            Manager.AddService(typeof(Services.IHostService),
                               new TestHost(Manager, false, false, false));

            Manager.EnablePackage(package);
            Assert.IsTrue(Flags[0], "Host was not called at package enabling time");
            Manager.DisablePackage(package.Configuration.Name);
            Assert.IsTrue(Flags[1], "Host was not called at package disabling time");
        }
Esempio n. 10
0
        /// <summary>
        /// Disables a package.
        /// </summary>
        /// <param name="packageName">Name of the package to disable.</param>
        /// <remarks>
        /// Disabling a package causes it to be disposed also.
        /// </remarks>
        public void DisablePackage(string packageName)
        {
            if (packageName == null)
            {
                throw new ArgumentNullException("packageName");
            }
            GuidancePackage package = GetPackage(packageName);

            if (package != null)
            {
                package.AfterRecipeExecution -= new RecipeEventHandler(package_AfterRecipeExecution);
                Remove(package);
            }
        }
Esempio n. 11
0
        //[Ignore("Test display a dialog and waits for input, Daniel to fix it")]
        public void ValueEditorChangeMonitoring()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("ValueProviderTests.xml"));

            EnablePackage(package);

            // Set a value for the FirstValueProvider class to pick.
            Values["FirstValueProvider"]  = "Hi there";
            Values["ConcatValueProvider"] = " from B";

            package.Execute(new MockObjects.MockReference("ValueEditorChangeMonitoring", ""));
            Assert.IsTrue(Flags[0]);
            Assert.AreEqual("Bye Hi there from B", Values["ConcatValueProvider"]);
        }
Esempio n. 12
0
        public void TryChangeValueProviderAfter()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(
                                                              Utils.MakeTestRelativePath("Services\\ReadOnlyDictionaryServiceTests.xml")));

            EnablePackage(package, true);
            try
            {
                package.Execute(new MockObjects.MockReference("TryChangeValueProviderAfter", ""));
            }
            catch (ValueProviderException aex)
            {
                throw aex.InnerException;
            }
        }
Esempio n. 13
0
        public void LoadPackage()
        {
            RecipeManager mgr = new RecipeManager();

            // Setup dependent services.
            mgr.RemoveService(typeof(System.ComponentModel.Design.ITypeResolutionService));
            mgr.AddService(typeof(System.ComponentModel.Design.ITypeResolutionService), new MockServices.MockTypeResolutionService());
            mgr.AddService(typeof(Services.IPersistenceService), new MockServices.MockPersistenceService());
            Configuration.GuidancePackage config = new Configuration.GuidancePackage();
            config.Name          = "Test package";
            config.SchemaVersion = "1.0";
            config.Caption       = "Test package caption";
            GuidancePackage package = new GuidancePackage(config);

            mgr.Add(package);
        }
Esempio n. 14
0
        public void SetUp()
        {
            Manager = new RecipeManager();
            Manager.AddService(typeof(IPersistenceService), new MockPersistenceService());
            Manager.AddService(typeof(EnvDTE._DTE), new MockServices.MockDte());
            Manager.AddService(typeof(IValueGatheringService), new WizardFramework.WizardGatheringService());
            Flags = new bool[10];

            Configuration.GuidancePackage package = GuidancePackage.ReadConfiguration(
                Utils.MakeTestRelativePath("PackageManagementTest.xml"));

            Manager.AddService(typeof(IHostService), new TestHost(package.Host));

            //// Install host
            //ManifestInstallerTest.InstallHost(package.Host, typeof(TestInstaller), false);
            //// Install package.
            //ManifestInstallerTest.InstallPackage(
            //    Utils.MakeTestRelativePath("PackageManagementTest.xml"), false);
        }
Esempio n. 15
0
        /// <summary>
        /// Enables a package.
        /// </summary>
        /// <param name="configuration">
        /// Configuration to use for the new package.
        /// </param>
        /// <returns>
        /// Returns the loaded and enabled package.
        /// </returns>
        public GuidancePackage EnablePackage(Configuration.GuidancePackage configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            GuidancePackage package = new GuidancePackage(configuration);

            try
            {
                package.AfterRecipeExecution += new RecipeEventHandler(package_AfterRecipeExecution);
                Add(package);
            }
            catch
            {
                package.Dispose();
                throw;
            }
            return(package);
        }
Esempio n. 16
0
        public void FailAction()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(Utils.MakeTestRelativePath("ActionExecutionTests.xml")));

            Manager.EnablePackage(package);

            try
            {
                // Must fail.
                package.Execute(new MockObjects.MockReference("FailAction", ""));
            }
            catch
            {
                // We passed.
                return;
            }

            Assert.Fail("Execution should have failed.");
        }
Esempio n. 17
0
        public void FailedActionIsNotUndone()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(new XmlTextReader(Utils.MakeTestRelativePath("ActionExecutionTests.xml")));

            Manager.EnablePackage(package);

            try
            {
                // Must fail.
                package.Execute("FailAction");
            }
            catch (ActionExecutionException)
            {
                Assert.IsNull(Tracker.Undone[typeof(FailAction)]);

                // We passed.
                return;
            }

            Assert.Fail("Execution should have failed.");
        }
Esempio n. 18
0
        public void ExecuteNullWizardNoGathering()
        {
            // Load the package from the config.
            GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("RecipeTest.xml"));

            // Don't add the gathering service to the package.
            Manager.EnablePackage(package);
            Manager.AddService(typeof(IUIService), new MockServices.MockUIService());
            try
            {
                ExecutionResult result = package.Execute(new MockObjects.MockReference("TestRecipe", ""));
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                else
                {
                    throw e;
                }
            }
        }
Esempio n. 19
0
 public TestConfigurationService(string basePath, Microsoft.Practices.RecipeFramework.GuidancePackage parentPackage)
 {
     this.basePath      = basePath;
     this.parentPackage = parentPackage;
 }
Esempio n. 20
0
 private void EnablePackage(GuidancePackage package)
 {
     Manager.EnablePackage(package);
     //package.AddService(typeof(IValueGatheringService), new MockServices.MockArgumentGatheringService());
     package.AddService(typeof(IValueGatheringService), new WizardFramework.WizardGatheringService());
 }
Esempio n. 21
0
        /// <summary>
        /// Adds a package to the manager, enabling it for use.
        /// </summary>
        /// <param name="component">The package component.</param>
        /// <param name="name">Optional name (can be <see langword="null"/>)
        /// that must match the package name.</param>
        /// <remarks>
        /// This method is also called to add to the container services that
        /// inherit from <see cref="IComponent"/>, so the type of the component
        /// is not enforced. Just special logic is applied to package component types.
        /// </remarks>
        public override void Add(IComponent component, string name)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (component is GuidancePackage)
            {
                GuidancePackage package = (GuidancePackage)component;
                if (name != null && name != package.Configuration.Name)
                {
                    throw new ArgumentException(String.Format(
                                                    System.Globalization.CultureInfo.CurrentCulture,
                                                    Properties.Resources.RecipeManager_NameDoesntMatch,
                                                    name, package.Configuration.Caption));
                }
                // If there's a host listening, query for name to see if they match.
                IHostService host = GetService <IHostService>();
                if (host != null && host.HostName != package.Configuration.Host)
                {
                    throw new ArgumentException(String.Format(
                                                    System.Globalization.CultureInfo.CurrentCulture,
                                                    Properties.Resources.RecipeManager_PackageHostMismatch,
                                                    package.Configuration.Caption,
                                                    package.Configuration.Host,
                                                    host.HostName));
                }

                try
                {
                    // Force the package to be sited at Enabling event time also.
                    base.Add(component, package.Configuration.Name);
                    bool executebinding = true;
                    if (EnablingPackage != null)
                    {
                        CancelPackageEventArgs args = new CancelPackageEventArgs(
                            package, false);
                        EnablingPackage(this, args);
                        if (args.Cancel)
                        {
                            base.Remove(component);
                            return;
                        }
                        executebinding = args.ExecuteBindingRecipe;
                    }
                    if (executebinding && package.Configuration.BindingRecipe != null &&
                        package.Configuration.BindingRecipe.Length > 0)
                    {
                        package.TurnOnOutput();
                        package.Execute(package.Configuration.BindingRecipe);
                        package.TurnOffOutput();
                    }
                    if (EnabledPackage != null)
                    {
                        EnabledPackage(this, new PackageEventArgs(package));
                    }
                }
                catch
                {
                    // Notify host that we're disabling.
                    if (DisablingPackage != null)
                    {
                        DisablingPackage(this, new CancelPackageEventArgs(package, false));
                    }
                    // Don't let the package be enabled if an exception happened.
                    base.Remove(component);
                    if (DisabledPackage != null)
                    {
                        DisabledPackage(this, new PackageEventArgs(package));
                    }
                    package.GetService <IPersistenceService>(true).ClearState(package.Configuration.Name);
                    throw;
                }
            }
            else
            {
                // Just add the component so it gets sited.
                // Services that implement IComponent will arrive here.
                base.Add(component, name);
            }
        }
 public TestConfigurationService(string basePath, Microsoft.Practices.RecipeFramework.GuidancePackage parentPackage )
 {
   this.basePath = basePath;
   this.parentPackage = parentPackage;
 }
Esempio n. 23
0
 public void DuplicateActionParameter()
 {
     // Load the package from the config.
     GuidancePackage package = new GuidancePackage(new XmlTextReader(
                                                       Utils.MakeTestRelativePath("Action-DuplicateParam.xml")));
 }
Esempio n. 24
0
 private void EnablePackage(GuidancePackage guidancePackage)
 {
     EnablePackage(guidancePackage, false);
 }
Esempio n. 25
0
 public void CircularDependencies()
 {
     // Load the package from the config.
     GuidancePackage package = new GuidancePackage(Utils.MakeTestRelativePath("ValueProviderTests-Circular.xml"));
 }
Esempio n. 26
0
 private void EnablePackage(GuidancePackage guidancePackage)
 {
     Manager.EnablePackage(guidancePackage);
     guidancePackage.AddService(typeof(IValueGatheringService), new WizardFramework.WizardGatheringService());
 }