Ejemplo n.º 1
0
        XElement ServiceInstallToXml(Project project)
        {
            var serviceInstall =
                new XElement("ServiceInstall",
                             new XAttribute("Id", Id),
                             new XAttribute("Name", Name),
                             new XAttribute("DisplayName", DisplayName ?? Name),
                             new XAttribute("Description", Description ?? DisplayName ?? Name),
                             new XAttribute("Type", Type),
                             new XAttribute("Start", StartType),
                             new XAttribute("ErrorControl", ErrorControl));

            serviceInstall.SetAttribute("Account", Account)
            .SetAttribute("Arguments", Arguments)
            .SetAttribute("Interactive", Interactive)
            .SetAttribute("LoadOrderGroup", LoadOrderGroup)
            .SetAttribute("Password", Password)
            .SetAttribute("EraseDescription", EraseDescription)
            .SetAttribute("Vital", Vital)
            .AddAttributes(Attributes);

            foreach (var item in DependsOn.Split(';'))
            {
                if (item.IsNotEmpty())
                {
                    serviceInstall.AddElement("ServiceDependency", "Id=" + item);
                }
            }

            if (DelayedAutoStart.HasValue ||
                PreShutdownDelay.HasValue ||
                ServiceSid != null)
            {
                var serviceConfig = new XElement("ServiceConfig");

                serviceConfig.SetAttribute("DelayedAutoStart", DelayedAutoStart)
                .SetAttribute("PreShutdownDelay", PreShutdownDelay)
                .SetAttribute("ServiceSid", ServiceSid)
                .SetAttribute("OnInstall", ConfigureServiceTrigger.Install.PresentIn(ConfigureServiceTrigger))
                .SetAttribute("OnReinstall", ConfigureServiceTrigger.Reinstall.PresentIn(ConfigureServiceTrigger))
                .SetAttribute("OnUninstall", ConfigureServiceTrigger.Uninstall.PresentIn(ConfigureServiceTrigger));

                serviceInstall.Add(serviceConfig);

                if (UrlReservations != null)
                {
                    foreach (UrlReservation urlReservation in UrlReservations)
                    {
                        serviceInstall.Add(urlReservation.ToXml());
                    }
                }
            }

            if (IsFailureActionSet ||
                ProgramCommandLine != null ||
                RebootMessage != null ||
                ResetPeriodInDays.HasValue ||
                RestartServiceDelayInSeconds.HasValue)
            {
                project?.Include(WixExtension.Util);

                var serviceConfig = new XElement(WixExtension.Util.ToXNamespace() + "ServiceConfig");

                serviceConfig.SetAttribute("FirstFailureActionType", FirstFailureActionType)
                .SetAttribute("SecondFailureActionType", SecondFailureActionType)
                .SetAttribute("ThirdFailureActionType", ThirdFailureActionType)
                .SetAttribute("ProgramCommandLine", ProgramCommandLine)
                .SetAttribute("RebootMessage", RebootMessage)
                .SetAttribute("ResetPeriodInDays", ResetPeriodInDays)
                .SetAttribute("RestartServiceDelayInSeconds", RestartServiceDelayInSeconds);

                serviceInstall.Add(serviceConfig);
            }

            return(serviceInstall);
        }