Пример #1
0
        public ResourcePublisher(RepositoryProvider publicationTarget, IPsCmdletLogger logger, string pluginFolder)
        {
            this.publicationTarget = publicationTarget;
            this.logger = logger;

            logger.Log("Loading plugins from " + pluginFolder);

            Assembly.LoadFrom(Path.Combine(pluginFolder, "umbraco.courier.providers.dll"));
            Assembly.LoadFrom(Path.Combine(pluginFolder, "umbraco.courier.dataresolvers.dll"));

            Context.Current.BaseDirectory = Directory.GetCurrentDirectory();
            Context.Current.HasHttpContext = false;

            logger.Log("Current directory set to " + Directory.GetCurrentDirectory());
        }
Пример #2
0
        public ResourcePublisher(RepositoryProvider publicationTarget, IPsCmdletLogger logger, string pluginFolder)
        {
            this.publicationTarget = publicationTarget;
            this.logger            = logger;

            logger.Log("Loading plugins from " + pluginFolder);

            Assembly.LoadFrom(Path.Combine(pluginFolder, "umbraco.courier.providers.dll"));
            Assembly.LoadFrom(Path.Combine(pluginFolder, "umbraco.courier.dataresolvers.dll"));

            Context.Current.BaseDirectory  = Directory.GetCurrentDirectory();
            Context.Current.HasHttpContext = false;

            logger.Log("Current directory set to " + Directory.GetCurrentDirectory());
        }
 public void WarmUpWebService()
 {
     try
     {
         var html = new WebClient().DownloadString(new Uri(CourierWebServiceUrl));
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
Пример #4
0
        private void Upload(IFileStreamWrap stream, string bucketName, string key, bool setPublicAccess)
        {
            try
            {
                key = key.ToLowerInvariant();

                var existsResponse = FileExists(bucketName, key);
                if (existsResponse != null && existsResponse.ContentLength == stream.Length)
                {
                    Logger.Log(string.Format("Skipping {0} because it already exists in {1}", key, bucketName));
                    return;
                }

                var uploadRequest = new TransferUtilityUploadRequest();
                uploadRequest.WithInputStream(stream.StreamInstance);
                uploadRequest.WithBucketName(bucketName);
                Logger.Log(String.Format("Bucket {0}", bucketName));
                if (setPublicAccess)
                {
                    uploadRequest.CannedACL = S3CannedACL.PublicRead;
                }
                uploadRequest.Key = key;
                Logger.Log(String.Format("Key {0}", key));
                uploadRequest.WithTimeout(14400000); // 4 Hours

                var lastKnownPercentage = 0;
                uploadRequest.UploadProgressEvent += (s, e) =>
                {
                    if (e.PercentDone <= lastKnownPercentage)
                    {
                        return;
                    }

                    Logger.Log(String.Format("UploadProgress:{0} :{1}%", key, e.PercentDone));
                    lastKnownPercentage = e.PercentDone;
                };

                TransferUtility.Upload(uploadRequest);
            }
            catch (Exception exception)
            {
                Logger.Log("Error uploading to s3");
                Logger.Log(exception.Message);
                throw;
            }
        }
Пример #5
0
        public void AugmentZip(
            string zipFileToAugment,
            string[] filenamesToAdd,
            string baseDirectory,
            string[] directoriesToAdd
            )
        {
            var allArgs = (filenamesToAdd ?? new string[0])
                          .Concat(directoriesToAdd ?? new string[0]);

            if (string.IsNullOrEmpty(zipFileToAugment))
            {
                throw new ArgumentException("zipFileToAugment");
            }

            if (!File.Exists(zipFileToAugment))
            {
                throw new ArgumentException(string.Format("Zip file {0} does not exist", zipFileToAugment),
                                            "zipFileToAugment");
            }

            if (!directoriesToAdd.NullOrEmpty() && !Directory.Exists(baseDirectory))
            {
                throw new ArgumentException(string.Format("Base directory {0} does not exist", baseDirectory));
            }

            if (!allArgs.Any())
            {
                throw new ArgumentException("No files or directories to add");
            }

            //Check the files to be added to ensure they all exist
            if (!filenamesToAdd.NullOrEmpty())
            {
                var filesToAddThatDontExist = new HashSet <string>();
                foreach (var fileToAdd in filenamesToAdd.Where(fileToAdd => !File.Exists(fileToAdd)))
                {
                    filesToAddThatDontExist.Add(fileToAdd);
                }

                if (filesToAddThatDontExist.Any())
                {
                    var fileNames = filesToAddThatDontExist.Aggregate();
                    throw new ArgumentException(string.Format("The following file(s) does not exist: {0}", fileNames),
                                                "filenamesToAdd");
                }
            }

            _logger.Log("---- Augmenting Zip {0} -----", zipFileToAugment);

            using (var zip = ZipFile.Read(zipFileToAugment))
            {
                //If the file name to add list is not invalid then UpdateFiles overwrites files that already exist, adds any that don't
                if (!filenamesToAdd.NullOrEmpty())
                {
                    zip.UpdateFiles(filenamesToAdd, "");
                }

                if (!directoriesToAdd.NullOrEmpty())
                {
                    foreach (var directory in directoriesToAdd)
                    {
                        var baseDir = directory.ToLower().Replace(baseDirectory.ToLower(), "");

                        zip.AddDirectory(directory, baseDir);
                    }
                }

                zip.Save();
            }

            _logger.Log("Done");
        }
Пример #6
0
        public string PublishPackage()
        {
            var expect100Continue = GetValueOrDefault(_settings, "Expect100Continue");

            if (expect100Continue.Equals(bool.FalseString, StringComparison.OrdinalIgnoreCase))
            {
                ServicePointManager.Expect100Continue = false;
            }

            var oneHour    = TimeSpan.FromMinutes(60);
            var httpClient = GetHttpClient();

            httpClient.Timeout = oneHour;
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            _logger.Log("---- Publishing package remotely -----");

            try
            {
                var request        = GetPublishRequestFromSettings();
                var remoteAgentUrl = _settings["RemoteAgentUrl"];

                _logger.Log("Contacting Remote Agent {0}", remoteAgentUrl);

                var pingResponseTask = httpClient.GetAsync(remoteAgentUrl);
                pingResponseTask.Wait();

                if (pingResponseTask.Result.StatusCode != HttpStatusCode.OK)
                {
                    var pingContentTask = pingResponseTask.Result.Content.ReadAsStringAsync();
                    pingContentTask.Wait();
                    var pingContent = pingContentTask.Result;

                    _logger.Log(pingContent);
                    throw new Exception(string.Format("Remote Agent is not listening: {0}", pingContent));
                }

                _logger.Log("Deploying via Remote Agent {0}", remoteAgentUrl);

                var publishResponseTask = httpClient.PostAsync(
                    remoteAgentUrl,
                    new StringContent(request.ToJsonString(), Encoding.UTF8, "application/json")
                    );
                publishResponseTask.Wait(oneHour);

                var contentTask = publishResponseTask.Result.Content.ReadAsStringAsync();
                contentTask.Wait(oneHour);

                var content = contentTask.Result;

                if (publishResponseTask.Result.StatusCode != HttpStatusCode.OK)
                {
                    throw new Exception(string.Format("Remote Agent publish failed: {0}", content));
                }

                return(content);
            }
            catch (Exception ex)
            {
                _logger.Log(ex);
                throw;
            }
            finally
            {
                httpClient.Dispose();
                httpClient = null;
            }
        }
Пример #7
0
        private void Deploy(string revisionFolder)
        {
            try
            {
                logger.Log("Loading extraction instance");

                var extractionManager = ExtractionManager.Instance;

                extractionManager.ExtractedItem += ManagerExtractedItem;
                extractionManager.Extracted     += ManagerExtracted;

                extractionManager.OverwriteExistingDependencies = true;
                extractionManager.OverwriteExistingitems        = true;
                extractionManager.OverwriteExistingResources    = true;

                logger.Log("Deployment manager loaded");

                var revFolder = Path.GetFullPath(revisionFolder);
                logger.Log("Loading folder: " + revFolder);

                var repository = new Repository(publicationTarget);

                logger.Log("Enabling remote deployment for: " + repository.Name);
                extractionManager.EnableRemoteExtraction(repository);

                logger.Log("Loading Contents: " + revFolder);
                extractionManager.Load(revFolder);

                logger.Log("Building graph...");
                extractionManager.BuildGraph();

                logger.Log(extractionManager.ExtractionGraph.CountUnique() + " Items added to graph");

                logger.Log("Extraction...");
                extractionManager.ExtractAll(false, true);

                logger.Log("Unloading...");
                extractionManager.Unload();

                logger.Log("DONE...");
            }
            catch (Exception ex)
            {
                logger.Log(ex);
            }
            finally
            {
                ExtractionManager.Instance.ExtractedItem -= ManagerExtractedItem;
                ExtractionManager.Instance.Extracted     -= ManagerExtracted;
            }
        }