コード例 #1
0
        private ThresholdAttainment[] generateThresholdAttainments(DateTime?moderatedAt, DateTime?respondedAt, DateTime?debatedAt)
        {
            List <ThresholdAttainment>  thresholdAttainments = new List <ThresholdAttainment>();
            Dictionary <string, string> thresholds           = IdRetrieval.GetSubjectsDictionary("thresholdName", logger);

            foreach (KeyValuePair <string, string> threshold in thresholds)
            {
                DateTime?timestamp = null;
                switch (threshold.Key.ToLower())
                {
                case "moderation":
                    timestamp = moderatedAt;
                    break;

                case "response":
                    timestamp = respondedAt;
                    break;

                case "debate":
                    timestamp = debatedAt;
                    break;
                }
                if (timestamp.HasValue)
                {
                    ThresholdAttainment thresholdAttainment = new ThresholdAttainment();
                    thresholdAttainment.Id = GenerateNewId();
                    thresholdAttainment.ThresholdAttainmentAt           = timestamp;
                    thresholdAttainment.ThresholdAttainmentHasThreshold = new Threshold()
                    {
                        Id = new Uri(threshold.Value)
                    };
                    thresholdAttainments.Add(thresholdAttainment);
                }
            }
            return(thresholdAttainments.ToArray());
        }
コード例 #2
0
        public override BaseResource[] SynchronizeIds(BaseResource[] source, Uri subjectUri, BaseResource[] target)
        {
            UkgapEPetition ePetition = source.OfType <UkgapEPetition>().SingleOrDefault();

            ePetition.Id = subjectUri;

            GovernmentResponse governmentResponse = target.OfType <GovernmentResponse>().SingleOrDefault();

            if (governmentResponse != null)
            {
                ePetition.EPetitionHasGovernmentResponse.SingleOrDefault().Id = governmentResponse.Id;
            }
            Parliament.Model.Debate debate = target.OfType <Parliament.Model.Debate>().SingleOrDefault();
            if (debate != null)
            {
                ePetition.EPetitionHasDebate.SingleOrDefault().Id = debate.Id;
            }
            IEnumerable <Approval> approvals          = target.OfType <Approval>();
            List <Approval>        ePetitionApprovals = source.OfType <Approval>().ToList();

            foreach (Approval approval in approvals)
            {
                Approval foundModeration = ePetitionApprovals
                                           .SingleOrDefault(m => m.ApprovedAt == approval.ApprovedAt);
                if (foundModeration != null)
                {
                    foundModeration.Id = approval.Id;
                }
                else
                {
                    ePetitionApprovals.Add(approval);
                }
            }
            foreach (Approval approval in ePetitionApprovals)
            {
                approval.ApprovalHasApprovedEPetition = new ApprovedEPetition[]
                {
                    new ApprovedEPetition()
                    {
                        Id = subjectUri
                    }
                }
            }
            ;

            IEnumerable <Parliament.Model.Rejection> rejects             = target.OfType <Parliament.Model.Rejection>();
            List <Parliament.Model.Rejection>        ePetitionRejections = source.OfType <Parliament.Model.Rejection>().ToList();

            foreach (Parliament.Model.Rejection rejection in rejects)
            {
                Parliament.Model.Rejection foundModeration = ePetitionRejections
                                                             .SingleOrDefault(m => m.RejectedAt == rejection.RejectedAt);
                if (foundModeration != null)
                {
                    foundModeration.Id = rejection.Id;
                }
                else
                {
                    ePetitionRejections.Add(rejection);
                }
            }
            foreach (Parliament.Model.Rejection rejection in ePetitionRejections)
            {
                rejection.RejectionHasRejectedEPetition = new RejectedEPetition[]
                {
                    new RejectedEPetition()
                    {
                        Id = subjectUri
                    }
                }
            }
            ;

            IEnumerable <ThresholdAttainment> thresholdAttainments = target.OfType <ThresholdAttainment>();

            foreach (ThresholdAttainment thresholdAttainment in thresholdAttainments)
            {
                ThresholdAttainment foundThresholdAttainment = ePetition.EPetitionHasThresholdAttainment.SingleOrDefault(t => t.ThresholdAttainmentAt == thresholdAttainment.ThresholdAttainmentAt);
                if (foundThresholdAttainment != null)
                {
                    foundThresholdAttainment.Id = thresholdAttainment.Id;
                }
            }
            IEnumerable <LocatedSignatureCount> signatures = target.OfType <LocatedSignatureCount>();

            foreach (LocatedSignatureCount signature in signatures)
            {
                LocatedSignatureCount foundLocatedSignatureCount = ePetition.EPetitionHasLocatedSignatureCount
                                                                   .SingleOrDefault(s => s.LocatedSignatureCountHasPlace.Id == signature.LocatedSignatureCountHasPlace.Id);
                if (foundLocatedSignatureCount != null)
                {
                    foundLocatedSignatureCount.Id = signature.Id;
                    if (foundLocatedSignatureCount.SignatureCount.SingleOrDefault() == signature.SignatureCount.SingleOrDefault())
                    {
                        foundLocatedSignatureCount.SignatureCountRetrievedAt = signature.SignatureCountRetrievedAt;
                    }
                }
            }
            foreach (LocatedSignatureCount signature in ePetition.EPetitionHasLocatedSignatureCount.Where(s => s.Id == null))
            {
                signature.Id = GenerateNewId();
            }

            return(ePetitionApprovals.AsEnumerable <BaseResource>().Concat(ePetitionRejections).Concat(ePetition.AsEnumerable()).ToArray());
        }