Example #1
0
 public static void Insert(ShoppingCartEntity cart)
 {
     using (MongoDBHelper mongoDb = new MongoDBHelper("Server=127.0.0.1:27017", "ShoppingCart"))
     {
         mongoDb.GetCollection<ShoppingCartEntity>().Insert(cart);
     }
 }
Example #2
0
 public static void Update(ShoppingCartEntity cart)
 {
     using (MongoDBHelper mm = new MongoDBHelper())
     {
         mm.GetCollection<ShoppingCartEntity>().Update(cart, new { CartId = cart.CartId });
     }
 }
Example #3
0
File: Mongodb.cs Project: kangwl/xk
        public bool DeleteUser()
        {
            MongoDBHelper<UserModel> dbHelper = new MongoDBHelper<UserModel>("User");

            Task<bool> a = dbHelper.DbExcute.Delete(u => u.Age > 12);
            return a.Result;
        }
Example #4
0
 public static ShoppingCartEntity GetById(string cartId)
 {
     using (MongoDBHelper mongoDb = new MongoDBHelper("Server=127.0.0.1:27017", "ShoppingCart"))
     {
         var data=mongoDb.GetCollection<ShoppingCartEntity>().FindOne(new { CartId = cartId });
         return data;
     }
 }
Example #5
0
        public string GetByLocationName(string locname)
        {
            var filter = Builders <CarPark> .Filter.Regex("name", new BsonRegularExpression(locname, "i"));

            Task <string> x = MongoDBHelper.FindCollectionByFilterAsync <CarPark>(filter);

            x.Wait();
            return(x.Result);
        }
Example #6
0
        private void DeletePublishItem(PublishItem pitem)
        {
            MongoDBHelper <PublishItem> mongo = new MongoDBHelper <PublishItem>();
            var iDelete = new QueryDocument();

            iDelete.Add("MAC", pitem.MAC);
            iDelete.Add("FileName", pitem.FileName);
            //删除老计划
            mongo.Delete(MSPublishItemCollectionName, iDelete);
        }
 /// <summary>
 /// 插入日志
 /// </summary>
 /// <param name="model">日志模型</param>
 /// <returns></returns>
 public string InsertLog(ZFTLogModel model)
 {
     byte[] by = new byte[Request.InputStream.Length];
     Request.InputStream.Read(by, 0, by.Length);
     string a = System.Text.Encoding.UTF8.GetString(by);
     ZFTLogModel insert = Newtonsoft.Json.JsonConvert.DeserializeObject<ZFTLogModel>(a);
     var Dao = new MongoDBHelper<GeepLogSystem.Models.ZFTLogModel>();
     var result = Dao.InsterOneAsync(insert);
     return null;
 }
Example #8
0
        public ActionResult Content(FormCollection fc)
        {
            var title   = fc["title"];
            var content = fc["editor"];
            var area    = fc["areaName"];

            MongoDBHelper.insterMongoDB(title, area, content);

            return(Redirect("Index"));
        }
        protected async Task AssertMessageDocumentInserted(string collectionName, string database = null)
        {
            var db     = MongoDBHelper.Connect(ConnectionStringSettings, database);
            var coll   = db.GetCollection <BsonDocument>(collectionName);
            var filter = Builders <BsonDocument> .Filter.Eq("headers.Platibus-MessageId", Message.Headers.MessageId.ToString());

            var msg = await coll.Find(filter).FirstOrDefaultAsync();

            Assert.NotNull(msg);
        }
Example #10
0
        private List <PublishItem> ReadPublish(string mac)
        {
            MongoDBHelper <PublishItem> mongo = new MongoDBHelper <PublishItem>();
            QueryDocument query = new QueryDocument();

            query.Add("MAC", mac);
            MongoCursor <PublishItem> mongoCursor = mongo.Query(MSPublishItemCollectionName, query);
            var dataList = mongoCursor.ToList();

            return(dataList);
        }
 /// <summary>
 /// 转账电话(异常)
 /// </summary>
 /// <param name="p">页码</param>
 /// <returns></returns>
 public ActionResult CVEPTError(int p = 1)
 {
     var model = new MongoDBHelper<GeepLogSystem.Models.ZFTLogModel>();
     long count;
     ViewBag.ZFTList = model.FindAllError(LogNameEnum.CVEPT, out count, p);
     ViewBag.Count = count;
     ViewBag.Page = p < 1 ? 1 : p;
     ViewBag.Title = "转账电话(异常)";
     ViewBag.ActiveId = 7;
     return View("Common");
 }
Example #12
0
        private void InsertFile(string mac, CY.IoTM.Common.Item.ADFile file)
        {
            MongoDBHelper <File> mongo = new MongoDBHelper <File>();
            File f = new File()
            {
                MAC = mac, FileName = file.FileName, Length = file.FileLength, State = FileState.Loading, segIndex = 0
            };

            f.TotalSeg = file.FileLength / 1024 + (file.FileLength % 1024 > 0 ? 1 : 0);
            mongo.Insert(FileCollectionName, f);
        }
Example #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLoadMongo_Click(object sender, EventArgs e)
        {
            try {
                var data = MongoDBHelper <Entity.CasePartTemplateInfo> .Select <Entity.CasePartTemplateInfo>(Core.ConnHelper.MongoConn, Core.ConnHelper.MongoName, "CasePartTemplate");

                this.dataGridView1.DataSource = data;
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #14
0
        public void ToDocument(IGraph g, IDocument <Document, Document> document)
        {
            //Generate our JSON String
            String json = VDS.RDF.Writing.StringWriter.Write(g, this._writer);

            //Then convert this to a Document
            Document mongoDoc = document.BeginWrite(false);

            mongoDoc["graph"] = MongoDBHelper.JsonArrayToObjects(json);
            document.EndWrite();
        }
Example #15
0
        /// <summary>
        /// 全文检索功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            var textSearchCommand = new CommandDocument
            {
                { "text", SystemManager.GetCurrentCollection().Name },
                { "search", txtKey.Text }
            };
            CommandResult SearchResult = SystemManager.GetCurrentCollection().Database.RunCommand(textSearchCommand);

            MongoDBHelper.FillDataToTreeView("MapReduce Result", trvResult, SearchResult.Response);
        }
        protected async Task AssertSubscriptionDocumentInserted(string collectionName, string database = null)
        {
            var db     = MongoDBHelper.Connect(ConnectionStringSettings, database);
            var coll   = db.GetCollection <BsonDocument>(collectionName);
            var filter = Builders <BsonDocument> .Filter.Eq("topic", Topic.ToString())
                         & Builders <BsonDocument> .Filter.Eq("subscriber", Subscriber.ToString());

            var msg = await coll.Find(filter).FirstOrDefaultAsync();

            Assert.NotNull(msg);
        }
Example #17
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog savefile = new SaveFileDialog();

            if (savefile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DataFilter NewDataFilter = MongoDBHelper.ConvertQuerySql(txtSql.Text);
                NewDataFilter.SaveFilter(savefile.FileName);
            }
            this.Close();
        }
Example #18
0
        public GetLastActiveCountryOM GetLastActiveCountry(Guid accountId)
        {
            var model = MongoDBHelper.FindSingleIndex <AccountActiveCountry>(item => item.AccountId == accountId);

            return(new GetLastActiveCountryOM()
            {
                CountryId = model?.CountryId ?? -1,
                Country_CN = model?.Country_CN,
                Country_EN = model?.Country_EN,
                IsFirst = model == null
            });
        }
        /// <summary>
        /// 添加成员
        /// </summary>
        /// <param name="businessModuleId">模块ID</param>
        /// <param name="taskId">任务ID</param>
        /// <param name="member">成员</param>
        /// <param name="sc">上下文</param>
        /// <returns></returns>
        public override bool AddMember(string businessModuleId, string taskId, BsonDocument member, IServerContext sc)
        {
            var collection = MongoDBHelper.GetMongoCollectionForNoType(GetTableName(businessModuleId));

            var where = Builders <BsonDocument> .Filter.Eq(BaseField.Id, taskId);

            var set = Builders <BsonDocument> .Update.Push(BaseField.Members, member);

            var result = collection.UpdateOne(where, set);

            return(result.ModifiedCount > 0);
        }
Example #20
0
 /// <summary>
 /// Copy Element
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CopyElementToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MongoDBHelper._ClipElement = trvData.DatatreeView.SelectedNode.Tag;
     if (trvData.DatatreeView.SelectedNode.Parent.Text.EndsWith(MongoDBHelper.Array_Mark))
     {
         MongoDBHelper.CopyValue((BsonValue)trvData.DatatreeView.SelectedNode.Tag);
     }
     else
     {
         MongoDBHelper.CopyElement((BsonElement)trvData.DatatreeView.SelectedNode.Tag);
     }
 }
        public async void Execute()
        {
            var contact      = _message.Contact;
            var phone        = contact.PhoneNumber;
            var telegramName = $"{contact.FirstName} {contact.LastName}";

            var keyboardRemove = BotHelper.GetRemoveKeyboard();

            await MongoDBHelper.SaveContact(_chatId, phone, telegramName);

            await _botClient.SendTextMessageAsync(_chatId, MessageFactory.AskNameMessage, replyMarkup : keyboardRemove);
        }
Example #22
0
 public bool UpdateAndDelMongoDb(T_BG_DisplayPartition displayGuideFile, string mongDbName)
 {
     try
     {
         MongoDBHelper.DelFileByName(mongDbName, displayGuideFile.FileName);
         return(_bgDisplayPartitionRepository.Update(displayGuideFile));
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #23
0
        private void frmGroup_Load(object sender, EventArgs e)
        {
            this.cmbForfinalize.SelectedIndexChanged += new EventHandler(
                (x, y) => { this.txtfinalizeJs.Text = MongoDBHelper.LoadJavascript(cmbForfinalize.Text); }
                );
            cmbForReduce.SelectedIndexChanged += new EventHandler(
                (x, y) => { txtReduceJs.Text = MongoDBHelper.LoadJavascript(cmbForReduce.Text); }
                );
            foreach (var item in SystemManager.GetJsNameList())
            {
                cmbForfinalize.Items.Add(item);
                cmbForReduce.Items.Add(item);
            }

            MongoCollection mongoCol      = SystemManager.GetCurrentCollection();
            List <String>   MongoColumn   = MongoDBHelper.GetCollectionSchame(mongoCol);
            Point           _conditionPos = new Point(50, 20);

            foreach (String item in MongoColumn)
            {
                //动态加载控件
                CheckBox ctrItem = new CheckBox();
                ctrItem.Name     = item;
                ctrItem.Location = _conditionPos;
                ctrItem.Text     = item;
                this.panColumn.Controls.Add(ctrItem);
                //纵向位置的累加
                _conditionPos.Y += ctrItem.Height;
            }
            _conditionPos = new Point(50, 20);
            ctlAddBsonEl firstAddBsonElCtl = new ctlAddBsonEl();

            firstAddBsonElCtl.Location = _conditionPos;
            firstAddBsonElCtl.Name     = "BsonEl" + _conditionCount.ToString();
            BsonElement el = new BsonElement("count", new BsonInt32(0));

            firstAddBsonElCtl.setElement(el);
            panBsonEl.Controls.Add(firstAddBsonElCtl);

            if (!SystemManager.IsUseDefaultLanguage)
            {
                lblReduceFunction.Text   = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Group_Tab_Reduce);
                cmdSaveReduceJs.Text     = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Common_Save);
                lblfinalizeFunction.Text = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Group_Tab_Finalize);
                cmdSavefinalizeJs.Text   = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Common_Save);
                lblSelectGroupField.Text = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Group_Tab_Group_Notes);
                lblAddInitField.Text     = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Group_Tab_InitColumn_Note);
                cmdAddInitField.Text     = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Group_Tab_InitColumn);
                lblResult.Text           = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Group_Tab_Result);
                cmdQuery.Text            = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Group_LoadQuery);
                cmdRun.Text = SystemManager.mStringResource.GetText(MagicMongoDBTool.Module.StringResource.TextType.Common_OK);
            }
        }
        /// <summary>
        /// 将聚合条件放入可视化控件
        /// </summary>
        private void FillAggreationTreeview()
        {
            List <BsonDocument> ConditionList = new List <BsonDocument>();

            foreach (BsonDocument item in _AggrArray)
            {
                ConditionList.Add(item);
            }
            MongoDBHelper.FillDataToTreeView("Aggregation", trvCondition, ConditionList, 0);
            trvCondition.DatatreeView.BeginUpdate();
            trvCondition.DatatreeView.ExpandAll();
            trvCondition.DatatreeView.EndUpdate();
        }
Example #25
0
        /// <summary>
        /// DownLoad File
        /// </summary>
        public void DownloadFileStripButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog downfile    = new SaveFileDialog();
            String         strFileName = lstData.SelectedItems[0].Text;

            //For Winodws,Linux user DirectorySeparatorChar Replace with @"\"
            downfile.FileName = strFileName.Split(System.IO.Path.DirectorySeparatorChar)[strFileName.Split(System.IO.Path.DirectorySeparatorChar).Length - 1];
            if (downfile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                MongoDBHelper.DownloadFile(downfile.FileName, strFileName);
            }
            RefreshGUI();
        }
Example #26
0
        public string GetByLatLong(Double lat, Double lng)
        {
            List <CarPark> location = MongoDBHelper.GetCollection <CarPark>()
                                      .FindAllAs <CarPark>().Where <CarPark>(sb => sb.name.ToLower().Contains("mahape")).ToList <CarPark>();
            // .Where<CarPark>(sb => sb.loc.coordinates[0] == lat && sb.loc.coordinates[1] == lng).ToList<CarPark>();
            var json = JsonConvert.SerializeObject(location);

            return(json);

            //var coord = new GeoCoordinate(lat, lng);
            //var nearest = MongoDBHelper.GetCollection<CarPark>().FindAll().Select(x => new GeoCoordinate(x.loc.coordinates[0], x.loc.coordinates[1]))
            //.OrderBy(x => x.GetDistanceTo(coord));
        }
Example #27
0
 public void testSaveData()
 {
     using (var mongo = new MongoDBHelper <MyDataInfo>()) {
         for (int i = 0; i < 10000; i++)
         {
             mongo.Save(new MyDataInfo()
             {
                 ID = 1, Name = "我的测试"
             });
         }
     }
     //Console.WriteLine("测试成功!");
 }
Example #28
0
        /// <summary>
        /// 运行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdRun_Click(object sender, EventArgs e)
        {
            BsonJavaScript map    = new BsonJavaScript(ctlMapFunction.Context);
            BsonJavaScript reduce = new BsonJavaScript(ctlReduceFunction.Context);
            //TODO:这里可能会超时,失去响应
            //需要设置SocketTimeOut
            MapReduceResult mMapReduceResult = _mongocol.MapReduce(map, reduce);

            MongoDBHelper.FillDataToTreeView("MapReduce Result", trvResult, mMapReduceResult.Response);
            trvResult.DatatreeView.BeginUpdate();
            trvResult.DatatreeView.ExpandAll();
            trvResult.DatatreeView.EndUpdate();
        }
Example #29
0
        /// <summary>
        /// 获取某一个语言的页数
        /// </summary>
        /// <param name="cultureID"></param>
        /// <returns></returns>
        private static int Select(int cultureID)
        {
            IMongoQuery query = Query <MongoDBSpuItemModel> .EQ(item => item.CultureID, cultureID);

            long recordCount = MongoDBHelper.Count <MongoDBSpuItemModel>(query);
            int  pageCount   = TypeParseHelper.StrToInt32(recordCount / PAGE_SIZE);

            if (recordCount % PAGE_SIZE != 0)
            {
                pageCount += 1;
            }
            return(pageCount);
        }
        public void Init(Action callback)
        {
            MongoCursor <BsonDocument> list = MongoDBHelper.Search(collectionName);

            if (list != null)
            {
                foreach (BsonDocument doc in list)
                {
                    this.classTypeList.Add(new ClassType(doc));
                }
            }
            callback();
        }
        /// <summary>
        /// 删除成员
        /// </summary>
        /// <param name="businessModuleId"></param>
        /// <param name="taskId"></param>
        /// <param name="users"></param>
        /// <param name="sc"></param>
        /// <returns></returns>
        public override bool RemoveMembers(string businessModuleId, string taskId, Dictionary <string, string> users, IServerContext sc)
        {
            var collection = MongoDBHelper.GetMongoCollectionForNoType(GetTableName(businessModuleId));

            var where = Builders <BsonDocument> .Filter.Eq(BaseField.Id, taskId);

            BsonDocument pushData = new BsonDocument();
            var          remove   = Builders <BsonDocument> .Update.PullFilter(BaseField.Members, Builders <BsonDocument> .Filter.And(Builders <BsonDocument> .Filter.In(BaseMemberField.UserId, users.Keys), Builders <BsonDocument> .Filter.In(BaseMemberField.OrganizationId, users.Values)));

            var result = collection.UpdateOne(where, remove);

            return(result.ModifiedCount > 0);
        }
Example #32
0
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            string taskID = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();

            MongoDBHelper <CY.IoTM.Common.Business.Command> mongo = new MongoDBHelper <CY.IoTM.Common.Business.Command>();
            QueryDocument query = new QueryDocument();

            query.Add("TaskID", taskID);

            var list = mongo.Query("Command", query);

            this.bindingSource2.DataSource = list;
        }
Example #33
0
        public ActionResult ShowImage(int type, string picid)
        {
            try
            {
                if (type > MongoDbNameArray.Length)
                {
                    return(Json(new JsonBaseEntity {
                        ErrorCode = "10000", ErrorMessage = "上传参数错误!"
                    }));
                }
                string mongodbName = MongoDbNameArray[type];
                if (string.IsNullOrEmpty(mongodbName))
                {
                    return(Json(new JsonBaseEntity {
                        ErrorCode = "10000", ErrorMessage = "上传参数错误!"
                    }));
                }

                if (!string.IsNullOrWhiteSpace(picid) && Regex.IsMatch(picid, @"[\w\W]+.[jpeg|gif|jpg|png|bmp|pic]", RegexOptions.IgnoreCase) && picid.Length > 32 && MongoDBHelper.ExistsFile(mongodbName, picid))
                {
                    try
                    {
                        byte[] filebytearray = MongoDBHelper.GetFileByteArrayByName(mongodbName, picid);
                        //return File(filebytearray, ContentTypeHelper.GetValue(Path.GetExtension(picid)), picid);//下载图片
                        return(File(filebytearray, ContentTypeHelper.GetValue(Path.GetExtension(picid))));
                    }
                    catch (Exception ex)
                    {
                        logger.ErrorFormat("function:{0},location:{1},params:id={2},Message={3},StackTrace={4},Source={5}", "GET", "MongoDBLegacyHelper.GetFileByteArrayByName", picid, ex.Message, ex.StackTrace, ex.Source);
                        return(new EmptyResult());
                    }
                }
                else
                {
                    string filename = string.IsNullOrEmpty(picid) ? "beijing1.jpg" : picid;
                    if (filename.Length > 32)
                    {
                        filename = "beijing1.jpg";
                    }
                    return(JavaScript("windows.loaction.href='" + string.Format("{0}/images/personalhomepage/big/{1}", CommonHelper.GetConfigValue("SourceAction"), filename) + "'"));
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("function:{0},location:{1},params:id={2},Message={3},StackTrace={4},Source={5}", "ShowImage", "MongoDBLegacyHelper.ExistsFile", picid, ex.Message, ex.StackTrace, ex.Source);
                return(new EmptyResult());
            }
            finally
            {
            }
        }
Example #34
0
        /// <summary>
        /// 连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdConnect_Click(object sender, EventArgs e)
        {
            List <ConfigHelper.MongoConnectionConfig> connLst = new List <ConfigHelper.MongoConnectionConfig>();

            if (lstServerce.SelectedItems.Count > 0)
            {
                foreach (String item in lstServerce.SelectedItems)
                {
                    connLst.Add(SystemManager.ConfigHelperInstance.ConnectionList[item.Split("@".ToCharArray())[0]]);
                }
                MongoDBHelper.AddServer(connLst);
            }
            this.Close();
        }
Example #35
0
 private void ctlMatchItem_Load(object sender, EventArgs e)
 {
     foreach (string item in MongoDBHelper.getComparisonfunction())
     {
         this.cmbComparisonfunction.Items.Add(item);
     }
     if (SystemManager.GetCurrentCollection() != null)
     {
         foreach (var item in MongoDBHelper.GetCollectionSchame(SystemManager.GetCurrentCollection()))
         {
             cmbField.Items.Add(item);
         }
     }
 }
Example #36
0
 private void JsEditor_Load(object sender, EventArgs e)
 {
     if (JsName != null && JsName != String.Empty)
     {
         txtJavaScript.Text = MongoDBHelper.LoadJavascript(JsName);
         txtJavaScript.Select(0, 0);
     }
     this.txtJavaScript.GotFocus += new EventHandler(
         (x, y) =>
     {
         SystemManager.SelectObjectTag = strDBtag;
     }
         );
 }
Example #37
0
 /// <summary>
 /// 获取访问日志列表
 /// </summary>
 /// <param name="GalleryID"></param>
 /// <returns></returns>
 public Pager<AccessLog> GetArtistListByGalleryID(AccessLogQuery query)
 {
     Pager<AccessLog> accessLogList = null;
     using (MongoDBHelper mongoHelper = new MongoDBHelper(null, true))
     {
         accessLogList = mongoHelper.GetAll<AccessLog>(EnumMongoDBTable.AccessLog.ToString(),
             null, query.PageSize, query.CurrentPage, SortBy.Ascending("LogDateTime"), null);
         if (accessLogList == null)
         {
             accessLogList = new Pager<AccessLog>();
         }
     }
     return accessLogList;
 }
Example #38
0
 /// <summary>
 /// 记录访问日志
 /// </summary>
 /// <param name="logEntity"></param>
 public void AddAccessLog(AccessLog logEntity)
 {
     try
     {
         using (MongoDBHelper mongoHelper = new MongoDBHelper(null,true))
         {
             mongoHelper.InsertOne<AccessLog>(EnumMongoDBTable.AccessLog.ToString(), logEntity);
         }
     }
     catch (Exception ex)
     {
         LogProvider.Instance.Error("添加访问记录出现异常:" + ex.Message);
         throw ex;
     }
 }
 /// <summary>
 /// 插入单条日志
 /// </summary>
 /// <param name="model">ZFTLogModel模型类</param>
 public string PostInsert(GeepLogSystem.Models.ZFTLogModel model)
 {
     if (model == null)
     {
         return "null";
     }
     //byte[] by = new byte[Request.InputStream.Length];
     //Request.InputStream.Read(by, 0, by.Length);
     //string a = System.Text.Encoding.Default.GetString(by);
     //byte[] by = Request.Content.ReadAsByteArrayAsync().Result;
     //string a = Request.Content.ReadAsStringAsync().Result;
     byte[] byts = new byte[System.Web.HttpContext.Current.Request.InputStream.Length];
     System.Web.HttpContext.Current.Request.InputStream.Read(byts, 0, byts.Length);
     string req = System.Text.Encoding.Default.GetString(byts);
     model.Ip = GetIp();
     model.Time = DateTime.Now;
     var Dao = new MongoDBHelper<GeepLogSystem.Models.ZFTLogModel>();
     //var result = Dao.InsterOneAsync(model);
     return "ok";
 }
 /// <summary>
 /// 协议组件(异常)
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public ActionResult ProtocolComponentError(int p = 1)
 {
     var model = new MongoDBHelper<GeepLogSystem.Models.ZFTLogModel>();
     long count;
     ViewBag.ZFTList = model.FindAllError(LogNameEnum.ProtocolComponent, out count, p);
     ViewBag.Count = count;
     ViewBag.Page = p < 1 ? 1 : p;
     ViewBag.Title = "协议组件(异常)";
     ViewBag.ActiveId = 9;
     return View("Common");
 }
Example #41
0
File: Program.cs Project: kangwl/xk
        private static void Main(string[] args) {
            //TestM testM = new TestM();
            //Console.WriteLine(testM.GetResult("3"));
            //Console.WriteLine(testM.GetResultBridge("3"));
            //Console.WriteLine("end");
            //Console.Read();

            //       string xmlSend = @"<xml>
            //                  <ToUserName><![CDATA[123]]></ToUserName>
            //                  <FromUserName><![CDATA[2]]></FromUserName>
            //                  <CreateTime>123</CreateTime>
            //                  <MsgType><![CDATA[text]]></MsgType>
            //                  <Content><![CDATA[333]]></Content>
            //                  </xml>";
            //  XmlDocument xmldoc = new XmlDocument();
            //  xmldoc.LoadXml(xmlSend);
            //  string a = XK.Common.XmlHelper.GetXmlNodeTextByXpath(xmldoc, "//ToUserName");
            //  Console.WriteLine(a);
            //  Console.WriteLine("end");
            //  Console.Read();

            //XK.Common.web.HttpWebHelper webHelper = new HttpWebHelper("http://sd");
            //string res = webHelper.GetResponseStr();
            //int firstIndex = res.IndexOf('{');
            //string s = res.Substring(firstIndex).TrimEnd(')');

            //JObject jo = (JObject)JsonConvert.DeserializeObject(s);
            //string zone = jo["items"]["7"].ToString();
            //Newtonsoft.Json.JsonReader reader=new JTokenReader();

            //List<XK.Common.help.Where> wheres = new List<Where> {
            //    new Where("1", "=", "1")
            //};
            //DataTable dt = XK.Bll.User_Bll.GetDataTable(wheres, 100);
            //Console.WriteLine(dt.Rows.Count);

            //List<XK.Common.help.WhereItem> wheres = new List<WhereItem> {
            //    new WhereItem("ID", "=", "6")
            //};
            //Dictionary<string, dynamic> dic = new Dictionary<string, dynamic>();
            //dic.Add("Name", "kwl110");
            //bool success = XK.Bll.User_Bll.Update(wheres, dic);
            //Console.WriteLine(success);
            //List<WhereItem> whereItems=new List<WhereItem> {
            //    new WhereItem("ID","=","6")
            //};
            //bool success = XK.Bll.User_Bll.Delete(whereItems);
            //Console.WriteLine(success);

            //XK.Model.User_Model userModel = XK.Bll.User_Bll.GetModel(5);
            //Console.WriteLine(userModel.Name);

            //List<XK.Common.help.WhereItem> whereItems = new List<WhereItem>();
            //whereItems.Add(new WhereItem("ID", "<=", 10));
            //List<XK.Model.User_Model> userModels;
            //userModels = XK.Bll.User_Bll.GetModels(whereItems, 1, 3, "ID ASC");
            //userModels.ForEach(u => Console.WriteLine(u.Name));
            //XK.Model.User_Model user = XK.Bll.User_Bll.GetModel(5);
            //Console.WriteLine(user.UserPassword);

            //List<XK.Model.User_Model> userModels = new List<User_Model>() {
            //    new User_Model(){AddDateTime = DateTime.Now,Age = 12,Email = "*****@*****.**",MobilePhone = "1223334",Name = "k5",Sex = 1,UpdateDateTime = DateTime.Now,UserID = "kwl2011",UserPassword = "******",UserType = 2},
            //    new User_Model(){AddDateTime = DateTime.Now,Age = 13,Email = "*****@*****.**",MobilePhone = "122356",Name = "k4",Sex = 1,UpdateDateTime = DateTime.Now,UserID = "kwl2012",UserPassword = "******",UserType = 2},
            //    new User_Model(){AddDateTime = DateTime.Now,Age = 16,Email = "*****@*****.**",MobilePhone = "122321",Name = "k3",Sex = 2,UpdateDateTime = DateTime.Now,UserID = "kwl2013",UserPassword = "******",UserType = 2},
            //    new User_Model(){AddDateTime = DateTime.Now,Age = 12,Email = "*****@*****.**",MobilePhone = "122677",Name = "k2",Sex = 1,UpdateDateTime = DateTime.Now,UserID = "kwl2014",UserPassword = "******",UserType = 2}
            //};

            //int retIndex = XK.Bll.User_Bll.InsertTran(userModels);
            //Console.WriteLine(retIndex);
           // XK.Dal.Mongo.Query query = new Query();
           // bool success = query.InsertUserModel();
           // Console.WriteLine(success);
           //XK.Model.User_Model user= query.TestMongoDB();
           // Console.WriteLine(user.Name);
            //XK.Model.User_Model user = query.GetUer();
            //if (user == null) {
            //    Console.WriteLine("user not exist");
            //    Console.Read();
            //    return;
            //}
            //Console.WriteLine(user.Name);
            //Console.WriteLine("edb");

            MongoDBHelper<XK.Model.User_Model> dbHelper=new MongoDBHelper<User_Model>("User");
            //User_Model user = new User_Model() {
            //    _id =Guid.NewGuid(),
            //    AddDateTime = DateTime.Now,
            //    Age = 12,
            //    Email = "*****@*****.**",
            //    MobilePhone = "1223334",
            //    Name = "k1199",
            //    Sex = 1,
            //    UpdateDateTime = DateTime.Now,
            //    UserID = "kwl2011",
            //    UserPassword = "******",
            //    UserType = 2
            //};
            //Task t = dbHelper.DbExcute.Add(user);
            //Console.WriteLine(t.IsCompleted);
            //t.Wait();
            //Console.WriteLine(t.IsCompleted);

            //Task<User_Model> usertTask = dbHelper.DbExcute.Get(U => U.Name == "k555");
            //usertTask.Wait();
            //Console.WriteLine(usertTask.Result.Name);
            //list
            //Task<List<User_Model>> userModelsTask = dbHelper.DbExcute.GetList(u => u.Age < 220);
            //userModelsTask.Result.ForEach(u => Console.WriteLine(u.Name));

           // dbHelper.DbExcute.GetListAction(u => u.Age < 222, (userm) => Console.WriteLine(userm.Name));

            //Task<List<User_Model>> userModelsTask = dbHelper.DbExcute.GetPaged(u => u.Age < 222, 2, 2, m => m.Name, false);
            //userModelsTask.Result.ForEach(u => Console.WriteLine(u.Name));

            //Task<User_Model> user1 = dbHelper.DbExcute.Get(u => u.Name == "k1199");
            //user1.Wait();

            //Console.WriteLine(user1.Result == null ? "" : user1.Result.Name);

            //List<User_Model> users=new List<User_Model>();
            //users.Add(user);
            //bool success = dbHelper.DbExcute.Update(u => u.Name == "k77711", users);
            //Console.WriteLine(success);

            //Console.WriteLine("main thread start");
            //Task<string> task = GetName();
           
            //Console.WriteLine("main thread do some");
            //Console.WriteLine("name thread start");

            //Console.WriteLine(task.Result);

            //Console.WriteLine("end");

            List<string> ips = ServerIPS.HongKongList();
            Dictionary<string, long> dicIP = new Dictionary<string, long>();

            ips.ForEach(ip => {
                long millsecond = XK.Common.NetHelper.PingTime(ip, 1000*5);
                dicIP.Add(ip, millsecond);
            });

            //找出最快的
            var dicIPSort = dicIP.OrderBy(pair => pair.Value);
            dicIPSort.ToList().ForEach(pair => Console.WriteLine(pair.Key + "---" + pair.Value));

         

            Console.WriteLine("red");
            Console.Read();
        }
        public string inserttest(int num)
        {
            var Dao = new MongoDBHelper<GeepLogSystem.Models.ZFTLogModel>();

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            for (int i = 1; i <= num; i++)
            {
                var model = new ZFTLogModel();
                model.IsErrorLog = false;
                model.LogName = LogNameEnum.ZFT;
                model.AccNo = i.ToString();
                model.Time = DateTime.Now;
                var result = Dao.InsterOneAsync(model);
            }
            watch.Stop();
            return watch.Elapsed.ToStr();
        }