Exemplo n.º 1
0
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;



            this.cache      = new List <Thing>();
            this.dalOutputs = new List <CDP4Common.DTO.Thing>();
            var sitedirectory = new CDP4Common.DTO.SiteDirectory(Guid.NewGuid(), 22);

            this.dalOutputs.Add(sitedirectory);
            this.tokenSource = new CancellationTokenSource();
            CDPMessageBus.Current.Listen <ObjectChangedEvent>(typeof(SiteDirectory)).Subscribe(x => this.OnEvent(x.ChangedThing));

            this.mockedDal = new Mock <IDal>();
            this.mockedDal.Setup(x => x.Close());

            this.uri = "http://www.rheagroup.com/";
            var credentials = new Credentials("John", "Doe", new Uri(this.uri));

            var session = new Session(this.mockedDal.Object, credentials);

            this.sessionViewModel = new SessionViewModel(session);
            var openTaskCompletionSource = new TaskCompletionSource <IEnumerable <CDP4Common.DTO.Thing> >();

            openTaskCompletionSource.SetResult(this.dalOutputs);
            this.mockedDal.Setup(x => x.Open(It.IsAny <Credentials>(), It.IsAny <CancellationToken>())).Returns(openTaskCompletionSource.Task);
        }
Exemplo n.º 2
0
        public async Task VerifyThatReloadUpdatesTheLastUpdateDatetime()
        {
            var updatedSiteDir = new CDP4Common.DTO.SiteDirectory(this.dalOutputs.Single().Iid, 30);

            var openTaskCompletionSource = new TaskCompletionSource <IEnumerable <CDP4Common.DTO.Thing> >();

            openTaskCompletionSource.SetResult(this.GetTestDtos());
            this.mockedDal.Setup(x => x.Open(It.IsAny <Credentials>(), this.tokenSource.Token)).Returns(openTaskCompletionSource.Task);

            var readTaskCompletionSource = new TaskCompletionSource <IEnumerable <CDP4Common.DTO.Thing> >();

            readTaskCompletionSource.SetResult(new List <CDP4Common.DTO.Thing> {
                updatedSiteDir
            });
            this.mockedDal.Setup(x => x.Read(It.IsAny <CDP4Common.DTO.Thing>(), It.IsAny <CancellationToken>(), It.IsAny <IQueryAttributes>())).Returns(readTaskCompletionSource.Task);

            await this.sessionViewModel.Session.Open();

            this.cache.Clear();

            var datetime = DateTime.Now;

            this.sessionViewModel.Reload.Execute(null);

            Assert.IsFalse(datetime > this.sessionViewModel.LastUpdateDateTime);
            Assert.AreNotEqual(0, this.cache.Count);
        }
        public void SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.uri = new Uri("http://www.rheageoup.com");
            this.SetupRecognizePackUir();

            this.assembler = new Assembler(this.uri);

            this.session = new Mock <ISession>();

            var dtos = new List <CDP4Common.DTO.Thing>();

            var siteDirectory = new CDP4Common.DTO.SiteDirectory(Guid.NewGuid(), 0);

            dtos.Add(siteDirectory);
            var engineeringModel = new CDP4Common.DTO.EngineeringModel(Guid.NewGuid(), 0);

            dtos.Add(engineeringModel);
            var iteration = new CDP4Common.DTO.Iteration(Guid.NewGuid(), 0);

            engineeringModel.Iteration.Add(iteration.Iid);
            dtos.Add(iteration);

            this.assembler.Synchronize(dtos);

            this.session.Setup(x => x.DataSourceUri).Returns("test");
            this.session.Setup(x => x.Assembler).Returns(this.assembler);

            this.panelNavigationService       = new Mock <IPanelNavigationService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.dialogNavigationService      = new Mock <IDialogNavigationService>();
            this.serviceLocator = new Mock <IServiceLocator>();

            this.excelQuery = new Mock <IExcelQuery>();
            this.excelQuery.Setup(x => x.IsActiveWorkbookAvailable(It.IsAny <NetOffice.ExcelApi.Application>())).Returns(true);
            this.officeApplicationWrapper = new Mock <IOfficeApplicationWrapper>();

            this.permittingPermissionService = new Mock <IPermissionService>();
            this.permittingPermissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true);
            this.permittingPermissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);

            this.pluginSettingsService = new Mock <IPluginSettingsService>();

            this.amountOfRibbonControls = 10;
            this.order = 1;

            this.ribbonPart = new ParameterSheetGeneratorRibbonPart(this.order, this.panelNavigationService.Object, this.thingDialogNavigationService.Object, this.dialogNavigationService.Object, this.pluginSettingsService.Object, this.officeApplicationWrapper.Object);

            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IThingDialogNavigationService>())
            .Returns(this.thingDialogNavigationService.Object);
        }
        public async Task SetUp()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();
            this.uri   = new Uri("http://www.rheagroup.com");
            var assembler = new Assembler(this.uri);

            var siteDirectoryDto = new CDP4Common.DTO.SiteDirectory(Guid.NewGuid(), 0);
            var dtos             = new List <CDP4Common.DTO.Thing>();

            dtos.Add(siteDirectoryDto);

            await assembler.Synchronize(dtos);

            this.session = new Mock <ISession>();
            this.session.Setup(x => x.Assembler).Returns(assembler);
        }
        /// <summary>
        /// Instantiate and deserialize the properties of a <paramref name="SiteDirectory"/>
        /// </summary>
        /// <param name="jObject">The <see cref="JObject"/> containing the data</param>
        /// <returns>The <see cref="SiteDirectory"/> to instantiate</returns>
        public static CDP4Common.DTO.SiteDirectory FromJsonObject(JObject jObject)
        {
            var iid            = jObject["iid"].ToObject <Guid>();
            var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject <int>();
            var siteDirectory  = new CDP4Common.DTO.SiteDirectory(iid, revisionNumber);

            if (!jObject["annotation"].IsNullOrEmpty())
            {
                siteDirectory.Annotation.AddRange(jObject["annotation"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["createdOn"].IsNullOrEmpty())
            {
                siteDirectory.CreatedOn = jObject["createdOn"].ToObject <DateTime>();
            }

            if (!jObject["defaultParticipantRole"].IsNullOrEmpty())
            {
                siteDirectory.DefaultParticipantRole = jObject["defaultParticipantRole"].ToObject <Guid?>();
            }

            if (!jObject["defaultPersonRole"].IsNullOrEmpty())
            {
                siteDirectory.DefaultPersonRole = jObject["defaultPersonRole"].ToObject <Guid?>();
            }

            if (!jObject["domain"].IsNullOrEmpty())
            {
                siteDirectory.Domain.AddRange(jObject["domain"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["domainGroup"].IsNullOrEmpty())
            {
                siteDirectory.DomainGroup.AddRange(jObject["domainGroup"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["excludedDomain"].IsNullOrEmpty())
            {
                siteDirectory.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["excludedPerson"].IsNullOrEmpty())
            {
                siteDirectory.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["lastModifiedOn"].IsNullOrEmpty())
            {
                siteDirectory.LastModifiedOn = jObject["lastModifiedOn"].ToObject <DateTime>();
            }

            if (!jObject["logEntry"].IsNullOrEmpty())
            {
                siteDirectory.LogEntry.AddRange(jObject["logEntry"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["model"].IsNullOrEmpty())
            {
                siteDirectory.Model.AddRange(jObject["model"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["modifiedOn"].IsNullOrEmpty())
            {
                siteDirectory.ModifiedOn = jObject["modifiedOn"].ToObject <DateTime>();
            }

            if (!jObject["name"].IsNullOrEmpty())
            {
                siteDirectory.Name = jObject["name"].ToObject <string>();
            }

            if (!jObject["naturalLanguage"].IsNullOrEmpty())
            {
                siteDirectory.NaturalLanguage.AddRange(jObject["naturalLanguage"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["organization"].IsNullOrEmpty())
            {
                siteDirectory.Organization.AddRange(jObject["organization"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["participantRole"].IsNullOrEmpty())
            {
                siteDirectory.ParticipantRole.AddRange(jObject["participantRole"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["person"].IsNullOrEmpty())
            {
                siteDirectory.Person.AddRange(jObject["person"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["personRole"].IsNullOrEmpty())
            {
                siteDirectory.PersonRole.AddRange(jObject["personRole"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["shortName"].IsNullOrEmpty())
            {
                siteDirectory.ShortName = jObject["shortName"].ToObject <string>();
            }

            if (!jObject["siteReferenceDataLibrary"].IsNullOrEmpty())
            {
                siteDirectory.SiteReferenceDataLibrary.AddRange(jObject["siteReferenceDataLibrary"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["thingPreference"].IsNullOrEmpty())
            {
                siteDirectory.ThingPreference = jObject["thingPreference"].ToObject <string>();
            }

            return(siteDirectory);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a  <see cref="IEnumerable{Thing}"/> that contains references to those objects that are to be included
        /// in the JSON file
        /// </summary>
        /// <param name="siteDirectory">
        /// The <see cref="SiteDirectory"/> object that is to be serialized to the JSON file
        /// </param>
        /// <param name="siteReferenceDataLibraries">
        /// The <see cref="SiteReferenceDataLibrary"/> instances that are to be included
        /// </param>
        /// <param name="domainOfExpertises">
        /// The <see cref="DomainOfExpertise"/> instances that are to be included
        /// </param>
        /// <param name="persons">
        /// The <see cref="Person"/> instances that are to be included
        /// </param>
        /// <param name="personRoles">
        /// The <see cref="PersonRole"/> instances that are to be included
        /// </param>
        /// <param name="participantRoles">
        /// The <see cref="ParticipantRole"/> instances that are to be included
        /// </param>
        /// <param name="organizations">
        /// The <see cref="Organization"/> instances that are to be included
        /// </param>
        /// <param name="engineeringModelSetups">
        /// The engineering Model Setups.
        /// </param>
        /// <param name="iterIterationSetups">
        /// The Iteration Setups.
        /// </param>
        /// <returns>
        /// The pruned <see cref="Thing"/> collection.
        /// </returns>
        internal static IEnumerable <CDP4Common.DTO.Thing> CreateSiteDirectoryAndPrunedContainedThingDtos(
            SiteDirectory siteDirectory,
            HashSet <SiteReferenceDataLibrary> siteReferenceDataLibraries,
            HashSet <DomainOfExpertise> domainOfExpertises,
            HashSet <Person> persons,
            HashSet <PersonRole> personRoles,
            HashSet <ParticipantRole> participantRoles,
            HashSet <Organization> organizations,
            HashSet <EngineeringModelSetup> engineeringModelSetups,
            HashSet <IterationSetup> iterIterationSetups)
        {
            var dtos = new List <CDP4Common.DTO.Thing>();

            CDP4Common.DTO.SiteDirectory siteDirectoryDto = null;

            // collect the SiteDirectory objec graph, except for the graph branches that need to be pruned
            foreach (var siteDirectoryItem in siteDirectory.QueryContainedThingsDeep())
            {
                if (siteDirectoryItem.GetType() == typeof(SiteDirectory))
                {
                    // include the SiteDirectory shallow DTO
                    siteDirectoryDto = (CDP4Common.DTO.SiteDirectory)siteDirectoryItem.ToDto();
                    dtos.Add(siteDirectoryDto);
                }
                else if (siteDirectoryItem.GetType() == typeof(SiteReferenceDataLibrary))
                {
                    // include the SiteReferenceDataLibrary shallow DTO
                    dtos.Add(siteDirectoryItem.ToDto());
                }
                else if (
                    siteDirectoryItem.GetContainerOfType <SiteReferenceDataLibrary>() == null &&
                    siteDirectoryItem.GetContainerOfType <DomainOfExpertise>() == null &&
                    siteDirectoryItem.GetContainerOfType <ParticipantRole>() == null &&
                    siteDirectoryItem.GetContainerOfType <PersonRole>() == null &&
                    siteDirectoryItem.GetContainerOfType <Organization>() == null &&
                    siteDirectoryItem.GetContainerOfType <Person>() == null &&
                    siteDirectoryItem.GetContainerOfType <EngineeringModelSetup>() == null)
                {
                    if (!dtos.Any(x => x.Iid != siteDirectoryItem.Iid))
                    {
                        dtos.Add(siteDirectoryItem.ToDto());
                    }
                }
            }

            if (siteDirectoryDto == null)
            {
                throw new ThingNotFoundException("The SiteDirectory DTO could not be found");
            }

            // remove the domains-of-expertise that should not be included in the cloned SiteDirectory
            siteDirectoryDto.Domain.Clear();
            foreach (var domainOfExpertise in domainOfExpertises)
            {
                foreach (var thing in domainOfExpertise.QueryContainedThingsDeep())
                {
                    if (!dtos.Any(x => x.Iid == thing.Iid))
                    {
                        dtos.Add(thing.ToDto());
                    }
                }

                siteDirectoryDto.Domain.Add(domainOfExpertise.Iid);
            }

            // remove the persons that should not be included in SiteDirectory DTO from the DTO
            siteDirectoryDto.Person.Clear();
            foreach (var person in persons)
            {
                foreach (var thing in person.QueryContainedThingsDeep())
                {
                    if (!dtos.Any(x => x.Iid == thing.Iid))
                    {
                        dtos.Add(thing.ToDto());
                    }
                }

                siteDirectoryDto.Person.Add(person.Iid);
            }

            siteDirectoryDto.PersonRole.Clear();
            foreach (var personRole in personRoles)
            {
                foreach (var thing in personRole.QueryContainedThingsDeep())
                {
                    if (!dtos.Any(x => x.Iid == thing.Iid))
                    {
                        dtos.Add(thing.ToDto());
                    }
                }

                siteDirectoryDto.PersonRole.Add(personRole.Iid);
            }

            siteDirectoryDto.ParticipantRole.Clear();
            foreach (var participantRole in participantRoles)
            {
                foreach (var thing in participantRole.QueryContainedThingsDeep())
                {
                    if (!dtos.Any(x => x.Iid == thing.Iid))
                    {
                        dtos.Add(thing.ToDto());
                    }
                }

                siteDirectoryDto.ParticipantRole.Add(participantRole.Iid);
            }

            siteDirectoryDto.Organization.Clear();
            foreach (var organization in organizations)
            {
                if (organization != null)
                {
                    if (!dtos.Any(x => x.Iid == organization.Iid))
                    {
                        dtos.Add(organization.ToDto());
                    }

                    siteDirectoryDto.Organization.Add(organization.Iid);
                }
            }

            // remove the EngineeringModelSetup instances and replace with pruned onces only inlcuding the required iterationsetups
            var clonedEngineeringModelSetups = new List <EngineeringModelSetup>();

            foreach (var engineeringModelSetup in engineeringModelSetups)
            {
                var clonedEngineeringModelSetup = engineeringModelSetup.Clone(false);
                clonedEngineeringModelSetup.IterationSetup.Clear();

                foreach (var iterIterationSetup in iterIterationSetups)
                {
                    if (iterIterationSetup.Container == engineeringModelSetup)
                    {
                        clonedEngineeringModelSetup.IterationSetup.Add(iterIterationSetup);
                    }
                }

                clonedEngineeringModelSetups.Add(clonedEngineeringModelSetup);
            }

            siteDirectoryDto.Model.Clear();
            foreach (var engineeringModelSetup in clonedEngineeringModelSetups)
            {
                // retrieve the EngineeringModelSetup contained object graph, including a shallow copy of the ModelReferenceDataLibrary
                // the ModelReferenceDataLibrary contained objects are written to its respective JSON file
                var nonModelReferenceLibrary = engineeringModelSetup.QueryContainedThingsDeep().Where(x =>
                                                                                                      x.GetType() == typeof(ModelReferenceDataLibrary) ||
                                                                                                      x.GetContainerOfType <ModelReferenceDataLibrary>() == null);
                dtos.AddRange(nonModelReferenceLibrary.Select(poco => poco.ToDto()));

                siteDirectoryDto.Model.Add(engineeringModelSetup.Iid);
            }

            return(dtos);
        }