コード例 #1
0
ファイル: RapideDdl_f_v1.cs プロジェクト: 24/source_04
        public static void Test_RapideDdl_Images_01()
        {
            //pb.Data.Mongo.MongoCommand.FindAs("dl", "RapideDdl_Detail", "{}", fields: "{ 'download.images.Source': 1, 'download.images.ImageWidth': 1, 'download.images.ImageHeight': 1 }", limit: 5);
            //string query = "{ 'download.images.ImageHeight': { $gt: 100 } }";
            string query  = "{}";
            string fields = "{ 'download.images.Source': 1, 'download.images.ImageWidth': 1, 'download.images.ImageHeight': 1 }";
            int    limit  = 0;
            MongoCursor <BsonDocument> cursor = MongoCommand.GetDatabase(null, "dl").GetCollection("RapideDdl_Detail").zFind <BsonDocument>(new QueryDocument(BsonSerializer.Deserialize <BsonDocument>(query)));

            cursor.SetFields(new FieldsWrapper(BsonSerializer.Deserialize <BsonDocument>(fields)));
            if (limit != 0)
            {
                cursor.SetLimit(limit);
            }
            //DataTable dt = new DataTable();
            //dt.Load()
            //dt.LoadDataRow()
            //dt.ReadXml()
            //foreach (BsonDocument document in cursor)
            //{
            //    BsonArray array = document.GetElement("download").Value.AsBsonDocument.GetElement("images").Value.AsBsonArray;
            //    foreach (BsonValue value in array)
            //    {
            //        //Trace.WriteLine("BsonType : {0}", value.BsonType);
            //        Trace.WriteLine(value.ToJson());
            //    }
            //}
            //DataTable dt = Test_Bson.Test_Bson_f.BsonDocumentsToDataTable(cursor);
            DataTable dt = cursor.zToDataTable2();

            //dt.Select();
            //dt.Rows[0].Delete
            //foreach (DataRow row in dt.Rows)
            //{
            //    object imageHeightValue = row["download.images.ImageHeight"];
            //    //if (imageHeight is int && (int)imageHeight <= 60)
            //    //    row.Delete();
            //    int imageHeight;
            //    if (imageHeightValue is string && int.TryParse((string)imageHeightValue, out imageHeight))
            //    {
            //        if (imageHeight <= 60)
            //            row.Delete();
            //    }
            //}

            for (int i = 0; i < dt.Rows.Count;)
            {
                DataRow row = dt.Rows[i];
                object  imageHeightValue = row["download.images.ImageHeight"];
                //if (imageHeight is int && (int)imageHeight <= 60)
                //    row.Delete();
                int imageHeight;
                if (imageHeightValue is string && int.TryParse((string)imageHeightValue, out imageHeight) && imageHeight <= 60)
                {
                    //if (imageHeight <= 60)
                    row.Delete();
                }
                else
                {
                    i++;
                }
            }

            RunSource.CurrentRunSource.SetResult(dt);
        }