public LoadTVLinking(string _filepath) { Init(_filepath); if (vs == default(VariableScheme)) { var client = Utility.GetClient(); var facet = new SearchFacet(); facet.ItemTypes.Add(DdiItemType.VariableScheme); facet.SearchTargets.Add(DdiStringType.Name); facet.SearchTerms.Add("Topic Variable Groups"); facet.SearchLatestVersion = true; SearchResponse response = client.Search(facet); var graphPopulator = new GraphPopulator(client) { ChildProcessing = ChildReferenceProcessing.PopulateLatest, }; //graphPopulator.TypesToPopulate.Add(DdiItemType.Variable); graphPopulator.TypesToPopulate.Add(DdiItemType.VariableGroup); if (response.Results.Count == 1) { vs = client.GetItem( response.Results[0].CompositeId, ChildReferenceProcessing.PopulateLatest) as VariableScheme; vs.Accept(new GraphPopulator(client)); } } }
public void RewriteCCS() { MultilingualString.CurrentCulture = "en-GB"; VersionableBase.DefaultAgencyId = "example.org"; var client = RepositoryIntro.GetClient(); var instance = client.GetItem(new Guid("b9ee3aa5-5bc5-43ed-a24e-f560abb30801"), "example.org", 2) as DdiInstance; //DDIWorkflowDeserializer deserializer = new DDIWorkflowDeserializer(); //var instance = deserializer.LoadDdiFile(@"D:\Downloads\filesforMinneapolis\filesforMinneapolis\bcs08v08.xml"); GraphPopulator populator = new GraphPopulator(client); populator.ChildProcessing = ChildReferenceProcessing.Populate; instance.Accept(populator); var resourcePackage = instance.ResourcePackages[0]; var instrument = instance.ResourcePackages[0].DataCollections[0].Instruments[0]; //var topLevelSequence = client.GetLatestItem(new Guid("ceaa9acf-2b2f-4c41-b298-b9f419412586"), "cls") // as CustomSequenceActivity; var topLevelSequence = instrument.Sequence; var moduleSequences = topLevelSequence.Activities; foreach (CustomSequenceActivity module in moduleSequences.OfType <CustomSequenceActivity>()) { DirtyItemGatherer gatherer = new DirtyItemGatherer(true); module.Accept(gatherer); var allChildren = gatherer.DirtyItems; ControlConstructScheme ccs = new ControlConstructScheme(); ccs.ItemName.Copy(module.ItemName); foreach (var child in allChildren.OfType <ActivityBase>()) { ccs.ControlConstructs.Add(child); } //client.RegisterItem(ccs, new CommitOptions()); resourcePackage.ControlConstructSchemes.Add(ccs); } DDIWorkflowSerializer serializer = new DDIWorkflowSerializer(); serializer.UseConciseBoundedDescription = false; var doc = serializer.Serialize(instance); doc.Save(@"d:\ColecticaOutput\bcsv8.xml"); }
public byte[] CreateReport(RepositoryItemMetadata item, RepositoryClientBase client) { // Get the DDI PhysicalInstance (dataset description) var dataset = client.GetItem(item.CompositeId, ChildReferenceProcessing.Instantiate) as PhysicalInstance; // Populate all its variable information. var populator = new GraphPopulator(client); dataset.Accept(populator); // Use the Colectica.Reporting MigraDoc helper to create a PDF that // simply lists all variables with their names, labels, and types. var document = new Document(); document.Info.Title = "Sample Variable Summary"; // Add a title. var section = document.AddSection(); var paragraph = section.AddParagraph(dataset.DublinCoreMetadata.Title.Best); paragraph.Format.Font.Bold = true; // Create the report helper. ReportContext context = new ReportContext(); var builder = new ItemBuilderBase(document, context); // Get all variables in the dataset. var allVariables = dataset .DataRelationships .SelectMany(x => x.LogicalRecords) .SelectMany(x => x.VariablesInRecord) .ToList(); // Make a list with one item for each variable. builder.DefineList(); foreach (var variable in allVariables) { string lineText = $"{variable.ItemName.Best} - {variable.Label.Best} - {variable.RepresentationType}"; builder.AddListItem(lineText); } // Render the PDF and return it. var pdfRenderer = new PdfDocumentRenderer(true); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); using (var stream = new MemoryStream()) { pdfRenderer.Save(stream, true); var fileContents = stream.ToArray(); return(fileContents); } }
/// <summary> /// Search for some items, retrieve one, and populate its children. /// </summary> public void SearchRetrievePopulate() { var client = GetClient(); // Create a SearchFacet, which lets us set the parameters of the search. SearchFacet facet = new SearchFacet(); // Find all VariableSchemes in the Repository. facet.ItemTypes.Add(DdiItemType.VariableScheme); // If we wanted, we could search for certain text. //facet.SearchTerms.Add("Variables"); // Submit the search to the Repository. SearchResponse response = client.Search(facet); if (response.ReturnedResults > 0) { // Use GetItem to retrieve the first VariableScheme in the search results. // By passing in Populate as the last parameter, we are requesting the // Repository to send back the VariableScheme along with all child Variables information. // By default, the Repository would only Instantiate the child Variables, meaning // they would contain identification information, but all other properties would be blank. var item = client.GetItem(response.Results[0].CompositeId, ChildReferenceProcessing.Populate); // You can use the IsPopulated property to determine whether a particular has its // information present, or if only the identification is present. Console.WriteLine("Is the item populated? " + item.IsPopulated); var unpopulatedVariableScheme = client.GetItem( response.Results[0].CompositeId, ChildReferenceProcessing.Instantiate) as VariableScheme; Console.WriteLine("Is the first Variable populated? " + unpopulatedVariableScheme.Variables[0].IsPopulated); // If the child Variables are not populated, we can manually request them to be // populated using the PopulateItem method. foreach (var variable in unpopulatedVariableScheme.Variables) { // Check to make sure this variable isn't already populated. We don't want to // populate an item more than once. if (!variable.IsPopulated) { client.PopulateItem(variable, false, ChildReferenceProcessing.Populate); } } // As another alternative, you can fully populate all an item's children // (and their children) by using the GraphPopulator. This object will // visit every child item and call PopulateItem for that item. GraphPopulator populator = new GraphPopulator(client); unpopulatedVariableScheme.Accept(populator); } }
public void RewriteCCS() { MultilingualString.CurrentCulture = "en-GB"; VersionableBase.DefaultAgencyId = "example.org"; var client = RepositoryIntro.GetClient(); var instance = client.GetItem(new Guid("b9ee3aa5-5bc5-43ed-a24e-f560abb30801"), "example.org", 2) as DdiInstance; //DDIWorkflowDeserializer deserializer = new DDIWorkflowDeserializer(); //var instance = deserializer.LoadDdiFile(@"D:\Downloads\filesforMinneapolis\filesforMinneapolis\bcs08v08.xml"); GraphPopulator populator = new GraphPopulator(client); populator.ChildProcessing = ChildReferenceProcessing.Populate; instance.Accept(populator); var resourcePackage = instance.ResourcePackages[0]; var instrument = instance.ResourcePackages[0].DataCollections[0].Instruments[0]; //var topLevelSequence = client.GetLatestItem(new Guid("ceaa9acf-2b2f-4c41-b298-b9f419412586"), "cls") // as CustomSequenceActivity; var topLevelSequence = instrument.Sequence; var moduleSequences = topLevelSequence.Activities; foreach (CustomSequenceActivity module in moduleSequences.OfType<CustomSequenceActivity>()) { DirtyItemGatherer gatherer = new DirtyItemGatherer(true); module.Accept(gatherer); var allChildren = gatherer.DirtyItems; ControlConstructScheme ccs = new ControlConstructScheme(); ccs.ItemName.Copy(module.ItemName); foreach (var child in allChildren.OfType<ActivityBase>()) { ccs.ControlConstructs.Add(child); } //client.RegisterItem(ccs, new CommitOptions()); resourcePackage.ControlConstructSchemes.Add(ccs); } DDIWorkflowSerializer serializer = new DDIWorkflowSerializer(); serializer.UseConciseBoundedDescription = false; var doc = serializer.Serialize(instance); doc.Save(@"d:\ColecticaOutput\bcsv8.xml"); }
public static PhysicalInstance GetPhysicalInstance(ManagedFile file, string agencyID) { var client = RepositoryHelper.GetClient(); var pi = client.GetLatestItem(file.Id, agencyID) as PhysicalInstance; var populator = new GraphPopulator(client); populator.ChildProcessing = ChildReferenceProcessing.PopulateLatest; pi.Accept(populator); return(pi); }
/// <summary> /// Search for some items, retrieve one, and populate its children. /// </summary> public void SearchRetrievePopulate() { var client = GetClient(); // Create a SearchFacet, which lets us set the parameters of the search. SearchFacet facet = new SearchFacet(); // Find all VariableSchemes in the Repository. facet.ItemTypes.Add(DdiItemType.VariableScheme); // If we wanted, we could search for certain text. //facet.SearchTerms.Add("Variables"); // Submit the search to the Repository. SearchResponse response = client.Search(facet); if (response.ReturnedResults > 0) { // Use GetItem to retrieve the first VariableScheme in the search results. // By passing in Populate as the last parameter, we are requesting the // Repository to send back the VariableScheme along with all child Variables information. // By default, the Repository would only Instantiate the child Variables, meaning // they would contain identification information, but all other properties would be blank. var item = client.GetItem(response.Results[0].CompositeId, ChildReferenceProcessing.Populate); // You can use the IsPopulated property to determine whether a particular has its // information present, or if only the identification is present. Console.WriteLine("Is the item populated? " + item.IsPopulated); var unpopulatedVariableScheme = client.GetItem( response.Results[0].CompositeId, ChildReferenceProcessing.Instantiate) as VariableScheme; Console.WriteLine("Is the first Variable populated? " + unpopulatedVariableScheme.Variables[0].IsPopulated); // If the child Variables are not populated, we can manually request them to be // populated using the PopulateItem method. foreach (var variable in unpopulatedVariableScheme.Variables) { // Check to make sure this variable isn't already populated. We don't want to // populate an item more than once. if (!variable.IsPopulated) { client.PopulateItem(variable, false, ChildReferenceProcessing.Populate); } } // As another alternative, you can fully populate all an item's children // (and their children) by using the GraphPopulator. This object will // visit every child item and call PopulateItem for that item. GraphPopulator populator = new GraphPopulator(client); unpopulatedVariableScheme.Accept(populator); } }
public ActionResult Details(Guid id) { using (var db = ApplicationDbContext.Create()) { var model = new CheckForMissingLabelsViewModel(); TaskHelpers.InitializeTaskModel(model, id, this.task, db); if (!model.File.CatalogRecord.Curators.Any(x => x.UserName == User.Identity.Name)) { throw new HttpException(403, "Only curators may perform this task."); } // Find and add any missing labels. try { var physicalInstance = FileToVariableEditorMapper.GetPhysicalInstance(model.File, model.File.CatalogRecord.Organization.AgencyID); var variablesWithMissingLabels = new List <VariableModel>(); var client = RepositoryHelper.GetClient(); var populator = new GraphPopulator(client); populator.ChildProcessing = ChildReferenceProcessing.PopulateLatest; physicalInstance.Accept(populator); foreach (var variable in physicalInstance.DataRelationships .SelectMany(x => x.LogicalRecords) .SelectMany(x => x.VariablesInRecord)) { bool isUnlabeled = false; // Check if the variable is unlabeled. if (variable.Label.IsEmpty) { isUnlabeled = true; } // Check if any categories are unlabeled. if (variable.CodeRepresentation != null && variable.CodeRepresentation.Codes != null && variable.CodeRepresentation.Codes.Codes.Any(x => x.Category == null || x.Category.Label.IsEmpty)) { isUnlabeled = true; } if (isUnlabeled) { var variableModel = new VariableModel { Id = variable.Identifier.ToString(), Agency = variable.AgencyId, Name = variable.ItemName.Current, Label = variable.Label.Current, Version = variable.Version, LastUpdated = variable.VersionDate.ToShortDateString() }; variablesWithMissingLabels.Add(variableModel); } } model.VariablesJson = JsonConvert.SerializeObject(variablesWithMissingLabels); return(View("~/Areas/Ddi/Views/CheckForMissingLabels/Details.cshtml", model)); } catch (Exception ex) { return(View("~/Areas/Ddi/Views/CheckForMissingLabels/Details.cshtml", model)); } } }
public void RunGlobalActions(bool prepare = false) { bool prepared = false; if (prepare) { prepared = Prepare(); } if (prepare == prepared) { foreach (var action in actions) { try { action.Validate(); workingSet.AddRange(action.Build(workingSet)); } catch (Exception e) { console.WriteLine("{0}", e.Message); continue; } } var client = Utility.GetClient(); var facet = new SearchFacet(); facet.ItemTypes.Add(DdiItemType.DdiInstance); facet.SearchTargets.Add(DdiStringType.Name); //Compare var repoItems = new List<IVersionable>(); var wsIs = workingSet.OfType<DdiInstance>(); var countint = wsIs.Count(); foreach (var wsI in wsIs) { facet.SearchTerms.Clear(); facet.SearchTerms.Add(wsI.ItemName.Best); var response = client.Search(facet); foreach (var res in response.Results) { var rp = client.GetItem( res.CompositeId, ChildReferenceProcessing.PopulateLatest) as DdiInstance; var graphPopulator = new GraphPopulator(client) { ChildProcessing = ChildReferenceProcessing.PopulateLatest }; rp.Accept(graphPopulator); var gatherer = new ItemGathererVisitor(); rp.Accept(gatherer); repoItems.AddRange(gatherer.FoundItems); } } toBeAdded = workingSet; var toBeRemoved = new List<IVersionable>(); foreach (var repoItem in repoItems) { if (repoItem.UserIds.Count == 0) continue; var wsItem = workingSet.Find(x => (x.UserIds.Count > 0 ? x.UserIds[0].ToString() : "") == repoItem.UserIds[0].ToString()); if (wsItem != default(IVersionable)) { if (toBeAdded.IndexOf(wsItem) != -1) { toBeAdded.Remove(wsItem); } else { var node = toBeAdded.Where( item => item.UserIds.Count > 0 ).FirstOrDefault( item => item.UserIds[0] == wsItem.UserIds[0] ); if (node != default(IVersionable)) { toBeAdded.Remove(node); } } } else { toBeRemoved.Add(repoItem); } } console.WriteLine("Global: Commiting {0} items...", workingSet.Count); client.RegisterItems(workingSet, new CommitOptions()); } else { console.WriteLine("Failed to prepare build."); } console.Publish(); }
public void Compare() { if (workingSet.Count == 0) { return; } if (rp == default(ResourcePackage)) { //New resource package rp = new ResourcePackage { DublinCoreMetadata = { Title = new MultilingualString(name, "en-GB") } }; } var client = Utility.GetClient(); var graphPopulator = new GraphPopulator(client) { ChildProcessing = ChildReferenceProcessing.PopulateLatest }; rp.Accept(graphPopulator); var gatherer = new ItemGathererVisitor(); rp.Accept(gatherer); var rpItems = gatherer.FoundItems.ToList(); comparator.repoSet = rpItems; foreach (var item in rpItems) { item.IsDirty = false; } DataCollection dc = null; if (rp.DataCollections.Count == 1) { dc = rp.DataCollections.First(); } var wsRPs = workingSet.OfType <ResourcePackage>(); Guid[] dcBindings = { DdiItemType.Instrument }; Guid[] suBindings = { DdiItemType.LogicalProduct, DdiItemType.PhysicalDataProduct, DdiItemType.PhysicalInstance, }; var updated = false; foreach (var wsRP in wsRPs) { foreach (var item in wsRP.GetChildren()) { item.IsDirty = false; var rpFind = rpItems.FirstOrDefault(x => x.UserIds.Count > 0 ? item.UserIds[0].Identifier == x.UserIds[0].Identifier : false); if (rpFind == default(IVersionable)) { counter[Counters.Added] += item.GetChildren().Count + 1; rp.AddItem(item); if (dc != null && dcBindings.Contains(item.ItemType)) { dc.AddChild(item); continue; } if (dc != null && item.ItemType == DdiItemType.InstrumentScheme) { foreach (var instrument in item.GetChildren()) { dc.AddChild(instrument); } } if (su != default(StudyUnit) && suBindings.Contains(item.ItemType)) { su.AddChild(item); continue; } item.IsDirty = true; var gthr = new ItemGathererVisitor(); item.Accept(gthr); foreach (var i in gthr.FoundItems) { i.IsDirty = true; } } else { rpFind.IsDirty = false; updated = true; counter[Counters.Compared] += comparator.Compare(rpFind, item); } } } var allGthr = new ItemGathererVisitor(); rp.Accept(allGthr); toBeAdded.AddRange(allGthr.FoundItems); }