public static async Task CreatedAsync <T>(T entity, IContextInfo context) { var createListeners = Loader.GetEntriesFor <IListenCreated <T> >(); foreach (var createListener in createListeners) { await((IListenCreated <T>)createListener).OnCreatedAsync(entity, context); } }
public static async Task ModificationFailedAsync <T>(T original, T modified, IContextInfo context) { var modifyListeners = Loader.GetEntriesFor <IListenModificationFailed <T> >(); foreach (var listener in modifyListeners) { await((IListenModificationFailed <T>)listener).OnModificationFailedAsync(original, modified, context); } }
private void clearContextInfo(sql.SqlConnection connection, IContextInfo contextInfo) { if (contextInfo == null || string.IsNullOrWhiteSpace(contextInfo.Key)) { return; } setSessionContext(connection, contextInfo.Key, null); }
public static async Task RemoveFailedAsync <T>(T entity, IContextInfo context) { var modifyListeners = Loader.GetEntriesFor <IListenRemoveFailed <T> >(); foreach (var listener in modifyListeners) { await((IListenRemoveFailed <T>)listener).OnRemoveFailedAsync(entity, context); } }
public void AddContext(string contextType) { IContextInfo newContext = logContextFactory.Create(contextType); if (newContext != null) { logContext.Add(newContext); } }
// output context information, not required, but useful // information for the translator private void WriteContext(string ContextContent) { IContextProperties contextProperties = PropertiesFactory.CreateContextProperties(); IContextInfo contextInfo = PropertiesFactory.CreateContextInfo(ContextContent); contextInfo.DisplayCode = "EL"; contextInfo.DisplayName = "Element"; contextInfo.Description = ContextContent; contextInfo.DisplayColor = Color.Beige; contextProperties.Contexts.Add(contextInfo); Output.ChangeContext(contextProperties); }
public string GetAdditionalInformation(IContextInfo context) { var additionalInfo = new StringBuilder(); foreach (var metaPair in context.MetaData) { var metaDataInfoDescriptionKey = PluginResources.ResourceManager.GetString("StructureContextInfo_MetaKey_" + metaPair.Key); if (!string.IsNullOrEmpty(metaDataInfoDescriptionKey)) { additionalInfo.Append($"{metaDataInfoDescriptionKey}: {GetMetaValue(metaPair.Value)}; "); } } return(additionalInfo.ToString()); }
public virtual async Task OnModificationFailedAsync(T original, T modified, IContextInfo user) { if (original != null) { EntitesWereNotTheSameOnCalling = !original.Equals(modified); } else if (modified != null) { EntitesWereNotTheSameOnCalling = !modified.Equals(original); } else { EntitesWereNotTheSameOnCalling = false; } WasOnModificationFailedCalled = true; }
private IContextProperties CreateContext(string unitId) { IContextProperties contextProperties = PropertiesFactory.CreateContextProperties(); IContextInfo contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.Paragraph); contextInfo.Purpose = ContextPurpose.Information; // add unit id as metadata IContextInfo contextId = PropertiesFactory.CreateContextInfo("UnitId"); contextId.SetMetaData("UnitID", unitId); contextId.Description = "Original paragraph unit id"; contextId.DisplayCode = "ID"; contextProperties.Contexts.Add(contextInfo); contextProperties.Contexts.Add(contextId); return(contextProperties); }
private static string GetColorFromMetadata(IContextInfo contextInfo) { if (contextInfo.HasMetaData && contextInfo.MetaDataContainsKey("ParagraphFormatting")) { var paragraphValue = contextInfo.GetMetaData("ParagraphFormatting"); if (paragraphValue.Contains("color")) { var regex = new Regex("(w:val=\"[0-9a-fA-F]*\")"); var matches = regex.Matches(paragraphValue); foreach (Match match in matches) { var value = match.Value; //color string is like this "code" - we need to remove the "" characters var color = value.Substring(value.IndexOf('"') + 1).TrimEnd('"'); return(color); } } } return(string.Empty); }
private IContextProperties CreateContext(string id, string paraId) { IContextProperties contextProperties = PropertiesFactory.CreateContextProperties(); IContextInfo contextId = PropertiesFactory.CreateContextInfo("id"); contextId.SetMetaData("ID", id); contextId.Description = "Trans-unit id"; contextId.DisplayCode = "ID"; IContextInfo contextParaId = PropertiesFactory.CreateContextInfo("para-id"); contextParaId.SetMetaData("PARA ID", paraId); contextParaId.Description = "Para-id"; contextParaId.DisplayCode = "PARA ID"; contextProperties.Contexts.Add(contextId); contextProperties.Contexts.Add(contextParaId); return(contextProperties); }
private IContextProperties CreateContext(string spec, string unitID) { // context info for type information, e.g. heading, paragraph, etc. IContextProperties contextProperties = PropertiesFactory.CreateContextProperties(); IContextInfo contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.Paragraph); contextInfo.Purpose = ContextPurpose.Information; // add unit id as metadata IContextInfo contextId = PropertiesFactory.CreateContextInfo("UnitId"); contextId.SetMetaData("UnitID", unitID); switch (spec) { case "Heading": contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.Topic); contextInfo.DisplayColor = Color.Green; break; case "Box": contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.TextBox); contextInfo.DisplayColor = Color.Gold; break; case "Paragraph": contextInfo = PropertiesFactory.CreateContextInfo(StandardContextTypes.Paragraph); contextInfo.DisplayColor = Color.Silver; break; default: break; } contextProperties.Contexts.Add(contextInfo); contextProperties.Contexts.Add(contextId); return(contextProperties); }
public override async Task <IQueryable <MockEntity> > AuthorizeCollectionAsync(IQueryable <MockEntity> entities, IContextInfo ctx) { return(await Task.Factory.StartNew(() => entities.Where(a => a.IsVisible))); }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public override async Task <AuthorizationResult> CanCreateAsync(MockEntity entity, IContextInfo ctx) { if (entity.IsValid) { return(AuthorizationResult.Success()); } return(AuthorizationResult.Fail("The entity is not valid :( ", entity)); }
public override async Task <IQueryable <DummyClass> > AuthorizeCollectionAsync(IQueryable <DummyClass> entities, IContextInfo ctx) { return(await Task.Factory.StartNew(() => entities)); }
public static void RemoveFailed <T>(T entity, IContextInfo context) { RemoveFailedAsync(entity, context).Wait(); }
public static async Task <IEnumerable <AuthorizationResult> > ModifyAsync <T>(T originalEntity, T modifiedEntity, IContextInfo context) { var modifyAuthorizers = Loader.GetEntriesFor <IAuthorizeModify <T> >(); List <AuthorizationResult> results = new List <AuthorizationResult>(); foreach (var authorizer in modifyAuthorizers) { var auth = (IAuthorizeModify <T>)authorizer; results.Add(await auth.CanModifyAsync(originalEntity, modifiedEntity, context)); } return(results); }
public void Remove(IContextInfo info) { contextInfo.Remove(info); }
public static void ModificationFailed <T>(T original, T modified, IContextInfo context) { ModificationFailedAsync(original, modified, context).Wait(); }
public override async Task OnRemovedAsync(MockEntity entity, IContextInfo context) { await base.OnRemovedAsync(entity, context); RemovedEntities.Add(entity); }
public void Add(IContextInfo info) { contextInfo.Add(info); }
public static T BeforeModify <T>(T originalEntity, T modifiedEntity, IContextInfo context) { var modifyInterpreters = Loader.GetEntriesFor <IInterpretBeforeModify <T, T> >(); return(modifyInterpreters.Cast <IInterpretBeforeModify>().Aggregate(modifiedEntity, (current, intr) => (T)intr.DoInterpret(originalEntity, current, context))); }
public abstract Task <AuthorizationResult> CanModifyAsync(T originalEntity, T modifiedEntity, IContextInfo ctx);
public static async Task <IQueryable <T> > CollectionAsync <T>(IQueryable <T> entities, IContextInfo context) where T : class { var collectionAuthorizers = Loader.GetEntriesFor <IAuthorizeCollection <T, T> >(); foreach (var collectionAuthorizer in collectionAuthorizers) { var auth = (IAuthorizeCollection)collectionAuthorizer; entities = (await auth.AuthorizeCollectionAsync(entities, context)).Cast <T>(); } return(entities); }
public static async Task <IEnumerable <AuthorizationResult> > RemoveAsync <T>(T entity, IContextInfo context) { var removeAuthorizers = Loader.GetEntriesFor <IAuthorizeRemove <T> >(); List <AuthorizationResult> results = new List <AuthorizationResult>(); foreach (var authorizer in removeAuthorizers) { var auth = (IAuthorizeRemove <T>)authorizer; results.Add(await auth.CanRemoveAsync(entity, context)); } return(results); }
public override async Task OnModifiedAsync(MockEntity originalEntity, MockEntity modifiedEntity, IContextInfo context) { await base.OnModifiedAsync(originalEntity, modifiedEntity, context); ModifiedOriginalEntities.Add(originalEntity); ModifiedNewEntities.Add(modifiedEntity); }
public virtual async Task OnCreateFailedAsync(T entity, IContextInfo user) { WasOnCreationValidationFailedCalled = true; }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public override async Task <AuthorizationResult> CanModifyAsync(MockEntity originalEntity, MockEntity modifiedEntity, IContextInfo ctx) { if (modifiedEntity.IsValid) { return(AuthorizationResult.Success()); } return(AuthorizationResult.Fail("The entity is not valid :( ", modifiedEntity)); }
public virtual async Task OnRemoveFailedAsync(T entity, IContextInfo user) { WasOnDeletionFailedCalled = true; }
public static IQueryable <T> Collection <T>(IQueryable <T> entities, IContextInfo context) where T : class { return(CollectionAsync <T>(entities, context).Result); }
public static T BeforeCreate <T>(T entity, IContextInfo context) { var createInterpreters = Loader.GetEntriesFor <IInterpretBeforeCreate <T, T> >(); return(createInterpreters.Cast <IInterpretBeforeCreate>().Aggregate(entity, (current, intr) => (T)intr.DoInterpret(current, context))); }
public static void CreateFailed <T>(T entity, IContextInfo context) { CreateFailedAsync(entity, context).Wait(); }