Ejemplo n.º 1
0
        internal static List<object> GetRatings(
            IEnumerable<PartVersion<PersonRatingDO>> includedRatings,
            IEnumerable<PartVersion<PersonRatingEditionDO>> editions,
            ILotRepository lotRepository,
            INomRepository nomRepository)
        {
            List<object> ratingEditions = new List<object>();
            foreach (var edition in editions)
            {
                var rating = includedRatings.Where(r => r.Part.Index == edition.Content.RatingPartIndex).Single();
                var ratingTypesCodes = rating.Content.RatingTypes.Count() > 0 ? string.Join(", ",  nomRepository.GetNomValues("ratingTypes", rating.Content.RatingTypes.ToArray()).Select(rt => rt.Code)) : "";
                var ratingClassName = rating.Content.RatingClassId.HasValue ?  nomRepository.GetNomValue("ratingClasses", rating.Content.RatingClassId.Value).Code : null;
                var authorizationCode = rating.Content.AuthorizationId.HasValue ? nomRepository.GetNomValue("authorizations", rating.Content.AuthorizationId.Value).Code : null;
                var firstRatingEdition = lotRepository.GetLotIndex(rating.Part.LotId)
                        .Index.GetParts<PersonRatingEditionDO>("ratingEditions")
                        .Where(epv => epv.Content.RatingPartIndex == rating.Part.Index)
                        .OrderByDescending(epv => epv.Content.Index)
                        .Last();

                ratingEditions.Add(new
                {
                    CLASS_AUTH = string.IsNullOrEmpty(ratingClassName) && string.IsNullOrEmpty(ratingTypesCodes) ?
                        authorizationCode :
                        string.Format(
                            "{0} {1} {2}",
                            ratingTypesCodes,
                            ratingClassName,
                            string.IsNullOrEmpty(authorizationCode) ? string.Empty : " / " + authorizationCode).Trim(),
                    ISSUE_DATE = firstRatingEdition.Content.DocumentDateValidFrom,
                    VALID_DATE = edition.Content.DocumentDateValidTo
                });
            }

            return Utils.FillBlankData(ratingEditions, 11);
        }
Ejemplo n.º 2
0
        public void MigrateLicenceDocuments(
            ConcurrentQueue<int> personIds,
            Dictionary<int, int> personIdToLotId,
            Dictionary<int, IEnumerable<JObject>> personsLicences,
            CookieCollection cookies,
            //cancellation
            CancellationTokenSource cts,
            CancellationToken ct)
        {
            try
            {
                this.oracleConn.Open();
            }
            catch (Exception)
            {
                cts.Cancel();
                throw;
            }

            ct.ThrowIfCancellationRequested();
            using (var dependencies = this.dependencyFactory())
            {
                this.unitOfWork = dependencies.Value.Item1;
                this.lotRepository = dependencies.Value.Item2;
                var printRepository = dependencies.Value.Item3;
                this.lotEventDispatcher = dependencies.Value.Item4;
                this.userContext = dependencies.Value.Item5;

                string connectionString = ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString;

                int personId = -1;
                try
                {
                    while (personIds.TryDequeue(out personId))
                    {
                        if (personIdToLotId.ContainsKey(personId))
                        {
                            var lot = lotRepository.GetLotIndex(personIdToLotId[personId], fullAccess: true);

                            JObject licence = null;
                            ConcurrentQueue<JObject> personLicences = new ConcurrentQueue<JObject>(personsLicences[personId]);

                            while (personLicences.TryDequeue(out licence))
                            {
                                string queryString = licence.Get<string>("query_string");
                                int oldId = licence.Get<int>("old_id");

                                int editionPartIndex = lot.Index.GetParts<dynamic>("licenceEditions")
                                    .Where(e => e.Content.__oldId == oldId)
                                    .Single().Part.Index;

                                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(queryString);
                                request.CookieContainer = new CookieContainer();
                                request.CookieContainer.Add(cookies);

                                using (HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse())
                                using (var responseStream = httpResponse.GetResponseStream())
                                using (var stream = printRepository.ConvertWordStreamToPdfStream(responseStream))
                                {
                                    var licenceEditionDocBlobKey = printRepository.SaveStreamToBlob(stream, connectionString);
                                    this.UpdateLicenceEdition(licenceEditionDocBlobKey, editionPartIndex, lot);
                                }
                            }
                            Console.WriteLine("Migrated printed licences of personId: {0}", personId);
                        }
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Error in migration of printed licences of personId: {0}", personId);
                    cts.Cancel();
                    throw;
                }
            }
        }
Ejemplo n.º 3
0
        internal static List<object> GetEndorsements(
            IEnumerable<PartVersion<PersonRatingDO>> includedRatings,
            IEnumerable<PartVersion<PersonRatingEditionDO>> ratingEditions,
            ILotRepository lotRepository,
            INomRepository nomRepository)
        {
            List<object> endorsments = new List<object>();
            foreach (var edition in ratingEditions)
            {
                var rating = includedRatings.Where(r => r.Part.Index == edition.Content.RatingPartIndex).Single();
                if (rating.Content.AuthorizationId.HasValue)
                {
                    var firstRatingEdition = lotRepository.GetLotIndex(rating.Part.LotId)
                        .Index.GetParts<PersonRatingEditionDO>("ratingEditions")
                        .Where(epv => epv.Content.RatingPartIndex == rating.Part.Index)
                        .OrderByDescending(epv => epv.Content.Index)
                        .Last();

                    endorsments.Add(new
                    {
                        NAME = nomRepository.GetNomValue("authorizations", rating.Content.AuthorizationId.Value).Code,
                        DATE = firstRatingEdition.Content.DocumentDateValidFrom.Value
                    });
                }
            };

            return (from endorsment in endorsments
                    group endorsment by ((dynamic)endorsment).NAME into newGroup
                    let d = newGroup.OrderBy(g => ((dynamic)g).DATE).FirstOrDefault()
                    select d)
                 .ToList<object>();
        }