Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        private void clearContextInfo(sql.SqlConnection connection, IContextInfo contextInfo)
        {
            if (contextInfo == null || string.IsNullOrWhiteSpace(contextInfo.Key))
            {
                return;
            }

            setSessionContext(connection, contextInfo.Key, null);
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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());
        }
Пример #8
0
 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;
 }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #13
0
 public override async Task <IQueryable <MockEntity> > AuthorizeCollectionAsync(IQueryable <MockEntity> entities, IContextInfo ctx)
 {
     return(await Task.Factory.StartNew(() => entities.Where(a => a.IsVisible)));
 }
Пример #14
0
#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));
        }
Пример #15
0
 public override async Task <IQueryable <DummyClass> > AuthorizeCollectionAsync(IQueryable <DummyClass> entities, IContextInfo ctx)
 {
     return(await Task.Factory.StartNew(() => entities));
 }
Пример #16
0
 public static void RemoveFailed <T>(T entity, IContextInfo context)
 {
     RemoveFailedAsync(entity, context).Wait();
 }
Пример #17
0
        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);
        }
Пример #18
0
 public void Remove(IContextInfo info)
 {
     contextInfo.Remove(info);
 }
Пример #19
0
 public static void ModificationFailed <T>(T original, T modified, IContextInfo context)
 {
     ModificationFailedAsync(original, modified, context).Wait();
 }
Пример #20
0
        public override async Task OnRemovedAsync(MockEntity entity, IContextInfo context)
        {
            await base.OnRemovedAsync(entity, context);

            RemovedEntities.Add(entity);
        }
Пример #21
0
 public void Add(IContextInfo info)
 {
     contextInfo.Add(info);
 }
Пример #22
0
        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)));
        }
Пример #23
0
 public abstract Task <AuthorizationResult> CanModifyAsync(T originalEntity, T modifiedEntity, IContextInfo ctx);
Пример #24
0
        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);
        }
Пример #25
0
        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);
        }
Пример #26
0
        public override async Task OnModifiedAsync(MockEntity originalEntity, MockEntity modifiedEntity, IContextInfo context)
        {
            await base.OnModifiedAsync(originalEntity, modifiedEntity, context);

            ModifiedOriginalEntities.Add(originalEntity);
            ModifiedNewEntities.Add(modifiedEntity);
        }
Пример #27
0
 public virtual async Task OnCreateFailedAsync(T entity, IContextInfo user)
 {
     WasOnCreationValidationFailedCalled = true;
 }
Пример #28
0
#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));
        }
Пример #29
0
 public virtual async Task OnRemoveFailedAsync(T entity, IContextInfo user)
 {
     WasOnDeletionFailedCalled = true;
 }
Пример #30
0
 public static IQueryable <T> Collection <T>(IQueryable <T> entities, IContextInfo context) where T : class
 {
     return(CollectionAsync <T>(entities, context).Result);
 }
Пример #31
0
        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)));
        }
Пример #32
0
 public static void CreateFailed <T>(T entity, IContextInfo context)
 {
     CreateFailedAsync(entity, context).Wait();
 }