Exemplo n.º 1
0
 /// <summary>
 ///     初始化
 /// </summary>
 /// <param name="value"></param>
 public BsonValueEx(BsonValue value)
 {
     if (value.IsString)
     {
         MBsonType = "BsonString";
         MBsonString = value.ToString();
     }
     if (value.IsInt32)
     {
         MBsonType = "BsonInt32";
         MBsonInt32 = value.AsInt32;
     }
     if (value.IsValidDateTime)
     {
         MBsonType = "BsonDateTime";
         MBsonDateTime = value.ToUniversalTime();
     }
     if (value.IsBoolean)
     {
         MBsonType = "BsonBoolean";
         MBsonBoolean = value.AsBoolean;
     }
     if (value.IsDouble)
     {
         MBsonType = "BsonDouble";
         MBsonDouble = value.AsDouble;
     }
 }
Exemplo n.º 2
0
 public string GetValue(BsonValue value)
 {
     if (value.IsBsonNull)
         return "null";
     else
         return value.ToString();
 }
        public OplogNamespace(BsonValue bsonValue)
        {
            if(bsonValue == null)
            {
                throw new MongoRiverException("Namespace not defined on document.");
            }

            BuildParts(bsonValue.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        ///     初始化
        /// </summary>
        /// <param name="value"></param>
        public BsonValueEx(BsonValue value)
        {
            if (value.IsString)
            {
                mBsonType = BasicType.BsonString;
                mBsonString = value.ToString();
            }

            if (value.IsInt32)
            {
                mBsonType = BasicType.BsonInt32;
                mBsonInt32 = value.AsInt32;
            }
            if (value.IsInt64)
            {
                mBsonType = BasicType.BsonInt64;
                mBsonInt64 = value.AsInt64;
            }

            if (value.IsDecimal128)
            {
                mBsonType = BasicType.BsonDecimal128;
                mBSonDecimal128 = value.AsDecimal;
            }
            if (value.IsDouble)
            {
                mBsonType = BasicType.BsonDouble;
                mBsonDouble = value.AsDouble;
            }

            if (value.IsValidDateTime)
            {
                mBsonType = BasicType.BsonDateTime;
                mBsonDateTime = value.ToUniversalTime();
            }
            if (value.IsBoolean)
            {
                mBsonType = BasicType.BsonBoolean;
                mBsonBoolean = value.AsBoolean;
            }

            if (value.IsBsonMaxKey)
            {
                mBsonType = BasicType.BsonMaxKey;
            }
            if (value.IsBsonMinKey)
            {
                mBsonType = BasicType.BsonMinKey;
            }

            if (value.IsBsonBinaryData)
            {
                mBsonType = BasicType.BsonBinary;
                mBsonBinary = value.AsBsonBinaryData.Bytes;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="value"></param>
 public BsonValueEx(BsonValue value)
 {
     if (value.IsString)
     {
         mBsonType = "BsonString";
         mBsonString = value.ToString();
     }
     if (value.IsInt32)
     {
         mBsonType = "BsonInt32";
         mBsonInt32 = value.AsInt32;
     }
     if (value.IsDateTime)
     {
         mBsonType = "BsonDateTime";
         mBsonDateTime = value.AsDateTime;
     }
     if (value.IsBoolean)
     {
         mBsonType = "BsonBoolean";
         mBsonBoolean = value.AsBoolean;
     }
 }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Please give the database server address <IP:Port>");
                Environment.Exit(0);
            }

            // The database server address
            string sdbIP = args[0];
            // The collection space name
            string csName = "SAMPLE";
            // The collection name
            string cName = "employee";

            BsonDocument insertor1 = CreateEnglisthRecord();
            BsonDocument insertor2 = CreateChineseRecord();

            Sequoiadb sdb = new Sequoiadb(sdbIP);

            Common.Connect(sdb);
            CollectionSpace cs  = Common.GetCollecitonSpace(sdb, csName);
            DBCollection    dbc = Common.GetColleciton(cs, cName);

            try
            {
                BsonValue id = dbc.Insert(insertor1);
                Console.WriteLine("Successfully inserted english records, object ID = {0}", id.ToString());
            }
            catch (BaseException e)
            {
                Console.WriteLine("Failed to insert english record, ErrorType = {0}", e.ErrorType);
                Environment.Exit(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }

            try
            {
                BsonValue id = dbc.Insert(insertor2);
                Console.WriteLine("Successfully inserted chinese records, object ID = {0}", id.ToString());
            }
            catch (BaseException e)
            {
                Console.WriteLine("Failed to insert chinese record, ErrorType = {0}", e.ErrorType);
                Environment.Exit(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(0);
            }

            Common.Disconnect(sdb);
        }
 /// <summary>
 /// 处理id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 private BsonValue HandleID(BsonValue id)
 {
     return(id.IsObjectId ? id.ToString() : id);
 }
Exemplo n.º 8
0
 private static void AssertToString(string expectedToString, BsonValue bsonValue)
 {
     Assert.Equal(expectedToString, bsonValue.ToString());
 }
Exemplo n.º 9
0
 /// <summary>
 /// Verify that the property contains the string value.
 /// </summary>
 /// <param name="value">Value to replace with.</param>
 /// <param name="value">Value to replace with.</param>
 /// <param name="caseSensitive">Matching is case sensitive.</param>
 /// <param name="diacriticSensitive">Matching is diacritic sensitive.</param>
 /// <returns></returns>
 public static BsonElement Contains(string propertyName, BsonValue value, bool caseSensitive = false, bool diacriticSensitive = false) => new BsonElement(propertyName, new BsonRegularExpression($"{(!diacriticSensitive ? Tools.GetDiacriticInsensitiveRegex(value.ToString()) : value)}", !caseSensitive ? "i" : string.Empty));
Exemplo n.º 10
0
        private static object ConvertRawValue(BsonValue bsonValue)
        {
            if (bsonValue == null)
                return null;

            if (BsonTypeMapper.MapToDotNetValue(bsonValue) != null)
            {
                if (bsonValue.IsObjectId)
                {
                    return bsonValue.ToString();
                }
                else if (bsonValue.IsGuid)
                {
                    return bsonValue.AsGuid;
                }
                else
                {
                    switch (bsonValue.BsonType)
                    {
                        case BsonType.DateTime:
                            return UnixEpoch + TimeSpan.FromMilliseconds(bsonValue.AsBsonDateTime.MillisecondsSinceEpoch);
                        default:
                            return BsonTypeMapper.MapToDotNetValue(bsonValue);
                    }
                }
            }
            else
            {
                switch (bsonValue.BsonType)
                {
                    case BsonType.Binary:
                        return bsonValue.AsBsonBinaryData.Bytes;
                    default:
                        return BsonTypeMapper.MapToDotNetValue(bsonValue);
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// BsonValue转展示用字符
 /// </summary>
 /// <param name="val"></param>
 /// <returns></returns>
 public static string ConvertForShow(BsonValue val)
 {
     string strVal;
     if (val.IsBsonBinaryData)
     {
         _hasBSonBinary = true;
         return "[二进制数据]";
     }
     if (val.IsBsonNull)
     {
         return "[空值]";
     }
     if (val.IsBsonDocument)
     {
         strVal = val.ToString() + "[包含" + val.ToBsonDocument().ElementCount + "个元素的文档]";
     }
     else
     {
         strVal = val.ToString();
     }
     return strVal;
 }
Exemplo n.º 12
0
        public static string RunCommand(string conn, string command)
        {
            //List<BsonDocument> results = new List<BsonDocument>();
            BsonValue bv = new BsonValue();
            string retval_bvv = string.Empty; // bv.ToString();
            try
            {
                using (var db = new LiteDatabase(conn))
                {
                    Console.WriteLine( bv.ToString());
                    //BsonValue bv = db.RunCommand("db.customer.insert { Name: \"John Doe\" }");
                    //BsonValue bv = db.RunCommand("db.f**k.find  glossary.GlossDiv.GlossList.GlossEntry.ID like \"SGML\"");
                    //BsonValue bv = db.RunCommand(@"db.f**k.bulk C:\FxM\Dev\vs12\LiteDB\LiteDB-master\LiteDB.Shell\bin\Debug\test.dmp");
                    //BsonValue bv = db.RunCommand(@"db.f**k.bulk ..\..\..\..\test.dmp");

                    bv = db.RunCommand(command);

                    //JObject json22 = bv.// JObject.Parse(bv.ToString);

                    retval_bvv = bv.ToString();
                    //var json = LiteDB.JsonSerializer.Serialize(bv);
                    //Console.WriteLine(json.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("wtf: " + ex.Message);
                retval_bvv = ex.Message;
            }

            return retval_bvv;
        }
Exemplo n.º 13
0
 /// <summary>
 /// 使用属性会发生一些MONO上的移植问题
 /// </summary>
 /// <returns></returns>
 public void setValue(BsonValue value)
 {
     txtBsonValue.Visible = false;
     txtBsonValue.Text = String.Empty;
     txtBsonValue.ReadOnly = false;
     radTrue.Visible = false;
     radFalse.Visible = false;
     radFalse.Checked = true;
     dateTimePicker.Visible = false;
     NumberPick.Visible = false;
     if (value.IsString)
     {
         cmbDataType.SelectedIndex = 0;
         txtBsonValue.Visible = true;
         txtBsonValue.Text = value.ToString();
     }
     if (value.IsInt32)
     {
         cmbDataType.SelectedIndex = 1;
         NumberPick.Visible = true;
         NumberPick.Value = value.AsInt32;
     }
     if (value.IsValidDateTime)
     {
         dateTimePicker.Visible = true;
         dateTimePicker.Value = value.ToUniversalTime();
         cmbDataType.SelectedIndex = 2;
     }
     if (value.IsBoolean)
     {
         radTrue.Visible = true;
         radFalse.Visible = true;
         if (value.AsBoolean)
         {
             radTrue.Checked = true;
         }
         else
         {
             radFalse.Checked = true;
         }
         cmbDataType.SelectedIndex = 3;
     }
     if (value.IsBsonArray)
     {
         frmArrayCreator frmInsertArray = new frmArrayCreator();
         SystemManager.OpenForm(frmInsertArray, false, true);
         if (frmInsertArray.mBsonArray != null)
         {
             mBsonArray = frmInsertArray.mBsonArray;
             txtBsonValue.Visible = true;
             txtBsonValue.Text = mBsonArray.ToString();
             txtBsonValue.ReadOnly = true;
             cmbDataType.SelectedIndex = 4;
         }
     }
     if (value.IsBsonDocument)
     {
         frmNewDocument frmInsertDoc = new frmNewDocument();
         SystemManager.OpenForm(frmInsertDoc, false, true);
         if (frmInsertDoc.mBsonDocument != null)
         {
             mBsonDocument = frmInsertDoc.mBsonDocument;
             txtBsonValue.Visible = true;
             txtBsonValue.Text = mBsonDocument.ToString();
             txtBsonValue.ReadOnly = true;
             cmbDataType.SelectedIndex = 5;
         }
     }
 }
Exemplo n.º 14
0
        /// <summary>
        ///     AddTagRange
        /// </summary>
        /// <param name="routeSvr">路由服务器</param>
        /// <param name="nameSpace">名字空间</param>
        /// <param name="min">最小值</param>
        /// <param name="max">最大值</param>
        /// <param name="tag">标签</param>
        /// <returns></returns>
        public static CommandResult AddTagRange(MongoServer routeSvr, string nameSpace, BsonValue min, BsonValue max,
            string tag)
        {
            //mongos> sh.addTagRange
            //function (ns, min, max, tag) {
            //    var config = db.getSisterDB("config");
            //    config.tags.update(
            //                       {_id:{ns:ns, min:min}},
            //                       {
            //                             _id:{ns:ns, min:min},
            //                             ns:ns,
            //                             min:min,
            //                             max:max, 
            //                             tag:tag
            //                       }, 
            //                       true
            //                       );
            //    sh._checkLastError(config);
            //}
            var maxValue = string.Empty;
            var minValue = string.Empty;
            if (min.IsString)
            {
                minValue = "'" + min + "'";
            }
            if (max.IsString)
            {
                maxValue = "'" + max + "'";
            }

            if (min.IsNumeric)
            {
                minValue = min.ToString();
            }
            if (max.IsNumeric)
            {
                maxValue = max.ToString();
            }
            return ExecuteJsShell(
                "sh.addTagRange('" + nameSpace + "'," + minValue + "," + maxValue + ",'" + tag + "')", routeSvr);
        }
        /// <summary>
        /// AddTagRange
        /// </summary>
        /// <param name="routeSvr">路由服务器</param>
        /// <param name="NameSpace">名字空间</param>
        /// <param name="Min">最小值</param>
        /// <param name="Max">最大值</param>
        /// <param name="Tag">标签</param>
        /// <returns></returns>
        public static CommandResult AddTagRange(MongoServer routeSvr, String NameSpace, BsonValue Min, BsonValue Max, String Tag)
        {
            //mongos> sh.addTagRange
            //function (ns, min, max, tag) {
            //    var config = db.getSisterDB("config");
            //    config.tags.update(
            //                       {_id:{ns:ns, min:min}},
            //                       {
            //                             _id:{ns:ns, min:min},
            //                             ns:ns,
            //                             min:min,
            //                             max:max,
            //                             tag:tag
            //                       },
            //                       true
            //                       );
            //    sh._checkLastError(config);
            //}
            CommandDocument mongoCmd = new CommandDocument();
            String MaxValue = String.Empty;
            String MinValue = String.Empty;
            if (Min.IsString)
            {
                MinValue = "'" + Min.ToString() + "'";
            }
            if (Max.IsString)
            {
                MaxValue = "'" + Max.ToString() + "'";
            }

            if (Min.IsNumeric)
            {
                MinValue = Min.ToString();
            }
            if (Max.IsNumeric)
            {
                MaxValue = Max.ToString();
            }
            return ExecuteJsShell("sh.addTagRange('" + NameSpace + "'," + MinValue + "," + MaxValue + ",'" + Tag + "')", routeSvr);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Converts BSON to CLR value 1:1, without type change
        /// </summary>
        protected virtual object DirectConvertBSONValue(BsonValue value, Func<BsonDocument, BsonElement, bool> filter = null)
        {
          if (value==null || value is BsonNull) return null;
          
          if (value is BsonDocument) return BSONDocumentToJSONMap((BsonDocument)value, filter);
         
          if (value is BsonArray) 
          {
            var arr = (BsonArray)value;
            var lst = new List<object>();
            foreach(var elm in arr)
             lst.Add( DirectConvertBSONValue(elm, filter) );
            return lst.ToArray();
          }

          if (value is BsonString)   return ((BsonString)value).Value;
          if (value is BsonInt32)    return ((BsonInt32)value).Value;
          if (value is BsonInt64)    return ((BsonInt64)value).Value;
          if (value is BsonDouble)   return ((BsonDouble)value).Value;
          if (value is BsonBoolean)   return ((BsonBoolean)value).Value;
          if (value is BsonDateTime)   return ((BsonDateTime)value).ToUniversalTime();
          if (value is BsonBinaryData)   return ((BsonBinaryData)value).Bytes;

          return value.ToString(); 
        }
Exemplo n.º 17
0
        // parameters:
        //      field   字段名。例如 groups/subjects
        public async Task GetFieldAggregate(
            string field,
            GroupQuery group_query,
            string userCondition,
            string timeRange,
            string idCondition,
            string subjectCondition,
            int start,
            int count,
            Delegate_outputMessage proc)
        {
            IMongoCollection <MessageItem> collection = this._collection;

            FilterDefinition <MessageItem> filter = BuildQuery(// groupName,
                group_query,
                userCondition,
                timeRange,
                idCondition,
                subjectCondition);

#if NO
            var group = new BsonDocument {
                { "$group",
                  new BsonDocument
                  {
                      { "_id", new BsonDocument
                            {
                                {
                                    "MyUser", "$subject"
                                }
                            } },

                      {
                          "Count", new BsonDocument
                          {
                              {
                                  "$sum", 1
                              }
                          }
                      }
                  } }
            };
#endif

            var myresults = await collection.Aggregate().Match(filter)
//.Group(new BsonDocument("_id", "$subjects"))
                            .Group(
                new BsonDocument
            {
                { "_id", "$" + field },

                {
                    "c", new BsonDocument
                    {
                        {
                            "$sum", 1
                        }
                    }
                }
            }
                )
                            .ToListAsync().ConfigureAwait(false);

            long totalCount = myresults.Count;
            var  index      = 0;
            foreach (BsonDocument doc in myresults)
            {
                if (count != -1 && index - start >= count)
                {
                    break;
                }
                Type type = null;
                if (index >= start)
                {
                    MessageItem item = new MessageItem();

                    // BsonArray array = (doc.GetValue("_id") as BsonArray);
                    if (type == null)
                    {
                        type = item.GetPropertyType(field);
                    }
                    BsonValue temp = doc.GetValue("_id");
                    if (type.Equals(typeof(string[])))
                    {
                        item.SetPropertyValue(field, GetStringArray(temp as BsonArray));
                    }
                    else if (type.Equals(typeof(List <string>))) // 2018/11/14
                    {
                        item.SetPropertyValue(field, new List <string>(GetStringArray(temp as BsonArray)));
                    }
                    else
                    {
                        item.SetPropertyValue(field, temp.ToString());
                    }

                    item.data = doc.GetValue("c").ToString();
                    if (proc(totalCount, item) == false)
                    {
                        return;
                    }
                }

                index++;
            }

            proc(totalCount, null); // 表示结束
        }
Exemplo n.º 18
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            var selectedStore = Request["val"];
            Session["selstore"] = selectedStore;
            MyDB        db                     = new MyDB();
            var         coll                   = db.GetBColl("registration");
            var         query                  = new QueryDocument("storename", selectedStore);
            BsonElement bmerchantcollname      = null;
            BsonValue   bmerchantcollnamevalue = null;
            foreach (BsonDocument bcat in coll.Find(query))
            {
                bmerchantcollname      = bcat.GetElement("colname");
                bmerchantcollnamevalue = bmerchantcollname.Value;
            }
            //var merchcol = db.GetBColl("bakkupavankumar7382476952");
            var merchcol = db.GetBColl(bmerchantcollnamevalue.ToString());
            IEnumerable <BsonValue> typesregex = merchcol.Distinct("type");
            var         outjson       = "";
            var         outjsonconcat = "";
            var         varjson       = "";
            BsonElement btype         = null;
            BsonValue   btypevalue    = null;
            BsonElement bmeasures     = null;
            BsonElement boffer        = null;
            string      dums          = null;
            var         jsonoffer     = "";
            foreach (string str in typesregex)
            {
                dums = null;
                var query1 = new QueryDocument("type", str);
                foreach (BsonDocument docs in merchcol.Find(query1))
                {
                    btype      = docs.GetElement("type");
                    btypevalue = btype.Value;
                    boffer     = docs.GetElement("offer");
                    var offervalue = boffer.Value;

                    bmeasures = docs.GetElement("measures");
                    string bmes         = bmeasures.ToString();
                    var    s            = bmes.Replace(";", "\",\"");
                    var    squareconcat = "[\"" + "1" + "\",\"" + "1.5" + "\",\"" + "2" + "\",\"" + "2.5" + "\",\"" + "3" + "\",\"" + "5" + "\",\"" + "10" + "\"]";
                    var    addtobson    = squareconcat;

                    docs.Remove("_id");
                    docs.Remove("measures");
                    docs.Add("measures", addtobson);
                    varjson   = docs.ToJson();
                    jsonoffer = MongoDB.Bson.Serialization.BsonSerializer.Deserialize <BsonDocument>(varjson.ToString()).ToString();
                    dums     += jsonoffer.ToString() + ",";
                }
                outjsonconcat += "{\"category\":" + "\"" + btypevalue + "\"" + ",\"items\":[" + dums.Remove(dums.Length - 1, 1) + "]}" + ",";
                outjson        = outjsonconcat;
            }
            var stringremove = "[" + outjson.Remove(outjson.Length - 1, 1) + "]";
            outjson.Remove(outjson.Length - 1, 1);

            FileInfo fi = new FileInfo(Server.MapPath("inventory/" + selectedStore + ".json"));
            if (!File.Exists(Server.MapPath("inventory/" + selectedStore + ".json").ToString()))
            {
                File.Create(Server.MapPath("inventory/" + selectedStore + ".json").ToString());
                using (TextWriter tw = new StreamWriter(fi.Open(FileMode.Truncate)))
                {
                    tw.Write(stringremove);
                    //fi.Refresh();
                }
            }
            else //if (File.Exists(Server.MapPath("inventory/" + selectedStore + ".json").ToString()))
            {
                using (TextWriter tw = new StreamWriter(fi.Open(FileMode.Truncate)))
                {
                    tw.Write(stringremove);
                    //fi.Refresh();
                }
            }
        }
        catch (ThreadAbortException ee) { }
        catch (Exception eee)
        {
            Response.Clear();
            Response.CacheControl = "no-cache";
            Response.ContentType  = "application/json";
            Response.Write("exception");  //Valid User
            Response.End();
        }
    }
Exemplo n.º 19
0
 private string ValueToString(BsonValue value)
 {
     return(value == BsonNull.Value ? null : value.ToString());
 }
Exemplo n.º 20
0
        protected override bool TrySetArgument(string name, BsonValue value)
        {
            switch (name)
            {
            case "filter":
                _filter = (BsonDocument)value;
                return(true);

            case "update":
                _update = value;
                return(true);

            case "projection":
                _options.Projection = (BsonDocument)value;
                return(true);

            case "sort":
                _options.Sort = (BsonDocument)value;
                return(true);

            case "upsert":
                _options.IsUpsert = value.ToBoolean();
                return(true);

            case "returnDocument":
                _options.ReturnDocument = (ReturnDocument)Enum.Parse(typeof(ReturnDocument), value.ToString());
                return(true);

            case "collation":
                _options.Collation = Collation.FromBsonDocument(value.AsBsonDocument);
                return(true);

            case "arrayFilters":
                var arrayFilters = new List <ArrayFilterDefinition>();
                foreach (BsonDocument arrayFilterDocument in value.AsBsonArray)
                {
                    var arrayFilter = new BsonDocumentArrayFilterDefinition <BsonDocument>(arrayFilterDocument);
                    arrayFilters.Add(arrayFilter);
                }
                _options.ArrayFilters = arrayFilters;
                return(true);
            }

            return(false);
        }
Exemplo n.º 21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            var          tempOrders   = Session["order"];
            var          json         = Request["reqdata"];
            BsonDocument p            = MongoDB.Bson.Serialization.BsonSerializer.Deserialize <BsonDocument>(json);
            BsonValue    typeofuser   = p.GetElement("type").Value;
            BsonValue    stname       = p.GetElement("sn").Value;
            BsonValue    Name         = p.GetElement("Name").Value;
            BsonValue    Mobile       = p.GetElement("mobileNo").Value;
            BsonValue    Email        = p.GetElement("email").Value;
            BsonValue    Password     = p.GetElement("passWord").Value;
            BsonValue    Address      = p.GetElement("address").Value;
            BsonValue    State        = p.GetElement("state").Value;
            BsonValue    City         = p.GetElement("city").Value;
            BsonValue    Pincode      = p.GetElement("pincode").Value;
            string       dedcolname   = Name + Mobile.ToString();
            MyDB         md           = new MyDB();
            var          registration = md.GetBColl("registration");

            myEncryption me       = new myEncryption();
            string       PASSWORD = me.getMD5Hash(Password.ToString());
            BsonDocument document = new BsonDocument();
            document.Add("name", Name);
            document.Add("mobile", Convert.ToInt64(Mobile));
            document.Add("email", Email);
            document.Add("password", PASSWORD);
            document.Add("address", Address);
            document.Add("state", State);
            document.Add("city", City);
            document.Add("pincode", Pincode);
            document.Add("status", 0);
            document.Add("type", typeofuser);
            document.Add("storename", stname);
            document.Add("colname", dedcolname);
            registration.Insert(document);
            registration.Save(document);
            BsonElement bid = document.GetElement("_id");


            string     ActivationUrl = Server.HtmlEncode("http://118.139.160.32/sivanstreet.com/activateusers.aspx");
            SmtpClient sc            = new SmtpClient();
            sc.Credentials = new NetworkCredential("*****@*****.**", "9885139782");         //from address and password
            sc.Port        = 587;
            sc.Host        = "smtp.gmail.com";
            sc.EnableSsl   = true;

            MailMessage mm = new MailMessage();
            mm.From = new MailAddress("*****@*****.**", "Confirmation", System.Text.Encoding.UTF8);
            mm.To.Add(Email.ToString());
            mm.IsBodyHtml = true;
            mm.Subject    = "Confirmation";
            mm.Body       = "Welcome to SivanStreet<br/>" + "Hi " + Name + "<br/>Please <a href=" + ActivationUrl + ">click here to Activate your Account</a> <br/>\nEnjoy Shopping in SivanStreet :)<br/><br/>With Regards,<br/>SivanStreet.com.";
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            sc.Send(mm);

            if (tempOrders != null)
            {
                string       ordersend = "[" + tempOrders + "]";
                var          res       = MongoDB.Bson.Serialization.BsonSerializer.Deserialize <BsonArray>(ordersend.ToString());
                var          temporder = md.GetBColl("temporders");
                BsonDocument btemp     = new BsonDocument();
                btemp.Add("regtoship", "yes");
                btemp.Add("user", bid.Value.ToString());
                btemp.Add("order", res);
                temporder.Insert(btemp);
                temporder.Save(btemp);
            }
        }
        catch (ThreadAbortException ee) { }
        catch (Exception eee)
        {
            Response.Clear();
            Response.CacheControl = "no-cache";
            Response.ContentType  = "application/json";
            Response.Write("exception" + eee.Message);  //Valid User
            Response.End();
        }
    }
Exemplo n.º 22
0
        private void AddToDataTable(string name, BsonValue value)
        {
            if (value is BsonDocument)
            {
                AddToDataTable(name, (BsonDocument)value);
            }
            else if (value is BsonArray)
            {
                BsonArrayToDataTable arrayToDataTable = new BsonArrayToDataTable(this, name, (BsonArray)value);
                _arrays.Add(arrayToDataTable);
            }
            else
            {
                //string textValue;
                object dataValue;
                if (value is BsonTimestamp)
                {
                    dataValue = value.AsBsonTimestamp.ToLocalTime().ToString("s");
                }
                else if (value is BsonNull)
                {
                    //textValue = string.Empty;
                    dataValue = DBNull.Value;
                }
                else
                {
                    dataValue = value.ToString();
                }

                if (name == null)
                    name = "value";
                if (!_dt.Columns.Contains(name))
                {
                    DataColumn column = _dt.Columns.Add(name);
                    column.SetOrdinal(++_lastColumnIndex);
                }
                else
                    _lastColumnIndex = _dt.Columns[name].Ordinal;
                //if (name == null)
                //    name = "value";
                _row[name] = dataValue;
            }
        }
        protected override bool TrySetArgument(string name, BsonValue value)
        {
            switch (name)
            {
            case "filter":
                _filter = (BsonDocument)value;
                return(true);

            case "replacement":
                _replacement = (BsonDocument)value;
                return(true);

            case "projection":
                _options.Projection = (BsonDocument)value;
                return(true);

            case "sort":
                _options.Sort = (BsonDocument)value;
                return(true);

            case "upsert":
                _options.IsUpsert = value.ToBoolean();
                return(true);

            case "returnDocument":
                _options.ReturnDocument = (ReturnDocument)Enum.Parse(typeof(ReturnDocument), value.ToString());
                return(true);

            case "collation":
                _options.Collation = Collation.FromBsonDocument(value.AsBsonDocument);
                return(true);

            case "hint":
                _options.Hint = value;
                return(true);
            }

            return(false);
        }
Exemplo n.º 24
0
 /// <summary>
 ///     使用属性会发生一些MONO上的移植问题
 /// </summary>
 /// <returns></returns>
 public void SetValue(BsonValue value)
 {
     txtBsonValue.Visible = false;
     txtBsonValue.Text = string.Empty;
     txtBsonValue.ReadOnly = false;
     radTrue.Visible = false;
     radFalse.Visible = false;
     radFalse.Checked = true;
     dateTimePicker.Visible = false;
     NumberPick.Visible = false;
     if (value.IsString)
     {
         cmbDataType.SelectedIndex = 0;
         txtBsonValue.Visible = true;
         txtBsonValue.Text = value.ToString();
     }
     if (value.IsInt32)
     {
         cmbDataType.SelectedIndex = 1;
         NumberPick.Visible = true;
         NumberPick.Value = value.AsInt32;
     }
     if (value.IsValidDateTime)
     {
         dateTimePicker.Visible = true;
         dateTimePicker.Value = value.ToUniversalTime();
         cmbDataType.SelectedIndex = 2;
     }
     if (value.IsBoolean)
     {
         radTrue.Visible = true;
         radFalse.Visible = true;
         if (value.AsBoolean)
         {
             radTrue.Checked = true;
         }
         else
         {
             radFalse.Checked = true;
         }
         cmbDataType.SelectedIndex = 3;
     }
     if (value.IsBsonArray)
     {
         var t = GetArray();
         if (t != null)
         {
             _mBsonArray = t;
             txtBsonValue.Visible = true;
             txtBsonValue.Text = _mBsonArray.ToString();
             txtBsonValue.ReadOnly = true;
             cmbDataType.SelectedIndex = 4;
         }
     }
     if (value.IsBsonDocument)
     {
         var t = GetDocument();
         if (t != null)
         {
             _mBsonDocument = t;
             txtBsonValue.Visible = true;
             txtBsonValue.Text = _mBsonDocument.ToString();
             txtBsonValue.ReadOnly = true;
             cmbDataType.SelectedIndex = 5;
         }
     }
 }
Exemplo n.º 25
0
        private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            e.DrawDefault = false;
            Rectangle rect = e.Bounds;

            if (rect.Height == 0)
            {
                ///在展开节点的时候会出现根节点绘制错误的问题
                return;
            }
            if ((e.State & TreeNodeStates.Selected) != 0)
            {
                if ((e.State & TreeNodeStates.Focused) != 0)
                {
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, rect);
                }
                else
                {
                    e.Graphics.FillRectangle(SystemBrushes.Control, rect);
                }
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.White, rect);
            }
            int IndentWidth = DatatreeView.Indent * e.Node.Level + 25;

            e.Graphics.DrawRectangle(SystemPens.Control, rect);
            Rectangle StringRect = new Rectangle(e.Bounds.X + IndentWidth, e.Bounds.Y, colName.Width - IndentWidth, e.Bounds.Height);

            e.Graphics.DrawString(e.Node.Text, this.Font, new SolidBrush(Color.Black), StringRect);


            BsonElement mElement = e.Node.Tag as BsonElement;
            BsonValue   mValue   = e.Node.Tag as BsonValue;

            //画框
            if (e.Node.GetNodeCount(true) > 0 || (mElement != null && (mElement.Value.IsBsonDocument || mElement.Value.IsBsonArray)))
            {
                if (VisualStyleRenderer.IsSupported)
                {
                    int LeftPoint = e.Bounds.X + IndentWidth - 20;
                    //感谢 Shadower http://home.cnblogs.com/u/14697/ 贡献的代码
                    var thisNode = e.Node;
                    var glyph    = thisNode.IsExpanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;
                    var vsr      = new VisualStyleRenderer(glyph);
                    vsr.DrawBackground(e.Graphics, new Rectangle(LeftPoint, e.Bounds.Y + 4, 16, 16));
                }
                else
                {
                    int LeftPoint = e.Bounds.X + IndentWidth - 20;
                    e.Graphics.DrawRectangle(new Pen(Color.Black), new Rectangle(LeftPoint, e.Bounds.Y + 4, 12, 12));
                    Point LeftMid   = new Point(LeftPoint + 2, e.Bounds.Y + 10);
                    Point RightMid  = new Point(LeftPoint + 10, e.Bounds.Y + 10);
                    Point TopMid    = new Point(LeftPoint + 6, e.Bounds.Y + 6);
                    Point BottomMid = new Point(LeftPoint + 6, e.Bounds.Y + 14);
                    e.Graphics.DrawLine(new Pen(Color.Black), LeftMid, RightMid);
                    if (!e.Node.IsExpanded)
                    {
                        e.Graphics.DrawLine(new Pen(Color.Black), TopMid, BottomMid);
                    }
                }
            }

            for (int intColumn = 1; intColumn < 3; intColumn++)
            {
                rect.Offset(this.listView1.Columns[intColumn - 1].Width, 0);
                rect.Width = this.listView1.Columns[intColumn].Width;
                e.Graphics.DrawRectangle(SystemPens.Control, rect);
                if (mElement != null || mValue != null)
                {
                    string strColumnText = String.Empty;
                    if (intColumn == 1)
                    {
                        if (mElement != null)
                        {
                            if (!mElement.Value.IsBsonDocument && !mElement.Value.IsBsonArray)
                            {
                                strColumnText = mElement.Value.ToString();
                            }
                        }
                        else
                        {
                            if (mValue != null)
                            {
                                if (!mValue.IsBsonDocument && !mValue.IsBsonArray)
                                {
                                    strColumnText = mValue.ToString();
                                }
                                else
                                {
                                    if (mValue.IsBsonDocument)
                                    {
                                        strColumnText = MongoDBHelper.Document_Mark;
                                    }
                                    if (mValue.IsBsonArray)
                                    {
                                        strColumnText = MongoDBHelper.Array_Mark;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (mElement != null)
                        {
                            strColumnText = mElement.Value.GetType().Name.Substring(4);
                        }
                        else
                        {
                            strColumnText = mValue.GetType().Name.Substring(4);
                        }
                    }

                    TextFormatFlags flags = TextFormatFlags.EndEllipsis;
                    switch (this.listView1.Columns[intColumn].TextAlign)
                    {
                    case HorizontalAlignment.Center:
                        flags |= TextFormatFlags.HorizontalCenter;
                        break;

                    case HorizontalAlignment.Left:
                        flags |= TextFormatFlags.Left;
                        break;

                    case HorizontalAlignment.Right:
                        flags |= TextFormatFlags.Right;
                        break;

                    default:
                        break;
                    }

                    rect.Y++;
                    if ((e.State & TreeNodeStates.Selected) != 0 &&
                        (e.State & TreeNodeStates.Focused) != 0)
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect, SystemColors.HighlightText, flags);
                    }
                    else
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect, e.Node.ForeColor, e.Node.BackColor, flags);
                    }
                    rect.Y--;
                }
            }
        }
        /// <summary>
        /// BsonValue转展示用字符
        /// </summary>
        /// <param name="bsonValue"></param>
        /// <returns></returns>
        public static String ConvertToString(BsonValue bsonValue)
        {
            //二进制数据
            if (bsonValue.IsBsonBinaryData)
            {
                return "[Binary]";
            }
            //空值
            if (bsonValue.IsBsonNull)
            {
                return "[Empty]";
            }
            //文档
            if (bsonValue.IsBsonDocument)
            {
                return bsonValue.ToString() + "[Contains" + bsonValue.ToBsonDocument().ElementCount + "Documents]";
            }
            //时间
            if (bsonValue.IsBsonDateTime)
            {
                DateTime bsonData = bsonValue.AsDateTime;
                //@flydreamer提出的本地化时间要求
                return bsonData.ToLocalTime().ToString();
            }

            //字符
            if (bsonValue.IsString)
            {
                //只有在字符的时候加上""
                return "\"" + bsonValue.ToString() + "\"";
            }

            //其他
            return bsonValue.ToString();
        }
Exemplo n.º 27
0
        /// <summary>
        ///     使用属性会发生一些MONO上的移植问题
        /// </summary>
        /// <returns></returns>
        public void SetValue(BsonValue value, BsonValueEx.BasicType DataType = BsonValueEx.BasicType.BsonUndefined)
        {
            txtBsonValue.Visible   = false;
            txtBsonValue.Text      = string.Empty;
            txtBsonValue.ReadOnly  = false;
            radTrue.Visible        = false;
            radFalse.Visible       = false;
            radFalse.Checked       = true;
            dateTimePicker.Visible = false;
            NumberPick.Visible     = false;

            if (value.IsString)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Text    = value.ToString();
            }

            if (value.IsInt32)
            {
                NumberPick.Visible = true;
                NumberPick.Value   = value.AsInt32;
            }

            if (value.IsInt64)
            {
                NumberPick.Visible = true;
                NumberPick.Value   = value.AsInt64;
            }

            if (value.IsDecimal128)
            {
                NumberPick.Visible = true;
                NumberPick.Value   = value.AsDecimal;
            }

            if (value.IsDouble)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Text    = value.AsDouble.ToString();
            }

            if (value.IsValidDateTime)
            {
                dateTimePicker.Visible = true;
                dateTimePicker.Value   = value.ToUniversalTime();
            }

            if (value.IsBsonMaxKey || value.IsBsonMinKey)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Enabled = false;
                txtBsonValue.Text    = value.ToString();
            }

            if (value.IsBoolean)
            {
                radTrue.Visible  = true;
                radFalse.Visible = true;
                if (value.AsBoolean)
                {
                    radTrue.Checked = true;
                }
                else
                {
                    radFalse.Checked = true;
                }
            }
            if (value.IsBsonArray)
            {
                if (GetArray == null)
                {
                    MessageBox.Show("GetArray委托不存在!");
                    return;
                }
                if (DataType == BsonValueEx.BasicType.BsonLegacyPoint)
                {
                    //地理
                    var t = GetGeoPoint();
                    if (t != null)
                    {
                        _mBsonArray           = t;
                        txtBsonValue.Visible  = true;
                        txtBsonValue.Text     = _mBsonArray.ToString();
                        txtBsonValue.ReadOnly = true;
                    }
                }
                else
                {
                    //普通数组
                    var t = GetArray();
                    if (t != null)
                    {
                        _mBsonArray           = t;
                        txtBsonValue.Visible  = true;
                        txtBsonValue.Text     = _mBsonArray.ToString();
                        txtBsonValue.ReadOnly = true;
                    }
                }
            }
            if (value.IsBsonDocument)
            {
                if (GetDocument == null)
                {
                    MessageBox.Show("GetDocument委托不存在!");
                    return;
                }

                if (DataType == BsonValueEx.BasicType.BsonGeoJSON)
                {
                    //地理
                    var t = GetGeoPoint();
                    if (t != null)
                    {
                        _mBsonDocument = new BsonDocument("type", "Point");
                        _mBsonDocument.Add("coordinates", t);
                        txtBsonValue.Visible  = true;
                        txtBsonValue.Text     = _mBsonDocument.ToString();
                        txtBsonValue.ReadOnly = true;
                    }
                }
                else
                {
                    var t = GetDocument();
                    if (t != null)
                    {
                        _mBsonDocument        = t;
                        txtBsonValue.Visible  = true;
                        txtBsonValue.Text     = _mBsonDocument.ToString();
                        txtBsonValue.ReadOnly = true;
                    }
                }
            }
            if (value.IsBsonBinaryData)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Text    = Encoding.Default.GetString(value.AsBsonBinaryData.Bytes);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// BsonValue转展示用字符
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static string ConvertForShow(BsonValue val)
        {
            //二进制数据
            if (val.IsBsonBinaryData)
            {
                _hasBSonBinary = true;
                return "[二进制数据]";
            }
            //空值
            if (val.IsBsonNull)
            {
                return "[空值]";
            }

            //文档
            if (val.IsBsonDocument)
            {
                return val.ToString() + "[包含" + val.ToBsonDocument().ElementCount + "个元素的文档]";
            }

            //时间
            if (val.IsBsonDateTime)
            {
                DateTime bsonData = val.AsDateTime;
                //@flydreamer提出的本地化时间要求
                return bsonData.ToLocalTime().ToString();
            }

            //字符
            if (val.IsString)
            {
                //只有在字符的时候加上""
                return "\"" + val.ToString() + "\"";
            }

            //其他
            return val.ToString();
        }
Exemplo n.º 29
0
 private string ConvertData(BsonValue val)
 {
     string str = val.ToString();
     if (val.IsValidDateTime) str = (val as BsonDateTime).ToLocalTime().ToString();
     else if (val.IsBsonNull) str = string.Empty;
     return str;
 }
Exemplo n.º 30
0
        /// <summary>
        ///     使用属性会发生一些MONO上的移植问题
        /// </summary>
        /// <returns></returns>
        public void SetValue(BsonValue value, BsonValueEx.BasicType DataType = BsonValueEx.BasicType.BsonUndefined)
        {
            txtBsonValue.Visible = false;
            txtBsonValue.Text = string.Empty;
            txtBsonValue.ReadOnly = false;
            radTrue.Visible = false;
            radFalse.Visible = false;
            radFalse.Checked = true;
            dateTimePicker.Visible = false;
            NumberPick.Visible = false;

            if (value.IsString)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Text = value.ToString();
            }

            if (value.IsInt32)
            {
                NumberPick.Visible = true;
                NumberPick.Value = value.AsInt32;
            }

            if (value.IsInt64)
            {
                NumberPick.Visible = true;
                NumberPick.Value = value.AsInt64;
            }

            if (value.IsDecimal128)
            {
                NumberPick.Visible = true;
                NumberPick.Value = value.AsDecimal;
            }

            if (value.IsDouble)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Text = value.AsDouble.ToString();
            }

            if (value.IsValidDateTime)
            {
                dateTimePicker.Visible = true;
                dateTimePicker.Value = value.ToUniversalTime();
            }

            if (value.IsBsonMaxKey || value.IsBsonMinKey)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Enabled = false;
                txtBsonValue.Text = value.ToString();
            }

            if (value.IsBoolean)
            {
                radTrue.Visible = true;
                radFalse.Visible = true;
                if (value.AsBoolean)
                {
                    radTrue.Checked = true;
                }
                else
                {
                    radFalse.Checked = true;
                }
            }
            if (value.IsBsonArray)
            {
                if (GetArray == null)
                {
                    MessageBox.Show("GetArray委托不存在!");
                    return;
                }
                if (DataType == BsonValueEx.BasicType.BsonLegacyPoint)
                {
                    //地理
                    var t = GetGeoPoint();
                    if (t != null)
                    {
                        _mBsonArray = t;
                        txtBsonValue.Visible = true;
                        txtBsonValue.Text = _mBsonArray.ToString();
                        txtBsonValue.ReadOnly = true;
                    }
                }
                else
                {
                    //普通数组
                    var t = GetArray();
                    if (t != null)
                    {
                        _mBsonArray = t;
                        txtBsonValue.Visible = true;
                        txtBsonValue.Text = _mBsonArray.ToString();
                        txtBsonValue.ReadOnly = true;
                    }
                }

            }
            if (value.IsBsonDocument)
            {
                if (GetDocument == null)
                {
                    MessageBox.Show("GetDocument委托不存在!");
                    return;
                }

                if (DataType == BsonValueEx.BasicType.BsonGeoJSON)
                {
                    //地理
                    var t = GetGeoPoint();
                    if (t != null)
                    {
                        _mBsonDocument = new BsonDocument("type", "Point");
                        _mBsonDocument.Add("coordinates", t);
                        txtBsonValue.Visible = true;
                        txtBsonValue.Text = _mBsonDocument.ToString();
                        txtBsonValue.ReadOnly = true;
                    }
                }
                else
                {
                    var t = GetDocument();
                    if (t != null)
                    {
                        _mBsonDocument = t;
                        txtBsonValue.Visible = true;
                        txtBsonValue.Text = _mBsonDocument.ToString();
                        txtBsonValue.ReadOnly = true;
                    }
                }
            }
            if (value.IsBsonBinaryData)
            {
                txtBsonValue.Visible = true;
                txtBsonValue.Text = Encoding.Default.GetString(value.AsBsonBinaryData.Bytes);
            }
        }
Exemplo n.º 31
0
        private string ValueToString(BsonValue value)
        {
            if (value == BsonNull.Value)
            {
                return null;
            }

            return value.ToString();
        }
Exemplo n.º 32
0
        private object GetDataTypeValueFromBsonValue(BsonValue value, DataType dt)
        {
            if (dt == DataType.DT_I8 | dt == DataType.DT_I4)
            {
                if (value.IsString)
                {
                    Int64 parsedInt = -1;
                    if (!Int64.TryParse(value.ToString(), out parsedInt))
                    {
                        bool pbCancel = true;
                        ComponentMetaData.FireError(0, "MongoDataSource", "Cannot parse string value to integer: " + value.ToString(), "", 0, out pbCancel);
                    }
                    return parsedInt;
                }
                else
                {
                    return value.ToInt64();
                }
            }
            else if (dt == DataType.DT_BOOL)
            {
                return value.ToBoolean();
            }
            else if (dt == DataType.DT_R8 | dt == DataType.DT_R4)
            {
                return value.ToDouble();
            }
            else if (dt == DataType.DT_DATE | dt == DataType.DT_DBTIMESTAMPOFFSET | dt == DataType.DT_DBTIMESTAMP)
            {
                return DateTime.Parse(value.ToString());
            }
            else
            {
                if (dt != DataType.DT_STR && !value.IsObjectId && !value.IsString && !value.IsBsonSymbol)
                    ComponentMetaData.FireWarning(0, "MongoDataSource", "Converting " + value.BsonType + " to string, though datatype was " + dt, String.Empty, 0);

                return value.ToString();
            }
        }
Exemplo n.º 33
0
        public static T Get <T>(BsonDocument _document) where T : AbstractTGObject, new()
        {
            if (_document != null)
            {
                TGSerializedObject tso = new TGSerializedObject();

                foreach (string name in _document.Names)
                {
                    if (!name.Equals("_id"))
                    {
                        BsonValue val = _document[name];

                        TGSerializedProperty serializedProperty = new TGSerializedProperty(name, val.ToString());
                        tso.Properties.Add(name, serializedProperty);
                    }
                }

                return(TGSerializedObject.GetTGSerializable <T>(tso));
            }

            return(default(T));
        }