/// <summary>
        /// Deletes the file.
        /// </summary>
        /// <param name="properties">The properties.</param>
        /// <param name="relativeRemoteFileName">Name of the relative remote file.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">Connection properties cannot be null.;properties</exception>
        public bool DeleteFile(ConnectionProperties properties, string relativeRemoteFileName)
        {
            if (properties == null) throw new ArgumentException("Connection properties cannot be null.", "properties");
            properties.Validate();

            ServicePointManager.ServerCertificateValidationCallback = (s, c, chain, err) => true;

            var destionationOptions = new DeploymentBaseOptions
            {
                ComputerName = BuildMsDeployUri(properties).ToString(),
                UserName = properties.Username,
                Password = properties.Password,
                UseDelegation = true,
                AuthenticationType = "Basic"
            };

            var syncOptions = new DeploymentSyncOptions
            {
                DeleteDestination = true
            };

            var remotePath = String.Format("{0}/{1}", properties.IISWebsiteName, relativeRemoteFileName.Trim(new[] { '/', '\\' }));

            using (var deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, remotePath, destionationOptions))
            {
                var results = deploymentObject.SyncTo(destionationOptions, syncOptions);
                if (results.ObjectsDeleted == 1) return true;
            }

            return true;
        }
        public void Initialise()
        {
            _connectionProperties = new ConnectionProperties
            {
                MsDeployEndpointUri = TestConfiguration.MsDeployEndPoint,
                AllowUntrustedCertificates = true,
                IISWebsiteName = TestConfiguration.MsDeployIISWebsite,
                Username = TestConfiguration.MsDeployUsername,
                Password = TestConfiguration.MsDeployPassword
            };

            _tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
            File.WriteAllText(_tempFilePath,"test upload content");
        }
        private static Uri BuildMsDeployUri(ConnectionProperties properties)
        {
            properties.Validate();

            var builder = new UriBuilder(properties.MsDeployEndpointUri) { Query = String.Format("site={0}", properties.IISWebsiteName) };

            return builder.Uri;
        }
        /// <summary>
        /// Fetches the remote servers file list.
        /// </summary>
        /// <param name="properties">The properties.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">Connection properties cannot be null.;properties</exception>
        public DeploymentObjectList FetchFileList(ConnectionProperties properties)
        {
            if (properties == null) throw new ArgumentException("Connection properties cannot be null.", "properties");
            properties.Validate();

            var results = new DeploymentObjectList { Folders = new List<string>(), Files = new List<string>() };

            if (properties.AllowUntrustedCertificates)
            {
                ServicePointManager.ServerCertificateValidationCallback = (s, c, chain, err) => true;
            }

            var destOptions = new DeploymentBaseOptions
                                  {
                                      ComputerName = BuildMsDeployUri(properties).ToString(),
                                      UserName = properties.Username,
                                      Password = properties.Password,
                                      UseDelegation = true,
                                      AuthenticationType = "Basic"
                                  };

            foreach (var extension in destOptions.LinkExtensions.Where(extension => extension.Name == "ContentExtension"))
            {
                extension.Enabled = false;
                break;
            }

            using (var deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, properties.IISWebsiteName, destOptions))
            {
                var xmlResult = GetDeploymentObjectAsXmlDocument(deploymentObject);
                TextReader tr = new StringReader(xmlResult.InnerXml);
                var doc = XDocument.Load(tr);

                results.Files = (from f in doc.Element("MSDeploy.contentPath").Element("contentPath")
                                    .Element("dirPath")
                                    .Elements("filePath")
                                 select f.Attribute("path").Value).ToList();

                results.Folders = (from f in doc.Element("MSDeploy.contentPath").Element("contentPath")
                                    .Element("dirPath")
                                    .Elements("dirPath")
                                   select f.Attribute("path").Value).ToList();
            }

            return results;
        }