public async Task <List <PostMiniDto> > GetPostsMiniAsync() { List <PostMiniDto> list = new List <PostMiniDto>(); await Context1.Find(post => true).SortByDescending(post => post.Date).ForEachAsync(post => list.Add(new PostMiniDto() { Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, Comments = post.Comments.HierarchyCount(), Likes = post.Likes.LongCount(), Descreption = post.Descreption, Id = post.Id })); return(list); return(await Context1.AsQueryable().Select(post => new PostMiniDto() { Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, Comments = post.Comments.HierarchyCount(), Likes = post.Likes.LongCount(), Descreption = post.Descreption, Id = post.Id }).ToListAsync()); }
public async Task <List <PostDto> > GetPostsSearchAsync(string text) { List <PostDto> list = new List <PostDto>(); var AllPost = await Context1.AsQueryable().ToListAsync(); var QueryTuple = AllPost.Select(x => (x.Id, x.Descreption ?? "")).ToList(); var Ids = JolijoberExtensions.FuzzySearchLinq(text, QueryTuple, 0.7).Select(x => x.Item1); bool ifff = Ids.Any(); list = AllPost.Where(x => ifff?Ids.Contains(x.Id): x.Descreption?.Contains(text) ?? false).OrderByDescending(post => post.Date).Select(post => new PostDto() { Id = post.Id, Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, AccountId = post.AccountId, PostType = post.PostType, AccountName = post.AccountName, AccountType = post.AccountType, Availabilty = post.Availabilty, Categories = post.Categories, Comments = post.Comments, Descreption = post.Descreption, Hours = post.Hours, KindPay = post.KindPay, Likes = post.Likes, Region = post.Region, Sallaries = post.Sallaries, Skills = post.Skills, Specifications = post.Specifications }).ToList(); return(list); }
public async Task <List <PostDto> > GetPostsAsync(bool IsJob = true, bool IsProject = true) { List <PostDto> list = new List <PostDto>(); var filterBuilder = Builders <Post> .Filter; var filter = IsJob && IsProject?((filterBuilder.Eq(x => x.PostType, PostTypes.Job) | filterBuilder.Eq(x => x.PostType, PostTypes.Project))) :(IsJob? filterBuilder.Eq(x => x.PostType, PostTypes.Job): filterBuilder.Eq(x => x.PostType, PostTypes.Project)); await Context1.Find(filter) .SortByDescending(post => post.Date).ForEachAsync(post => list.Add(new PostDto() { Id = post.Id, Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, AccountId = post.AccountId, PostType = post.PostType, AccountName = post.AccountName, AccountType = post.AccountType, Availabilty = post.Availabilty, Categories = post.Categories, Comments = post.Comments, Descreption = post.Descreption, Hours = post.Hours, KindPay = post.KindPay, Likes = post.Likes, Region = post.Region, Sallaries = post.Sallaries, Skills = post.Skills, Specifications = post.Specifications })); return(list); }
public static void TestExpression(LambdaExpression source) { var random = new Random(); int u; var Context1 = new Context1 { A = random.Next(), B = random.Next(), C = (u = random.Next(0, 2)) == 0 ? null : (int?)u, Array = new[] { random.Next() }, Func = () => u }; //var settings = new JsonSerializerSettings(); //settings.Converters.Add(new ExpressionJsonConverter( // Assembly.GetAssembly(typeof (ExpressionJsonSerializerTest)) //)); //var json = JsonConvert.SerializeObject(source, settings); //var target = JsonConvert.DeserializeObject<LambdaExpression>(json, settings); //Assert.AreEqual( // ExpressionResult(source, Context1), // ExpressionResult(target, Context1) //); }
public void TestGetBytes() { var result1 = Context1.GetBytes(); var result2 = Context2.GetBytes(); // The length of the array should be sector size. result1.Length.Should().Be(512); result2.Length.Should().Be(2048); }
public override void drawHouse(int centerPointX, int centerPointY, int width, int height) { Context1.SetSourceRGB(0.9, 0.0, 0.0); Context1.Rectangle(centerPointX - width / 2, centerPointY - height / 2, width, height); Context1.MoveTo(centerPointX - width / 1.2, centerPointY - height / 2); Context1.LineTo(centerPointX + width / 1.2, centerPointY - height / 2); Context1.LineTo(centerPointX, centerPointY - height); Context1.ClosePath(); Context1.Stroke(); }
public static void Add(Unit one, UnitCarrier other) { if (contexts1 == null) { contexts1 = new List <Context1>(); } Context1 context = new Context1(); context.Self = one; context.Other = other; contexts1.Add(context); }
protected void saveHabit_Click(object sender, EventArgs e) { var Id = Request.QueryString["Id"]; Habit1 = Context1.Habits.First(p => p.Id.ToString() == Id); Habit1.Name = habitName.Text; Habit1.HabitTime = (int.Parse(habitTime.Text.Split(':')[0])) * 60 + (int.Parse(habitTime.Text.Split(':')[1])); Habit1.Image = habitImage.Text; Habit1.Description = description.Text; Context1.SaveChanges(); Response.Redirect("HabitShow.aspx?Id=" + Habit1.Id); }
// add 10-DATA every reqest private async Task Seed() { List <SimpleModel> list = new List <SimpleModel>(); for (int i = 0; i < 10; i++) { list.Add(new SimpleModel() { Simple = i.ToString() + "$" + Guid.NewGuid() }); } await Context1.InsertManyAsync(list); }
public async Task <object> GetSimplesAsync() { //will throw eception until pass true or MongoDBRepository<SimpleModel,Foo> , Foo should inherent BaeEntity //var data = await Context<Foo>(true).AsQueryable().ToListAsync(); // create and use fine , out of MongoDBRepository<SimpleModel> var data = await Context <Foo>(true).AsQueryable().ToListAsync(); await Seed(); // two way to use // await Context<SimpleModel>().Find(s => true).ToListAsync(); return(await Context1.Find(s => true).ToListAsync()); }
public async Task <PostMiniDto> GetPostByIdMiniAsync(string id) { var post = await Context1.Find(post => post.Id == id).SingleOrDefaultAsync <Post>(); return(new PostMiniDto() { Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, Likes = post.Likes.LongCount(), Descreption = post.Descreption, Id = post.Id, Comments = post.Comments.LongCount(), }); }
public override void drawStar(int centerPointX, int centerPointY, int outerRadius, int innerRadius) { int[,] points = { { 0 + centerPointX, 85 + centerPointY }, { 75 + centerPointX, 75 + centerPointY }, { 100 + centerPointX, 10 + centerPointY }, { 125 + centerPointX, 75 + centerPointY }, { 200 + centerPointX, 85 + centerPointY }, { 150 + centerPointX, 125 + centerPointY }, { 160 + centerPointX, 190 + centerPointY }, { 100 + centerPointX, 150 + centerPointY }, { 40 + centerPointX, 190 + centerPointY }, { 50 + centerPointX, 125 + centerPointY }, { 0 + centerPointX, 85 + centerPointY } }; Context1.SetSourceRGB(0.9, 0.0, 0.0); int i; for (i = 0; i < 10; i++) { Context1.LineTo(points[i, 0], points[i, 1]); } Context1.ClosePath(); Context1.StrokePreserve(); //Context1.Fill(); }
public async Task <List <PostDto> > GetPostsFilterAsync(FilterDto filter) { List <PostDto> list = new List <PostDto>(); var filterBuilder = Builders <Post> .Filter; var exfilter = filterBuilder.Eq(x => x.PostType, PostTypes.Job); var exfilterd = (filterBuilder.Eq(x => x.Title, filter.Title) | filterBuilder.ElemMatch(x => x.Tags, filter.Tag) | filterBuilder.Eq(x => x.Region, filter.Region) | filterBuilder.ElemMatch(x => x.Specifications, filter.Specification) | filterBuilder.Eq(x => x.Sallaries, new MinMax(filter.Min, filter.Max)) | filterBuilder.Eq(x => x.Availabilty, filter.Availabilty)); await Context1.Find(exfilter) .SortByDescending(post => post.Date).ForEachAsync(post => list.Add(new PostDto() { Id = post.Id, Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, AccountId = post.AccountId, PostType = post.PostType, AccountName = post.AccountName, AccountType = post.AccountType, Availabilty = post.Availabilty, Categories = post.Categories, Comments = post.Comments, Descreption = post.Descreption, Hours = post.Hours, KindPay = post.KindPay, Likes = post.Likes, Region = post.Region, Sallaries = post.Sallaries, Skills = post.Skills, Specifications = post.Specifications })); list = list.Where(x => x.Availabilty == filter.Availabilty && x.Title.Contains(filter.Title ?? "")).ToList(); return(list); }
public void Run() { using (DbConnection connection = GetConnection()) { using (var context = new Context1(connection)) { context.MyEntities.Count(); } using (var context = new Context2(connection)) { context.MyEntities.Count(); context.MyEntities.Where(_ => _.Description2.Contains("a")).Count(); } using (var context = new Context2(connection)) { context.MyEntities.Where(_ => _.Description2.Contains("a")).Count(); } } }
public async Task <PostDto> AddPostAsync(PostDto post) { string Id = httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); var Account = await Context2.Find(x => x.SecurId == Id).SingleOrDefaultAsync(); Account = Account ?? new Identity(); var set = new Post() { Date = post.Date, Title = post.Title, Tags = post.Tags, Views = post.Views, AccountId = Account.Id, AccountName = Account.FisrtName + " " + Account.SureName, AccountType = Account.Type, PostType = post.PostType, Availabilty = post.Availabilty, Categories = post.Categories, Comments = post.Comments, Descreption = post.Descreption, Hours = post.Hours, KindPay = post.KindPay, Likes = post.Likes, Region = post.Region, Sallaries = post.Sallaries, Skills = post.Skills, Specifications = post.Specifications }; await Context1.InsertOneAsync(set); post.Id = set.Id; return(post); }
/// <summary> /// The PostBack /// </summary> /// <param name="dlmsg">The dlmsg<see cref="DownloadMessage"/></param> /// <param name="ctx1A">The ctx1A<see cref="Context1"/></param> /// <param name="status">The status<see cref="HttpStatusCode"/></param> /// <param name="excp1">The excp1<see cref="Exception"/></param> private static void PostBack(DownloadMessage dlmsg, Context1 ctx1A, HttpStatusCode status, Exception excp1) { var failmsg = new DownloadedMessage(dlmsg, ctx1A.DownloadMessage.TargetPath, status, excp1); ctx1A.OrigSender.Tell(failmsg); }
public override void dispose() { Graphics1.Dispose(); Context1.Dispose(); Surface1.Dispose(); }
private static string ExpressionResult(LambdaExpression expr, Context1 Context1) { return(JsonConvert.SerializeObject(expr.Compile().DynamicInvoke(Context1))); }
static void Main(string[] args) { var db = new Context1(); db.Database.EnsureCreated(); }
/* * bool DownloadPage(DownloadMessage msg) * { * var origmsg = msg; * var tcs = new TaskCompletionSource<GotContentMessage>(); * var gotMsg = new GotContentMessage(msg); * Client.GetAsync(msg.DownloadUri,HttpCompletionOption.ResponseContentRead) * .ContinueWith((response, origmsg2) => { response.Result.Content.ReadAsStringAsync(); * return tcs.Task; * }) * .ContinueWith(t2=> DoResponse(t2)) * .PipeTo(Self); * return true; // show ActorSystem we handled message [expect next one immediately!] * } */ /// <summary> /// process incoming DownloadMessage /// </summary> /// <param name="msg">incoming msg<see cref="DownloadMessage"/></param> /// <returns>true to state that message has been accepted</returns> internal bool DownloadPage(DownloadMessage msg) { var uri = msg.DownloadUri; SysDiag.Debug.Assert(uri.IsAbsoluteUri, $"DownloadActor.DownloadPage({uri}) called with non-absolute Url"); var fs = msg.TargetPath; var fi = new FileInfo(fs); var dn = fi.DirectoryName; // string representing the directory's full path if (Directory.Exists(dn)) { if (msg.EnumDisposition == DownloadMessage.E_FileDisposition.LeaveIfExists && File.Exists(fs)) { var failmsg = new DownloadedMessage(msg, fs, HttpStatusCode.NotModified); Sender.Tell(failmsg); } } else { _Log.Info("DownloadPage creating directory {0} for {1}.{2}", dn, fi.Name, fi.Extension); Directory.CreateDirectory(dn); } // preserve volatile state now (before t1 that starts hot) for use by subsequent completion var ctx1 = new Context1(Sender, msg); var t1 = Client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead); // returns Task<HttpResponseMessage> var t2A = t1.ContinueWith((req, state) => { var ctx1A = state as Context1; // recover entry context var dlmsg = ctx1A.DownloadMessage; var status = req.Result.StatusCode; if (req.IsFaulted) { var s = ""; Console.WriteLine(); PostBack(dlmsg, ctx1A, status, req.Exception); } else { var hrm = req.Result; try { hrm.EnsureSuccessStatusCode(); // throw if !IsSuccessStatusCode // TODO: refine the destination filename.extn from the response // TODO: decide if file already exists and if overwrite/transform #pragma warning disable GCop302 // Since '{0}' implements IDisposable, wrap it in a using() statement var outfs = new FileStream(fs, FileMode.Create); // open stream to write file. Disposed later ! #pragma warning restore GCop302 // Since '{0}' implements IDisposable, wrap it in a using() statement _Log.Info($"DownloadActor.DownloadPage({msg.Url} => {fs}) started"); } catch (Exception excp1) { PostBack(dlmsg, ctx1A, status, excp1); } } }, ctx1); var t2 = t1.ContinueWith(GetStuff, ctx1, TaskContinuationOptions.OnlyOnRanToCompletion); // happy path (no cancel/fault) var t2F = t1.ContinueWith((req2, state) => { var ctx1f = (Context1)state; }, TaskContinuationOptions.NotOnRanToCompletion); var t3 = t2.ContinueWith(t_gotContent) .PipeTo(Self); // Task return(true); // show ActorSystem we handled message [expect next one immediately!] }