private void doLog(IEngineContext context){ if (waserror){ return; } try{ var conversation = myapp.conversation.Current; var stopwatch = conversation.Data[_stopwatch] as DateRange; stopwatch.Finish = DateTime.Now; conversation.Data.Remove(_stopwatch); var log = storage.New(); log.Range = stopwatch; log.Elapsed = (int) (stopwatch.Finish - stopwatch.Start).TotalMilliseconds; log.Usr = myapp.usrName; log.System = context.Request.Uri.GetLeftPart(UriPartial.Path).find(@"^\w+://[^/]+?/\w+"); log.Url = context.Request.Url; prepareLogEntry(log, context); using (var s = new TemporaryTransactionSession()){ storage.Save(log); s.Commit(); } } catch (Exception ex){ logger.get("comdiv.sys").Error("operation log error", ex); waserror = true; } }
public void Update(){ object target = null; using (var c = new TemporaryTransactionSession()){ var meta = Container.get<IMetadataHelper>().GetMeta(TargetType, GetAlias()); if (!meta.AllowEdit){ ErrorsController.RedirectToException(Context, this, new Exception( "Попытка обновления объекта, запрещенного для создания данным пользователем " + TargetType.FullName)); return; } MVCLog.Write(this, "ioc.getstart", null, ItemDesc); target = GetTarget(); new DefaultParametersBinder().Bind(target, editObjectPrefix, Params, GetAlias()); CommonPrepare(); try{ if (getIsValid("update", target)){ if (!getCustomPerformed("update", target)){ Db.Save(target); } MVCLog.Write(this, "ioc.getend", null, ItemDesc); c.Commit(); } } catch (Exception){ MVCLog.Write(this, "ioc.geterror", null, ItemDesc); throw; } } ReloadItem(target); }
public void Insert(){ object target = null; using (var c = new TemporaryTransactionSession()){ var meta = Container.get<IMetadataHelper>().GetMeta(TargetType, GetAlias()); if (!meta.AllowNew){ ErrorsController.RedirectToException(Context, this, new Exception( "Попытка создания объекта, запрещенного для создания данным пользователем " + TargetType.FullName)); return; } CancelView(); logInsertStart(); target = Db.New(TargetType); new DefaultParametersBinder().Bind(target, newObjectPrefix, Params, GetAlias()); SetupItem(target); CommonPrepare(); try{ if (getIsValid("insert", target)){ if (!getCustomPerformed("insert", target)){ Db.Save(target); Response.Write(((IWithId) target).Id.ToString(CultureInfo.InvariantCulture.NumberFormat)); } } logInsertEnd(); c.Commit(); } catch (Exception ex){ logInsertError(); Response.Write(ex.ToString()); } } ReloadItem(target); }
public void Delete(){ using (var c = new TemporaryTransactionSession()){ var meta = Container.get<IMetadataHelper>().GetMeta(TargetType, GetAlias()); if (!meta.AllowDelete){ ErrorsController.RedirectToException(Context, this, new Exception( "Попытка удаления объекта, запрещенного для создания данным пользователем " + TargetType.FullName)); return; } CancelView(); // ExecuteExtenders("^{0}action.delete.before."); //using (var s = new SessionScope()){ //DROPPED: TODO : Рефакторить и такая обработка нужна еще и в Update var obj = Db.Load(TargetType, Id); if (null == obj){ var template = "Невозможно удалить объект типа {0} c идентификатором {1}\r\nобъект уже отсутствует в базе"; Response.Write(String.Format(template, TargetType.Name, Id)); MVCLog.Write(this, "ioc.geterror", null, ItemDesc); return; } MVCLog.Write(this, "ioc.getstart", null, ItemDesc); try{ if (getIsValid("delete", obj)){ if (!getCustomPerformed("delete", obj)){ //TODO: Перенести этот блок преудаления в персистер if (obj is IWithHooks){ ((IWithHooks) obj).PreDelete(); } Db.Delete(obj); //c.SessionWrapper.Session.Delete(obj); MVCLog.Write(this, "ioc.getend", null, ItemDesc); } c.Commit(); } } catch (Exception e){ Response.Write(String.Format("{0} - {1}\r\n{2}", e.GetType().Name, e.Message, e)); MVCLog.Write(this, "ioc.geterror", null, ItemDesc); } } }
public void delete() { using (var tts = new TemporaryTransactionSession(myapp.ioc.get<ISessionFactoryProvider>().Get(System))) { var map = Enumerable.FirstOrDefault(myapp.ioc.get<IConfigurationProvider>().Get(this.System).ClassMappings, x => { if (Type.Contains(".")) { return x.EntityName.ToLower() == Type.ToLower(); } else { return x.EntityName.ToLower().EndsWith("." + Type.ToLower()); } }); var obj = tts.Session.Load(map.ClassName.toType(), Id); tts.Session.Delete(obj); tts.Session.Flush(); tts.Commit(); } RenderText("OK"); }
protected void tranaction(Action action){ using (var sw = new TemporaryTransactionSession()){ action(); sw.Commit(); } }