public static void Delete(this SsdsContainer source, IEnumerable <string> entities, Func <string, Exception, bool> onError) { object concurrency = new object(); Parallel.ForEach <string>(entities, delegate(string entityId, ParallelState ps) { try { source.Delete(entityId); } catch (Exception ex) { lock (concurrency) { if (!ps.IsStopped) { if (onError != null) { if (!onError(entityId, ex)) { ps.Stop(); } } } } } }); }
public string Update(Profile profile) { SsdsContainer c1 = DbContext.OpenContainer("Profile"); var p = c1.Single <Profile>(c => c.Entity.OpenId == profile.OpenId && c.Entity.IdType == profile.IdType ); if (p == null) { profile.LogOnTime = DateTime.Now; profile.RegisterTime = DateTime.Now; profile.Role = "User"; profile.Id = Guid.NewGuid().ToString(); c1.Insert(new SsdsEntity <Profile> { Id = profile.Id, Kind = "Profile", Entity = profile, }); return(profile.Id); } var newp = p.Entity; newp.Name = profile.Name; //if (profile.Name == "Öصä") // newp.Role = "Admin"; newp.NickName = profile.NickName; newp.School = profile.School; newp.SchoolDetails = profile.SchoolDetails; newp.Sex = profile.Sex; c1.Update(newp, p.Id, ConcurrencyPattern.IfNoneMatch); return(p.Id); }
public static void Update <T>(this SsdsContainer source, IEnumerable <SsdsEntity <T> > entities, Func <SsdsEntity <T>, Exception, bool> onError) where T : class, new() { object concurrency = new object(); Parallel.ForEach <SsdsEntity <T> >(entities, delegate(SsdsEntity <T> entity, ParallelState ps) { try { source.Update <T>(entity.Entity, entity.Id); } catch (Exception ex) { lock (concurrency) { if (!ps.IsStopped) { if (onError != null) { if (!onError(entity, ex)) { ps.Stop(); } } } } } }); }
public IEnumerable <Answer> Status() { SsdsContainer c1 = DbContext.OpenContainer("Answer"); return(c1.Query <Answer>(c => true).Select(c => c.Entity) .OrderByDescending(c => c.AddTime)); }
public static void Insert(this SsdsContainer source, IEnumerable <SsdsBlobEntity> entities, Func <SsdsBlobEntity, Exception, bool> onError) { object concurrency = new object(); Parallel.ForEach <SsdsBlobEntity>(entities, delegate(SsdsBlobEntity entity, ParallelState ps) { try { source.Insert(entity); } catch (Exception ex) { lock (concurrency) { if (!ps.IsStopped) { if (onError != null) { if (!onError(entity, ex)) { ps.Stop(); } } } } } }); }
public IEnumerable <Answer> QuestionStatus(string questionId, int page, int pageSize) { SsdsContainer c1 = DbContext.OpenContainer("Answer"); return(c1.Query <Answer>(c => c.Entity.QuestionId == questionId) .Select(c => c.Entity) .OrderByDescending(c => c.AddTime)); }
public IEnumerable <Profile> RankList(int n) { SsdsContainer c1 = DbContext.OpenContainer("Profile"); return(c1.Query <Profile>(c => true) .Select(c => c.Entity) .OrderByDescending(c => c.Accepted).Take(n)); }
public IEnumerable <Question> AllQuestion() { SsdsContainer c1 = DbContext.OpenContainer("Question"); return(c1 .Query <Question>(c => true) .Select(c => c.Entity) .OrderBy(c => c.AddTime)); }
public void Update(Wiki wiki) { SsdsContainer c1 = DbContext.OpenContainer("Wiki"); var m = c1.Single <Wiki>(c => c.Id == wiki.Id).Entity; m.Title = wiki.Title; m.Body = wiki.Body; c1.Update <Wiki>(m, wiki.Id, ConcurrencyPattern.Always); }
public void Add(Group group) { SsdsContainer c1 = DbContext.OpenContainer("Group"); group.BeginTime = DateTime.Now; group.EndTime = DateTime.Now; group.Id = Guid.NewGuid().ToString(); c1.Insert(group, group.Id); }
public Profile Details(string openId, string idType) { SsdsContainer c1 = DbContext.OpenContainer("Profile"); var ret = c1.Single <Profile>(c => c.Entity.IdType == idType && c.Entity.OpenId == openId); if (ret == null) { return(null); } return(ret.Entity); }
public void Add(Wiki wiki) { SsdsContainer c1 = DbContext.OpenContainer("Wiki"); wiki.Id = Guid.NewGuid().ToString(); c1.Insert <Wiki>(new SsdsEntity <Wiki> { Id = wiki.Id, Entity = wiki }); }
public void Add(Question question) { SsdsContainer c1 = DbContext.OpenContainer("Question"); var id = Guid.NewGuid().ToString(); question.Id = id; c1.Insert <Question>(new SsdsEntity <Question> { Id = id, Entity = question }); }
public void Update(Question question) { SsdsContainer c1 = DbContext.OpenContainer("Question"); var q = c1.Single <Question>(c => c.Id == question.Id).Entity; q.Title = question.Title; q.Body = question.Body; q.MemoryLimit = question.MemoryLimit; q.TimeLimit = question.TimeLimit; q.Test = question.Test; q.GroupId = question.GroupId; c1.Update <Question>(q, question.Id, ConcurrencyPattern.Always); }
public void SaveAnswer(Answer answer) { //answer SsdsContainer c1 = DbContext.OpenContainer("Answer"); c1.Insert(answer, answer.Id); var count = c1.Query <Answer>( c => c.Entity.QuestionId == answer.QuestionId && c.Entity.Status == (int)AnswerType.Accepted && c.Entity.UserId == answer.UserId && c.Id != answer.Id ).Count(); //question var answerType = (AnswerType)answer.Status; var c2 = DbContext.OpenContainer("Question"); var q = c2.Single <Question>( c => c.Id == answer.QuestionId ); if (q != null) { q.Entity.SubmitCount++; if (answerType == AnswerType.Accepted && count == 0) { q.Entity.AcceptedCount++; } c2.Update(q); } //user var c3 = DbContext.OpenContainer("Profile"); var p = c3.Single <Profile>(c => c.Id == answer.UserId); if (p != null) { p.Entity.Submit++; if (answerType == AnswerType.Accepted && count == 0) { p.Entity.Accepted++; } c3.Update(p); } }
public static void UpdateAsync <T>(this SsdsContainer source, IEnumerable <SsdsEntity <T> > entities, Action <IEnumerable <SsdsEntity <T> > > onUpdateComplete, Func <SsdsEntity <T>, Exception, bool> onError) where T : class, new() { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(delegate(object sender, DoWorkEventArgs e) { Update(source, entities, onError); }); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate(object sender, RunWorkerCompletedEventArgs e) { if (onUpdateComplete != null) { onUpdateComplete(entities); } }); worker.RunWorkerAsync(); }
public static void InsertAsync(this SsdsContainer source, IEnumerable <SsdsBlobEntity> entities, Action <IEnumerable <SsdsBlobEntity> > onInsertComplete, Func <SsdsBlobEntity, Exception, bool> onError) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new DoWorkEventHandler(delegate(object sender, DoWorkEventArgs e) { Insert(source, entities, onError); }); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate(object sender, RunWorkerCompletedEventArgs e) { if (onInsertComplete != null) { onInsertComplete(entities); } }); worker.RunWorkerAsync(); }
public Wiki Get(string title) { SsdsContainer c1 = DbContext.OpenContainer("Wiki"); return(c1.Single <Wiki>(c => c.Entity.Title == title).Entity); }
public void Delete(string id) { SsdsContainer c1 = DbContext.OpenContainer("Group"); c1.Delete(id); }
public void Delete(string id) { SsdsContainer c1 = DbContext.OpenContainer("Question"); c1.Delete(id); }
public Group GetGroup(string id) { SsdsContainer c1 = DbContext.OpenContainer("Group"); return(c1.Single <Group>(c => c.Entity.Id == id).Entity); }
public IEnumerable <Group> GroupList() { SsdsContainer c1 = DbContext.OpenContainer("Group"); return(c1.Query <Group>(c => true).Select(c => c.Entity)); }
public Wiki GetById(string id) { SsdsContainer c1 = DbContext.OpenContainer("Wiki"); return(c1.Single <Wiki>(c => c.Id == id).Entity); }
public IEnumerable <Wiki> List() { SsdsContainer c1 = DbContext.OpenContainer("Wiki"); return(c1.Query <Wiki>(c => true).Select(c => c.Entity)); }