Exemple #1
0
 public LichtBildController(
     IOptions <LichtBildConfiguration> lichtBildConfiguration,
     LichtBildConnector lichtBildConnector,
     MongoDBConnector mongoDBConnector,
     OpenDataHubConnector openDataHupConnector
     )
 {
     this._lichtBildConnector     = lichtBildConnector;
     this._lichtBildConfiguration = lichtBildConfiguration;
     this._mongoDBConnector       = mongoDBConnector;
     this._openDataHupConnector   = openDataHupConnector;
 }
Exemple #2
0
        public GastronomyController(
            OpenDataHubConnector openDataHupConnector,
            MongoDBConnector mongoDBConnector
            )
        {
            this._openDataHupConnector = openDataHupConnector;
            _mongoDBConnector          = mongoDBConnector;


            var mapperConfig = new MapperConfiguration(cfg => cfg.CreateMap <Gastronomy, MergedGastronomy>());

            mapper = mapperConfig.CreateMapper();
        }
    public void CheckDevice(NetworkMessage message)
    {
        DeviceDataMessage    msg = message.ReadMessage <DeviceDataMessage>();
        DeviceIdentification deviceIdentification = msg.DeviceIdentification;
        var db         = MongoDBConnector.GetInstance().GetDatabase();
        var collection = db.GetCollection <BsonDocument>("Devices");
        var results    = collection.Find(new BsonDocument {
            { "DevId", deviceIdentification.DevId }
        }).ToList();
        int addr = -1;

        if (results.Count > 0)
        {
            foreach (var result in results)
            {
                if (result["ScreenWidth"].AsInt32 == deviceIdentification.ScreenWidth &&
                    result["ScreenHeight"].AsInt32 == deviceIdentification.ScreenHeight &&
                    result["DeviceClass"].AsInt32 == (int)deviceIdentification.DeviceClass)
                {
                    addr = result["id"].AsInt32;
                }
            }
        }
        if (addr == -1)
        {
            var value = collection.Find(new BsonDocument()).Sort(new BsonDocument {
                { "id", -1 }
            }).Limit(1).Project(Builders <BsonDocument> .Projection.Exclude("_id").Include("id"));
            int maxid;
            if (value.Count() > 0)
            {
                maxid = JsonUtility.FromJson <int>(value.ToJson());
            }
            else
            {
                maxid = 0;
            }
            var document = new BsonDocument
            {
                { "id", maxid + 1 },
                { "DevId", deviceIdentification.DevId },
                { "ScreenWidth", deviceIdentification.ScreenWidth },
                { "ScreenHeight", deviceIdentification.ScreenHeight },
                { "DeviceClass", deviceIdentification.DeviceClass }
            };
            collection.InsertOne(document);
            addr = maxid;
        }
        NetworkServer.SendToClient(message.conn.connectionId, MyMsgType.DeviceId, new IntegerMessage(addr));
    }
        public MainWindow()
        {
            MongoDBConnector.CreateSession("nliis");

            _openFileDialog = new OpenFileDialog
            {
                DefaultExt      = "txt",
                CheckFileExists = true,
                Multiselect     = false
            };

            InitializeComponent();
            Sentences.SelectionChanged += BuildSyntaxTree;
            DocumentService.Language    = "English";
        }
Exemple #5
0
        void Page_Load(Object sender, EventArgs e)
        {
            if (!IsPostBack) {
                MongoDBConnector connector = new MongoDBConnector ();
                var collection = connector.GetCollection<User> ("Users");
                var query = Query.EQ ("id", (ObjectId)Cache.Get ("currentUser"));
                var result = collection.FindOne (query);
                if (result != null) {
                    cachedUser = result;
                    ContentPlaceHolder.Page.Title = cachedUser.email;
                } else {
                    //Response.Redirect("/Default.aspx");

                }
            }
        }
        public void read()
        {
            Console.WriteLine("Connecting....");
            string           dbname = System.Configuration.ConfigurationManager.AppSettings["mongodatabase"];
            MongoDBConnector getCon = new MongoDBConnector();
            MongoServer      con    = getCon.GetCon();

            try
            {
                con.Connect();
                Console.WriteLine("Connected\n");
                var db = con.GetDatabase("est");
                using (con.RequestStart(db))
                {
                    var collection = db.GetCollection <BsonDocument>("user_login");
                    var query      = new QueryDocument();
                    foreach (BsonDocument record in collection.Find(query))
                    {
                        BsonElement Id       = record.GetElement("id");
                        BsonElement Fname    = record.GetElement("fname");
                        BsonElement Lname    = record.GetElement("lname");
                        BsonElement Password = record.GetElement("password");
                        Console.WriteLine("{0}\t{1}" + " " + "{2}\t{3}", Id.Value.ToString(), Fname.Value.ToString(), Lname.Value.ToString(), Password.Value.ToString());
                    }
                    con.Disconnect();
                }
            }
            catch (MongoException e)
            {
                Console.WriteLine("\tError: " + e.HResult.ToString() + "\n\t has occurred: " + e.Message.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                if (con.State == MongoServerState.Connected)
                {
                    con.Disconnect();
                }
            }
        }
Exemple #7
0
 bool VerifyCredentials(string email, string password)
 {
     MongoDBConnector dbConnector = new MongoDBConnector ();
     var collection = dbConnector.GetCollection<User> ("Users");
     var q = Query.EQ ("email", email);
     var queryResult = collection.FindOne (q);
     if (queryResult != null) {
         return queryResult.password == password;
     }
     return false;
 }
Exemple #8
0
 ObjectId GetUserByEmail(string email)
 {
     MongoDBConnector dbConnector = new MongoDBConnector ();
     var collection = dbConnector.GetCollection<User> ("Users");
     var q = Query.EQ ("email", email);
     var queryResult = collection.FindOne (q);
     if (queryResult == null)
         throw new Exception ("User Not Found");
     return queryResult.Id;
 }
Exemple #9
0
 void Page_Load(Object sender, EventArgs e)
 {
     if (!IsPostBack) {
         if (Cache.Get ("currentUser") != null) {
             LoginStatus.Text = "Cached User Exists";
             Response.Redirect (@"~/Profile.aspx");
         } else {
             if ((Request.Browser.Cookies)) {
                 if (Request.Cookies.Get ("com.xdegtyarev.kickstart.login.email") != null &&
                     Request.Cookies.Get ("com.xdegtyarev.kickstart.login.password") != null) {
                     if (VerifyCredentials (Request.Cookies.Get ("com.xdegtyarev.kickstart.login.email").Value, Request.Cookies.Get ("com.xdegtyarev.kickstart.login.password").Value)) {
                         LoginStatus.Text = "Login from Cookies";
                         Cache.Insert ("currentUser", GetUserByEmail (Request.Cookies.Get ("com.xdegtyarev.kickstart.login.email").Value));
                         //No need to save cookies can extend cookie expiration
                         Response.Redirect ("/Profile.aspx");
                     } else {
                         //Empty Cookies
                     }
                 }
             }
         }
         MongoDBConnector connector = new MongoDBConnector ();
         var roles = connector.GetCollection<Role> ("Roles");
         if (roles.Count () > 0) {
             List<String> l = new List<String> ();
             foreach (var o in roles.FindAll()) {
                 l.Add (o.type);
             }
             AcountTypeDropdownList.DataSource = l;
             AcountTypeDropdownList.DataBind ();
         } else {
             RegisterButton.Visible = false;
         }
     }
 }
 public PlayerController()
 {
     var connector = new MongoDBConnector();
     _playerService = new PlayerService(connector.GetDatabase());
 }
Exemple #11
0
 bool EmailNotRegistered(string mail)
 {
     MongoDBConnector dbConnector = new MongoDBConnector ();
     var collection = dbConnector.GetCollection<User> ("Users");
     var q = Query.EQ ("email", mail);
     return collection.Find (q).Count () == 0;
 }
Exemple #12
0
        public static Result SaveObjects(List <Object> objects)
        {
            Result result = new Result()
            {
                Code = ResultCode.Success
            };

            try
            {
                foreach (Object obj in objects)
                {
                    //new object to be saved...
                    BsonDocument doc = GetBSONDocument(obj);

                    //get if any existing object from db...
                    //FilterDefinition<BsonDocument> fc = Builders<BsonDocument>.Filter.Eq(Constants.AttribObjectId,obj.Id);
                    FilterDefinition <BsonDocument> fc = Builders <BsonDocument> .Filter.And(new FilterDefinition <BsonDocument>[] {
                        Builders <BsonDocument> .Filter.Eq(Constants.AttribObjectId, obj.Id),
                        Builders <BsonDocument> .Filter.Lt(Constants.AttribTimestamp, new BsonTimestamp((long)obj.Timestamp))
                    });

                    BsonDocument existing = MongoDBConnector.FindOne <BsonDocument>(obj.Type, fc);
                    //find - ObjectId, order by timestamp desc top 1
                    if (existing != null)
                    {
                        existing.Remove("_id");
                        foreach (BsonElement e in doc.Elements)
                        {
                            existing[e.Name] = e.Value;
                        }
                        doc = existing;
                    }
                    Task.Run(() => MongoDBConnector.insert <BsonDocument>(doc, obj.Type)).Wait();

                    #region "Update future records"
                    //to update future records if any..
                    BsonDocument filterCriteria = new BsonDocument();
                    filterCriteria.Add(Constants.AttribObjectId, obj.Id);
                    filterCriteria.Add(Constants.AttribTimestamp, new BsonDocument().Add("$gte", new BsonTimestamp((long)obj.Timestamp)));
                    List <BsonDocument> docs = null;
                    try
                    {
                        docs = MongoDBConnector.find <BsonDocument>(obj.Type, filterCriteria);
                    }
                    catch
                    {
                        //no docs found...
                    }
                    if (docs != null)
                    {
                        foreach (BsonDocument futureDoc in docs)
                        {
                            bool changed = false;
                            foreach (BsonElement e in doc.Elements)
                            {
                                if (futureDoc.Elements.Where(fe => fe.Name == e.Name).Count() == 0)
                                {
                                    futureDoc.Add(e);
                                    changed = true;
                                }
                            }
                            if (changed)
                            {
                                fc = Builders <BsonDocument> .Filter.Eq("_id", futureDoc.GetElement("_id").Value);

                                Task.Run(() => MongoDBConnector.ReplaceOne <BsonDocument>(obj.Type, fc, futureDoc)).Wait();
                            }
                        }
                    }
                    #endregion
                }
            }
            catch
            {
                result.Code = ResultCode.Error;
            }

            return(result);
        }
Exemple #13
0
 public DishController(
     MongoDBConnector mongoDBConnector
     )
 {
     this._mongoDBConnector = mongoDBConnector;
 }
    public void AddUser(NetworkMessage message)
    {
        StoredUserMessage msg  = message.ReadMessage <StoredUserMessage>();
        StoredUser        user = msg.User;

        user.TestGroup = _config.TestGroup;
        //Generate random code:
        string code;
        var    resultDb = MongoDBConnector.GetInstance().GetResultsDatabase();
        var    registeredUsersCollection = resultDb.GetCollection <BsonDocument>("Users");
        int    count;

        do
        {
            code  = GenRandomCode();
            count = registeredUsersCollection.Find(new BsonDocument {
                { "_id", code }
            }).Limit(1).ToList().Count;
        } while (count != 0);
        user.Code = code;
        var db         = MongoDBConnector.GetInstance().GetDatabase();
        var collection = db.GetCollection <BsonDocument>("Users");
        var document   = new BsonDocument
        {
            { "Name", user.Name },
            { "TestGroup", user.TestGroup },
            { "Code", user.Code },
            { "Questionarie", new BsonDocument {
                  { "AgeGroup", user.Results.AgeGroup },
                  { "TouchFrequency", user.Results.TouchFrequency },
                  { "None", user.Results.None },
                  { "Smaller5", user.Results.Smaller5 },
                  { "Smaller11", user.Results.Smaller11 },
                  { "Greater11", user.Results.Greater11 },
                  { "Activities", user.Results.Activities },
                  { "ColorPerception", user.Results.ColorPerception }
              } }
        };

        collection.InsertOne(document);
        var devices = (user.Results.None.ToInt() << 3) +
                      (user.Results.Smaller5.ToInt() << 2) +
                      (user.Results.Smaller11.ToInt() << 1) +
                      user.Results.Greater11.ToInt();

        document = new BsonDocument
        {
            { "_id", code },
            { "AgeGroup", user.Results.AgeGroup },
            { "ColorPerception", user.Results.ColorPerception },
            { "TouchFrequency", user.Results.TouchFrequency },
            { "Activities", user.Results.Activities },
            { "Devices", devices }
        };
        registeredUsersCollection.InsertOne(document);
        var filter = Builders <BsonDocument> .Filter.Eq("_id", "UserCount");

        var update = Builders <BsonDocument> .Update.Inc("Count", 1);

        resultDb.GetCollection <BsonDocument>("counters").FindOneAndUpdate(filter, update);
    }
Exemple #15
0
        public static ObjectState FindObjectState(string type, string id, double timestamp)
        {
            ObjectState objStateResult = new ObjectState()
            {
                Code = ResultCode.Success
            };
            FilterDefinition <BsonDocument> fc = Builders <BsonDocument> .Filter.And(new FilterDefinition <BsonDocument>[]
            {
                Builders <BsonDocument> .Filter.Eq(Constants.AttribObjectId, id),
                Builders <BsonDocument> .Filter.Lte(Constants.AttribTimestamp, new BsonTimestamp((long)timestamp))
            });

            BsonDocument objState;

            try
            {
                objState = MongoDBConnector.FindOne <BsonDocument>(type, fc);
            }
            catch
            {
                objStateResult.Code = ResultCode.Error;
                return(objStateResult);
            }
            if (objState != null)
            {
                if (type.Equals("Invoice"))
                {
                    //find the latest order record...
                    BsonElement beOrderId = objState.Elements.Where(e => e.Name == "order_id").FirstOrDefault();
                    if (beOrderId != null)
                    {
                        fc = Builders <BsonDocument> .Filter.Eq("ObjectId", beOrderId.Value.ToString());

                        BsonDocument bOrder = MongoDBConnector.FindOne <BsonDocument>("Order", fc);
                        if (bOrder != null)
                        {
                            bOrder.Remove("_id");
                            bOrder.Remove(Constants.AttribTimestamp);
                            bOrder.Remove(Constants.AttribObjectId);
                            objState.Add("OrderDetails", bOrder);
                        }
                    }
                    //find the latest product records...
                    BsonElement beProductIds = objState.Elements.Where(e => e.Name == "product_ids").FirstOrDefault();
                    if (beProductIds != null)
                    {
                        IEnumerable <string> productIds = ((BsonArray)beProductIds.Value).Select(e => e.ToString()).Distinct();

                        BsonDocument filterCriteria = new BsonDocument();
                        filterCriteria.Add("ObjectId", new BsonDocument("$in", new BsonArray(productIds)));


                        IEnumerable <BsonDocument> bProducts = MongoDBConnector.find <BsonDocument>("Product", filterCriteria);
                        if (bProducts != null && bProducts.Count() > 0)
                        {
                            bProducts = bProducts.GroupBy(d => d.GetElement(Constants.AttribObjectId).Value)
                                        .Select(grp => grp.OrderByDescending(d1 => d1.GetElement(Constants.AttribTimestamp)).First());


                            BsonArray baProducts = new BsonArray(bProducts);
                            foreach (BsonDocument bdoc in baProducts)
                            {
                                bdoc.Remove("_id");
                                bdoc.Remove(Constants.AttribTimestamp);
                            }
                            objState.Add(new BsonElement("Products", baProducts));
                        }
                    }
                }

                objState.Remove("_id");
                objState.Remove(Constants.AttribTimestamp);
                objState.Remove(Constants.AttribObjectId);
                objStateResult.state = objState.ToJson().Replace(":", "=>");
            }
            else
            {
                objStateResult.Code = ResultCode.NoRecordFound;
                return(objStateResult);
            }
            return(objStateResult);
        }
Exemple #16
0
 ObjectId CreateAccount(string emailField, string passwordField, string selectedValue)
 {
     MongoDBConnector dbConnector = new MongoDBConnector ();
     var collection = dbConnector.GetCollection<User> ("Users");
     var roles = dbConnector.GetCollection<Role> ("Roles");
     var q = Query.EQ ("type", selectedValue);
     var user = new User {email = emailField, password = passwordField, role = roles.FindOne(q).Id};
     collection.Insert (user);
     collection.Save (user);
     return user.Id;
 }
Exemple #17
0
 public FarmerController(
     MongoDBConnector mongoDBConnector
     )
 {
     this._mongoDBConnector = mongoDBConnector;
 }
Exemple #18
0
 public ValuesController(MongoDBConnector mongoDBConnector)
 {
     _mongoDBConnector = mongoDBConnector;
 }
Exemple #19
0
 public LinearSearchService()
 {
     MongoDBConnector.CreateSession("nliis");
 }
Exemple #20
0
        public override void DictDeserialize(IDictionary <string, object> docu, Scenario scenario = Scenario.Database)
        {
            base.DictDeserialize(docu);
            var doc = docu as FreeDocument;

            if (doc.Children != null)
            {
                var items = doc.Children;

                foreach (var item in items)
                {
                    var proces = new ProcessTask();
                    proces.Project = this;
                    proces.DictDeserialize(item);

                    Tasks.Add(proces);
                }
            }

            if (docu["DBConnections"] != null)
            {
                var items = docu["DBConnections"] as FreeDocument;

                if (items?.Children != null)
                {
                    foreach (var item in items.Children)
                    {
                        var type = item["TypeName"].ToString();
                        var conn = PluginProvider.GetObjectByType <IDataBaseConnector>(type) as DBConnectorBase;
                        if (conn == null)
                        {
                            continue;
                        }
                        conn.DictDeserialize(item);

                        DBConnections.Add(conn);
                    }
                }
            }
            if (DBConnections.FirstOrDefault(d => d.TypeName == "文件管理") == null)
            {
                var filemanager = new FileManager()
                {
                    Name = "最近打开的文件"
                };
                DBConnections.Add(filemanager);
            }
            if (DBConnections.FirstOrDefault(d => d.TypeName == "MongoDB") == null)
            {
                var mongo = new MongoDBConnector()
                {
                    Name = "MongoDB连接器"
                };
                mongo.DBName = "hawk";
                DBConnections.Add(mongo);
            }
            if (DBConnections.FirstOrDefault(d => d.TypeName == "SQLite数据库") == null)
            {
                var sqlite = new SQLiteDatabase()
                {
                    Name = "SQLite数据库"
                };
                sqlite.DBName = "hawk-sqlite";
                DBConnections.Add(sqlite);
            }
        }
Exemple #21
0
        public override void DictDeserialize(IDictionary <string, object> docu, Scenario scenario = Scenario.Database)
        {
            base.DictDeserialize(docu);
            var doc = docu as FreeDocument;

            if (doc.Children != null)
            {
                var items = doc.Children;

                foreach (var item in items)
                {
                    var proces = new ProcessTask();
                    proces.Project = this;
                    proces.DictDeserialize(item);

                    Tasks.Add(proces);
                }
            }

            if (docu["DBConnections"] != null)
            {
                var items = docu["DBConnections"] as FreeDocument;

                if (items?.Children != null)
                {
                    foreach (var item in items.Children)
                    {
                        var type = item["TypeName"].ToString();
                        var conn = PluginProvider.GetObjectByType <IDataBaseConnector>(type) as DBConnectorBase;
                        if (conn == null)
                        {
                            continue;
                        }
                        conn.DictDeserialize(item);

                        DBConnections.Add(conn);
                    }
                }
            }
            if (docu["RunningTasks"] != null)
            {
                var tasks = docu["RunningTasks"] as FreeDocument;


                SavedRunningTasks = tasks?.Children;
            }

            if (docu["Parameters"] != null)
            {
                var tasks = docu["Parameters"] as FreeDocument;

                if (tasks != null)
                {
                    Parameters.AddRange(tasks?.Children?.Select(d =>
                    {
                        var param = new ParameterItem();
                        param.UnsafeDictDeserialize(d);
                        return(param);
                    }));
                }
            }

            ConfigSelector.SelectItem =
                docu["ParameterName"].ToString();

            if (DBConnections.FirstOrDefault(d => d.TypeName == GlobalHelper.Get("FileManager")) == null)
            {
                var filemanager = new FileManager {
                    Name = GlobalHelper.Get("recent_file")
                };
                DBConnections.Add(filemanager);
            }
            if (DBConnections.FirstOrDefault(d => d.TypeName == "MongoDB") == null)
            {
                var mongo = new MongoDBConnector {
                    Name = "MongoDB连接器"
                };
                mongo.DBName = "hawk";
                DBConnections.Add(mongo);
            }
            if (DBConnections.FirstOrDefault(d => d.TypeName == GlobalHelper.Get("SQLiteDatabase")) == null)
            {
                var sqlite = new SQLiteDatabase {
                    Name = GlobalHelper.Get("SQLiteDatabase")
                };
                sqlite.DBName = "hawk-sqlite";
                DBConnections.Add(sqlite);
            }
        }
Exemple #22
0
 public static MongoDBConnector GetInstance()
 {
     return(_instance ?? (_instance = new MongoDBConnector()));
 }