コード例 #1
0
        public override void PostSync(DeploymentSyncContext syncContext)
        {
            var provider = syncContext.DestinationObject;

            if (provider.Name == "MSDeploy." + ServicePathProvider.ObjectName &&
                !ServicePathHelper.IsAbsolutePhysicalPath(provider.ProviderContext.Path))
            {
                var serviceName = ServicePathHelper.GetServiceName(provider.ProviderContext.Path);

                var serviceController = new ServiceController(serviceName);

                if (serviceController.Status == ServiceControllerStatus.Stopped)
                {
                    syncContext.SourceObject.BaseContext.RaiseEvent(new WindowsServiceTraceEvent(TraceLevel.Info, Resources.StartingServiceEvent, serviceName));

                    if (!syncContext.WhatIf)
                    {
                        serviceController.Start();
                    }
                }

                if (!syncContext.WhatIf)
                {
                    int serviceTimeoutSeconds = provider.ProviderContext.ProviderOptions.ProviderSettings.GetValueOrDefault("serviceTimeout", 20);
                    serviceController.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(serviceTimeoutSeconds));
                }
            }

            base.PostSync(syncContext);
        }
コード例 #2
0
        public override IEnumerable <DeploymentObjectProvider> GetChildProviders()
        {
            string physicalPath = ServicePathHelper.GetPhysicalPath(providerContext.Path);

            string childProviderName = _isDirectory ? "dirPath" : "filePath";

            yield return(CreateProvider(childProviderName, physicalPath, Name));
        }
コード例 #3
0
        DeploymentObjectProvider CreateDirPathProvider()
        {
            var providerOptions = new DeploymentProviderOptions("dirPath");

            providerOptions.Path = ServicePathHelper.GetPhysicalPath(Path);

            DeploymentObjectProvider provider = CreateProvider(providerOptions, ObjectName + LibFolderName);

            return(provider);
        }
コード例 #4
0
 public override IEnumerable <DeploymentObjectProvider> GetChildProviders()
 {
     if (_isDirectory)
     {
         yield return(CreateDirPathProvider());
     }
     else
     {
         string physicalPath = ServicePathHelper.GetPhysicalPath(Path);
         yield return(CreateProvider("filePath", physicalPath, Name));
     }
 }
コード例 #5
0
        public override void Add(DeploymentObject source, bool whatIf)
        {
            ServicePathHelper.GetPhysicalPath(providerContext.Path);

            foreach (var deploymentObject in source.GetChildren())
            {
                if (deploymentObject.Name == "dirPath")
                {
                    _isDirectory = true;
                    break;
                }
            }
        }
コード例 #6
0
        public override DeploymentObjectProvider AddChild(DeploymentObject source, int position, bool whatIf)
        {
            string physicalPath = ServicePathHelper.GetPhysicalPath(Path);

            if (source.Name == "contentPathLib")
            {
                return(CreateProvider("contentPathLib", Path, "ContentPathLib"));
            }

            if (source.Name == "dirPath" && !_isDirectory)
            {
                throw new DeploymentException(Resources.FileAlreadyExists, physicalPath);
            }

            throw new DeploymentException(Resources.DirectoryAlreadyExists, physicalPath);
        }
コード例 #7
0
        void StopService(DeploymentSyncContext syncContext)
        {
            if (_hasStoppedService)
            {
                return;
            }

            _hasStoppedService = true;

            var provider = syncContext.DestinationObject;

            if (provider.Name == "MSDeploy." + ServicePathProvider.ObjectName &&
                !ServicePathHelper.IsAbsolutePhysicalPath(provider.ProviderContext.Path))
            {
                var serviceName = ServicePathHelper.GetServiceName(provider.ProviderContext.Path);

                var serviceController = new ServiceController(serviceName);

                if (serviceController.Status == ServiceControllerStatus.Running ||
                    serviceController.Status == ServiceControllerStatus.Paused)
                {
                    syncContext.SourceObject.BaseContext.RaiseEvent(new WindowsServiceTraceEvent(TraceLevel.Info, Resources.StoppingServiceEvent, serviceName));

                    if (!syncContext.WhatIf)
                    {
                        serviceController.Stop();
                    }
                }

                if (!syncContext.WhatIf)
                {
                    int serviceTimeoutSeconds = provider.ProviderContext.ProviderOptions.ProviderSettings.GetValueOrDefault("serviceTimeout", 20);
                    serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(serviceTimeoutSeconds));
                }

                // TODO: Info, service already stopped
                // TODO: Invalid service name
                // TODO: Can't stop service (perms)
                // TODO: Can't stop service (timeout)
            }

            base.PreSync(syncContext);
        }
コード例 #8
0
 internal void EnsureNodeExists(out bool isDirectory)
 {
     isDirectory = false;
     EnsureNodeExists(ServicePathHelper.GetPhysicalPath(Path), out isDirectory);
 }
コード例 #9
0
 public override void GetAttributes(DeploymentAddAttributeContext addContext)
 {
     EnsureNodeExists(ServicePathHelper.GetPhysicalPath(Path), out _isDirectory);
 }