Exemplo n.º 1
0
        private async void RenameVariables()
        {
            RepositoryClientBase client = null;                                            // TODO Fill this in.

            IdentifierTriple[] idList = new[] { new IdentifierTriple(new Guid(), 1, "") }; // TODO Get appropriate IDs.

            // Set up a transaction.
            var transaction = await client.CreateTransactionAsync();

            var request = new RepositoryTransactionAddItemsRequest();

            request.TransactionId = transaction.TransactionId;

            foreach (var id in idList)
            {
                var item = client.GetItem(id) as Variable;
                item.ItemName["en-GB"] = "MyNewName";
                RepositoryItem repoItem = GetRepositoryItemFromVersionable(client, item);
                request.Items.Add(repoItem);
            }


            // Push the transaction.
            var addItemsResult = await client.AddItemsToTransactionAsync(request);

            var commitOptions = new RepositoryTransactionCommitOptions();

            commitOptions.TransactionType = RepositoryTransactionType.CommitAsLatestWithLatestChildrenAndPropagateVersions;
            var commitResult = await client.CommitTransactionAsync(commitOptions);
        }
Exemplo n.º 2
0
        void GetReferencingItems(RepositoryClientBase client, IdentifierTriple variableId, out PhysicalInstance physicalInstance, out DataRelationship dataRelationship, out VariableStatistic variableStatistic)
        {
            dataRelationship  = null;
            variableStatistic = null;

            physicalInstance = VariableMapper.GetPhysicalInstanceWithVariable(variableId, client);

            foreach (var dr in physicalInstance.DataRelationships)
            {
                client.PopulateItem(dr, false, ChildReferenceProcessing.Populate);

                if (dr.LogicalRecords
                    .SelectMany(x => x.VariablesInRecord)
                    .Any(x => x.CompositeId == variableId))
                {
                    dataRelationship = dr;
                }
            }


            foreach (var stats in physicalInstance.Statistics)
            {
                client.PopulateItem(stats);

                if (stats.AgencyId == variableId.AgencyId &
                    stats.VariableReference.Identifier == variableId.Identifier)
                {
                    variableStatistic = stats;
                    break;
                }
            }
        }
        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);
            }
        }
Exemplo n.º 4
0
        private static RepositoryItem GetRepositoryItemFromVersionable(RepositoryClientBase client, Variable item)
        {
            RepositoryItem repositoryItem = new RepositoryItem()
            {
                CompositeId = item.CompositeId,
                Item        = client.GetRepresentation(item, RepositoryFormats.Ddi33),
                ItemType    = item.ItemType,
                ItemFormat  = RepositoryFormats.Ddi33,
                //IsDepricated
                IsPublished           = item.IsPublished,
                Notes                 = new Collection <Note>(),
                VersionDate           = item.VersionDate,
                VersionRationale      = item.VersionRationale,
                VersionResponsibility = item.VersionResponsibility,
                Tag = item
            };

            return(repositoryItem);
        }
Exemplo n.º 5
0
        public static IdentifierTriple GetSet(IdentifierTriple identifier, Guid variableidentifier, RepositoryClientBase client)
        {
            Collection <IdentifierTriple> identifiers = new Collection <IdentifierTriple>();

            // Collection<IdentifierTriple> selected = new Collection<IdentifierTriple>();
            // var clientitem = ClientHelper.GetClient();
            identifiers = client.GetSet(identifier);
            IdentifierTriple selected = identifiers.Where(a => a.Identifier == variableidentifier).FirstOrDefault();

            return(selected);
        }
Exemplo n.º 6
0
        public static List <RepositoryItemMetadata> GetAllRepositoryQuestions(string agency, Guid id, RepositoryClientBase client)
        {
            // Retrieves data for the selected study from the repository to be used in determining equivalences

            List <RepositoryItemMetadata> infoList = new List <RepositoryItemMetadata>();

            MultilingualString.CurrentCulture = "en-GB";

            //IVersionable item = client.GetLatestItem(id, agency,
            //     ChildReferenceProcessing.Populate);

            IVersionable item = client.GetLatestItem(id, agency);

            var studyUnit = item as StudyUnit;

            SetSearchFacet setFacet = new SetSearchFacet();

            setFacet.ItemTypes.Add(DdiItemType.QuestionItem);

            if (studyUnit == null)
            {
                return(infoList);
            }
            var matches = client.SearchTypedSet(studyUnit.CompositeId,
                                                setFacet);

            infoList = client.GetRepositoryItemDescriptions(matches.ToIdentifierCollection()).ToList();
            return(infoList);
        }
Exemplo n.º 7
0
 public Search()
 {
     this.client = RepositoryIntro.GetClient();
 }
        public byte[] CreateReport(DublinCore citation, List <RepositoryItemMetadata> items, RepositoryClientBase client)
        {
            // Get identification for all the DDI variables in the item list.
            var variableIDs = items
                              .Where(x => x.ItemType == DdiItemType.Variable)
                              .Select(x => x.CompositeId)
                              .ToIdentifierCollection();

            // Fetch all the variables.
            var allVariables = client.GetItems(variableIDs)
                               .OfType <Variable>();

            // 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(citation.Title.Best);

            paragraph.Format.Font.Bold = true;

            // Create the report helper.
            ReportContext context = new ReportContext();
            var           builder = new ItemBuilderBase(document, context);

            // 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);
            }
        }
Exemplo n.º 9
0
 public Search()
 {
     this.client = RepositoryIntro.GetClient();
 }
Exemplo n.º 10
0
        public static IdentifierTriple GetContainingPhysicalInstance(IdentifierTriple id, RepositoryClientBase client)
        {
            var facet = new SetSearchFacet();

            facet.ItemTypes.Add(DdiItemType.PhysicalInstance);
            facet.ReverseTraversal = true;
            facet.LeafItemTypes.Add(DdiItemType.VariableScheme);
            facet.LeafItemTypes.Add(DdiItemType.VariableGroup);

            var response = client.SearchTypedSet(id, facet);

            var piID = response.OrderByDescending(x => x.Version).FirstOrDefault();

            if (piID == null)
            {
                return(null);
            }

            return(piID.CompositeId);
        }
Exemplo n.º 11
0
        public static PhysicalInstance GetPhysicalInstanceWithVariable(IdentifierTriple variableId, RepositoryClientBase client)
        {
            var piID = GetContainingPhysicalInstance(variableId, client);

            if (piID != null)
            {
                return(client.GetItem(piID) as PhysicalInstance);
            }

            return(null);
        }