Пример #1
0
        public async Task <bool> PushItemsToFeedAsync(
            IEnumerable <string> items,
            PushOptions options)
        {
            Log.LogMessage(MessageImportance.Low, $"START pushing items to feed");

            if (!items.Any())
            {
                Log.LogMessage("No items to push found in the items list.");
                return(true);
            }

            try
            {
                bool result = await PushAsync(items, options);

                return(result);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }

            return(!Log.HasLoggedErrors);
        }
Пример #2
0
        public async Task <bool> CreateFeedContainer()
        {
            ValidateContainerName(ContainerName);
            string url = $"{FeedContainerUrl}?restype=container";

            using (HttpClient client = new HttpClient())
            {
                List <Tuple <string, string> > additionalHeaders = null;
                if (IsPublic)
                {
                    Tuple <string, string> headerBlobType = new Tuple <string, string>("x-ms-blob-public-access", "blob");
                    additionalHeaders = new List <Tuple <string, string> >()
                    {
                        headerBlobType
                    };
                }
                var createRequest = AzureHelper.RequestMessage("PUT", url, AccountName, AccountKey, additionalHeaders);

                using (HttpResponseMessage response = await AzureHelper.RequestWithRetry(Log, client, createRequest))
                {
                    try
                    {
                        Log.LogMessage(
                            MessageImportance.Low,
                            "Received response to create Container {0}: Status Code: {1} {2}",
                            ContainerName, response.StatusCode, response.Content.ToString());
                    }
                    catch (Exception e)
                    {
                        Log.LogErrorFromException(e, true);
                    }
                }
            }
            string item       = GenerateRootServiceIndex(RelativePath);
            string uploadPath = CalculateBlobPath(item, RelativePath);

            Log.LogMessage($"Uploading root index.json to {uploadPath}.");
            try
            {
                UploadClient uploadClient = new UploadClient(Log);
                await
                uploadClient.UploadBlockBlobAsync(
                    CancellationToken,
                    AccountName,
                    AccountKey,
                    ContainerName,
                    item,
                    uploadPath);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }
            return(!Log.HasLoggedErrors);
        }
Пример #3
0
        /// <summary>
        /// Reads contents of a key file. Reused from vsdesigner code.
        /// </summary>
        /// <param name="log"></param>
        /// <param name="keyFile"></param>
        /// <param name="keyPair"></param>
        /// <param name="publicKey"></param>
        internal static void ReadKeyFile(TaskLoggingHelper log, string keyFile, out StrongNameKeyPair keyPair, out byte[] publicKey)
        {
            // Initialize parameters
            keyPair = null;
            publicKey = null;

            byte[] keyFileContents;

            try
            {
                // Read the stuff from the file stream
                using (FileStream fs = new FileStream(keyFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    keyFileContents = new byte[(int)fs.Length];
                    fs.Read(keyFileContents, 0, (int)fs.Length);
                }
            }
            catch (ArgumentException e)
            {
                log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFile);
                log.LogErrorFromException(e);
                throw new StrongNameException(e);
            }
            catch (IOException e)
            {
                log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFile);
                log.LogErrorFromException(e);
                throw new StrongNameException(e);
            }
            catch (SecurityException e)
            {
                log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", keyFile);
                log.LogErrorFromException(e);
                throw new StrongNameException(e);
            }

            // Make a new key pair from what we read
            StrongNameKeyPair snp = new StrongNameKeyPair(keyFileContents);

            // If anything fails reading the public key portion of the strong name key pair, then
            // assume that keyFile contained only the public key portion of the public/private pair.
            try
            {
                publicKey = snp.PublicKey;

                // If we didn't throw up to this point then we have a valid public/private key pair,
                // so assign the object just created above to the out parameter.  
                keyPair = snp;
            }
            catch (ArgumentException)
            {
                publicKey = keyFileContents;
            }
        }
Пример #4
0
        public async Task <bool> PushItemToFeed(string item, string relativePath, SemaphoreSlim clientThrottle, bool allowOverwrite)
        {
            try
            {
                string uploadPath       = feed.CalculateBlobPath(item, relativePath);
                string packageDirectory = feed.CalculateRelativeUploadPath(item, relativePath);

                await UploadAsync(CancellationToken, item, uploadPath, clientThrottle, allowOverwrite);

                List <string> listAzureBlobs = await ListAzureBlobs.ListBlobs(Log, feed.AccountName, feed.AccountKey, feed.ContainerName, packageDirectory);

                if (!listAzureBlobs.Any(x => x.Contains(uploadPath)))
                {
                    throw new Exception($"Uploaded package {uploadPath} is not present on feed. Cannot update index.json.");
                }

                await UploadIndexJson(clientThrottle, true, packageDirectory, listAzureBlobs);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }

            return(!Log.HasLoggedErrors);
        }
Пример #5
0
        public async Task <bool> PushItemsToFeedAsync(IEnumerable <string> items, bool allowOverwrite)
        {
            Log.LogMessage(MessageImportance.Low, $"START pushing items to feed");
            Random rnd = new Random();

            try
            {
                bool result = await PushAsync(items.ToList(), allowOverwrite);

                return(result);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }

            return(!Log.HasLoggedErrors);
        }
 internal static void ReadKeyFile(TaskLoggingHelper log, string keyFile, out StrongNameKeyPair keyPair, out byte[] publicKey)
 {
     byte[] buffer;
     keyPair = null;
     publicKey = null;
     try
     {
         using (FileStream stream = new FileStream(keyFile, FileMode.Open, FileAccess.Read, FileShare.Read))
         {
             buffer = new byte[(int) stream.Length];
             stream.Read(buffer, 0, (int) stream.Length);
         }
     }
     catch (ArgumentException exception)
     {
         log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", new object[] { keyFile });
         log.LogErrorFromException(exception);
         throw new StrongNameException(exception);
     }
     catch (IOException exception2)
     {
         log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", new object[] { keyFile });
         log.LogErrorFromException(exception2);
         throw new StrongNameException(exception2);
     }
     catch (SecurityException exception3)
     {
         log.LogErrorWithCodeFromResources("StrongNameUtils.KeyFileReadFailure", new object[] { keyFile });
         log.LogErrorFromException(exception3);
         throw new StrongNameException(exception3);
     }
     StrongNameKeyPair pair = new StrongNameKeyPair(buffer);
     try
     {
         publicKey = pair.PublicKey;
         keyPair = pair;
     }
     catch (ArgumentException)
     {
         publicKey = buffer;
     }
 }
 internal static void GetStrongNameKey(TaskLoggingHelper log, string keyFile, string keyContainer, out StrongNameKeyPair keyPair, out byte[] publicKey)
 {
     keyPair = null;
     publicKey = null;
     if ((keyContainer != null) && (keyContainer.Length != 0))
     {
         try
         {
             keyPair = new StrongNameKeyPair(keyContainer);
             publicKey = keyPair.PublicKey;
             return;
         }
         catch (SecurityException exception)
         {
             log.LogErrorWithCodeFromResources("StrongNameUtils.BadKeyContainer", new object[] { keyContainer });
             log.LogErrorFromException(exception);
             throw new StrongNameException(exception);
         }
         catch (ArgumentException exception2)
         {
             log.LogErrorWithCodeFromResources("StrongNameUtils.BadKeyContainer", new object[] { keyContainer });
             log.LogErrorFromException(exception2);
             throw new StrongNameException(exception2);
         }
     }
     if ((keyFile != null) && (keyFile.Length != 0))
     {
         ReadKeyFile(log, keyFile, out keyPair, out publicKey);
     }
 }
Пример #8
0
 /// <summary>
 /// Given a key file or container, extract private/public key data. Reused from vsdesigner code.
 /// </summary>
 /// <param name="log"></param>
 /// <param name="keyFile"></param>
 /// <param name="keyContainer"></param>
 /// <param name="keyPair"></param>
 /// <param name="publicKey"></param>
 internal static void GetStrongNameKey(TaskLoggingHelper log, string keyFile, string keyContainer, out StrongNameKeyPair keyPair, out byte[] publicKey)
 {
     // Gets either a strong name key pair from the key file or a key container.
     // If keyFile and keyContainer are both null/zero length then returns null.
     // Initialize parameters
     keyPair = null;
     publicKey = null;
     if (keyContainer != null && keyContainer.Length != 0)
     {
         try
         {
             keyPair = new StrongNameKeyPair(keyContainer);
             publicKey = keyPair.PublicKey;
         }
         catch (SecurityException e)
         {
             log.LogErrorWithCodeFromResources("StrongNameUtils.BadKeyContainer", keyContainer);
             log.LogErrorFromException(e);
             throw new StrongNameException(e);
         }
         catch (ArgumentException e)
         {
             log.LogErrorWithCodeFromResources("StrongNameUtils.BadKeyContainer", keyContainer);
             log.LogErrorFromException(e);
             throw new StrongNameException(e);
         }
     }
     else if (keyFile != null && keyFile.Length != 0)
     {
         ReadKeyFile(log, keyFile, out keyPair, out publicKey);
     }
 }
Пример #9
0
		public static bool DoWork(dynamic taskOptions, TaskLoggingHelper log) {
			var options = GetOptions(taskOptions, log);
			if (options == null)
				return false;

			var driver = new CompilerDriver(new TaskErrorReporter(log));
			try {
				return driver.Compile(options);
			}
			catch (Exception ex) {
				log.LogErrorFromException(ex);
				return false;
			}
		}