示例#1
0
 private static T FindInstaller <T>(InstallerCollection installers)
     where T : Installer
 {
     return(installers.Cast <Installer>()
            .Select(i => i as T ?? FindInstaller <T>(i.Installers))
            .FirstOrDefault(i => i != null));
 }
示例#2
0
    public static void Main()
    {
// <Snippet1>
        AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
        ServiceInstaller  myServiceInstaller  = new ServiceInstaller();
        EventLogInstaller myEventLogInstaller = new EventLogInstaller();

        InstallerCollection myInstallerCollection = myAssemblyInstaller.Installers;

        // Add Installers to the InstallerCollection of 'myAssemblyInstaller'.
        myInstallerCollection.Add(myServiceInstaller);
        myInstallerCollection.Add(myEventLogInstaller);

        Installer[] myInstaller = new Installer[2];
        myInstallerCollection.CopyTo(myInstaller, 0);
        // Show the contents of the InstallerCollection of 'myAssemblyInstaller'.
        Console.WriteLine("Installers in the InstallerCollection : ");
        for (int iIndex = 0; iIndex < myInstaller.Length; iIndex++)
        {
            Console.WriteLine(myInstaller[iIndex].ToString());
        }
// </Snippet1>
        Console.WriteLine("");
// <Snippet2>
        AssemblyInstaller   myAssemblyInstaller1   = new AssemblyInstaller();
        InstallerCollection myInstallerCollection1 = myAssemblyInstaller1.Installers;

        // 'myAssemblyInstaller' is an installer of type 'AssemblyInstaller'.
        myInstallerCollection1.Add(myAssemblyInstaller);

        Installer myInstaller1 = myAssemblyInstaller.Parent;

        Console.WriteLine("Parent of myAssembly : {0}", myInstaller1.ToString());
// </Snippet2>
    }
        private void setServiceProcessCredentials(string user, string pass, InstallerCollection installers)
        {
            ServiceProcessInstaller si = getServiceProcessInstaller(installers);

            si.Account = ServiceAccount.User;

            if (!user.Contains('\\'))
            {
                user = user.Insert(0, ".\\");
            }

            si.Username = user;
            si.Password = pass;
        }
示例#4
0
        /// <summary>
        /// Set the unistall action of the event log installers to remove.
        /// </summary>
        /// <param name="installer">The installer to proccess.</param>
        private static void SetInstallers(Installer installer)
        {
            InstallerCollection installers = installer.Installers;

            foreach (Installer I in installers)
            {
                var eventLogInstall = I as EventLogInstaller;
                if (eventLogInstall != null)
                {
                    eventLogInstall.UninstallAction = UninstallAction.Remove;
                    break;
                }
                SetInstallers(I);
            }
        }
    public static void Main()
    {
        try
        {
// <Snippet1>
            TransactedInstaller myTransactedInstaller = new TransactedInstaller();
            AssemblyInstaller   myAssemblyInstaller;
            InstallContext      myInstallContext;

            // Create a instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
            myAssemblyInstaller =
                new AssemblyInstaller("MyAssembly1.exe", null);

            // Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
            myTransactedInstaller.Installers.Add(myAssemblyInstaller);

            // Create a instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
            myAssemblyInstaller =
                new AssemblyInstaller("MyAssembly2.exe", null);

            // Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
            myTransactedInstaller.Installers.Add(myAssemblyInstaller);

            //Print the assemblies to be installed.
            InstallerCollection myInstallers = myTransactedInstaller.Installers;
            Console.WriteLine("\nPrinting all assemblies to be installed");
            for (int i = 0; i < myInstallers.Count; i++)
            {
                if ((myInstallers[i].GetType()).Equals(typeof(AssemblyInstaller)))
                {
                    Console.WriteLine("{0} {1}", i + 1,
                                      ((AssemblyInstaller)myInstallers[i]).Path);
                }
            }
// </Snippet1>
            // Create a instance of 'InstallContext' with log file named 'Install.log'.
            myInstallContext =
                new InstallContext("Install.log", null);
            myTransactedInstaller.Context = myInstallContext;

            // Install an assembly .
            myTransactedInstaller.Install(new Hashtable());
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception raised : {0}", e.Message);
        }
    }
        private ServiceProcessInstaller getServiceProcessInstaller(InstallerCollection fromCollection)
        {
            foreach (var item in fromCollection)
            {
                if (item is ServiceProcessInstaller)
                {
                    return((ServiceProcessInstaller)item);
                }
                if (item is ProjectInstaller)
                {
                    return(getServiceProcessInstaller(((ProjectInstaller)item).Installers));
                }
            }

            throw new InvalidOperationException("ServiceInstaller unavailiable. Assembly corrupted.");
        }
示例#7
0
        private IEnumerable <EventLogInstaller> FindInstaller(InstallerCollection installers)
        {
            foreach (Installer installer in installers)
            {
                var eventLogInstaller = installer as EventLogInstaller;
                if (eventLogInstaller != null)
                {
                    yield return(eventLogInstaller);
                }

                foreach (var i in FindInstaller(installer.Installers).Where(i => i != null))
                {
                    yield return(i);
                }
            }
        }
示例#8
0
        private EventLogInstaller FindInstaller(InstallerCollection installers)
        {
            foreach (Installer installer in installers)
            {
                if (installer is EventLogInstaller logInstaller)
                {
                    return(logInstaller);
                }

                var eventLogInstaller = FindInstaller(installer.Installers);
                if (eventLogInstaller != null)
                {
                    return(eventLogInstaller);
                }
            }
            return(null);
        }
    public static void Main()
    {
        try
        {
// <Snippet1>
// <Snippet2>
// <Snippet3>
            TransactedInstaller myTransactedInstaller = new TransactedInstaller();
            AssemblyInstaller   myAssemblyInstaller1;
            AssemblyInstaller   myAssemblyInstaller2;
            InstallContext      myInstallContext;

            // Create a instance of 'AssemblyInstaller' that installs 'MyAssembly1.exe'.
            myAssemblyInstaller1 =
                new AssemblyInstaller("MyAssembly1.exe", null);

            // Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
            myTransactedInstaller.Installers.Insert(0, myAssemblyInstaller1);

            // Create a instance of 'AssemblyInstaller' that installs 'MyAssembly2.exe'.
            myAssemblyInstaller2 =
                new AssemblyInstaller("MyAssembly2.exe", null);

            // Add the instance of 'AssemblyInstaller' to the 'TransactedInstaller'.
            myTransactedInstaller.Installers.Insert(1, myAssemblyInstaller2);

            // Remove the 'myAssemblyInstaller2' from the 'Installers' collection.
            if (myTransactedInstaller.Installers.Contains(myAssemblyInstaller2))
            {
                Console.WriteLine("\nInstaller at index : {0} is being removed",
                                  myTransactedInstaller.Installers.IndexOf(myAssemblyInstaller2));
                myTransactedInstaller.Installers.Remove(myAssemblyInstaller2);
            }
// </Snippet3>
// </Snippet2>
// </Snippet1>
            //Print the installers to be installed.
            InstallerCollection myInstallers = myTransactedInstaller.Installers;
            Console.WriteLine("\nPrinting all installers to be installed\n");
            for (int i = 0; i < myInstallers.Count; i++)
            {
                if ((myInstallers[i].GetType()).Equals(typeof(AssemblyInstaller)))
                {
                    Console.WriteLine("{0} {1}", i + 1,
                                      ((AssemblyInstaller)myInstallers[i]).Path);
                }
            }

            // Create a instance of 'InstallContext' with log file named 'Install.log'.
            myInstallContext =
                new InstallContext("Install.log", null);
            myTransactedInstaller.Context = myInstallContext;

            // Install an assembly.
            myTransactedInstaller.Install(new Hashtable());
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception raised : {0}", e.Message);
        }
    }
示例#10
0
 public void AddRange(InstallerCollection value)
 {
 }
	public void AddRange(InstallerCollection value) {}