Ejemplo n.º 1
0
        public async Task GetZones_ValidServer_ZonesReturned()
        {
            using (var udpClient = new UdpClient())
            {
                var networkClient = new UdpNetworkClient(udpClient);
                var target        = new DirectoryClient(networkClient, IPAddress.Parse("108.61.133.122"));

                var actual = await target.GetZonesAsync();

                Assert.AreNotEqual(0, actual.Count);
            }
        }
Ejemplo n.º 2
0
        public async Task DownloadAsync()
        {
            // Create a temporary Lorem Ipsum file on disk that we can upload
            string originalPath = CreateTempFile(SampleFileContent);

            // Get a temporary path on disk where we can download the file
            string downloadPath = CreateTempPath();

            // Get a connection string to our Azure Storage account.
            string connectionString = ConnectionString;

            // Get a reference to a share named "sample-share" and then create it
            ShareClient share = new ShareClient(connectionString, Randomize("sample-share"));
            await share.CreateAsync();

            try
            {
                // Get a reference to a directory named "sample-dir" and then create it
                DirectoryClient directory = share.GetDirectoryClient(Randomize("sample-dir"));
                await directory.CreateAsync();

                // Get a reference to a file named "sample-file" in directory "sample-dir"
                FileClient file = directory.GetFileClient(Randomize("sample-file"));

                // Upload the file
                using (FileStream stream = File.OpenRead(originalPath))
                {
                    await file.CreateAsync(stream.Length);

                    await file.UploadRangeAsync(
                        FileRangeWriteType.Update,
                        new HttpRange(0, stream.Length),
                        stream);
                }

                // Download the file
                StorageFileDownloadInfo download = await file.DownloadAsync();

                using (FileStream stream = File.OpenWrite(downloadPath))
                {
                    await download.Content.CopyToAsync(stream);
                }

                // Verify the contents
                Assert.AreEqual(SampleFileContent, File.ReadAllText(downloadPath));
            }
            finally
            {
                // Clean up after the test when we're finished
                await share.DeleteAsync();
            }
        }
Ejemplo n.º 3
0
        public async Task GivenDirectoryEntry_WhenRoundTrip_Success()
        {
            DirectoryClient client = TestApplication.GetDirectoryClient();

            var documentId = new DocumentId("test/unit-tests/entry1");

            var query = new QueryParameter()
            {
                Filter    = "test/unit-tests",
                Recursive = false,
            };

            IReadOnlyList <DatalakePathItem> search = (await client.Search(query).ReadNext()).Records;

            if (search.Any(x => x.Name == (string)documentId))
            {
                await client.Delete(documentId);
            }

            var entry = new DirectoryEntryBuilder()
                        .SetDirectoryId(documentId)
                        .SetClassType("test")
                        .AddProperty(new EntryProperty {
                Name = "property1", Value = "value1"
            })
                        .Build();

            await client.Set(entry);

            search = (await client.Search(query).ReadNext()).Records;
            search.Any(x => x.Name == (string)documentId).Should().BeTrue();

            DirectoryEntry?readEntry = await client.Get(documentId);

            readEntry.Should().NotBeNull();

            readEntry !.DirectoryId.Should().Be(entry.DirectoryId);
            readEntry.ClassType.Should().Be(entry.ClassType);
            readEntry.ETag.Should().NotBeNull();
            readEntry.Properties.Count.Should().Be(1);

            readEntry.Properties.Values.First().Action(x =>
            {
                (x == entry.Properties.Values.First()).Should().BeTrue();
            });

            await client.Delete(documentId);

            search = (await client.Search(query).ReadNext()).Records;
            search.Any(x => x.Name == (string)documentId).Should().BeFalse();
        }
Ejemplo n.º 4
0
        public async Task UploadAsync()
        {
            // Create a temporary Lorem Ipsum file on disk that we can upload
            string path = CreateTempFile(SampleFileContent);

            // Get a connection string to our Azure Storage account.  You can
            // obtain your connection string from the Azure Portal (click
            // Access Keys under Settings in the Portal Storage account blade)
            // or using the Azure CLI with:
            //
            //     az storage account show-connection-string --name <account_name> --resource-group <resource_group>
            //
            // And you can provide the connection string to your application
            // using an environment variable.
            string connectionString = ConnectionString;

            // Get a reference to a share named "sample-share" and then create it
            ShareClient share = new ShareClient(connectionString, Randomize("sample-share"));
            await share.CreateAsync();

            try
            {
                // Get a reference to a directory named "sample-dir" and then create it
                DirectoryClient directory = share.GetDirectoryClient(Randomize("sample-dir"));
                await directory.CreateAsync();

                // Get a reference to a file named "sample-file" in directory "sample-dir"
                FileClient file = directory.GetFileClient(Randomize("sample-file"));

                // Upload the file
                using (FileStream stream = File.OpenRead(path))
                {
                    await file.CreateAsync(stream.Length);

                    await file.UploadRangeAsync(
                        FileRangeWriteType.Update,
                        new HttpRange(0, stream.Length),
                        stream);
                }

                // Verify the file exists
                StorageFileProperties properties = await file.GetPropertiesAsync();

                Assert.AreEqual(SampleFileContent.Length, properties.ContentLength);
            }
            finally
            {
                // Clean up after the test when we're finished
                await share.DeleteAsync();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called after a client gets the first packet of CS_ZoneList()
        /// </summary>
        /// <param name="pkt"></param>
        /// <param name="client"></param>
        public static void Handle_CS_AckZoneList(CS_AckZoneList pkt, DirectoryClient client)
        {
            //Update the zone list first..
            //Program.server.grabZones();

            List <SC_ZoneList> packets = Program.server.ZoneStream.Packets;

            UInt16 frame = pkt.frameReceived;

            // Can we send the next frame?
            if (++frame < packets.Count)
            {
                client.send(packets[frame]);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Called when a client clicks "Refresh Zone List"
        /// </summary>
        /// <param name="pkt"></param>
        /// <param name="client"></param>
        public static void Handle_CS_ZoneList(CS_ZoneList pkt, DirectoryClient client)
        {
            //Update the zone list first..
            //Program.server.grabZones();

            // Begin sending the zone list packets
            client.ZoneListToken = pkt.Token;

            // Send the first packet
            List <SC_ZoneList> packets = Program.server.ZoneStream.Packets;

            if (packets.Count != 0)
            {
                client.send(packets[0]);
            }
        }
Ejemplo n.º 7
0
        public async Task DirectorySample()
        {
            // Instantiate a new FileServiceClient using a connection string.
            FileServiceClient fileServiceClient = new FileServiceClient(TestConfigurations.DefaultTargetTenant.ConnectionString);

            // Instantiate new ShareClient
            ShareClient shareClient = fileServiceClient.GetShareClient($"myshare2-{Guid.NewGuid()}");

            try
            {
                // Create Share in the Service
                await shareClient.CreateAsync();

                // Instantiate new DirectoryClient
                DirectoryClient directoryClient = shareClient.GetDirectoryClient("mydirectory");

                // Create Directory in the Service
                await directoryClient.CreateAsync();

                // Instantiate new DirectoryClient
                DirectoryClient subDirectoryClient = directoryClient.GetSubdirectoryClient("mysubdirectory");

                // Create sub directory
                await subDirectoryClient.CreateAsync();

                // List Files and Directories
                await foreach (StorageFileItem item in directoryClient.GetFilesAndDirectoriesAsync())
                {
                    var type = item.IsDirectory ? "dir" : "file";
                    Console.WriteLine($"{type}: {item.Name}");
                }

                // Delete sub directory in the Service
                await subDirectoryClient.DeleteAsync();

                // Delete Directory in the Service
                await directoryClient.DeleteAsync();
            }
            finally
            {
                // Delete Share in the service
                await shareClient.DeleteAsync();
            }
        }
        private string InitialiseBuildRun(string sourcePath, string project)
        {
            var tasksDestinationPath = Path.Combine(ConfigurationManager.AppSettings["tasksRunnerRootPath"], project);

            //root path for the source task artifacts
            var tasksSourcePath = sourcePath;

            //create new directory for tasks to run
            if (!Directory.Exists(tasksDestinationPath))
            {
                Directory.CreateDirectory(tasksDestinationPath);
            }

            int latestCount = GetNextBuildNumber(tasksDestinationPath);

            var runPath = Path.Combine(tasksDestinationPath, string.Format("{0}", latestCount));

            Directory.CreateDirectory(runPath);

            //generate basic log to identify task run
            string path = Path.Combine(runPath, string.Format("{0}", WebConfigurationManager.AppSettings[BUILD_LOG_DATA_FILE]));

            // This text is added only once to the file.
            if (!System.IO.File.Exists(path))
            {
                // Create a file to write to.
                using (StreamWriter sw = System.IO.File.CreateText(path))
                {
                    sw.WriteLine(string.Format("{0} Ver: {1}", "Build Runner version", "2.1"));
                    sw.WriteLine(string.Format("{0} {1}", DateTime.UtcNow, runPath));
                }
            }

            //copy all build version specific definition files to latest build running path
            DirectoryClient.DirectoryCopy(tasksSourcePath, runPath, true);

            FileClient.CreateZipFromDirectory(tasksSourcePath, Path.Combine(runPath, WebConfigurationManager.AppSettings[TASK_DEFINITIONS_ARCHIVE]));


            return(runPath);
        }
Ejemplo n.º 9
0
        public async Task DirectorySample()
        {
            // Instantiate a new FileServiceClient using a connection string.
            FileServiceClient fileServiceClient = new FileServiceClient(TestConfigurations.DefaultTargetTenant.ConnectionString);

            // Instantiate new ShareClient
            ShareClient shareClient = fileServiceClient.GetShareClient("myshare2");

            try
            {
                // Create Share in the Service
                await shareClient.CreateAsync();

                // Instantiate new DirectoryClient
                DirectoryClient directoryClient = shareClient.GetDirectoryClient("mydirectory");

                // Create Directory in the Service
                await directoryClient.CreateAsync();

                // Instantiate new DirectoryClient
                DirectoryClient subDirectoryClient = directoryClient.GetDirectoryClient("mysubdirectory");

                // Create sub directory
                await subDirectoryClient.CreateAsync();

                // List Files and Directories
                Response <FilesAndDirectoriesSegment> listResponse = await directoryClient.ListFilesAndDirectoriesSegmentAsync();

                // Delete sub directory in the Service
                await subDirectoryClient.DeleteAsync();

                // Delete Directory in the Service
                await directoryClient.DeleteAsync();
            }
            finally
            {
                // Delete Share in the service
                await shareClient.DeleteAsync();
            }
        }
Ejemplo n.º 10
0
    public static async Task <IServiceCollection> ConfigureContractService(this IServiceCollection service, ApplicationOption option)
    {
        service.VerifyNotNull(nameof(service));

        ApplicationOption applicationOption = await DirectoryClient.Run(option.DirectoryUrl, option.DirectoryApiKey, async client =>
        {
            ServiceRecord contractRecord = await client.GetServiceRecord(option.RunEnvironment, "Contract");
            ServiceRecord artifactRecord = await client.GetServiceRecord(option.RunEnvironment, "Artifact");

            option = option with
            {
                HostUrl = contractRecord.HostUrl,
                ApiKey  = contractRecord.ApiKey,

                ArtifactUrl    = artifactRecord.HostUrl,
                ArtifactApiKey = artifactRecord.ApiKey,
            };

            return(option.Verify());
        });

        service.AddSingleton(applicationOption);
        service.AddSingleton <ContractService>();

        service.AddHttpClient <SigningClient>((service, httpClient) =>
        {
            ApplicationOption option = service.GetRequiredService <ApplicationOption>();
            httpClient.BaseAddress   = new Uri(option.DirectoryUrl);
            httpClient.DefaultRequestHeaders.Add(Constants.ApiKeyName, option.DirectoryApiKey);
        });

        service.AddHttpClient <ArtifactClient>((service, httpClient) =>
        {
            ApplicationOption option = service.GetRequiredService <ApplicationOption>();
            httpClient.BaseAddress   = new Uri(option.ArtifactUrl);
            httpClient.DefaultRequestHeaders.Add(Constants.ApiKeyName, option.ArtifactApiKey);
        });

        return(service);
    }
Ejemplo n.º 11
0
    public static async Task <IServiceCollection> ConfigureArtifactService(this IServiceCollection service, ApplicationOption option)
    {
        service.VerifyNotNull(nameof(service));

        ApplicationOption applicationOption = await DirectoryClient.Run <ApplicationOption>(option.DirectoryUrl, option.DirectoryApiKey, async client =>
        {
            ServiceRecord serviceRecord = await client.GetServiceRecord(option.RunEnvironment, "Artifact");
            IReadOnlyList <StorageRecord> storageRecords = await client.GetStorageRecord(option.RunEnvironment, "Artifact");

            return(option with
            {
                HostUrl = serviceRecord.HostUrl,
                ApiKey = serviceRecord.ApiKey,
                Storage = storageRecords,
            });
        });

        service.AddSingleton <IDocumentPackage, DocumentPackage>();
        service.AddSingleton(applicationOption);

        service.AddSingleton <DocumentPackageFactory>(service =>
        {
            ApplicationOption option     = service.GetRequiredService <ApplicationOption>();
            ILoggerFactory loggerFactory = service.GetRequiredService <ILoggerFactory>();

            var list = option.Storage
                       .Select(x => (Container: x.Container, Option: new DatalakeStoreOption
            {
                AccountName = x.AccountName,
                ContainerName = x.ContainerName,
                AccountKey = x.AccountKey,
                BasePath = x.BasePath
            }));

            return(new DocumentPackageFactory(list, loggerFactory));
        });

        return(service);
    }
        private string InitialiseBuildRun()
        {
            var tasksDestinationPath = ConfigurationManager.AppSettings["tasksRunnerRootPath"];

            //root path for the source task artifacts
            var tasksSourcePath = ConfigurationManager.AppSettings["tasksSourcePath"];

            //create new directory for tasks to run
            if (!Directory.Exists(tasksDestinationPath))
            {
                Directory.CreateDirectory(tasksDestinationPath);
            }

            int latestCount = GetNextBuildNumber(tasksDestinationPath);

            var runPath = Path.Combine(tasksDestinationPath, string.Format("{0}", latestCount));

            Directory.CreateDirectory(runPath);

            //generate basic log to identify task run
            string path = Path.Combine(runPath, string.Format("{0}", "build.log"));

            // This text is added only once to the file.
            if (!File.Exists(path))
            {
                // Create a file to write to.
                using (StreamWriter sw = File.CreateText(path))
                {
                    sw.WriteLine(string.Format("{0} Ver: {1}", "Build Runner version", "2.1"));
                    sw.WriteLine(string.Format("{0} {1}", DateTime.UtcNow, runPath));
                }
            }

            //copy build artifacts
            DirectoryClient.DirectoryCopy(tasksSourcePath, runPath, true);
            return(runPath);
        }
Ejemplo n.º 13
0
            public static async Task <DisposingDirectory> CreateAsync(DisposingShare test, DirectoryClient directory)
            {
                await directory.CreateAsync();

                return(new DisposingDirectory(test, directory));
            }
Ejemplo n.º 14
0
 public ListActivity(DirectoryClient directoryClient, ILogger <ListActivity> logger)
 {
     _directoryClient = directoryClient;
     _logger          = logger;
 }
Ejemplo n.º 15
0
        public async Task TraverseAsync()
        {
            // Create a temporary Lorem Ipsum file on disk that we can upload
            string originalPath = CreateTempFile(SampleFileContent);

            // Get a connection string to our Azure Storage account.
            string connectionString = ConnectionString;

            // Get a reference to a share named "sample-share" and then create it
            ShareClient share = new ShareClient(connectionString, Randomize("sample-share"));
            await share.CreateAsync();

            try
            {
                // Create a bunch of directories
                DirectoryClient first = await share.CreateDirectoryAsync("first");

                await first.CreateSubdirectoryAsync("a");

                await first.CreateSubdirectoryAsync("b");

                DirectoryClient second = await share.CreateDirectoryAsync("second");

                await second.CreateSubdirectoryAsync("c");

                await second.CreateSubdirectoryAsync("d");

                await share.CreateDirectoryAsync("third");

                DirectoryClient fourth = await share.CreateDirectoryAsync("fourth");

                DirectoryClient deepest = await fourth.CreateSubdirectoryAsync("e");

                // Upload a file named "file"
                FileClient file = deepest.GetFileClient("file");
                using (FileStream stream = File.OpenRead(originalPath))
                {
                    await file.CreateAsync(stream.Length);

                    await file.UploadRangeAsync(
                        FileRangeWriteType.Update,
                        new HttpRange(0, stream.Length),
                        stream);
                }

                // Keep track of all the names we encounter
                List <string> names = new List <string>();

                // Track the remaining directories to walk, starting from the root
                Queue <DirectoryClient> remaining = new Queue <DirectoryClient>();
                remaining.Enqueue(share.GetRootDirectoryClient());
                while (remaining.Count > 0)
                {
                    // Get all of the next directory's files and subdirectories
                    DirectoryClient dir = remaining.Dequeue();
                    await foreach (StorageFileItem item in dir.GetFilesAndDirectoriesAsync())
                    {
                        // Track the name of the item
                        names.Add(item.Name);

                        // Keep walking down directories
                        if (item.IsDirectory)
                        {
                            remaining.Enqueue(dir.GetSubdirectoryClient(item.Name));
                        }
                    }
                }

                // Verify we've seen everything
                Assert.AreEqual(10, names.Count);
                Assert.Contains("first", names);
                Assert.Contains("second", names);
                Assert.Contains("third", names);
                Assert.Contains("fourth", names);
                Assert.Contains("a", names);
                Assert.Contains("b", names);
                Assert.Contains("c", names);
                Assert.Contains("d", names);
                Assert.Contains("e", names);
                Assert.Contains("file", names);
            }
            finally
            {
                // Clean up after the test when we're finished
                await share.DeleteAsync();
            }
        }
Ejemplo n.º 16
0
 public SetActivity(DirectoryClient directoryClient, IdentityClient identityClient, ILogger <SetActivity> logger)
 {
     _directoryClient = directoryClient;
     _identityClient  = identityClient;
     _logger          = logger;
 }
Ejemplo n.º 17
0
 public IDisposable GetNewDirectory(out DirectoryClient directory, FileServiceClient service = default)
 {
     var disposingShare = this.GetNewShare(out var share, default, service);
Ejemplo n.º 18
0
 public IDisposable GetNewDirectory(out DirectoryClient directory, FileServiceClient service = default)
 {
     IDisposable disposingShare = GetNewShare(out ShareClient share, default, service);
Ejemplo n.º 19
0
 public DeleteActivity(DirectoryClient directoryClient, ILogger <DeleteActivity> logger)
 {
     _directoryClient = directoryClient;
     _logger          = logger;
 }
Ejemplo n.º 20
0
 private DisposingDirectory(DisposingShare test, DirectoryClient directory)
 {
     _test     = test;
     Directory = directory;
 }