예제 #1
0
        public async Task AssemblerSynchronizePerformanceTest()
        {
            this.dal = new CdpServicesDal();

            var returned = await this.dal.Open(this.credentials, this.cancelationTokenSource.Token);

            var       returnedlist    = returned.ToList();
            const int iterationNumber = 1000;
            var       elapsedTimes    = new List <long>();

            for (int i = 0; i < iterationNumber; i++)
            {
                var assemble  = new Assembler(this.uri);
                var stopwatch = Stopwatch.StartNew();
                await assemble.Synchronize(returnedlist);

                elapsedTimes.Add(stopwatch.ElapsedMilliseconds);
                await assemble.Clear();
            }

            var synchronizeMeanElapsedTime = elapsedTimes.Average();
            var maxElapsedTime             = elapsedTimes.Max();
            var minElapsedTime             = elapsedTimes.Min();
            // 204.64 | 181 | 458 ms
            // refactor: 31.61 | 26 | 283
        }
 public void TearDown()
 {
     CDPMessageBus.Current.ClearSubscriptions();
     this.credentials = null;
     this.dal         = null;
     this.session     = null;
 }
예제 #3
0
        public async Task VerifyThatReadIterationWorks()
        {
            var dal = new CdpServicesDal {
                Session = this.session
            };
            var credentials = new Credentials("admin", "pass", new Uri("https://cdp4services-public.cdp4.org"));
            var session     = new Session(dal, credentials);

            var returned = await dal.Open(credentials, this.cancelationTokenSource.Token);

            await session.Assembler.Synchronize(returned);

            var siteDir        = session.Assembler.RetrieveSiteDirectory();
            var modelSetup     = siteDir.Model.Single(x => x.ShortName == "LOFT");
            var iterationSetup = modelSetup.IterationSetup.First();

            var openCount = session.Assembler.Cache.Count;

            var model     = new EngineeringModel(modelSetup.EngineeringModelIid, null, null);
            var iteration = new Iteration(iterationSetup.IterationIid, null, null);

            iteration.Container = model;

            var modelDtos = await dal.Read((CDP4Common.DTO.Iteration) iteration.ToDto(), this.cancelationTokenSource.Token);

            await session.Assembler.Synchronize(modelDtos);

            var readCount = session.Assembler.Cache.Count;

            Assert.IsTrue(readCount > openCount);
        }
예제 #4
0
        public async Task VerifyThatReadReturnsCorrectDTO()
        {
            this.dal = new CdpServicesDal();

            var returned = (await this.dal.Open(this.credentials, this.cancelationTokenSource.Token)).ToList();

            Assert.NotNull(returned);
            Assert.IsNotEmpty(returned);

            var sd = returned.First();

            var attributes = new QueryAttributes();
            var readResult = await dal.Read(sd, this.cancelationTokenSource.Token, attributes);

            // General assertions for any kind of Thing we read
            Assert.NotNull(readResult);
            Assert.IsTrue(readResult.Count() == 1);
            var sd1 = readResult.Single();

            Assert.IsTrue(sd.ClassKind == sd1.ClassKind);
            Assert.IsTrue(sd.Iid == sd1.Iid);
            Assert.IsTrue(sd.Route == sd1.Route);

            // Specific assertions for Sitedirectory ClassKind
            var castedSd  = sd as CDP4Common.DTO.SiteDirectory;
            var castedSd1 = sd as CDP4Common.DTO.SiteDirectory;

            Assert.NotNull(castedSd);
            Assert.NotNull(castedSd1);
            Assert.IsTrue(castedSd.Name == castedSd1.Name);
            Assert.IsTrue(castedSd.Domain.Count == castedSd1.Domain.Count);
            Assert.IsTrue(castedSd.SiteReferenceDataLibrary == castedSd1.SiteReferenceDataLibrary);
            Assert.IsTrue(castedSd.Model == castedSd1.Model);
        }
예제 #5
0
        public async Task Verify_that_person_can_be_Posted()
        {
            var cdpServicesDal = new CdpServicesDal();
            var dtos           = await cdpServicesDal.Open(this.credentials, this.cancelationTokenSource.Token);

            var siteDirectory = (CDP4Common.DTO.SiteDirectory)dtos.Single(x => x.ClassKind == ClassKind.SiteDirectory);

            var context            = siteDirectory.Route;
            var operationContainer = new OperationContainer(context, siteDirectory.RevisionNumber);

            var person = new CDP4Common.DTO.Person(Guid.NewGuid(), 1);

            person.ShortName = Guid.NewGuid().ToString();
            person.Surname   = Guid.NewGuid().ToString();
            person.GivenName = Guid.NewGuid().ToString();
            person.AddContainer(ClassKind.SiteDirectory, siteDirectory.Iid);

            var operation1 = new Operation(null, person, OperationKind.Create);

            operationContainer.AddOperation(operation1);

            var siteDirectoryClone = siteDirectory.DeepClone <CDP4Common.DTO.SiteDirectory>();

            siteDirectoryClone.Person.Add(person.Iid);
            var operation2 = new Operation(siteDirectory, siteDirectoryClone, OperationKind.Update);

            operationContainer.AddOperation(operation2);

            var result = await cdpServicesDal.Write(operationContainer);

            var resultPerson = (CDP4Common.DTO.Person)result.Single(x => x.Iid == person.Iid);

            Assert.NotNull(resultPerson);
        }
예제 #6
0
        public void VerifyThatIsValidUriReturnsExpectedResult()
        {
            var dal = new CdpServicesDal();

            Assert.IsTrue(dal.IsValidUri("http://cdp4services-test.cdp4.org"));
            Assert.IsTrue(dal.IsValidUri("https://cdp4services-test.cdp4.org"));
            Assert.IsFalse(dal.IsValidUri("file://some file"));
        }
예제 #7
0
        public async Task VerifyThatSessionMustBeSetToReadIteration()
        {
            var iterationDto = new CDP4Common.DTO.Iteration(Guid.NewGuid(), 0);

            var dal = new CdpServicesDal();

            Assert.That(async() => await dal.Read(iterationDto, new CancellationToken()), Throws.TypeOf <InvalidOperationException>());
        }
예제 #8
0
        public async Task VerifThatAClosedDalCannotBeClosedAgain()
        {
            var dal = new CdpServicesDal();
            await dal.Open(this.credentials, new CancellationToken());

            dal.Close();

            Assert.Throws <InvalidOperationException>(() => dal.Close());
        }
예제 #9
0
        public async Task Vefify_that_when_OperationContainer_is_empty_an_empty_is_returned()
        {
            var dal = new CdpServicesDal();

            this.SetDalToBeOpen(dal);

            var context            = $"/EngineeringModel/{Guid.NewGuid()}/iteration/{Guid.NewGuid()}";
            var operationContainer = new OperationContainer(context);

            Assert.That(await dal.Write(operationContainer), Is.Empty);
        }
예제 #10
0
        public async Task VerifyThatIfCredentialsAreNullOnReadExceptionIsThrown()
        {
            var organizationIid = Guid.Parse("44d1ff16-8195-47d0-abfa-163bbba9bf39");
            var organizationDto = new CDP4Common.DTO.Organization(organizationIid, 0);

            organizationDto.AddContainer(ClassKind.SiteDirectory, Guid.Parse("eb77f3e1-a0f3-412d-8ed6-b8ce881c0145"));

            var dal = new CdpServicesDal();

            Assert.That(async() => await dal.Read(organizationDto, new CancellationToken()), Throws.TypeOf <InvalidOperationException>());
        }
예제 #11
0
        public async Task Verify_that_opens_returns_expected_result()
        {
            var uri = new Uri("https://cdp4services-test.cdp4.org");

            this.credentials = new Credentials("admin", "pass", uri);

            var dal    = new CdpServicesDal();
            var result = await dal.Open(this.credentials, new CancellationToken());

            Assert.NotNull(result);
        }
예제 #12
0
        /// <summary>
        /// Runs this console app
        /// </summary>
        public void Run()
        {
            // Setup NLog
            var config = new LoggingConfiguration();

            // Targets where to log to: Console
            var logConsole = new ConsoleTarget("logConsole");

            // Rules for mapping loggers to targets
            config.AddRule(LogLevel.Trace, LogLevel.Fatal, logConsole);

            // Apply config
            LogManager.Configuration = config;

            this.PrintSeparator();
            Console.WriteLine("Welcome to CDP4 SDK sample app!");
            this.PrintSeparator();

            Console.WriteLine("Enter your user name (default is admin, just press Enter):");
            var userName = string.IsNullOrWhiteSpace(Console.ReadLine()) ? "admin" : Console.ReadLine();

            Console.WriteLine("Enter your password (to use default just press Enter):");
            var pass = string.IsNullOrWhiteSpace(Console.ReadLine()) ? "pass" : Console.ReadLine();

            Console.WriteLine(
                "Enter a server's URL for future requests (default is https://cdp4services-test.cdp4.org, just press Enter):");
            this.uri = new Uri(string.IsNullOrWhiteSpace(Console.ReadLine())
                ? "https://cdp4services-test.cdp4.org"
                : Console.ReadLine());

            var dal = new CdpServicesDal();

            this.credentials = new Credentials(userName, pass, this.uri);
            this.session     = new Session(dal, this.credentials);

            this.PrintCommands();

            while (this.isRunning)
            {
                try
                {
                    this.ExecuteCommand(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    this.PrintSeparator();
                    Console.WriteLine("Something went wrong. Sorry about that.");
                    Console.WriteLine(ex.Message);
                    this.PrintSeparator();
                }
            }
        }
예제 #13
0
 public void TearDown()
 {
     CDPMessageBus.Current.ClearSubscriptions();
     this.credentials               = null;
     this.dal                       = null;
     this.session                   = null;
     this.siteDirectory             = null;
     this.siteReferenceDataLibrary  = null;
     this.modelReferenceDataLibrary = null;
     this.iterationSetup            = null;
     this.engineeringModelSetup     = null;
     this.engineeringModel          = null;
 }
예제 #14
0
        /// <summary>
        /// Opens a session and set the properties
        /// </summary>
        public void Open()
        {
            var dal = new CdpServicesDal();

            this.credentials = new Credentials(this.commandArguments.UserName, this.commandArguments.Password, this.commandArguments.ServerUri);
            this.Session ??= new Session(dal, this.credentials);
            this.Session.Open().GetAwaiter().GetResult();

            if (this.SetProperties())
            {
                this.filterService.ProcessFilters(this.Iteration, this.SiteDirectory.Domain);
            }
        }
예제 #15
0
        public void Setup()
        {
            this.cancelationTokenSource = new CancellationTokenSource();

            this.credentials = new Credentials("admin", "pass", this.uri);
            this.dal         = new CdpServicesDal();
            this.session     = new Session(this.dal, this.credentials);

            // Add SiteDirectory to cache
            this.siteDirectory = new SiteDirectory(Guid.Parse("f13de6f8-b03a-46e7-a492-53b2f260f294"), this.session.Assembler.Cache, this.uri);
            var lazySiteDirectory = new Lazy <Thing>(() => this.siteDirectory);

            lazySiteDirectory.Value.Cache.TryAdd(new CacheKey(lazySiteDirectory.Value.Iid, null), lazySiteDirectory);

            this.PopulateSiteDirectory();
        }
예제 #16
0
        /// <summary>
        /// Login (authenticate) with a username and password to an E-TM-10-25 data source
        /// </summary>
        /// <param name="userName">
        /// The username to authenticate with
        /// </param>
        /// <param name="password">
        ///The password to authenticate with
        /// </param>
        /// <returns>
        /// The <see cref="Person"/> object that corresponds to the provided <paramref name="userName"/>
        /// </returns>
        public async Task <Person> Login(string userName, string password)
        {
            var uri         = new Uri("https://cdp4services-public.cdp4.org");
            var credentials = new CDP4Dal.DAL.Credentials(userName, password, uri);
            var dal         = new CdpServicesDal();

            var session = new Session(dal, credentials);
            await session.Open();

            this.sessionAnchor.Session = session;

            ((CDP4AuthenticationStateProvider)this.authenticationStateProvider).NotifyAuthenticationStateChanged();

            Console.WriteLine($"user:{session.ActivePerson.Name}");

            return(session.ActivePerson);
        }
예제 #17
0
        public async Task VerifyThatOpenReturnsDTOs()
        {
            var uriBuilder = new UriBuilder(this.credentials.Uri)
            {
                Path = "/Data/Restore"
            };
            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes($"{credentials.UserName}:{credentials.Password}")));
            await httpClient.PostAsync(uriBuilder.Uri, null);

            var dal    = new CdpServicesDal();
            var result = await dal.Open(this.credentials, new CancellationToken());

            var amountOfDtos = result.ToList().Count;

            Assert.AreEqual(86, amountOfDtos);
        }
예제 #18
0
        public void VerifyThatWritingMultipleOperationContainersIsNotSupported()
        {
            var dal = new CdpServicesDal();

            this.SetDalToBeOpen(dal);

            var contextOne = $"/EngineeringModel/{Guid.NewGuid()}/iteration/{Guid.NewGuid()}";
            var contextTwo = $"/EngineeringModel/{Guid.NewGuid()}/iteration/{Guid.NewGuid()}";

            var operationContainerOne = new OperationContainer(contextOne);
            var operationContainerTwo = new OperationContainer(contextTwo);

            var operationContainers = new List <OperationContainer> {
                operationContainerOne, operationContainerTwo
            };

            Assert.Throws <NotSupportedException>(() => dal.Write(operationContainers));

            Assert.Throws <NotSupportedException>(() => dal.Write(operationContainers));
        }
예제 #19
0
        public async Task IntegrationTest()
        {
            this.dal = new CdpServicesDal();
            var returned = await this.dal.Open(this.credentials, this.cancelationTokenSource.Token);

            var assembler = new Assembler(this.credentials.Uri);

            await assembler.Synchronize(returned);

            var attributes = new DalQueryAttributes {
                RevisionNumber = 0
            };
            var topcontainers = assembler.Cache.Select(x => x.Value).Where(x => x.Value is CDP4Common.CommonData.TopContainer).ToList();

            foreach (var container in topcontainers)
            {
                returned = await this.dal.Read(container.Value.ToDto(), this.cancelationTokenSource.Token, attributes);

                await assembler.Synchronize(returned);
            }
        }
예제 #20
0
        public async Task Verify_that_multiple_read_requests_can_be_made_in_parallel()
        {
            var uri         = new Uri("https://cdp4services-test.cdp4.org");
            var credentials = new Credentials("admin", "pass", uri);
            var assembler   = new Assembler(this.uri);

            var dal     = new CdpServicesDal();
            var session = new Session(dal, credentials);

            var result = await dal.Open(credentials, new CancellationToken());

            var siteDirectory = result.OfType <CDP4Common.DTO.SiteDirectory>().Single();

            var queryAttributes = new QueryAttributes {
                Extent = ExtentQueryAttribute.deep
            };

            for (int i = 0; i < 9; i++)
            {
                dal.Read(siteDirectory, new CancellationToken(), queryAttributes);
            }

            var readresult = await dal.Read(siteDirectory, new CancellationToken());
        }
예제 #21
0
        public async Task Verify_that_opens_and_close_removes_items_from_cache()
        {
            this.dal = new CdpServicesDal {
                Session = this.session
            };
            this.credentials = new Credentials("admin", "pass", new Uri("https://cdp4services-public.cdp4.org"));

            this.session = new Session(dal, credentials);
            await this.session.Open();

            this.siteDirectory         = session.Assembler.RetrieveSiteDirectory();
            this.engineeringModelSetup = this.siteDirectory.Model.Single(x => x.ShortName == "LOFT");
            this.iterationSetup        = this.engineeringModelSetup.IterationSetup.First();
            var domainOfExpertise = this.engineeringModelSetup.ActiveDomain.First(x => x.ShortName == "SYS");

            var openCount = this.session.Assembler.Cache.Count;

            var cache = this.session.Assembler.Cache;

            var model = new EngineeringModel(this.engineeringModelSetup.EngineeringModelIid, null, null);

            this.iteration           = new Iteration(this.iterationSetup.IterationIid, null, null);
            this.iteration.Container = model;

            await this.session.Read(iteration, domainOfExpertise);

            var readCount = this.session.Assembler.Cache.Count;

            Assert.IsTrue(readCount > openCount);

            await this.session.CloseIterationSetup(this.iterationSetup);

            var closeCount = this.session.Assembler.Cache.Count;

            Assert.IsTrue(closeCount < readCount);
        }
예제 #22
0
        public async Task VerifyThatFileCanBeUploaded()
        {
            this.dal = new CdpServicesDal {
                Session = this.session
            };

            var filename  = @"TestData\testfile.pdf";
            var directory = TestContext.CurrentContext.TestDirectory;
            var filepath  = Path.Combine(directory, filename);
            var files     = new List <string> {
                filepath
            };

            var contentHash = "F73747371CFD9473C19A0A7F99BCAB008474C4CA";
            var uri         = new Uri("https://cdp4services-test.cdp4.org");

            this.credentials = new Credentials("admin", "pass", uri);

            var returned = await this.dal.Open(this.credentials, this.cancelationTokenSource.Token);

            var engineeringModeliid  = Guid.Parse("9ec982e4-ef72-4953-aa85-b158a95d8d56");
            var iterationiid         = Guid.Parse("e163c5ad-f32b-4387-b805-f4b34600bc2c");
            var domainFileStoreIid   = Guid.Parse("da7dddaa-02aa-4897-9935-e8d66c811a96");
            var fileIid              = Guid.NewGuid();
            var fileRevisionIid      = Guid.NewGuid();
            var domainOfExpertiseIid = Guid.Parse("0e92edde-fdff-41db-9b1d-f2e484f12535");
            var fileTypeIid          = Guid.Parse("b16894e4-acb5-4e81-a118-16c00eb86d8f"); //PDF
            var participantIid       = Guid.Parse("284334dd-e8e5-42d6-bc8a-715c507a7f02");

            var originalDomainFileStore = new CDP4Common.DTO.DomainFileStore(domainFileStoreIid, 0);

            originalDomainFileStore.AddContainer(ClassKind.Iteration, iterationiid);
            originalDomainFileStore.AddContainer(ClassKind.EngineeringModel, engineeringModeliid);

            var modifiedDomainFileStore = new CDP4Common.DTO.DomainFileStore(domainFileStoreIid, 0);

            modifiedDomainFileStore.File.Add(fileIid);
            modifiedDomainFileStore.AddContainer(ClassKind.Iteration, iterationiid);
            modifiedDomainFileStore.AddContainer(ClassKind.EngineeringModel, engineeringModeliid);

            var file = new CDP4Common.DTO.File(fileIid, 0)
            {
                Owner = domainOfExpertiseIid
            };

            file.FileRevision.Add(fileRevisionIid);
            file.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid);
            file.AddContainer(ClassKind.Iteration, iterationiid);
            file.AddContainer(ClassKind.EngineeringModel, engineeringModeliid);

            var fileRevision = new CDP4Common.DTO.FileRevision(fileRevisionIid, 0);

            fileRevision.Name        = "testfile";
            fileRevision.ContentHash = contentHash;
            fileRevision.FileType.Add(new OrderedItem()
            {
                K = 1, V = fileTypeIid
            });
            fileRevision.Creator = participantIid;
            fileRevision.AddContainer(ClassKind.File, fileIid);
            fileRevision.AddContainer(ClassKind.DomainFileStore, domainFileStoreIid);
            fileRevision.AddContainer(ClassKind.Iteration, iterationiid);
            fileRevision.AddContainer(ClassKind.EngineeringModel, engineeringModeliid);

            var context            = $"/EngineeringModel/{engineeringModeliid}/iteration/{iterationiid}";
            var operationContainer = new OperationContainer(context);

            var updateCommonFileStoreOperation = new Operation(originalDomainFileStore, modifiedDomainFileStore, OperationKind.Update);

            operationContainer.AddOperation(updateCommonFileStoreOperation);

            var createFileOperation = new Operation(null, file, OperationKind.Create);

            operationContainer.AddOperation(createFileOperation);

            var createFileRevisionOperation = new Operation(null, fileRevision, OperationKind.Create);

            operationContainer.AddOperation(createFileRevisionOperation);

            Assert.DoesNotThrowAsync(async() => await dal.Write(operationContainer, files));
        }
예제 #23
0
        /// <summary>
        /// Set the credentials property so DAL appears to be open
        /// </summary>
        /// <param name="dal">
        /// The <see cref="CdpServicesDal"/> that is to be opened
        /// </param>
        private void SetDalToBeOpen(CdpServicesDal dal)
        {
            var credentialsProperty = typeof(CdpServicesDal).GetProperty("Credentials");

            credentialsProperty.SetValue(dal, this.credentials);
        }
예제 #24
0
        public void VerifyThatCdpServicesDalCanBeConstructed()
        {
            var dal = new CdpServicesDal();

            Assert.IsNotNull(dal);
        }
예제 #25
0
        public async Task VerifyThatIfCredentialsAreNullExceptionIsThrown()
        {
            var dal = new CdpServicesDal();

            Assert.That(async() => await dal.Open(null, new CancellationToken()), Throws.TypeOf <ArgumentNullException>());
        }