Exemplo n.º 1
0
        public string DeleteObject(string text)
        {
            var dp = new DocumentParser();
            var d  = dp.Parse(text) as Document;

            if (d == null)
            {
                return("No object");
            }
            if (_lastCollectionUsed == null)
            {
                return("No collection");
            }

            using (var db = MDB.GetMongo())
            {
                if (d.Contains("_id") && d["_id"] != null)
                {
                    var selector = new Document();
                    selector["_id"] = d["_id"];
                    db[DataBaseName][_lastCollectionUsed].Delete(selector);
                    return(string.Format("Object with _id: {1} deleted in collection '{0}'", _lastCollectionUsed, d["_id"]));
                }
                return(string.Format("Object contains no id"));
            }
        }
        public void result(string taskid, string pipelineid, int state)
        {
            using (MDB db = new MDB())
            {
                MaratonAPI api  = new MaratonAPI();
                DbTask     task = db.Find <DbTask>(x => x.Id == taskid).FirstOrDefault();
                task.State = state;

                if (task == null)
                {
                    return;
                }

                for (int i = 0; i < task.Pipelines.Count; i++)
                {
                    if (task.Pipelines[i] != pipelineid)
                    {
                        continue;
                    }

                    if (task.Pipelines[i] == pipelineid &&
                        i < (task.Pipelines.Count - 1))
                    {
                        api.TaskDeliver(task, db.FindOne <DbPipeline>(x => x.Id == task.Pipelines[i + 1]));
                    }
                }

                db.UpdateOne <DbTask>(x => x.Id == taskid, task);
            }
        }
Exemplo n.º 3
0
        public ActionResult restart(string id)
        {
            using (MDB db = new MDB())
            {
                var task = db.Find <DbTask>(x => x.Id == id && x.State == 305).FirstOrDefault();
                if (task == null)
                {
                    return(RedirectToAction("index"));
                }

                var pipeline = db.Find <DbPipeline>(x => x.Id == task.Pipelines[0]).FirstOrDefault();

                if (pipeline == null)
                {
                    return(RedirectToAction("index"));
                }

                MaratonAPI api    = new MaratonAPI();
                var        result = api.TaskDeliver(task, pipeline);

                if (result.code == 0)
                {
                    task.ExecuteTime = DateTime.Now;
                    task.State       = 1;
                    db.UpdateOne <DbTask>(x => x.Id == id, task);
                }
                else
                {
                    task.State = 2;
                    db.UpdateOne <DbTask>(x => x.Id == id, task);
                }
            }

            return(RedirectToAction("index"));
        }
        public void ApproveApp(string id)
        {
            if (id == null)
            {
                return;
            }

            if (Session["UserID"] == null || ((List <UserUserType>)Session["UserTypes"]).Where(i => i.UserType.Name == Constants.UserTypes.Admin).Count() == 0)
            {
                return;
            }

            using (IMongo mongo = MDB.Instance().GetMongo())
            {
                var collection = mongo.GetCollection <AppApproval>();

                AppApproval aa = collection.AsQueryable().SingleOrDefault(i => i.PackageID == id);
                if (aa == null)
                {
                    return;
                }

                aa.IsApproved = true;
                collection.Save(aa);
            }
        }
        public JsonResult CheckName(string old, string name)
        {
            if (Session["UserID"] == null)
            {
                return(null);
            }

            if (old == name)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }

            using (IMongo mongo = MDB.Instance().GetMongo())
            {
                var collection = mongo.GetCollection <AdContainer>().AsQueryable();
                var check      = from t in collection
                                 where t.ContainerName == name && t.UserID == new Guid(Session["UserID"].ToString()).ToString()
                                 select t;

                if (check.Count() > 0)
                {
                    return(Json(true, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(false, JsonRequestBehavior.AllowGet));
                }
            }
        }
Exemplo n.º 6
0
        private void RefreshTreeViewMenu()
        {
            var dbs  = MDB.GetDatabases();
            var root = new RootNode("MongoDB", ctxMenuStripRoot);

            foreach (var db in dbs)
            {
                var dbName = db["name"].ToString();
                var dbNode = new DbNode(dbName, ctxMenuStripDb);
                root.Nodes.Add(dbNode);
                var collections = MDB.GetCollections(dbName);
                dbNode.Nodes.AddRange(collections.Where(x => !x["name"].ToString().Contains("$"))
                                      .Select(x => new CollectionNode(x["name"].ToString(), ctxMenuStripCol)).ToArray());

                foreach (CollectionNode node in dbNode.Nodes)
                {
                    //var indexNodes = collections.Where(x => x["name"].ToString().Contains("$") && x["name"].ToString().StartsWith(node.CollectionNamespace));
                    //node.Nodes.AddRange( indexNodes.Select(x => new IndexNode(x["name"].ToString(),ctxMenuStripIndex)).ToArray() );
                    node.Nodes.AddRange(MDB.GetIndexsByNS(dbName, node.CollectionNamespace).Select(x => new IndexNode(x, ctxMenuStripIndex)).ToArray());
                }
            }

            treeViewMenu.BeginUpdate();
            treeViewMenu.Nodes.Clear();
            treeViewMenu.Nodes.Add(root);
            root.Expand();
            treeViewMenu.EndUpdate();
        }
        public ActionResult Delete(string packageid, FormCollection form)
        {
            SetMenuSelection("Apps");

            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            using (IMongo mongo = MDB.Instance().GetMongo())
            {
                ViewData["PID"] = packageid;

                if (form["hdnDelete"] != null)
                {
                    DBContext db   = new DBContext();
                    var       list = db.AppUsers.Where(i => i.PackageID == packageid);

                    db.AppUsers.DeleteAllOnSubmit(list);
                    db.SubmitChanges();
                    return(RedirectToAction("List", "Apps"));
                }

                return(View());
            }
        }
        protected bool CheckAppSecurity(string packageid)
        {
            if (Session["UserID"] == null || packageid == null)
            {
                return(false);
            }

            using (IMongo mongo = MDB.Instance().GetMongo())
            {
                var collection = mongo.GetCollection <MetrixApp>();
                var app        = collection.AsQueryable().SingleOrDefault(i => i.PackageID == packageid);

                if (Session["UserID"] == null || ((List <UserUserType>)Session["UserTypes"]).Where(i => i.UserType.Name == Constants.UserTypes.Admin).Count() > 0)
                {
                    return(true);
                }

                if (app == null || app.UserID.ToString() != Session["UserID"].ToString())
                {
                    return(false);
                }

                return(true);
            }
        }
        public JsonResult upload()
        {
            if (this.Request.Files.Count == 0)
            {
                return(Json(new { code = 1, msg = "no files" }));
            }

            string name     = this.Request.Form[0];
            int    block    = 0;
            int    blockNum = 0;

            int.TryParse(this.Request.Form[1], out block);
            int.TryParse(this.Request.Form[2], out blockNum);

            for (int i = 0; i < this.Request.Files.Count; i++)
            {
                HttpPostedFileBase file = this.Request.Files[i];
                var localPath           = Server.MapPath("/TempFile/" + this.Request.Form[0]);

                var fs = System.IO.File.Open(localPath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);
                fs.Position = fs.Length;
                Int64  size   = fs.Length;
                byte[] buffer = new byte[1024 * 1024];

                while (true)
                {
                    var reads = file.InputStream.Read(buffer, 0, buffer.Length);
                    size += reads;

                    if (reads == 0)
                    {
                        break;
                    }

                    fs.Write(buffer, 0, reads);
                }

                fs.Close();

                if (block == (blockNum - 1))
                {
                    using (MDB mdb = new MDB())
                    {
                        DbAttachment dbAttr = new DbAttachment();
                        dbAttr.Name       = name;
                        dbAttr.Size       = size;
                        dbAttr.Path       = localPath;
                        dbAttr.RemotePath = "/website/" + DateTime.Now.ToString("yyyy_MM_dd") + "/" + DateTime.Now.ToString("HH_mm_ss") + "_" + dbAttr.Name;
                        dbAttr.CreateTime = DateTime.Now;
                        dbAttr.State      = 0;
                        mdb.Insert <DbAttachment>(dbAttr);
                    }
                }
            }

            YHFSUploader.Upload();

            return(Json(new { code = 0, msg = "" }));
        }
Exemplo n.º 10
0
 public ActionResult delete(string id)
 {
     using (MDB db = new MDB())
     {
         db.Delete <Models.DbPipeline>(x => x.Id == id);
         return(RedirectToAction("index"));
     }
 }
Exemplo n.º 11
0
 // GET: Template
 public ActionResult index()
 {
     using (MDB mdb = new MDB())
     {
         var dbt = mdb.Document <DbPipe>().Find(x => true).ToCursor().ToList();
         return(View(dbt));
     }
 }
Exemplo n.º 12
0
 public ActionResult pipelist()
 {
     using (MDB db = new MDB())
     {
         var pps = db.Find <Models.DbPipe>(x => true).ToList();
         return(View(pps));
     }
 }
Exemplo n.º 13
0
 public void ListCollectionViewGetItemAt(object sender, EventArgs e)
 {
     App.Current.Dispatcher.BeginInvoke(new Action(() =>
     {
         this.SelectedTestItem = (MDB)this.TestViewList.GetItemAt(this.TestViewList.Count - 1);
         logger.Info("Worked");
     }), System.Windows.Threading.DispatcherPriority.Background);
 }
Exemplo n.º 14
0
 public ActionResult edit(string id)
 {
     using (MDB mdb = new MDB())
     {
         var dbt = mdb.Document <DbPipe>().Find(x => x.Id == id).ToCursor().FirstOrDefault();
         return(View(dbt));
     }
 }
Exemplo n.º 15
0
 public ActionResult pipelinelist()
 {
     using (MDB db = new MDB())
     {
         var t = db.Find <DbPipeline>(x => true).ToList();
         return(View(t));
     }
 }
 public ActionResult delete(string id)
 {
     using (MDB mdb = new MDB())
     {
         var result = mdb.Delete <Models.DbAttachment>(x => x.Id == id && x.State != 2);
         return(RedirectToAction("index"));
     }
 }
        public ActionResult SaveContainer(string packageid, FormCollection form)
        {
            if (!CheckAppSecurity(packageid))
            {
                return(RedirectToAction("Login", "Home"));
            }

            string oldName = form["hdnOldName"];

            List <AdNetwork> networks = MDB.Instance().GetAdNetworks();

            using (IMongo mongo = MDB.Instance().GetMongo())
            {
                var containers = mongo.GetCollection <AdContainer>();

                List <AdContainer> conList = (from t in containers.AsQueryable()
                                              where t.AppPackageID == packageid && t.ContainerName == oldName
                                              select t).ToList();

                if (conList.Count() == 0) //new container
                {
                    foreach (var item in networks)
                    {
                        AdContainer con = new AdContainer();
                        con.AppPackageID = packageid;
                        con.UserID       = new Guid(Session["UserID"].ToString()).ToString();

                        con.AdNetworkID   = item.ID;
                        con.AdNetworkName = item.Name;

                        conList.Add(con);
                    }
                }

                foreach (var con in conList)
                {
                    con.ContainerName = form["txtName"];
                    con.ContainerSize = form["ddlSize"];

                    AdNetwork network = networks.Where(i => i.ID == con.AdNetworkID).First();

                    string val = form["txtPercent" + network.ID];

                    if (val == string.Empty)
                    {
                        con.ShowPercentage = 0;
                    }
                    else
                    {
                        con.ShowPercentage = int.Parse(val);
                    }

                    containers.Save(con);
                }

                return(RedirectToAction("AdStorm/" + packageid, "Apps"));
            }
        }
        public ActionResult AdStorm()
        {
            SetMenuSelection("AdminAdStorm");

            if (Session["UserID"] == null || ((List <UserUserType>)Session["UserTypes"]).Where(i => i.UserType.Name == Constants.UserTypes.Admin).Count() == 0)
            {
                return(RedirectToAction("Login", "Home"));
            }

            using (IMongo mongo = MDB.Instance().GetMongo())
            {
                var       apps = mongo.GetCollection <MApp>().AsQueryable();
                DBContext db   = new DBContext();

                var collection = mongo.GetCollection <AppApproval>().AsQueryable();
                var query      = from t in collection
                                 where t.IsApproved == false
                                 select t.PackageID;

                List <MApp> unapproved = new List <MApp>();
                if (query != null && query.Count() > 0)
                {
                    foreach (var packageID in query)
                    {
                        MApp a = apps.Where(i => i.PackageID == packageID).FirstOrDefault();
                        if (a != null)
                        {
                            unapproved.Add(a);
                        }
                    }
                }

                ViewData["Unapproved"] = unapproved;

                query = from t in collection
                        where t.IsApproved == true
                        select t.PackageID;

                List <MApp> approved = new List <MApp>();

                if (query != null && query.Count() > 0)
                {
                    foreach (var packageID in query)
                    {
                        MApp a = apps.Where(i => i.PackageID == packageID).FirstOrDefault();
                        if (a != null)
                        {
                            approved.Add(a);
                        }
                    }
                }

                ViewData["Approved"] = approved;

                return(View());
            }
        }
Exemplo n.º 19
0
        public ActionResult delete(string id)
        {
            using (MDB db = new MDB())
            {
                db.Delete <DbTask>(x => x.Id == id);
            }

            return(RedirectToAction("index"));
        }
Exemplo n.º 20
0
        public ActionResult delete(string id)
        {
            using (MDB mdb = new MDB())
            {
                mdb.Document <DbPipe>().DeleteOne(t => t.Id == id);
            }

            return(RedirectToAction("index"));
        }
Exemplo n.º 21
0
        public ActionResult log(string id)
        {
            using (MDB db = new MDB())
            {
                var task = db.Find <DbLog>(x => x.TaskID == id).OrderByDescending(x => x.Increase).ToList();
                return(View(task));
            }

            return(View());
        }
Exemplo n.º 22
0
        public void result(MaratonResult json)
        {
            if (json == null)
            {
                return;
            }

            MaratonAPI api      = new MaratonAPI();
            DbTask     task     = null;
            DbPipeline pipeline = null;

            using (MDB mdb = new MDB())
            {
                task     = mdb.Find <DbTask>(x => x.Id == json.taskid).FirstOrDefault();
                pipeline = mdb.Find <DbPipeline>(x => x.Id == json.pipelineid).FirstOrDefault();

                if (task == null ||
                    pipeline == null)
                {
                    return;
                }

                if (json.status == 303)
                {
                    for (int i = 0; i < task.Pipelines.Count; i++)
                    {
                        if (task.Pipelines[i] != pipeline.Id)
                        {
                            continue;
                        }

                        if (i < (task.Pipelines.Count - 1))
                        {
                            var p = mdb.FindOne <DbPipeline>(x => x.Id == task.Pipelines[i + 1]);
                            task.Inputs = json.data;
                            api.TaskDeliver(task, p);
                            return;
                        }
                        else if (i == (task.Pipelines.Count - 1))
                        {
                            task.State      = json.status;
                            task.Result     = json.data;
                            task.FinishTime = DateTime.Now;
                            task.Duratation = (int)((task.FinishTime - task.ExecuteTime).TotalSeconds);
                            mdb.UpdateOne <DbTask>(x => x.Id == json.taskid, task);
                        }
                    }
                }
                else
                {
                    task.State = json.status;
                    mdb.UpdateOne <DbTask>(x => x.Id == json.taskid, task);
                }
            }
        }
Exemplo n.º 23
0
        private void toolStripMenuItem7_Click(object sender, EventArgs e)
        {
            var node = treeViewMenu.SelectedNode;
            var nif  = new NewItemForm("Create new database", "Database name");

            if (nif.ShowDialog() == DialogResult.OK)
            {
                MDB.CreateDatabase(nif.EnteredValue);
                node.Nodes.Add(new DbNode(nif.EnteredValue, ctxMenuStripDb));
            }
        }
Exemplo n.º 24
0
        private void createToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var node   = treeViewMenu.SelectedNode;
            var dbNode = node as DbNode;
            var nif    = new NewItemForm("Create new collection", "Collection name");

            if (nif.ShowDialog() == DialogResult.OK)
            {
                MDB.CreateCollection(dbNode.DbName, nif.EnteredValue);
                dbNode.Nodes.Add(new CollectionNode(dbNode.DbName + "." + nif.EnteredValue, ctxMenuStripCol));
            }
        }
Exemplo n.º 25
0
        public ActionResult index(int?pageId)
        {
            VMTaskIndex mod = new VMTaskIndex();

            using (MDB db = new MDB())
            {
                mod.CurrentPage = pageId.GetValueOrDefault();
                mod.Tasks       = db.Find <DbTask>(x => true).OrderByDescending(x => x.Increase).Skip(mod.CurrentPage * mod.PageSize).Take(mod.PageSize).ToList();
                mod.TotalCount  = db.Find <DbTask>(x => true).Count;
            }

            return(View(mod));
        }
Exemplo n.º 26
0
        public ActionResult result(string id)
        {
            using (MDB db = new MDB())
            {
                var task = db.FindOne <DbTask>(x => x.Id == id);
                if (task == null)
                {
                    return(View(new DbTask()));
                }

                return(View(task));
            }
        }
Exemplo n.º 27
0
        public ActionResult create(FormCollection form)
        {
            using (MDB mdb = new MDB())
            {
                DbPipe dbt = new DbPipe();
                dbt.Name       = form["Name"];
                dbt.Executor   = form["Executor"];
                dbt.Parameters = form["Parameters"].Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                mdb.Document <DbPipe>().InsertOne(dbt);
            }

            return(RedirectToAction("index"));
        }
Exemplo n.º 28
0
 public ActionResult create(FormCollection form)
 {
     using (MDB db = new MDB())
     {
         Models.DbPipeline line = new Models.DbPipeline();
         line.Name = form["Name"];
         line.PipeIds.AddRange(form["Pipes"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
         line.ServantIds.AddRange(form["Servants"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
         line.IsParallel = form["IsParallel"] != "false";
         db.Insert(line);
         return(RedirectToAction("index"));
     }
 }
Exemplo n.º 29
0
 public ActionResult edit(FormCollection form)
 {
     using (MDB db = new MDB())
     {
         Models.DbPipeline line = new Models.DbPipeline();
         line.Id   = form["Id"];
         line.Name = form["Name"];
         line.PipeIds.AddRange(form["Pipes"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
         line.IsParallel = form["IsParallel"] != "false";
         db.UpdateOne(x => x.Id == line.Id, line);
         return(Redirect("index"));
     }
 }
Exemplo n.º 30
0
 public static async Task StartMDB()
 {
     try
     {
         MDB.MDBDebug    += MDB_MDBDebug;
         MDB.DebugEnabled = true;
         MDB.InitWithSerialPortExact("\\\\?\\FTDIBUS#VID_0403+PID_6001+6&38a36d0c&0&4#0000#{86e0d1e0-8089-11d0-9ce4-08003e301f73}", GlobalCancellationTokenSource.Token);
     }
     catch (Exception ex)
     {
         AddItemToLogBox(ex.Message);
     }
 }