Exemple #1
0
        public AzureFileRepositoryTests()
        {
            _azureFileRepository = new AzureFileRepository(
                DarioBotConfiguration.Get(DarioBotConfiguration.StorageConnectionStringKey),
                DarioBotConfiguration.Get(DarioBotConfiguration.RemoteResourcesPathKey),
                "happydariobottests");

            _badAzureFileRepository = new AzureFileRepository(
                "x",
                DarioBotConfiguration.Get(DarioBotConfiguration.RemoteResourcesPathKey),
                "xasxsaxsa");
        }
        static void Main(string[] args)
        {
            BuildConfiguration();
            var repository = new AzureFileRepository(
                new AzureFileReader(uploadStorageAcct, storageAccountKey, "gis-uploads"));
            var home = Guid.NewGuid().ToString();

            Console.WriteLine("Enter commands:");

            string line;

            Console.WriteLine("Enter list, file:[name], dir:[name] (press CTRL+Z to exit):");
            Console.WriteLine();
            do
            {
                line = Console.ReadLine();
                if (line != null)
                {
                    // Get the command to the left of the : //
                    var command = Regex.Match(line, @"^.*?(?=:)").Value;

                    // GETS fileNameArg FROM file:fileNameArg //
                    var argument = Regex.IsMatch(line, @"(?<=:)(.*)(?=/)")
                        ? Regex.Match(line, @"(?<=:)(.*)(?=/)").Value
                        : string.Empty;

                    // GETS fileName FROM file:directory/fileName //
                    var secondArg = Regex.IsMatch(line, @"[^/]+$")
                        ? Regex.Match(line, @"[^/]+$").Value
                        : string.Empty;

                    var directory = string.IsNullOrEmpty(argument) ? home : argument;

                    switch (command.ToLower())
                    {
                    case "get":
                    {
                        Task.Run(() => repository.Get(argument ?? home, secondArg));
                        break;
                    }

                    case "list":
                    {
                        Task.Run(async() =>
                            {
                                var items = await repository.GetDirectory(directory);
                                foreach (var d in items)
                                {
                                    Console.WriteLine(d.Directory);
                                }
                            });
                        break;
                    }

                    case "file":
                    {
                        var f = new File()
                        {
                            Name      = secondArg ?? "data.geojson",
                            Directory = directory
                        };
                        f.AddTextContent(FileSampleContent());
                        Task.Run(() => repository.Add(f));
                        break;
                    }

                    case "dir":
                    {
                        var f = new File()
                        {
                            Directory = directory
                        };
                        Task.Run(() => repository.Add(f));
                        break;
                    }

                    default:
                        break;
                    }
                }
            } while (line != null);
        }