예제 #1
0
        public static string GetOperationHelp(OperationSymbol symbol)
        {
            var type = OperationLogic.FindTypes(symbol).First();

            var operationInfo = OperationLogic.GetOperationInfo(type, symbol);

            switch (operationInfo.OperationType)
            {
            case OperationType.Execute: return(HelpMessage.Call0Over1OfThe2.NiceToString().ForGenderAndNumber(type.GetGender()).FormatWith(
                                                   operationInfo.OperationSymbol.NiceToString(),
                                                   operationInfo.Lite.Value ? HelpMessage.TheDatabaseVersion.NiceToString() : HelpMessage.YourVersion.NiceToString(),
                                                   type.NiceName()));

            case OperationType.Delete: return(HelpMessage.RemovesThe0FromTheDatabase.NiceToString(type.NiceName()));

            case OperationType.Constructor: return
                    (HelpMessage.ConstructsANew0.NiceToString().ForGenderAndNumber(type.GetGender()).FormatWith(type.NiceName()));

            case OperationType.ConstructorFrom: return
                    (HelpMessage.ConstructsANew0.NiceToString().ForGenderAndNumber(operationInfo.ReturnType.GetGender()).FormatWith(operationInfo.ReturnType.NiceName()) + " " +
                     HelpMessage.From0OfThe1.NiceToString().ForGenderAndNumber(type.GetGender()).FormatWith(operationInfo.Lite.Value ? HelpMessage.TheDatabaseVersion.NiceToString() : HelpMessage.YourVersion.NiceToString(), type.NiceName()));

            case OperationType.ConstructorFromMany: return
                    (HelpMessage.ConstructsANew0.NiceToString().ForGenderAndNumber(operationInfo.ReturnType.GetGender()).FormatWith(operationInfo.ReturnType.NiceName()) + " " +
                     HelpMessage.FromMany0.NiceToString().ForGenderAndNumber(type.GetGender()).FormatWith(type.NicePluralName()));
            }

            return("");
        }
예제 #2
0
        public static OperationAllowed MaxTypePermission(OperationSymbol operationKey, TypeAllowedBasic minimum, Func <Type, TypeAllowedAndConditions> allowed)
        {
            Func <Type, OperationAllowed> operationAllowed = t =>
            {
                if (!TypeLogic.TypeToEntity.ContainsKey(t))
                {
                    return(OperationAllowed.Allow);
                }

                var ta = allowed(t);

                return(minimum <= ta.MaxUI() ? OperationAllowed.Allow :
                       minimum <= ta.MaxDB() ? OperationAllowed.DBOnly :
                       OperationAllowed.None);
            };

            return(OperationLogic.FindTypes(operationKey).Max(t =>
            {
                var operation = OperationLogic.FindOperation(t, operationKey);

                Type resultType = operation.OperationType == OperationType.ConstructorFrom ||
                                  operation.OperationType == OperationType.ConstructorFromMany ? operation.ReturnType : operation.OverridenType;

                var result = operationAllowed(resultType);

                if (result == OperationAllowed.None)
                {
                    return result;
                }

                Type fromType = operation.OperationType == OperationType.ConstructorFrom ||
                                operation.OperationType == OperationType.ConstructorFromMany ? operation.OverridenType : null;

                if (fromType == null)
                {
                    return result;
                }

                var fromTypeAllowed = operationAllowed(fromType);

                return result < fromTypeAllowed ? result : fromTypeAllowed;
            }));
        }
예제 #3
0
        public static WikiLink LinkParser(string content)
        {
            Match m = HelpLogic.HelpLinkRegex.Match(content);

            if (m.Success)
            {
                string letter = m.Groups["letter"].ToString();
                string link   = m.Groups["link"].ToString();
                string text   = m.Groups["text"].ToString();

                switch (letter)
                {
                case WikiFormat.EntityLink:
                    Type t = TypeLogic.TryGetType(link);
                    return(new WikiLink(
                               HelpUrls.EntityUrl(t),
                               text.HasText() ? text : t.NiceName()));

                case WikiFormat.Hyperlink:
                    return(new WikiLink(link, text));

                case WikiFormat.OperationLink:
                    OperationSymbol operation = SymbolLogic <OperationSymbol> .TryToSymbol(link);

                    List <Type> types = OperationLogic.FindTypes(operation).Where(TypeLogic.TypeToEntity.ContainsKey).ToList();
                    if (types.Count == 1)
                    {
                        return(new WikiLink(
                                   HelpUrls.OperationUrl(types[0], operation),
                                   text.HasText() ? text : operation.NiceToString()));
                    }
                    else
                    {
                        return(new MultiWikiLink(operation.NiceToString())
                        {
                            Links = types.Select(currentType =>
                                                 new WikiLink(
                                                     HelpUrls.OperationUrl(currentType, operation),
                                                     currentType.NiceName(), operation.NiceToString())).ToList()
                        });
                    }

                case WikiFormat.PropertyLink:
                    PropertyRoute route = PropertyRoute.Parse(TypeLogic.TryGetType(link.Before('.')), link.After('.'));

                    while (route.PropertyRouteType == PropertyRouteType.LiteEntity ||
                           route.PropertyRouteType == PropertyRouteType.Mixin ||
                           route.PropertyRouteType == PropertyRouteType.MListItems)
                    {
                        route = route.Parent;
                    }

                    return(new WikiLink(HelpUrls.PropertyUrl(route), route.PropertyInfo.NiceName()));

                case WikiFormat.QueryLink:
                    object o = QueryLogic.TryToQueryName(link);
                    if (o as Enum != null)
                    {
                        Enum query = (Enum)o;
                        return(new WikiLink(
                                   HelpUrls.QueryUrl(query),
                                   text.HasText() ? text : QueryUtils.GetNiceName(query)));
                    }
                    else
                    {
                        Type query = (Type)o;
                        return(new WikiLink(
                                   HelpUrls.QueryUrl(query),
                                   text.HasText() ? text : QueryUtils.GetNiceName(query)));
                    }

                case WikiFormat.NamespaceLink:
                    NamespaceHelp nameSpace = HelpLogic.GetNamespaceHelp(link);
                    return(new WikiLink(
                               HelpUrls.NamespaceUrl(link),
                               text.HasText() ? text : link,
                               nameSpace != null ? "" : "unavailable"));

                case WikiFormat.AppendixLink:
                    AppendixHelp appendix = HelpLogic.GetAppendixHelp(link);
                    return(new WikiLink(
                               HelpUrls.AppendixUrl(link),
                               text.HasText() ? text : link,
                               appendix != null ? "" : "unavailable"));
                }
            }
            return(null);
        }