Exemplo n.º 1
0
        public override FileProviderBase CreateProvider()
        {
            FileProviderBase result = null;

            try
            {
                string   fileName = CommaDelimitedFileUnitTest.ComposeFileName();
                IMonitor monitor  = new ConsoleMonitor();
                result = new AccessConnectivityEngineFileProviderFactory(fileName, monitor).CreateProvider();
                return(result);
            }
            catch
            {
                if (result != null)
                {
                    result.Dispose();
                    result = null;
                }

                throw;
            }
        }
Exemplo n.º 2
0
        private static void Main(string[] arguments)
        {
            if (null == arguments)
            {
                Console.WriteLine(FileProvisioningServiceResources.InformationCommandLineArguments);
                return;
            }

            if (Program.NumberArguments > arguments.Length)
            {
                Console.WriteLine(FileProvisioningServiceResources.InformationCommandLineArguments);
                return;
            }

            string argumentBaseAddress = arguments[0];
            Uri    baseAddress         = null;

            if (!Uri.TryCreate(argumentBaseAddress, UriKind.Absolute, out baseAddress))
            {
                Console.WriteLine(FileProvisioningServiceResources.InformationCommandLineArguments);
                return;
            }

            string informationBaseAddress =
                string.Format(
                    CultureInfo.InvariantCulture,
                    FileProvisioningServiceResources.InformationBaseAddressTemplate,
                    argumentBaseAddress);

            Console.WriteLine(informationBaseAddress);

            IMonitor monitor = new ProvisioningAgentMonitor(FileProvisioningServiceResources.PromptTerminate);

            FileProviderBase provider = null;

            try
            {
                provider =
                    new AccessConnectivityEngineFileProviderFactory(
                        arguments[1],
                        monitor)
                    .CreateProvider();
                Service webService = null;
                try
                {
                    webService = new WebService(monitor, provider);
                    webService.Start(baseAddress);

                    string informationStarted =
                        string.Format(
                            CultureInfo.InvariantCulture,
                            FileProvisioningServiceResources.InformationServiceStartedTemplate,
                            argumentBaseAddress);
                    Console.WriteLine(informationStarted);

                    Console.WriteLine(FileProvisioningServiceResources.PromptTerminate);
                    Console.ReadKey(true);
                }
                finally
                {
                    if (webService != null)
                    {
                        webService.Dispose();
                        webService = null;
                    }
                }
            }
            finally
            {
                if (provider != null)
                {
                    provider.Dispose();
                    provider = null;
                }
            }
        }
Exemplo n.º 3
0
        private static void Main(string[] arguments)
        {
            if (null == arguments)
            {
                Console.WriteLine(FileProvisioningAgentResources.InformationCommandLineArguments);
                return;
            }

            if (Program.NumberArguments != arguments.Length)
            {
                Console.WriteLine(FileProvisioningAgentResources.InformationCommandLineArguments);
                return;
            }

            Guid   tenantIdentifier           = new Guid(arguments[1]);
            Guid   servicePrincipalIdentifier = new Guid(arguments[2]);
            string provisioningTaskIdentifier =
                new AzureToAgentTaskIdentifierFactory()
                .Create(
                    tenantIdentifier,
                    servicePrincipalIdentifier);

            IMonitor monitor = new ProvisioningAgentMonitor(FileProvisioningAgentResources.PromptTerminate);

            FileProviderBase provider = null;

            try
            {
                provider =
                    new AccessConnectivityEngineFileProviderFactory(
                        arguments[0],
                        monitor)
                    .CreateProvider();

                TokenFactory tokenFactory = null;
                try
                {
                    tokenFactory = new AzureHubClientTokenFactory(arguments[3], arguments[4]);

                    IAgent agent = null;
                    try
                    {
                        agent =
                            new Agent(
                                provisioningTaskIdentifier,
                                tokenFactory,
                                provider,
                                monitor);
                        tokenFactory = null;

                        CancellationTokenSource terminationTokenSource = null;
                        try
                        {
                            terminationTokenSource = new CancellationTokenSource();
                            CancellationToken terminationToken     = terminationTokenSource.Token;
                            Func <Task>       provisioningFunction =
                                new Func <Task>(
                                    () =>
                                    agent.ProvisionAsync(terminationToken));
                            Task provisioningTask = null;
                            try
                            {
                                provisioningTask = Task.Run(provisioningFunction, terminationToken);
                                Console.WriteLine(FileProvisioningAgentResources.PromptTerminate);
                                Console.ReadKey(true);
                                terminationTokenSource.Cancel();
                            }
                            catch (AggregateException exception)
                            {
                                if (!Program.IsOperationCancelledException(exception))
                                {
                                    throw;
                                }
                            }
                            catch (OperationCanceledException)
                            {
                            }
                            finally
                            {
                                if (provisioningTask != null)
                                {
                                    provisioningTask.Wait();
                                    provisioningTask.Dispose();
                                    provisioningTask = null;
                                }
                            }
                        }
                        finally
                        {
                            if (terminationTokenSource != null)
                            {
                                terminationTokenSource.Dispose();
                                terminationTokenSource = null;
                            }
                        }
                    }
                    finally
                    {
                        if (agent != null)
                        {
                            agent.Dispose();
                            agent = null;
                        }
                    }
                }
                finally
                {
                    if (tokenFactory != null)
                    {
                        tokenFactory.Dispose();
                        tokenFactory = null;
                    }
                }
            }
            finally
            {
                if (provider != null)
                {
                    provider.Dispose();
                    provider = null;
                }
            }
        }
        public void TestCreateUser()
        {
            Uri resourceBase  = new Uri(WebServiceUnitTest.AddressBase);
            Uri resourceUsers = new Uri(WebServiceUnitTest.AddressRelativeUsers, UriKind.Relative);

            IMonitor monitor  = new ConsoleMonitor();
            string   fileName = CommaDelimitedFileUnitTest.ComposeFileName();

            FileProviderBase provider = null;

            try
            {
                provider = new AccessConnectivityEngineFileProviderFactory(fileName, monitor).CreateProvider();
                Service webService = null;
                try
                {
                    webService = new WebService(monitor, provider);
                    webService.Start(resourceBase);

                    IDictionary <string, object> json = SampleComposer.Instance.ComposeUserResource().ToJson();
                    string characters = WebServiceUnitTest.Serializer.Value.Serialize(json);
                    byte[] bytes      = Encoding.UTF8.GetBytes(characters);

                    Uri resource = new Uri(resourceBase, resourceUsers);

                    WebClient client = null;
                    try
                    {
                        client = new WebClient();
                        client.Headers.Add(HttpRequestHeader.ContentType, WebServiceUnitTest.ContentTypeJson);
                        byte[] response           = client.UploadData(resource.AbsoluteUri, WebRequestMethods.Http.Post, bytes);
                        string responseCharacters = Encoding.UTF8.GetString(response);
                        IReadOnlyDictionary <string, object> responseJson =
                            WebServiceUnitTest.Serializer.Value.Deserialize <Dictionary <string, object> >(responseCharacters);
                        Core2EnterpriseUser user = new Core2EnterpriseUserJsonDeserializingFactory().Create(responseJson);
                        Assert.IsNotNull(user);
                        Assert.IsNotNull(
                            user
                            .Schemas
                            .SingleOrDefault(
                                (string item) =>
                                string.Equals(
                                    SchemaIdentifiers.Core2EnterpriseUser,
                                    item,
                                    StringComparison.Ordinal)));
                        Assert.IsFalse(string.IsNullOrWhiteSpace(user.Identifier));
                        Assert.IsNotNull(user.Metadata);
                        Assert.IsFalse(string.IsNullOrWhiteSpace(user.Metadata.ResourceType));

                        string resourcePathValue =
                            string.Concat(WebServiceUnitTest.AddressRelativeUser, user.Identifier);
                        Uri resourcePath = new Uri(resourcePathValue, UriKind.Relative);
                        resource = new Uri(resourceBase, resourcePath);
                        bytes    = new byte[0];
                        client.UploadData(resource, WebServiceUnitTest.MethodDelete, bytes);
                    }
                    finally
                    {
                        if (client != null)
                        {
                            client.Dispose();
                            client = null;
                        }
                    }
                }
                finally
                {
                    if (webService != null)
                    {
                        webService.Dispose();
                        webService = null;
                    }
                }
            }
            finally
            {
                if (provider != null)
                {
                    provider.Dispose();
                    provider = null;
                }
            }
        }
        public void TestRetrieveGroup()
        {
            Uri resourceBase = new Uri(WebServiceUnitTest.AddressBase);

            IMonitor monitor = new ConsoleMonitor();

            string fileName = CommaDelimitedFileUnitTest.ComposeFileName();

            FileProviderBase provider = null;

            try
            {
                provider = new AccessConnectivityEngineFileProviderFactory(fileName, monitor).CreateProvider();
                Service webService = null;
                try
                {
                    webService = new WebService(monitor, provider);
                    webService.Start(resourceBase);

                    Guid   groupIdentifier       = Guid.NewGuid();
                    string resourceRelativeValue =
                        string.Format(
                            CultureInfo.InvariantCulture,
                            WebServiceUnitTest.AddressRelativeGroupTemplate,
                            groupIdentifier);
                    Uri resourceRelative = new Uri(resourceRelativeValue, UriKind.Relative);
                    Uri resource         = new Uri(resourceBase, resourceRelative);

                    HttpWebResponse response = null;

                    WebClient client = null;
                    try
                    {
                        client = new WebClient();
                        try
                        {
                            client.DownloadData(resource);
                        }
                        catch (WebException exception)
                        {
                            response = exception.Response as HttpWebResponse;
                        }
                    }
                    finally
                    {
                        if (client != null)
                        {
                            client.Dispose();
                            client = null;
                        }
                    }

                    Assert.IsNotNull(response);
                    Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
                }
                finally
                {
                    if (webService != null)
                    {
                        webService.Dispose();
                        webService = null;
                    }
                }
            }
            finally
            {
                if (provider != null)
                {
                    provider.Dispose();
                    provider = null;
                }
            }
        }