Ejemplo n.º 1
0
        public static string SearchPersonalInfo(string personId)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();

            MongoClient mclient = new MongoClient(GlobalVariables.mongolabConection);
            var db = mclient.GetDatabase(GlobalVariables.mongoDatabase);
            var collection = db.GetCollection<DocumentInfo>("DocumentsCollection");


            // var filter = Builders<PersonInfo>.Filter.Eq("name", "Mozart");

            var filter = Builders<DocumentInfo>.Filter.Eq("id", personId);

            DocumentInfo personData = new DocumentInfo();
            string jsString = "";
            try
            {
                collection.Find(filter).ForEachAsync(d => jsString += "{\"id\":\""
                   + d.id + "\",\"title\" : \"" + d.title + "\",\"startdate\" : \"" + d.startdate
                   + "\",\"enddate\" : \"" + endDate(d.enddate) + "\",\"importance\" : \""
                   + d.importance + "\",\"description\" : \"" + d.description + "\",\"link\" : \""
                   + d.link + "\",\"image\" : \"" + d.image + "\"},").Wait();

                //collection.Find(filter).ForEachAsync(d => { personData.id = d.id; 
                //    personData.name = d.name; 
                //    personData.nationality = d.nationality;
                //    personData.profession = d.profession;
                //    personData.religion = d.religion;
                //    personData.image = d.image;
                //}).Wait();




                //return jsString;
            }
            catch (Exception e)
            {
                return e.ToString();
            }




            //sw.Stop();
            //jsonData = sw.Elapsed.ToString();
            //JObject jsonData = JObject.Parse(jsString.TrimEnd(','));
            var serializer = new JavaScriptSerializer();
            var json = serializer.Serialize(jsString.TrimEnd(','));
            return json;

        }
Ejemplo n.º 2
0
        public static string RemoveInTagCollection(string tagName, string documentId)
        {
            MongoClient mclient = new MongoClient(GlobalVariables.mongolabConection);
            var db = mclient.GetDatabase(GlobalVariables.mongoDatabase);

            var collectionDocument = db.GetCollection<DocumentInfo>("DocumentsCollection");

            var filter = Builders<DocumentInfo>.Filter.Regex("id", new BsonRegularExpression(documentId));

            DocumentInfo documentInfo = new DocumentInfo();
            collectionDocument.Find(filter).ForEachAsync(d =>
            {
                documentInfo._id = d._id;
                documentInfo.name = d.name;
                documentInfo.id = d.id;

            }).Wait();

            // sterg inregistrarea tagului din document
            var updateDocument = Builders<DocumentInfo>.Update
                       .Pull(p => p.tags, new BsonDocument(){
            { "tagName", tagName } });

            collectionDocument.UpdateOneAsync(filter, updateDocument).Wait();

            // sterg inregistrarea din  tag
            var collectionTags = db.GetCollection<TagsCollection>("Tags");

            var filterTag = Builders<TagsCollection>.Filter.Regex("tagName", tagName);
            var updateTag = Builders<TagsCollection>.Update

                    .Pull(p => p.documentsBelonging, new BsonDocument(){
            { "_id", documentInfo._id } });

            collectionTags.UpdateOneAsync(filterTag, updateTag).Wait();

            return "Deleted";
        }
Ejemplo n.º 3
0
        public static string RemoveInCategoryCollection(string categoryName, string documentId)
        {
            MongoClient mclient = new MongoClient(GlobalVariables.mongolabConection);
            var db = mclient.GetDatabase(GlobalVariables.mongoDatabase);

            var collectionDocument = db.GetCollection<DocumentInfo>("DocumentsCollection");

            var filter = Builders<DocumentInfo>.Filter.Eq("id", documentId);

            DocumentInfo documentInfo = new DocumentInfo();
            collectionDocument.Find(filter).ForEachAsync(d =>
            {
                documentInfo._id = d._id;
                documentInfo.name = d.name;
                documentInfo.id = d.id;

            }).Wait();

            // sterg inregistrarea tagului din document
            var updateDocument = Builders<DocumentInfo>.Update
                       .Pull(p => p.categories, new BsonDocument(){
            { "categoryName", categoryName } });

            collectionDocument.UpdateOneAsync(filter, updateDocument).Wait();

            // sterg inregistrarea din  tag
            var collectionCategories = db.GetCollection<CategoriesCollection>("Categories");

            var filterCategory = Builders<CategoriesCollection>.Filter.Eq("categoryName", categoryName);
            var updateCategory = Builders<CategoriesCollection>.Update
            .Pull(p => p.documentsBelonging, new BsonDocument(){
             { "_id", documentInfo._id } });

            collectionCategories.UpdateOneAsync(filterCategory, updateCategory).Wait();

            return "Deleted";
        }
Ejemplo n.º 4
0
        public static string InsertInTagCollection(string tagName, string documentId, int relativeImportance)
        {
            MongoClient mclient = new MongoClient(GlobalVariables.mongolabConection);
            var db = mclient.GetDatabase(GlobalVariables.mongoDatabase);

            var collectionDocument = db.GetCollection<DocumentInfo>("DocumentsCollection");

            var filter = Builders<DocumentInfo>.Filter.Regex("id", new BsonRegularExpression(documentId));

            DocumentInfo documentInfo = new DocumentInfo();
            collectionDocument.Find(filter).ForEachAsync(d =>
            {
                documentInfo._id = d._id;
                documentInfo.name = d.name;
                documentInfo.id = d.id;

            }).Wait();

            // introduc inregistrarea tagului in document
            BsonDocument tagDocument = new BsonDocument {

                        { "tagName", tagName },
                        { "tagImportance", relativeImportance }
                 };

            var updateDocument = Builders<DocumentInfo>.Update
                    .Push(p => p.tags, tagDocument);

            collectionDocument.UpdateOneAsync(filter, updateDocument).Wait();

            var collectionTags = db.GetCollection<TagsCollection>("Tags");

            BsonDocument documentsBelonging = new BsonDocument()
            {

                { "_id", documentInfo._id },
                { "id", documentInfo.id },
                { "documentName", documentInfo.name },
                { "relativeImportance", relativeImportance}

            };

            var filterTag = Builders<TagsCollection>.Filter.Regex("tagName", tagName);
            var updateTag = Builders<TagsCollection>.Update
                    // .Inc("votes", 1)
                    .Push(p => p.documentsBelonging, documentsBelonging);

            collectionTags.UpdateOneAsync(filterTag, updateTag).Wait();

            return "True";
        }
Ejemplo n.º 5
0
        public static string InsertInCategoryCollection(string categoryName, string documentId, int relativeImportance)
        {
            MongoClient mclient = new MongoClient(GlobalVariables.mongolabConection);
            var db = mclient.GetDatabase(GlobalVariables.mongoDatabase);

            var collectionDocument = db.GetCollection<DocumentInfo>("DocumentsCollection");

            var filter = Builders<DocumentInfo>.Filter.Regex("id", new BsonRegularExpression(documentId));

            DocumentInfo documentInfo = new DocumentInfo();
            collectionDocument.Find(filter).ForEachAsync(d =>
            {
                documentInfo._id = d._id;
                documentInfo.name = d.name;
                documentInfo.id = d.id;

            }).Wait();

            // introduc inregistrarea categoriei in document
            BsonDocument categoryDocument = new BsonDocument {

                        { "categoryName", categoryName },
                        { "categoryImportance", relativeImportance }
                 };

            var updateDocument = Builders<DocumentInfo>.Update
                    .Push(p => p.categories, categoryDocument);

            collectionDocument.UpdateOneAsync(filter, updateDocument).Wait();

            var collectionCategories = db.GetCollection<CategoriesCollection>("Categories");

            BsonDocument documentsBelonging = new BsonDocument()
            {

                { "_id", documentInfo._id },
                { "id", documentInfo.id },
                { "documentName", documentInfo.name },
                { "relativeImportance", relativeImportance}

            };

            var filterCategory = Builders<CategoriesCollection>.Filter.Eq(p => p.categoryName, categoryName);
            var updateCategory = Builders<CategoriesCollection>.Update
                    .Push(p => p.documentsBelonging, documentsBelonging);

            collectionCategories.UpdateOneAsync(filterCategory, updateCategory).Wait();

            return "True";
        }
Ejemplo n.º 6
0
        public static string GetIndividualInfo(string documentId)
        {
            MongoClient mclient = new MongoClient(GlobalVariables.mongolabConection);
            var db = mclient.GetDatabase(GlobalVariables.mongoDatabase);
            var collection = db.GetCollection<DocumentInfo>("DocumentsCollection");
            var individualData = db.GetCollection<IndividualData>("IndividualData");

            var filter = Builders<DocumentInfo>.Filter.Eq(u => u.id, documentId);

            string data = "";
            // var dataD =new  DocumentInfo();

            DocumentInfo docInfo = new DocumentInfo();
            collection.Find(filter).ForEachAsync(d =>
            {

                data = "{ \"name\":\"" + d.name + "\"," +
                  " \"image\":\"" + d.image + "\"," +

                  GetTags(d.tags) +
                  GetCategories(d.categories) +
                // " \"tags\":" + d.tags + "," +
                   "\"dates\":\"" + d.startdate + "-" + d.enddate + "\",";
            }).Wait();

            var collection1 = db.GetCollection<IndividualData>("IndividualData");
            var filter1 = Builders<IndividualData>.Filter.Eq("id", documentId);

            bool beenHere = false;
            collection1.Find(filter1).ForEachAsync(d =>
            {

                if (!beenHere)
                {

                    data += " \"timesViewed\":\"" + d.timesViewed + "\"," +
                         " \"htmlInformation\":" +GetInfo(d.htmlInformation) + "," +

                         GetImages(d.imagesLinks) +
                        // GetResources(d.additionalResources) +
                         GetBooks(d.additionalBooks) +
                         GetVideo(d.videoLinks) +
                         GetLinks(d.additionalLinks) +

                          "\"end\":\"end1\"}";

                    beenHere = true;
                }
            }).Wait();

            // Aici incrementez numarul vizualizarilor
            var update = Builders<IndividualData>.Update
               .Inc("timesViewed", 1);
            collection1.UpdateOneAsync(filter1, update).Wait();

            return data;
        }