Esempio n. 1
0
        /// <summary>
        /// Gets an array of objects names for a specific object container
        /// </summary>
        /// <param name="objectType">object type to get its objects</param>
        public string[] ObjectNames(ObjectType objectType)
        {
            string[] result = new string[0];
            if (tree.Nodes.Count == 0)
            {
                return(result);
            }

            Containers          containers = AccessApp.ContainersFactory(tree.Nodes[0].Text);
            ObjectTypeExtension ote        = containers.Find(objectType);

            if (ote != null)
            {
                ContainerNames names      = ote.Container;
                TreeNode[]     matchNodes = tree.Nodes[0].Nodes.Find(names.DisplayPluralName, true);
                if (matchNodes.Length == 1)
                {
                    result = new string[matchNodes[0].Nodes.Count];
                    for (int i = 0; i < matchNodes[0].Nodes.Count; i++)
                    {
                        result[i] = matchNodes[0].Nodes[i].Text;
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public void FunctionHandler(ILambdaContext context)
        {
            string storageConnectionString;

            if (!ssmParameterManager.TryGetValue(Constants.StorageConnectionStringSSMPath, out storageConnectionString))
            {
                throw new Exception("Storage connection path not defined.");
            }
            else
            {
                Console.WriteLine($"Storage connection path is set at '{storageConnectionString}'");
            }

            if (!S3Manager.CheckS3Parameters())
            {
                return;
            }

            // Check whether the connection string can be parsed.
            if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount))
            {
                string ContainerNames;
                if (ssmParameterManager.TryGetValue(Constants.StorageContainerNamesSSMPath, out ContainerNames))
                {
                    var         arrContainerNames = ContainerNames.Split(',', StringSplitOptions.RemoveEmptyEntries);
                    List <Task> lstTasks          = new List <Task>();
                    foreach (var ContainerName in arrContainerNames)
                    {
                        var t = Task.Factory.StartNew(() =>
                        {
                            var lstBlobItems = AzureManager.ListBlobContainer(storageAccount, ContainerName, null);

                            if (lstBlobItems.Count > 0)
                            {
                                Console.WriteLine("Listing S3 items.");
                                var S3Objects = S3Manager.GetS3Items();

                                Console.WriteLine($"{S3Objects.Count.ToString()} items retrieved from S3.");

                                foreach (var S3Object in S3Objects)
                                {
                                    Console.WriteLine($"Item retrieved from S3: {S3Object.BucketName} - {S3Object.Key} ({S3Object.Size.ToString()} bytes) - ETag {S3Object.ETag}");
                                }

                                StringBuilder sb = new StringBuilder();

                                Amazon.SQS.AmazonSQSClient sqsClient = new Amazon.SQS.AmazonSQSClient();


                                lstBlobItems.ForEach((a) =>
                                {
                                    if (!S3Objects.Any(s => s.Key == a.BlobName && s.Size == a.Size))
                                    {
                                        CopyItem copyItem = new CopyItem {
                                            BlobItem = a
                                        };
                                        // No S3 objects that match the Azure blob, copy it over
                                        var strCopyItem = JsonConvert.SerializeObject(copyItem);
                                        SendMessageRequest sendRequest = new SendMessageRequest {
                                            MessageBody = strCopyItem, QueueUrl = System.Environment.GetEnvironmentVariable("QueueName")
                                        };

                                        var sendMessageResult = sqsClient.SendMessageAsync(sendRequest).GetAwaiter().GetResult();

                                        Console.WriteLine($"Item not found in S3, adding to copy queue - {a.BlobName} - send message result: {sendMessageResult.HttpStatusCode.ToString()}");
                                    }
                                });
                            }
                        });
                        lstTasks.Add(t);
                    }

                    Task.WaitAll(lstTasks.ToArray());
                }
            }
            else
            {
                // Otherwise, let the user know that they need to define the environment variable.
                throw new Exception("Storage connection path not defined.");
            }
        }
 private bool CanRunOnPlatform() =>
 Linux && RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
 OSX && RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ||
 Windows && RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ||
 ContainerNames != default && ContainerNames.Contains(Environment.GetEnvironmentVariable("DOCKER_CONTAINER_NAME"));