Exemple #1
0
        //public StandardResult ParserHolders(string[] holderAccounts)
        //{
        //    if (holderAccounts == null || holderAccounts.Length == 0) return Result(iTripExceptionCode.Error_Null_Reference);
        //    var resp = GetRespository<Holder>();
        //    var holders = resp.Select(h => holderAccounts.Contains(h.Account)).ToList();
        //    if (holders.Count == holderAccounts.Length)
        //        return Result(holders);
        //    List<Holder> hs = new List<Holder>();
        //    holderAccounts.ForEach(delegate(string acc)
        //    {
        //        if (!holders.Any(h => h.Account == acc))
        //            hs.Add(new Holder(acc));
        //    });
        //    resp.Insert(hs);
        //    hs.AddRange(holders);
        //    return Result(hs);
        //}
        public int AttachPackage(string[] holders, MongoDBRef package)
        {
            if (holders == null || holders.Length == 0) return 0;
            List<PackageHolding> phs = new List<PackageHolding>();

            holders.ForEach(a => phs.Add(new PackageHolding(a, package.Id.AsString)));
            GetRespository<PackageHolding>().Insert(phs);
            return phs.Count;
        }
        /// <summary>
        /// Fetches the document referred to by the DBRef.
        /// </summary>
        /// <param name="documentType">The nominal type of the document to fetch.</param>
        /// <param name="dbRef">The <see cref="MongoDBRef"/> to fetch.</param>
        /// <returns>The document (or null if the document was not found).</returns>
        public virtual object FetchDBRefAs(Type documentType, MongoDBRef dbRef)
        {
            if (dbRef.DatabaseName == null)
            {
                throw new ArgumentException("MongoDBRef DatabaseName missing.");
            }

            var database = GetDatabase(dbRef.DatabaseName);

            return(database.FetchDBRefAs(documentType, dbRef));
        }
        public void TestDeserializeMongoDBRef() {
            var dbRef = new MongoDBRef("test", ObjectId.GenerateNewId());
            var c = new C { DbRef = dbRef };
            collection.RemoveAll();
            collection.Insert(c);

            var rehydrated = collection.FindOne();
            Assert.IsNull(rehydrated.DbRef.DatabaseName);
            Assert.AreEqual(dbRef.CollectionName, rehydrated.DbRef.CollectionName);
            Assert.AreEqual(dbRef.Id, rehydrated.DbRef.Id);
        }
        /// <summary>
        /// Fetches the document referred to by the DBRef.
        /// </summary>
        /// <param name="documentType">The nominal type of the document to fetch.</param>
        /// <param name="dbRef">The <see cref="MongoDBRef"/> to fetch.</param>
        /// <returns>An instance of nominalType (or null if the document was not found).</returns>
        public virtual object FetchDBRefAs(Type documentType, MongoDBRef dbRef)
        {
            if (dbRef.DatabaseName != null && dbRef.DatabaseName != _namespace.DatabaseName)
            {
                return(_server.FetchDBRefAs(documentType, dbRef));
            }

            var collection = GetCollection(dbRef.CollectionName);
            var query      = Query.EQ("_id", dbRef.Id);

            return(collection.FindOneAs(documentType, query));
        }
 public DBClient(MongoUrl url, MongoDBRef dbRef)
 {
     if (url == null)
         throw new MongoAuthenticationException("Wrong MongoUrl");
     if (dbRef == null)
         throw new MongoAuthenticationException("Wrong Collection Value");
     _dbName = dbRef.DatabaseName;
     _collectionName = dbRef.CollectionName;
     //this._type = type;
     MongoClientSettings setting = MongoClientSettings.FromUrl(url);
     _client = new MongoClient(url);
 }
        public ActionResult ModifyContent(string formId, string fieldId,ContentAction contentAction)
        {
            if(formsCollection != null && !string.IsNullOrEmpty(formId) && !string.IsNullOrEmpty(fieldId))
            {
                Form form = GetForm(formId);
                if(form != null)
                {
                    if(DBHelper.GetInstance().GetField(fieldId) != null)
                    {
                        MongoDBRef dbref = new MongoDBRef(DBHelper.GetInstance().FieldsCollection().Name,fieldId);

                        if(new ContentAction[]{ContentAction.Remove,ContentAction.Up,ContentAction.Down}.Contains(contentAction))
                        {
                            if(form.Contents.Contains(dbref))
                            {
                                if(contentAction == ContentAction.Remove)
                                {
                                    form.Contents.Remove(dbref);
                                }
                                else if(contentAction == ContentAction.Up)
                                {
                                    LinkedListNode<MongoDBRef> prev = form.Contents.Find(dbref).Previous;
                                    if(prev != null)
                                    {
                                        form.Contents.Remove(dbref);
                                        form.Contents.AddBefore(prev,dbref);
                                    }
                                }
                                else if(contentAction == ContentAction.Down)
                                {
                                    LinkedListNode<MongoDBRef> next = form.Contents.Find(dbref).Next;
                                    if(next != null)
                                    {
                                        form.Contents.Remove(dbref);
                                        form.Contents.AddAfter(next,dbref);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if(!form.Contents.Contains(dbref))
                            {
                                form.Contents.AddLast(dbref);
                            }
                        }

                        formsCollection.Save(form);
                    }
                }
            }
            return RedirectToAction("Index",new{Id = formId});
        }
Exemple #7
0
        /// <summary>
        /// Fetches the document referred to by the DBRef, deserialized as a <typeparamref name="TDocument"/>.
        /// </summary>
        /// <param name="dbRef">The <see cref="MongoDBRef"/> to fetch.</param>
        /// <returns>A <typeparamref name="TDocument"/> (or null if the document was not found).</returns>
        public virtual TDocument FetchDBRefAs <TDocument>(
            MongoDBRef dbRef
            )
        {
            if (dbRef.DatabaseName == null)
            {
                throw new ArgumentException("MongoDBRef DatabaseName missing");
            }

            var database = GetDatabase(dbRef.DatabaseName);

            return(database.FetchDBRefAs <TDocument>(dbRef));
        }
        /// <summary>
        /// Fetches the document referred to by the DBRef, deserialized as a <typeparamref name="TDocument"/>.
        /// </summary>
        /// <param name="dbRef">The <see cref="MongoDBRef"/> to fetch.</param>
        /// <returns>A <typeparamref name="TDocument"/> (or null if the document was not found).</returns>
        public virtual TDocument FetchDBRefAs <TDocument>(
            MongoDBRef dbRef
            )
        {
            if (dbRef.DatabaseName != null && dbRef.DatabaseName != name)
            {
                return(server.FetchDBRefAs <TDocument>(dbRef));
            }

            var collection = GetCollection(dbRef.CollectionName);
            var query      = Query.EQ("_id", BsonValue.Create(dbRef.Id));

            return(collection.FindOneAs <TDocument>(query));
        }
        public void TestDateTimeRefId() {
            var id = ObjectId.GenerateNewId();
            var dateTime = BsonConstants.UnixEpoch; ;
            var dbRef = new MongoDBRef("collection", dateTime);
            var obj = new C { Id = id, DBRef = dbRef };
            var json = obj.ToJson();
            var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : ISODate('1970-01-01T00:00:00Z') } }";
            expected = expected.Replace("#id", id.ToString());
            expected = expected.Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<C>(bson);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
        public void TestDocumentRefId() {
            var id = ObjectId.GenerateNewId();
            var refId = new BsonDocument { { "x", 1 }, { "y", 2 } };
            var dbRef = new MongoDBRef("collection", refId);
            var obj = new C { Id = id, DBRef = dbRef };
            var json = obj.ToJson();
            var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : { 'x' : 1, 'y' : 2 } } }";
            expected = expected.Replace("#id", id.ToString());
            expected = expected.Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<C>(bson);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
        public void TestGuidRefId()
        {
            var id = ObjectId.GenerateNewId();
            var guid = Guid.NewGuid();
            var dbRef = new MongoDBRef("collection", guid);
            var obj = new C { Id = id, DBRef = dbRef };
            var json = obj.ToJson();
            var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : CSUUID('#guid') } }";
            expected = expected.Replace("#id", id.ToString());
            expected = expected.Replace("#guid", guid.ToString());
            expected = expected.Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<C>(bson);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
        public void TestFetchDBRef() {
            var collectionName = "testdbref";
            var collection = database.GetCollection(collectionName);
            var document = new BsonDocument { { "_id", ObjectId.GenerateNewId() }, { "P", "x" } };
            collection.Insert(document);

            var dbRef = new MongoDBRef(collectionName, document["_id"].AsObjectId);
            var fetched = database.FetchDBRef(dbRef);
            Assert.AreEqual(document, fetched);
            Assert.AreEqual(document.ToJson(), fetched.ToJson());

            var dbRefWithDatabaseName = new MongoDBRef(database.Name, collectionName, document["_id"].AsObjectId);
            fetched = server.FetchDBRef(dbRefWithDatabaseName);
            Assert.AreEqual(document, fetched);
            Assert.AreEqual(document.ToJson(), fetched.ToJson());
            Assert.Throws<ArgumentException>(() => { server.FetchDBRef(dbRef); });
        }
Exemple #13
0
        private void button2_Click(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server = MongoServer.Create(connectionString);
            var db = server.GetDatabase("Zalagaonica");
            byte[] slika_ugovora = File.ReadAllBytes(textBox1.Text);
            UgovorClass ugovor = new UgovorClass
            {
                datumPotpisivanja = dateTimePicker1.Value.ToString(),
                datumIsteka = dateTimePicker2.Value.ToString(),
                datNovac = Int32.Parse(textBox3.Text),
                slikaUgovora = slika_ugovora
            };
            var collection = db.GetCollection<UgovorClass>("ugovori");
            collection.Insert(ugovor);
            ovajUgovor = new MongoDBRef("ugovori",ugovor.Id);

            //var nc = db.GetCollection<UgovorClass>("ugovori");
            //foreach (UgovorClass item in nc.FindAll())
            //{
            //     MessageBox.Show(item.datumIsteka);
            //}
        }
Exemple #14
0
 public SocetProducts(Product product, WarehouseSocet warehouseSocet)
 {
     WarehouseSocetId = new MongoDBRef("WarehouseSocet", warehouseSocet.Id);
     ProductId = new MongoDBRef("Product", product.Id);
     this.TimeStamp = DateTime.Now;
 }
        public string InsertPat(mPatInfo pat, string User)
        {
            MongoServer server = ConnectDB();
             var db = server.GetDatabase("hdb");
             string pid = "";
            try
            {
                using (server.RequestStart(db))
                {

                    var Usercollection = db.GetCollection<mUser>("Users");

                    var query = new QueryDocument("UserName", User);
                    //mUser u = new mUser();
                    //u.UserName = "******";
                    //u.PassWord = "******";
                    mUser entity = Usercollection.FindOne(query);
                    MongoDBRef r = new MongoDBRef("Users", entity.Id);

                    var PatCollection = db.GetCollection<mPatInfo>("Pats");
                    pat.Doctor = r;
                    PatCollection.Insert(pat);
                    pid = pat.PatId.ToString();
                    //collection.Remove(query);

                }
                return pid;
            }
            catch (System.Exception ex)
            {
                return pid;
            }
        }
        //public static void InsertSort(List<mPatInfo> data)
        //{
        //    var count = data.Count;
        //    for (int i = 1; i < count; i++)
        //    {
        //        var t = data[i].VisitRecord.Last().VisitDate;
        //        var d = data[i];
        //        var j = i;
        //        while (j > 0 && data[j - 1].VisitRecord.Last().VisitDate < t)
        //        {
        //            data[j] = data[j - 1];
        //            --j;
        //        }
        //        data[j] = d;
        //    }
        //}
        public bool SaveRecord(string PatID, mVisitData VData)
        {
            try
            {
                MongoServer server = ConnectDB();
                var db = server.GetDatabase("hdb");
                mVisitData vdata = DataPreprocess(VData);

                using (server.RequestStart(db))
                {
                    var collection = db.GetCollection<mPatInfo>("Pats");
                    ObjectId id = new ObjectId(PatID);
                    // Create a document with the ID we want to find
                    var query = new QueryDocument { { "_id", id } };
                    mPatInfo entity = collection.FindOne(query);
                    var Visitcollection = db.GetCollection<mVisitRecord>("VisitRecords");

                    mVisitRecord vr = vdata.Visitrecord;
                    vr.VisitDate = DateTime.Now.Date;
                    Visitcollection.Insert(vr);
                    MongoDBRef r = new MongoDBRef("VisitRecords", vr.VisitrecordId);
                    entity.refs.Add(r);

                    mRelatedInfo mr = vdata.RelateInfo;
                    entity.relatedInfo = mr;
                    collection.Save(entity);
                }

                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
        public void TestWithDatabase() {
            var id = ObjectId.GenerateNewId();
            var dbRef = new MongoDBRef("database", "collection", ObjectId.GenerateNewId());
            var obj = new C { Id = id, DBRef = dbRef };
            var json = obj.ToJson();
            var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : ObjectId('#ref'), '$db' : 'database' } }";
            expected = expected.Replace("#id", id.ToString());
            expected = expected.Replace("#ref", dbRef.Id.ToString());
            expected = expected.Replace("'", "\"");
            Assert.AreEqual(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<C>(bson);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));
        }
        /// <summary>
        /// Links a contact
        /// </summary>
        /// <param name="link"></param>
        public void LinkContact(Contact link)
        {
            var refLink = new MongoDBRef(link.GetCollection().Name, link.Id);
            var refThis = new MongoDBRef(this.GetCollection().Name, this.Id);

            // Add link to all this references
            foreach (var reference in this.LinkedContacts)
            {
                if (reference.Id == link.Id)
                    continue;

                Contact.LinkContact(reference.Id, refLink);
                link.LinkContact(reference);
            }

            // Add this to all link references
            foreach (var reference in link.LinkedContacts)
            {
                Contact.LinkContact(reference.Id, refThis);
            }

            //
            // Add link to this
            LinkContact(refLink);

            // Add this to link
            link.LinkContact(refThis);
        }
 /// <summary>
 /// Fetches the document referred to by the DBRef, deserialized as a <typeparamref name="TDocument"/>.
 /// </summary>
 /// <typeparam name="TDocument">The nominal type of the document to fetch.</typeparam>
 /// <param name="dbRef">The <see cref="MongoDBRef"/> to fetch.</param>
 /// <returns>A <typeparamref name="TDocument"/> (or null if the document was not found).</returns>
 public virtual TDocument FetchDBRefAs <TDocument>(MongoDBRef dbRef)
 {
     return((TDocument)FetchDBRefAs(typeof(TDocument), dbRef));
 }
 public void TestFetchDBRef()
 {
     _collection.Drop();
     _collection.Insert(new BsonDocument { { "_id", 1 }, { "x", 2 } });
     var dbRef = new MongoDBRef(_database.Name, _collection.Name, 1);
     var document = _server.FetchDBRef(dbRef);
     Assert.AreEqual(2, document.ElementCount);
     Assert.AreEqual(1, document["_id"].AsInt32);
     Assert.AreEqual(2, document["x"].AsInt32);
 }
 public ActionResult SaveNextState(string flowId, string stateId, string route, string nextStateId, string nextTaskId)
 {
     if(flowsCollection != null && flowStatesCollection != null
        && !string.IsNullOrEmpty(flowId) && !string.IsNullOrEmpty(stateId)
        && !string.IsNullOrEmpty(route) && !string.IsNullOrEmpty(nextStateId)
        && !string.IsNullOrEmpty(nextTaskId))
     {
         Flow flow = GetFlow(flowId);
         FlowState state = GetFlowState(stateId);
         FlowState nextState = SaveFlowState(flowId,nextStateId,nextTaskId);
         if(state.NextStates == null)
         {
             state.NextStates = new Dictionary<string,MongoDBRef>();
         }
         if(nextState != null)
         {
             MongoDBRef stateRef = new MongoDBRef(flowStatesCollection.Name,nextState.State);
             if(!state.NextStates.Keys.Contains(route))
             {
                 state.NextStates.Add(route, stateRef);
             }
             else
             {
                 state.NextStates[route] = stateRef;
             }
             flowStatesCollection.Save(state);
         }
     }
     return RedirectToAction("Index");
 }
        public ActionResult ModifyContent(string flowId, string groupId, string taskId, ContentAction contentAction)
        {
            if(flowsCollection != null && !string.IsNullOrEmpty(flowId) && !string.IsNullOrEmpty(groupId) && !string.IsNullOrEmpty(taskId))
            {
                Flow flow = GetFlow(flowId);
                if(flow != null)
                {
                    Group group = DBHelper.GetInstance().GetGroup(groupId);
                    Task task = DBHelper.GetInstance().GetTask(taskId);
                    if(group != null && task != null)
                    {
                        MongoDBRef groupdbref = new MongoDBRef(DBHelper.GetInstance().GroupsCollection().Name,group.Name);
                        MongoDBRef taskdbref = new MongoDBRef(DBHelper.GetInstance().TasksCollection().Name,task.Name);
                        FlowContentRef dbref = new FlowContentRef{Group = groupdbref, Task = taskdbref};
                        if(new ContentAction[]{ContentAction.Remove,ContentAction.Up,ContentAction.Down}.Contains(contentAction))
                        {
                            bool found = false;
                            foreach(FlowContentRef fcref in flow.Contents)
                            {
                                if(fcref.Equals(dbref))
                                {
                                    dbref = fcref;
                                    found = true;
                                    break;
                                }
                            }

                            if(found)
                            {
                                if(contentAction == ContentAction.Remove)
                                {
                                    flow.Contents.Remove(dbref);
                                }
                                else if(contentAction == ContentAction.Up)
                                {
                                    LinkedListNode<FlowContentRef> prev = flow.Contents.Find(dbref).Previous;
                                    if(prev != null)
                                    {
                                        flow.Contents.Remove(dbref);
                                        flow.Contents.AddBefore(prev,dbref);
                                    }
                                }
                                else if(contentAction == ContentAction.Down)
                                {
                                    LinkedListNode<FlowContentRef> next = flow.Contents.Find(dbref).Next;
                                    if(next != null)
                                    {
                                        flow.Contents.Remove(dbref);
                                        flow.Contents.AddAfter(next,dbref);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if(!flow.Contents.Contains(dbref))
                            {
                                flow.Contents.AddLast(dbref);
                            }
                        }

                        flowsCollection.Save(flow);
                    }
                }
            }
            return RedirectToAction("Index",new{Id = flowId});
        }
        private void button5_Click(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server = MongoServer.Create(connectionString);
            var database = server.GetDatabase("Zalagaonica");

            Ugovor noviUgovorForm = new Ugovor();
            noviUgovorForm.ShowDialog();
            novi_ugovor = noviUgovorForm.vratiUgovor();
            textBox4.Text = novi_ugovor.Id.ToString();
        }
Exemple #24
0
        public void TestInt64RefId()
        {
            var id = ObjectId.GenerateNewId();
            var dbRef = new MongoDBRef("collection", 123456789012345L);
            var obj = new C { Id = id, DBRef = dbRef };
            var json = obj.ToJson();
            var expected = "{ '_id' : ObjectId('#id'), 'DBRef' : { '$ref' : 'collection', '$id' : NumberLong('123456789012345') } }";
            expected = expected.Replace("#id", id.ToString());
            expected = expected.Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<C>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
 /// <summary>
 /// Links a contact
 /// </summary>
 /// <param name="link"></param>
 private void LinkContact(MongoDBRef link)
 {
     if (this.LinkedContacts.All(reference => !MongoDBRef.ReferenceEquals(link, reference)))
     {
         this.LinkedContacts.Add(link);
         Save();
     }
 }
        /// <summary>
        /// Unlinks a contact
        /// </summary>
        /// <param name="link"></param>
        public void UnlinkContact(Contact link)
        {
            var refLink = new MongoDBRef(link.GetCollection().Name, link.Id);
            var refThis = new MongoDBRef(this.GetCollection().Name, this.Id);

            foreach (var reference in this.LinkedContacts)
                Contact.UnlinkContact(reference.Id, refLink);

            foreach (var reference in link.LinkedContacts)
                Contact.UnlinkContact(reference.Id, refThis);

            //if (this.LinkedContacts.All(reference => !MongoDBRef.ReferenceEquals(refLink, reference))
            UnlinkContact(refLink);
            link.UnlinkContact(refThis);
        }
Exemple #27
0
 public SocetProducts(string productId, string warehouseSocetId)
 {
     WarehouseSocetId = new MongoDBRef("WarehouseSocet", warehouseSocetId);
     ProductId = new MongoDBRef("Product", productId);
     this.TimeStamp = DateTime.Now;
 }
Exemple #28
0
 public int DealPackage(MongoDBRef package, string[] holders)
 {
     IHolderResolver holderResolver = new HolderResolver();
     return holderResolver.AttachPackage(holders, package);
 }
Exemple #29
0
        static async Task  MappingAuthor()
        {
            var client = new MongoClient("mongodb://*****:*****@app-svr.cloudapp.net:27017/forums");

            var forums = client.GetDatabase("forums");

            var users = forums.GetCollection<BsonDocument>("users");

            var threads = forums.GetCollection<BsonDocument>("uwp_threads");

            var updates = new List<WriteModel<BsonDocument>>();

            await threads.Find(new BsonDocument())
                .ForEachAsync(async (thread) => {
                    var filter = Builders<BsonDocument>.Filter.Eq("id", thread.GetElement("authorId").Value);

                    var author = await users.Find(filter).FirstOrDefaultAsync();

                    var dbref = new MongoDBRef("users", author.GetElement("_id").Value.AsObjectId);
                   
                    updates.Add(new UpdateOneModel<BsonDocument>(new BsonDocument("_id", thread.GetElement("_id").Value), new BsonDocument("$set", new BsonDocument("author", dbref.ToBsonDocument()))));
                });

            await threads.BulkWriteAsync(updates);
        }
 /// <summary>
 /// Fetches the document referred to by the DBRef.
 /// </summary>
 /// <param name="dbRef">The <see cref="MongoDBRef"/> to fetch.</param>
 /// <returns>A BsonDocument (or null if the document was not found).</returns>
 public virtual BsonDocument FetchDBRef(MongoDBRef dbRef)
 {
     return(FetchDBRefAs <BsonDocument>(dbRef));
 }
        public void TestEqualsWithDatabase()
        {
            var a1 = new MongoDBRef("d", "c", 1);
            var a2 = new MongoDBRef("d", "c", 1);
            var a3 = a2;
            var b = new MongoDBRef("x", "c", 1);
            var c = new MongoDBRef("d", "x", 1);
            var d = new MongoDBRef("d", "c", 2);
            var null1 = (MongoDBRef)null;
            var null2 = (MongoDBRef)null;

            Assert.AreNotSame(a1, a2);
            Assert.AreSame(a2, a3);
            Assert.IsTrue(a1.Equals((object)a2));
            Assert.IsFalse(a1.Equals((object)null));
            Assert.IsFalse(a1.Equals((object)"x"));

            Assert.IsTrue(a1 == a2);
            Assert.IsTrue(a2 == a3);
            Assert.IsFalse(a1 == b);
            Assert.IsFalse(a1 == c);
            Assert.IsFalse(a1 == d);
            Assert.IsFalse(a1 == null1);
            Assert.IsFalse(null1 == a1);
            Assert.IsTrue(null1 == null2);

            Assert.IsFalse(a1 != a2);
            Assert.IsFalse(a2 != a3);
            Assert.IsTrue(a1 != b);
            Assert.IsTrue(a1 != c);
            Assert.IsTrue(a1 != d);
            Assert.IsTrue(a1 != null1);
            Assert.IsTrue(null1 != a1);
            Assert.IsFalse(null1 != null2);

            Assert.AreEqual(a1.GetHashCode(), a2.GetHashCode());
        }
 /// <summary>
 /// Unlinks a contact
 /// </summary>
 /// <param name="link"></param>
 private void UnlinkContact(MongoDBRef link)
 {
     this.LinkedContacts.Remove(link);
     Save();
 }
 /// <summary>
 /// Unlinks a contact from a link
 /// </summary>
 /// <param name="source"></param>
 /// <param name="link"></param>
 public static void UnlinkContact(BsonValue source, MongoDBRef link)
 {
     Contact.Get(source).ContinueWith(t => t.Result.UnlinkContact(link));
 }