Beispiel #1
0
        public async Task AddMediaAsync(MongoDB.Driver.IMongoCollection <CatalogObject> collection, CatalogObject json)
        {
            try
            {
                //var found = vho.TryGetValue(json.AltCode, out r);
                var filter = Builders <CatalogObject> .Filter.Eq("AltCode", json.AltCode);

                var found = await collection.Find(filter).ToListAsync();

                if (found.Count > 0)
                {
                    //check to see if its an exact copy, if it is then skip
                    var r = found[0];
                    if (r.GetHashCode() != json.GetHashCode())
                    {
                        if (json.IsHD)//only add values/updates from the HD version
                        {
                            //vho[json.AltCode] = json;
                            if (null != collection.Find(json.AltCode))
                            {
                                await collection.ReplaceOneAsync(x => x.AltCode == json.AltCode, json);
                            }
                            else
                            {
                                await collection.InsertOneAsync(json);
                            }
                            Compare(r, json);
                        }
                        else
                        {
                            //need to Add Avails data for nonHD here which requires making the private fields into a list of...
                        }
                    }
                }
                else
                {
                    //Not this is unusual and an error
                    //So possible outcome here is we have same content but first four chars dont match, but content is same
                    //var dict = vho.Where(kvp => json.ProviderAssetID.Substring(4)).SelectMany(kvp => kvp.Value);
                    //var dict = vho.SelectMany(m => m).Where(k => vho.Keys.Contains(json.ProviderAssetID.Substring(4)));

                    /*var selectValues = (from keyValuePair in vho
                     *                  where keyValuePair.Key.Contains(json.ProviderAssetID.Substring(4))
                     *                  select keyValuePair.Value).ToList();
                     * if (selectValues.Count > 1)
                     *  Console.WriteLine(vhoNumber + " : " + json.AltCode);
                     */
                    //vho[json.AltCode] = json;
                    if (null == collection.Find(json.AltCode))
                    {
                        await collection.ReplaceOneAsync(x => x.AltCode == json.AltCode, json);
                    }
                    else
                    {
                        await collection.InsertOneAsync(json);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        public async Task AddMediaAsync(MongoDB.Driver.IMongoCollection<CatalogObject> collection, CatalogObject json)
        {
            try
            {
                //var found = vho.TryGetValue(json.AltCode, out r);
                var filter = Builders<CatalogObject>.Filter.Eq("AltCode", json.AltCode);
                var found = await collection.Find(filter).ToListAsync();

                if (found.Count > 0)
                {
                    //check to see if its an exact copy, if it is then skip
                    var r = found[0];
                    if (r.GetHashCode() != json.GetHashCode())
                    {
                        if (json.IsHD)//only add values/updates from the HD version
                        {
                            //vho[json.AltCode] = json;
                            if (null != collection.Find(json.AltCode))
                            {
                                await collection.ReplaceOneAsync(x => x.AltCode == json.AltCode, json);
                            }
                            else
                            {
                                await collection.InsertOneAsync(json);
                            }
                            Compare(r, json);
                        }
                        else
                        {
                            //need to Add Avails data for nonHD here which requires making the private fields into a list of...
                        }
                    }
                }
                else
                {
                    //Not this is unusual and an error
                    //So possible outcome here is we have same content but first four chars dont match, but content is same
                    //var dict = vho.Where(kvp => json.ProviderAssetID.Substring(4)).SelectMany(kvp => kvp.Value);
                    //var dict = vho.SelectMany(m => m).Where(k => vho.Keys.Contains(json.ProviderAssetID.Substring(4)));
                    /*var selectValues = (from keyValuePair in vho
                                        where keyValuePair.Key.Contains(json.ProviderAssetID.Substring(4))
                                        select keyValuePair.Value).ToList();
                    if (selectValues.Count > 1)
                        Console.WriteLine(vhoNumber + " : " + json.AltCode);
                    */
                    //vho[json.AltCode] = json;
                    if (null == collection.Find(json.AltCode))
                    {
                        await collection.ReplaceOneAsync(x => x.AltCode == json.AltCode, json);
                    }
                    else
                    {
                        await collection.InsertOneAsync(json);
                    }
                    
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }