本文整理汇总了C#中MongoRepository类的典型用法代码示例。如果您正苦于以下问题:C# MongoRepository类的具体用法?C# MongoRepository怎么用?C# MongoRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoRepository类属于命名空间,在下文中一共展示了MongoRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnActionExecuting
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
// Grab the arguments from the request.
var id = (string)actionContext.ActionArguments["id"];
var fundData = (Fund)actionContext.ActionArguments["fund"];
// Ensure the user has not mismatched the Id property.
if (id != fundData.Id)
{
throw new HttpException(400, "BadRequest: Data does not match item associated with request id.");
}
var fundRepository = new MongoRepository<Fund>();
var fund = fundRepository.GetById(id);
// Ensure the fund exists.
if (fund == null)
{
throw new HttpException(404, "NotFound. The requested fund does not exist.");
}
// Ensure the user has not mismatched the AreaId property.
if (fundData.AreaId != fund.AreaId)
{
throw new HttpException(400, "BadRequest: Data does not match item associated with request id.");
}
if (!this.IsAuthorizedToAccessArea(fund.AreaId))
{
throw new HttpException(401, "Unauthorized. You are not authorized to access this area.");
}
}
示例2: IsAuthorizedToAccessArea
protected bool IsAuthorizedToAccessArea(string areaId)
{
// Ensure the request contains the areaId
if (String.IsNullOrEmpty(areaId))
{
throw new HttpException(400, "BadRequest. Area not supplied.");
}
// Query for the area to match up its number to the associated Role.
var areaRepository = new MongoRepository<Area>();
var area = areaRepository.GetById(areaId);
// Ensure the supplied area exists.
if (area == null)
{
throw new HttpException(404, "NotFound. The requested area does not exist.");
}
// Ensure the user is in a role to allow accessing the area.
foreach (var role in RoleValidator.GetAuthorizedRolesForArea(area))
{
if (HttpContext.Current.User.IsInRole(role))
{
// Add the area to the Items dictionary to avoid duplicating the query.
HttpContext.Current.Items["area"] = area;
return true;
}
}
return false;
}
示例3: Main
static void Main(string[] args)
{
string mongoUrl = "mongodb://127.0.0.1:27017/mongodemo";
string databaseName = "MongoDemo";
//IMongoClient _client;
//IMongoDatabase db;
//_client = new MongoClient("mongodb://127.0.0.1:27017/mongodemo");
//db = _client.GetDatabase("MongoDemo");
//var list = db.GetCollection<Restaurant>("restaurants").Find(x => true).ToListAsync<Restaurant>().Result;
//foreach (var restaurant in list)
//{
// Console.WriteLine(restaurant.Name);
//}
MongoRepository<Restaurant> restaurantRepo = new MongoRepository<Restaurant>(mongoUrl, databaseName, "restaurants");
//var list = restaurantRepo.GetAll<Restaurant>();
var t1 = restaurantRepo.GetByIdAsync(new ObjectId("55e69a970e6672a2fb2cc624"));
var restaurant = restaurantRepo.GetById(new ObjectId("55e69a970e6672a2fb2cc624"));
Console.ReadLine();
}
示例4: ImportMotherboards
private void ImportMotherboards()
{
IRepository<Motherboard> motherboardRepository = new MongoRepository<Motherboard>(this.dbContext);
IRepository<Vendor> vendorRepository = new MongoRepository<Vendor>(this.dbContext);
var vendorsList = vendorRepository.GetAll().ToList();
textWriter.Write("Importing motherboards");
for (int i = 0; i < 45; i++)
{
if (i % 2 == 0)
{
textWriter.Write(".");
}
motherboardRepository.Add(new Motherboard()
{
Id = ObjectId.GenerateNewId(),
Model = RandomUtils.GenerateRandomString(RandomUtils.GenerateNumberInRange(2, 5)),
Price = RandomUtils.GenerateNumberInRange(150, 350),
VendorId = vendorsList[RandomUtils.GenerateNumberInRange(0, vendorsList.Count - 1)].Id
});
}
textWriter.WriteLine();
}
示例5: Main
static void Main(string[] args)
{
ZipExtractor zipReader = new ZipExtractor("../../../../../Matches - Results.zip");
zipReader.Extract("../../../../../");
MongoRepository mongoContext = new MongoRepository();
List<ReniumLeague.Entity.Mongo.Models.Team> allPlaces = mongoContext.GetAllTeams().ToList();
var xmlSerializer = new ReniumLeague.Entity.Serializer.XmlSerialzer();
var xmlString = xmlSerializer.Serialize < ReniumLeague.Entity.Mongo.Models.Team >> (allTeams);
var xmlFilePath = "../../teams.xml";
using (var str = new StreamWriter(xmlFilePath))
{
str.Write(xmlString);
}
var objectsFromXml = xmlSerializer.ParseXml < ReniumLeague.Entity.Mongo.Models.Team >> (xmlFilePath);
Console.WriteLine();
}
示例6: ImportCpus
private void ImportCpus()
{
int[] cpuCores = { 2, 3, 4, 6 };
IRepository<Cpu> cpuRepository = new MongoRepository<Cpu>(this.dbContext);
IRepository<Vendor> vendorRepository = new MongoRepository<Vendor>(this.dbContext);
var vendorsList = vendorRepository.GetAll().ToList();
textWriter.Write("Importing CPUs");
for (int i = 0; i < 42; i++)
{
if (i % 2 == 0)
{
textWriter.Write(".");
}
int currentCpuCoresCount = cpuCores[RandomUtils.GenerateNumberInRange(0, cpuCores.Length - 1)];
cpuRepository.Add(new Cpu()
{
Id = ObjectId.GenerateNewId(),
Cores = currentCpuCoresCount,
Model = RandomUtils.GenerateRandomString(RandomUtils.GenerateNumberInRange(2, 5)),
Price = currentCpuCoresCount * RandomUtils.GenerateNumberInRange(100, 120),
VendorId = vendorsList[RandomUtils.GenerateNumberInRange(0, vendorsList.Count - 1)].Id
});
}
textWriter.WriteLine();
}
示例7: Drop_IfHaveCollection_ReturnTrue
public void Drop_IfHaveCollection_ReturnTrue()
{
var repository = new MongoRepository<TestModel>();
repository.Insert(TestModel.CreateInstance());
var result = repository.Drop();
Assert.IsTrue(result);
}
示例8: TestInsert
public void TestInsert()
{
var t = new Team {Name = "Test"};
var repo = new MongoRepository<Team>(_db);
repo.Save(t);
Assert.NotNull(t.Id);
}
示例9: OnActionExecuting
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
// Run base method to handle Users and Roles filter parameters.
// Grab the fundId from the request.
var fundId = actionContext.ControllerContext.RouteData.Values["id"].ToString();
// Query for the fund.
var fundRepository = new MongoRepository<Fund>();
var fund = fundRepository.GetById(fundId);
// Ensure the supplied fund exists.
if (fund == null)
{
throw new HttpException(404, "NotFound");
}
if (this.IsAuthorizedToAccessArea(fund.AreaId))
{
// Add the fund to the Items dictionary to avoid duplicating the query.
HttpContext.Current.Items["fund"] = fund;
}
else
{
throw new HttpException(401, "Unauthorized. You are not authorized to access this area.");
}
}
示例10: Index
public ActionResult Index()
{
var model = new DeploymentJointModel();
var Companies = new MongoRepository<Company>();
model.ModelForView.Company = Companies.Select(c => new SelectListItem
{
Value = c.CompanyKey,
Text = c.CompanyName
});
var Environments = new MongoRepository<Entities.Environment>();
model.ModelForView.Environment = Environments.Select(e => new SelectListItem
{
Value = e.Id,
Text = e.Name
});
var Revisions = new MongoRepository<Revision>();
model.ModelForView.Revision = Revisions.Select(r => new SelectListItem
{
Value = r.Id,
Text = r.Tag
});
return View(model);
}
示例11: FirstDBTest
public void FirstDBTest()
{
using (var db = new MongoRepository<DBStub>())
{
db.Add(new DBStub() { Name = "test" });
}
}
示例12: CompetitionService
public CompetitionService(MongoRepository<Competition> competitionRepo, NodeService nodeService, MongoRepository<Team> teamRepo, PriceService priceService)
{
_competitionRepo = competitionRepo;
_nodeService = nodeService;
_teamRepo = teamRepo;
_priceService = priceService;
}
示例13: CellCounts
private static async Task CellCounts()
{
var mongoConnection = new MongoRepository("genomics");
var tbfsCollection = mongoConnection.GetCollection<EncodeTbfsPeak>("encode.tbfs-peaks");
var aggregate = tbfsCollection.Aggregate()
.Match(new BsonDocument { { "antibody", "CTCF" } })
.Group(new BsonDocument { { "_id", "$cell" }, { "count", new BsonDocument("$sum", 1) } });
var results = await aggregate.ToListAsync();
var ordered = results.OrderBy(x => x[0]);
// var aggregate = tbfsCollection.Aggregate()
// .Match(new BsonDocument { { "antibody", "CTCF" } })
// .Group(new BsonDocument { { "_id", "$chromosome" }, { "count", new BsonDocument("$sum", 1) } });
// var results = await aggregate.ToListAsync();
// var ordered = results.OrderBy(x => x[0]);
using (var writer = new StreamWriter(File.Open("C:\\_dev\\data\\genomics\\results.csv", FileMode.Create)))
{
foreach (var doc in ordered)
{
var line = doc[0] + "," + doc[1];
writer.WriteLine(line);
}
}
}
示例14: SyncEncodeTbfsData
public static async Task SyncEncodeTbfsData(string databaseName)
{
var mongoConnection = new MongoRepository(databaseName);
var sync = new EncodeWebDataSynchronizer(new JsonWrapper(), mongoConnection, new HttpWebRequestWrapper());
await sync.SyncTbfs();
}
示例15: GetPangramsLimit
public GetPangramResponse GetPangramsLimit(int limit)
{
IRepository<Pangram> _pangramRepo = new MongoRepository<Pangram>();
GetPangramResponse getPangramResponse = new GetPangramResponse();
if (limit > 0)
{
var pangrams = _pangramRepo.Select(p => p)
.Take(limit)
.ToList();
if (pangrams.Count() > 0)
{
foreach (var pa in pangrams)
{
getPangramResponse.pangrams.Add(pa.Sentence);
}
}
}
return new GetPangramResponse()
{
Content = new JsonContent2(
getPangramResponse
)
};
}