void Match(Tuple <List <T1>, List <T2> > result)
 {
     foreach (var child in result.Item2)
     {
         var matched = false;
         foreach (var parent in result.Item1)
         {
             if (m_JoinExpression(parent, child))
             {
                 matched = true;
                 m_TargetCollectionExpression(parent).Add(child);
                 if (!m_JoinOptions.HasFlag(JoinOptions.MultipleParents))
                 {
                     break;
                 }
             }
         }
         if (!matched && !m_JoinOptions.HasFlag(JoinOptions.IgnoreUnmatchedChildren))
         {
             var ex = new UnexpectedDataException("Found child object that couldn't be matched to a parent. See Exception.Data[\"ChildObject\"] for details.");
             ex.Data["ChildObject"] = child;
             throw ex;
         }
     }
 }
Esempio n. 2
0
        void MultiMatchParallel(Tuple <List <T1>, List <T2> > result, bool ignoreUnmatchedChildren)
        {
            //build the dictionary
            var parents1 = from p in result.Item1.AsParallel() group m_TargetCollectionExpression(p) by m_PrimaryKeyExpression(p) into g select g;

            var parents2 = parents1.ToDictionary(p => p.Key);

            Parallel.ForEach(result.Item2, child =>
            {
                var fk = m_ForeignKeyExpression(child);
                if (parents2.TryGetValue(fk, out var targetCollections))
                {
                    foreach (var targetCollection in targetCollections)
                    {
                        lock (targetCollection)
                            targetCollection.Add(child);
                    }
                }
                else
                if (!ignoreUnmatchedChildren)
                {
                    var ex = new UnexpectedDataException($"Found child object with the foreign key \"{ fk }\" that couldn't be matched to a parent. See Exception.Data[\"ChildObject\"] for details.");
                    ex.Data["ForeignKey"]  = fk;
                    ex.Data["ChildObject"] = child;
                    throw ex;
                }
            });
        }
Esempio n. 3
0
        void MatchSerial(Tuple <List <T1>, List <T2> > result, bool ignoreUnmatchedChildren)
        {
            //build the dictionary
            var parents = result.Item1.ToDictionary(m_PrimaryKeyExpression, m_TargetCollectionExpression);

            foreach (var child in result.Item2)
            {
                var fk = m_ForeignKeyExpression(child);
                if (parents.TryGetValue(fk, out var targetCollection))
                {
                    targetCollection.Add(child);
                }
                else if (!ignoreUnmatchedChildren)
                {
                    var ex = new UnexpectedDataException($"Found child object with the foreign key \"{ fk }\" that couldn't be matched to a parent. See Exception.Data[\"ChildObject\"] for details.");
                    ex.Data["ForeignKey"]  = fk;
                    ex.Data["ChildObject"] = child;
                    throw ex;
                }
            }
        }
        public async Task <GoogleApiGeoCodeResult> GeoCode(string streetAddress, string city, string state, string postalCode)
        {
            var address           = $"{streetAddress}, {city}, {state}";
            var encodedAddress    = _urlEncoder.Encode(address);
            var encodedPostalCode = _urlEncoder.Encode(postalCode);
            var query             = $"{encodedAddress}&components=postal_code:{encodedPostalCode}";
            var url = await BuildApiUrl(GoogleApiEndpointEnum.GeoCode, query);

            var responseMessage = await SendAsync(url);

            var json = await responseMessage.Content.ReadAsStringAsync();

            var geoCodeResults = System.Text.Json.JsonSerializer.Deserialize <GoogleApiGeoCodeRootObject>(json);

            if (geoCodeResults.results == null || !geoCodeResults.results.Any())
            {
                var innerException = new UnexpectedDataException("query", query);
                throw new UnexpectedDataException("No results for query", innerException);
            }

            return(geoCodeResults.results.FirstOrDefault());
        }