VI.Projector.Database/VI.Projector.Database.Outstanding/OutstandingHandler.cs
Decompiler Source FileVI.Projector.Database.OutstandingHandlerSandbox DB
Interpretation
- Decompiled source file. Use method/event registrations and call-site extraction to connect back to DialogMethod, QBMEvent, and API layers.
Relations
- CallMethod: DeleteOutstanding at line 91
- Generate: HandleOutStanding at line 112
- UnitOfWork.Generate: HandleOutStanding at line 112
Typed Edges
- No typed edges extracted for this source.
References
- No direct source references extracted.
Referenced By
- No direct source references extracted.
C# source-derived context
Generated by pattern extraction from the decompiled C# source and decompile index. This is factual source evidence, not inferred behavior.
references DB/Dialog objects Job/process related markers
Summary: classes OutstandingHandler; methods ExecuteAction, GetDependencies, _Translate, _ExecuteAction, _ExecuteOperationByCustomizers, Reset; references DialogTable, ESet, JobChain, JobEventGen, QBMClrType, QBMEvent; markers references DB/Dialog objects, Job/process related markers
Classes
OutstandingHandlerMethods
DB/Dialog object references
OIM key/entity markers
UID_DialogTable UID_JobChain UID_QBMEventAPI/entity calls
CallMethod StartUnitOfWork StartTempQueue MetaData From SourceRegistrations / handlers
None extracted.
Complete Source
1using System;2using System.Collections;3using System.Collections.Generic;4using System.Linq;5using System.Reflection;6using System.Runtime.CompilerServices;7using System.Threading;8using NLog;9using VI.Base;10using VI.DB;11using VI.DB.DataAccess;12using VI.DB.Entities;13using VI.DB.MetaData;14using VI.DB.Outstanding;15using VI.DB.Sync;16using VI.Projector.Database.Internal;1718namespace VI.Projector.Database.Outstanding;1920public abstract class OutstandingHandler21{22 private LogSession m_Log;2324 private readonly IDependencyResolver m_DepsResolver;2526 private readonly Lazy<HashSet<string>> m_TableWithHandleOutstandingChain;2728 private readonly ResetLazy<IOutstandingHandlingCustomizer[]> m_Customizers;2930 [field: CompilerGenerated]31 internal static IOutstandingHandlingCustomizer TestCustomizer32 {33 [CompilerGenerated]34 get;35 [CompilerGenerated]36 set;37 }3839 [field: CompilerGenerated]40 protected ISession Session41 {42 [CompilerGenerated]43 get;44 }4546 [field: CompilerGenerated]47 public string NameSpace48 {49 [CompilerGenerated]50 get;51 }5253 [field: CompilerGenerated]54 public bool UseBulkProcessing55 {56 [CompilerGenerated]57 get;58 [CompilerGenerated]59 set;60 }6162 protected LogSession Log => m_Log ?? (m_Log = new LogSession("OutstandingHandler", ((object)Guid.NewGuid()/*cast due to .constrained prefix*/).ToString()));6364 protected OutstandingHandler(ISession session, string nameSpace)65 {66 //IL_0011: Unknown result type (might be due to invalid IL or missing references)67 Session = session ?? throw new ArgumentNullException("session");68 m_DepsResolver = ((Session != null) ? new DependencyResolverLowLevel(Session) : null);69 NameSpace = nameSpace;70 m_TableWithHandleOutstandingChain = new Lazy<HashSet<string>>((Func<HashSet<string>>)_TableWithHandleOutstandingChainFactory, (LazyThreadSafetyMode)1);71 m_Customizers = new ResetLazy<IOutstandingHandlingCustomizer[]>(_LoadCustomizers, (LazyThreadSafetyMode)1);72 }7374 public void ExecuteAction(OutstandingAction action, System.Collections.Generic.IEnumerable<IEntity> entities, bool checkAndConfirmDependencies = true)75 {76 //IL_0008: Unknown result type (might be due to invalid IL or missing references)77 if (entities == null)78 {79 throw new ArgumentNullException("entities");80 }81 IEntity[] array = entities.ToArraySmart();82 if (array.Length == 0)83 {84 return;85 }86 switch (action)87 {88 case OutstandingAction.Delete:89 _ExecuteAction(OutstandingAction.Delete, (System.Collections.Generic.IReadOnlyCollection<IEntity>)(object)array, checkAndConfirmDependencies, delegate(IUnitOfWork unit, IEntity entity)90 {91 entity.CallMethod("DeleteOutstanding");92 unit.Put(entity);93 });94 break;95 case OutstandingAction.DeleteState:96 using (new DatabaseSyncBlock(Session, import: false, systemSyncMode: false))97 {98 _ExecuteAction(OutstandingAction.DeleteState, (System.Collections.Generic.IReadOnlyCollection<IEntity>)(object)array, checkAndConfirmDependencies, delegate(IUnitOfWork unit, IEntity entity)99 {100 entity.State &= ~EntityState.OutStanding;101 unit.Put(entity);102 });103 break;104 }105 case OutstandingAction.Publish:106 _ExecuteAction(OutstandingAction.Publish, (System.Collections.Generic.IReadOnlyCollection<IEntity>)(object)array, checkAndConfirmDependencies, [CompilerGenerated] (IUnitOfWork unit, IEntity entity) =>107 {108 entity.State &= ~EntityState.OutStanding;109 unit.Put(entity);110 if (m_TableWithHandleOutstandingChain.Value.ContainsKey(entity.Tablename))111 {112 unit.Generate(entity, "HandleOutStanding");113 }114 });115 break;116 }117 }118119 public DependencyCheckResult GetDependencies(OutstandingAction actionType, System.Collections.Generic.IEnumerable<IEntity> entities)120 {121 //IL_0008: Unknown result type (might be due to invalid IL or missing references)122 if (entities == null)123 {124 throw new ArgumentNullException("entities");125 }126 if (actionType == OutstandingAction.Delete || actionType == OutstandingAction.Publish)127 {128 OutstandingDependency[] array = m_DepsResolver.GetDependencies(entities, actionType == OutstandingAction.Publish).ToArraySmart();129 if (array != null && array.Length != 0)130 {131 return new DependencyCheckResult(array, Enumerable.Where<OutstandingDependency>((System.Collections.Generic.IEnumerable<OutstandingDependency>)array, (Func<OutstandingDependency, bool>)((OutstandingDependency d) => d.SortOrder > 0 && d.IsPureDependency)).ToArraySmart());132 }133 return null;134 }135 return null;136 }137138 private OutstandingOperation _Translate(OutstandingAction action)139 {140 return action switch141 {142 OutstandingAction.Delete => OutstandingOperation.Delete, 143 OutstandingAction.Publish => OutstandingOperation.Publish, 144 _ => (OutstandingOperation)(-1), 145 };146 }147148 private void _ExecuteAction(OutstandingAction actionType, System.Collections.Generic.IReadOnlyCollection<IEntity> entities, bool checkAndConfirmDependencies, Action<IUnitOfWork, IEntity> action)149 {150 OutstandingOperation operation = _Translate(actionType);151 DependencyCheckResult dependencyCheckResult = (checkAndConfirmDependencies ? GetDependencies(actionType, (System.Collections.Generic.IEnumerable<IEntity>)entities) : null);152 if (dependencyCheckResult != null && dependencyCheckResult.ToConfirm.Length != 0 && !OnConfirm(dependencyCheckResult.Dependencies, actionType))153 {154 return;155 }156 try157 {158 Session.Variables["NoCollisionTest"] = true;159 Session.Variables["ManageOutstanding"] = true;160 Session.Variables["ManageOutstandingOperation"] = ((object)actionType/*cast due to .constrained prefix*/).ToString();161 if (dependencyCheckResult != null)162 {163 dependencyCheckResult.Dependencies.ForEach(delegate(OutstandingDependency d)164 {165 d.Entity = null;166 });167 LoadEntities(Session, (System.Collections.Generic.IReadOnlyCollection<OutstandingDependency>)(object)dependencyCheckResult.Dependencies, full: true);168 if (actionType != OutstandingAction.DeleteState)169 {170 OutstandingOperationRestriction[] depsRestrictions = Enumerable.ToArray<OutstandingOperationRestriction>(Enumerable.Where<OutstandingOperationRestriction>(((System.Collections.Generic.IEnumerable<OutstandingOperationRestriction>)GetOperationsRestrictions((System.Collections.Generic.IReadOnlyCollection<IEntity>)(object)Enumerable.ToArray<IEntity>(Enumerable.Select<OutstandingDependency, IEntity>((System.Collections.Generic.IEnumerable<OutstandingDependency>)dependencyCheckResult.Dependencies, (Func<OutstandingDependency, IEntity>)((OutstandingDependency d) => d.Entity))))).AvoidNull(), (Func<OutstandingOperationRestriction, bool>)((OutstandingOperationRestriction r) => r.Operation == operation)));171 IEntity[] array = Enumerable.ToArray<IEntity>(Enumerable.Where<IEntity>((System.Collections.Generic.IEnumerable<IEntity>)entities, (Func<IEntity, bool>)((IEntity e) => Enumerable.Any<OutstandingOperationRestriction>((System.Collections.Generic.IEnumerable<OutstandingOperationRestriction>)depsRestrictions, (Func<OutstandingOperationRestriction, bool>)((OutstandingOperationRestriction r) => r.AffectsEntity(e))))));172 if (array.Length != 0)173 {174 OnAbort((System.Collections.Generic.IReadOnlyCollection<IEntity>)(object)array, actionType);175 return;176 }177 }178 }179 System.Collections.Generic.IReadOnlyCollection<IEntity> readOnlyCollection = (System.Collections.Generic.IReadOnlyCollection<IEntity>)(object)((dependencyCheckResult != null) ? Enumerable.ToArray<IEntity>(Enumerable.Select<OutstandingDependency, IEntity>((System.Collections.Generic.IEnumerable<OutstandingDependency>)dependencyCheckResult.Dependencies, (Func<OutstandingDependency, IEntity>)((OutstandingDependency d) => d.Entity))) : null);180 System.Collections.Generic.IReadOnlyCollection<IEntity> readOnlyCollection2 = readOnlyCollection ?? entities;181 System.Collections.Generic.IEnumerator<IEntity> enumerator;182 if (UseBulkProcessing)183 {184 using (Transaction transaction = new Transaction(Session))185 {186 using TransactionList transactionList = new TransactionList();187 using IUnitOfWork unitOfWork = Session.StartUnitOfWork();188 Session.StartTempQueue();189 transactionList.Add(Session);190 readOnlyCollection2 = (System.Collections.Generic.IReadOnlyCollection<IEntity>)(((object)_ExecuteOperationByCustomizers(readOnlyCollection2, operation, unitOfWork, transactionList)) ?? ((object)System.Array.Empty<IEntity>()));191 enumerator = ((System.Collections.Generic.IEnumerable<IEntity>)readOnlyCollection2).GetEnumerator();192 try193 {194 while (((System.Collections.IEnumerator)enumerator).MoveNext())195 {196 IEntity current = enumerator.Current;197 transactionList.Add(current);198 action.Invoke(unitOfWork, current);199 }200 }201 finally202 {203 ((System.IDisposable)enumerator)?.Dispose();204 }205 unitOfWork.Commit();206 transactionList.Commit();207 transaction.Commit();208 return;209 }210 }211 enumerator = ((System.Collections.Generic.IEnumerable<IEntity>)readOnlyCollection2).GetEnumerator();212 try213 {214 while (((System.Collections.IEnumerator)enumerator).MoveNext())215 {216 IEntity current2 = enumerator.Current;217 try218 {219 using TransactionList transactionList2 = new TransactionList();220 using IUnitOfWork unitOfWork2 = Session.StartUnitOfWork();221 transactionList2.Add(Session);222 transactionList2.Add(current2);223 System.Collections.Generic.IEnumerator<IEntity> enumerator2 = ((System.Collections.Generic.IEnumerable<IEntity>)_ExecuteOperationByCustomizers((System.Collections.Generic.IReadOnlyCollection<IEntity>)(object)new IEntity[1] { current2 }, operation, unitOfWork2, transactionList2)).AvoidNull().GetEnumerator();224 try225 {226 while (((System.Collections.IEnumerator)enumerator2).MoveNext())227 {228 IEntity current3 = enumerator2.Current;229 action.Invoke(unitOfWork2, current3);230 }231 }232 finally233 {234 ((System.IDisposable)enumerator2)?.Dispose();235 }236 unitOfWork2.Commit();237 transactionList2.Commit();238 }239 catch (System.Exception ex)240 {241 OnHandleException(ex);242 }243 }244 }245 finally246 {247 ((System.IDisposable)enumerator)?.Dispose();248 }249 }250 finally251 {252 Session.Variables.Remove("NoCollisionTest");253 Session.Variables.Remove("ManageOutstanding");254 Session.Variables.Remove("ManageOutstandingOperation");255 }256 }257258 private System.Collections.Generic.IReadOnlyCollection<IEntity> _ExecuteOperationByCustomizers(System.Collections.Generic.IReadOnlyCollection<IEntity> entities, OutstandingOperation operation, IUnitOfWork unit, TransactionList transaction)259 {260 if (operation != OutstandingOperation.Delete && operation != OutstandingOperation.Publish)261 {262 return entities;263 }264 OutstandingHandlingCustomizer.ExecutionArgs args = new OutstandingHandlingCustomizer.ExecutionArgs(transaction);265 System.Collections.Generic.IEnumerator<IOutstandingHandlingCustomizer> enumerator = ((System.Collections.Generic.IEnumerable<IOutstandingHandlingCustomizer>)Enumerable.OrderByDescending<IOutstandingHandlingCustomizer, int>((System.Collections.Generic.IEnumerable<IOutstandingHandlingCustomizer>)m_Customizers.Value, (Func<IOutstandingHandlingCustomizer, int>)((IOutstandingHandlingCustomizer c) => c.Priority))).GetEnumerator();266 try267 {268 while (((System.Collections.IEnumerator)enumerator).MoveNext())269 {270 entities = (System.Collections.Generic.IReadOnlyCollection<IEntity>)(((object)enumerator.Current.ExecuteOperation(entities, NameSpace, operation, unit, args)) ?? ((object)System.Array.Empty<IEntity>()));271 if (entities.Count == 0)272 {273 break;274 }275 }276 }277 finally278 {279 ((System.IDisposable)enumerator)?.Dispose();280 }281 return entities;282 }283284 public void Reset()285 {286 m_Customizers.Reset();287 }288289 public static void LoadEntities(ISession session, System.Collections.Generic.IReadOnlyCollection<OutstandingDependency> depsToLoad, bool full)290 {291 //IL_0008: Unknown result type (might be due to invalid IL or missing references)292 //IL_0016: Unknown result type (might be due to invalid IL or missing references)293 if (session == null)294 {295 throw new ArgumentNullException("session");296 }297 if (depsToLoad == null)298 {299 throw new ArgumentNullException("depsToLoad");300 }301 OutstandingDependency[] array = Enumerable.Where<OutstandingDependency>((System.Collections.Generic.IEnumerable<OutstandingDependency>)depsToLoad, (Func<OutstandingDependency, bool>)((OutstandingDependency d) => d.Entity == null)).ToArraySmart();302 if (array.Length == 0)303 {304 return;305 }306 System.Collections.Generic.IEnumerator<IGrouping<string, OutstandingDependency>> enumerator = Enumerable.GroupBy<OutstandingDependency, string>((System.Collections.Generic.IEnumerable<OutstandingDependency>)array, (Func<OutstandingDependency, string>)((OutstandingDependency d) => d.Tablename.ToLowerInvariant())).GetEnumerator();307 try308 {309 IEntity entity = default(IEntity);310 while (((System.Collections.IEnumerator)enumerator).MoveNext())311 {312 IGrouping<string, OutstandingDependency> current = enumerator.Current;313 IMetaTable table = session.MetaData().GetTable(current.Key);314 ISqlFormatter sqlFormatter = session.Resolve<ISqlFormatter>();315 System.Collections.Generic.IEnumerator<System.Collections.Generic.IReadOnlyList<OutstandingDependency>> enumerator2 = ((System.Collections.Generic.IEnumerable<OutstandingDependency>)current).Partition(sqlFormatter.InClauseLimit).GetEnumerator();316 try317 {318 while (((System.Collections.IEnumerator)enumerator2).MoveNext())319 {320 System.Collections.Generic.IReadOnlyList<OutstandingDependency> current2 = enumerator2.Current;321 ISelect obj = Query.From(table.Tablename).Where(sqlFormatter.InClause("xobjectkey", ValType.String, FormatterOptions.NonUnicodeLiterals, (System.Collections.IEnumerable)Enumerable.Select<OutstandingDependency, string>((System.Collections.Generic.IEnumerable<OutstandingDependency>)current2, (Func<OutstandingDependency, string>)((OutstandingDependency d) => d.Objectkey))));322 Query query = (full ? obj.SelectAll() : obj.Select("xobjectkey"));323 query.DisplayPattern(table.DisplayPatternLong.Translated);324 Dictionary<string, IEntity> val = Enumerable.ToDictionary<IEntity, string>((System.Collections.Generic.IEnumerable<IEntity>)session.Source().GetCollection(query, (EntityCollectionLoadType)((full ? 1 : 0) | 0xA00)), (Func<IEntity, string>)((IEntity e) => e.GetRaw("xobjectkey").ToString()));325 System.Collections.Generic.IEnumerator<OutstandingDependency> enumerator3 = ((System.Collections.Generic.IEnumerable<OutstandingDependency>)current2).GetEnumerator();326 try327 {328 while (((System.Collections.IEnumerator)enumerator3).MoveNext())329 {330 OutstandingDependency current3 = enumerator3.Current;331 if (val.TryGetValue(current3.Objectkey, ref entity))332 {333 current3.Entity = entity;334 }335 }336 }337 finally338 {339 ((System.IDisposable)enumerator3)?.Dispose();340 }341 }342 }343 finally344 {345 ((System.IDisposable)enumerator2)?.Dispose();346 }347 }348 }349 finally350 {351 ((System.IDisposable)enumerator)?.Dispose();352 }353 string text = string.Join(Environment.NewLine, Enumerable.Select<OutstandingDependency, string>(Enumerable.Where<OutstandingDependency>((System.Collections.Generic.IEnumerable<OutstandingDependency>)depsToLoad, (Func<OutstandingDependency, bool>)((OutstandingDependency d) => d.Entity == null)), (Func<OutstandingDependency, string>)((OutstandingDependency d) => d.Objectkey)));354 if (text.Length <= 0)355 {356 return;357 }358 throw new ViException(1779037, text);359 }360361 public string GetTableWhereClause(string tableName)362 {363 if (string.IsNullOrEmpty(tableName))364 {365 return null;366 }367 ISqlFormatter sqlFormatter = Session.Resolve<ISqlFormatter>();368 IStatementBuilder sb = Session.Resolve<IStatementBuilder>();369 return sqlFormatter.AndRelation(Enumerable.ToArray<string>(Enumerable.Where<string>(Enumerable.Select<IFilterClause, string>(Enumerable.Select<IOutstandingHandlingCustomizer, IFilterClause>((System.Collections.Generic.IEnumerable<IOutstandingHandlingCustomizer>)m_Customizers.Value, (Func<IOutstandingHandlingCustomizer, IFilterClause>)((IOutstandingHandlingCustomizer c) => c.GetTableFilter(NameSpace, tableName))), (Func<IFilterClause, string>)delegate(IFilterClause c)370 {371 //IL_0031: Unknown result type (might be due to invalid IL or missing references)372 //IL_0037: Unknown result type (might be due to invalid IL or missing references)373 //IL_0062: Unknown result type (might be due to invalid IL or missing references)374 if (c is WhereClause whereClause)375 {376 return whereClause.Where;377 }378 if (c is ExpressionClause clause)379 {380 return sb.FormatExpressionAsync(new TableReference(tableName), clause).Result;381 }382 if (c == null)383 {384 return (string)null;385 }386 throw new NotImplementedException("Unknown type of clause (" + ((MemberInfo)((object)c).GetType()).Name + ").");387 }), (Func<string, bool>)((string wc) => wc != null))));388 }389390 public System.Collections.Generic.IReadOnlyCollection<OutstandingOperationRestriction> GetOperationsRestrictions(System.Collections.Generic.IReadOnlyCollection<IEntity> entities)391 {392 return (System.Collections.Generic.IReadOnlyCollection<OutstandingOperationRestriction>)(object)Enumerable.ToArray<OutstandingOperationRestriction>(Enumerable.Where<OutstandingOperationRestriction>(Enumerable.SelectMany<IOutstandingHandlingCustomizer, OutstandingOperationRestriction>((System.Collections.Generic.IEnumerable<IOutstandingHandlingCustomizer>)m_Customizers.Value, (Func<IOutstandingHandlingCustomizer, System.Collections.Generic.IEnumerable<OutstandingOperationRestriction>>)((IOutstandingHandlingCustomizer c) => (System.Collections.Generic.IEnumerable<OutstandingOperationRestriction>)c.GetOperationsRestrictions(entities, NameSpace))), (Func<OutstandingOperationRestriction, bool>)((OutstandingOperationRestriction i) => i != null)));393 }394395 protected abstract bool OnConfirm(OutstandingDependency[] dependencies, OutstandingAction action);396397 protected virtual void OnAbort(System.Collections.Generic.IReadOnlyCollection<IEntity> depsWithRestrictions, OutstandingAction action)398 {399 string text = "- " + string.Join<IEntity>(Environment.NewLine + "- ", Enumerable.Take<IEntity>((System.Collections.Generic.IEnumerable<IEntity>)Enumerable.OrderBy<IEntity, string>((System.Collections.Generic.IEnumerable<IEntity>)depsWithRestrictions, (Func<IEntity, string>)((IEntity e) => e.Display)), 10));400 if (depsWithRestrictions.Count > 10)401 {402 text = text + Environment.NewLine + "...";403 }404 throw new ViException(1779034, ((object)action/*cast due to .constrained prefix*/).ToString(), text);405 }406407 private HashSet<string> _TableWithHandleOutstandingChainFactory()408 {409 return Enumerable.ToHashSet<string>(Enumerable.Select<IEntity, string>((System.Collections.Generic.IEnumerable<IEntity>)Session.Source().GetCollection(Query.From("DialogTable").Where("UID_DialogTable in \r\n(\r\n\tselect jc.UID_DialogTable from JobChain jc \r\n\t\tjoin JobEventGen jeg on jc.UID_JobChain = jeg.UID_JobChain\r\n\t\tjoin QBMEvent qe on qe.UID_QBMEvent = jeg.UID_QBMEvent and qe.EventName=N'HandleOutStanding'\r\n)").Select("TableName"), EntityCollectionLoadType.Slim), (Func<IEntity, string>)((IEntity e) => e.GetRaw("TableName").ToString())), (IEqualityComparer<string>)(object)StringComparer.OrdinalIgnoreCase);410 }411412 private IOutstandingHandlingCustomizer[] _LoadCustomizers()413 {414 List<IOutstandingHandlingCustomizer> obj = new List<IOutstandingHandlingCustomizer>();415 obj.Add((IOutstandingHandlingCustomizer)new BasicOutstandingCustomizer(new OutstandingHandlingCustomizer.Setup(Session)));416 List<IOutstandingHandlingCustomizer> val = obj;417 if (TestCustomizer != null)418 {419 val.Add(TestCustomizer);420 }421 System.Collections.Generic.IEnumerator<IEntity> enumerator = ((System.Collections.Generic.IEnumerable<IEntity>)Session.Source().GetCollection((from c in Query.From("QBMClrType")422 where c.Column("ExposedInterface").IsEqualTo("VI.DB.Outstanding.IOutstandingHandlingCustomizer")423 select c).SelectAll(), EntityCollectionLoadType.Slim)).GetEnumerator();424 try425 {426 while (((System.Collections.IEnumerator)enumerator).MoveNext())427 {428 IEntity current = enumerator.Current;429 string text = current.GetRaw("Assembly").ToString();430 IOutstandingHandlingCustomizer outstandingHandlingCustomizer = (IOutstandingHandlingCustomizer)Activator.CreateInstance(TypeLoader.GetType($"{current.GetRaw("FullTypeName")}, {text}", throwOnError: true), new object[1]431 {432 new OutstandingHandlingCustomizer.Setup(Session)433 });434 val.Add(outstandingHandlingCustomizer);435 }436 }437 finally438 {439 ((System.IDisposable)enumerator)?.Dispose();440 }441 return val.ToArray();442 }443444 protected abstract void OnHandleException(System.Exception ex);445}446