Ejemplo n.º 1
0
        /// <summary>
        /// Clone <paramref name="line"/>.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        /// <exception cref="LineException">on append error</exception>
        public static ILine Clone(this ILineFactory factory, ILine line)
        {
            ILine result = null;
            StructList16 <ILine> args = new StructList16 <ILine>();

            for (ILine l = line; l != null; l = l.GetPreviousPart())
            {
                if (l is ILineArgument || l is ILineArgumentEnumerable)
                {
                    args.Add(l);
                }
            }
            for (int i = args.Count - 1; i >= 0; i--)
            {
                ILine l = args[i];
                if (l is ILineArgumentEnumerable enumr)
                {
                    foreach (ILineArgument args_ in enumr)
                    {
                        result = factory.Create(result, args_);
                    }
                }

                if (l is ILineArgument arg)
                {
                    result = factory.Create(result, arg);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clone <see cref="ILineKey"/> parts.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="appender">(optional) appender to use for clone. If null uses the appender of <paramref name="line"/></param>
        /// <param name="parameterInfos">(optional) for checking which parameters are keys</param>
        /// <returns>clone of key parts</returns>
        /// <exception cref="LineException">If cloning failed.</exception>
        public static ILine CloneKey(this ILine line, ILineFactory appender = default, IParameterInfos parameterInfos = null)
        {
            if (appender == null)
            {
                appender = line.GetAppender();
            }
            ILine result = null;

            if (parameterInfos == null)
            {
                appender.TryGetParameterInfos(out parameterInfos);
            }

            StructList16 <ILine> args = new StructList16 <ILine>();

            for (ILine l = line; l != null; l = l.GetPreviousPart())
            {
                if (l is ILineArgument || l is ILineArgumentEnumerable)
                {
                    args.Add(l);
                }
            }

            for (int i = args.Count - 1; i >= 0; i--)
            {
                ILine l = args[i];
                if (l is ILineParameterEnumerable lineParameters)
                {
                    foreach (ILineParameter lineParameter in lineParameters)
                    {
                        if (lineParameter.IsCanonicalKey(parameterInfos))
                        {
                            result = appender.Create <ILineCanonicalKey, string, string>(result, lineParameter.ParameterName, lineParameter.ParameterValue);
                        }
                        else if (lineParameter.IsNonCanonicalKey(parameterInfos))
                        {
                            result = appender.Create <ILineNonCanonicalKey, string, string>(result, lineParameter.ParameterName, lineParameter.ParameterValue);
                        }
                    }
                }
                if (l is ILineParameter parameter)
                {
                    if (parameter.IsCanonicalKey(parameterInfos))
                    {
                        result = appender.Create <ILineCanonicalKey, string, string>(result, parameter.ParameterName, parameter.ParameterValue);
                    }
                    else if (parameter.IsNonCanonicalKey(parameterInfos))
                    {
                        result = appender.Create <ILineNonCanonicalKey, string, string>(result, parameter.ParameterName, parameter.ParameterValue);
                    }
                }
            }
            return(result ?? appender.Create <ILinePart>(null));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Inline <paramref name="value"/> to <paramref name="culture"/>.
        /// </summary>
        /// <param name="lineFactory"></param>
        /// <param name="culture">subkey in parametrized format, e.g. "Culture:en", or "Culture:en:N:One"</param>
        /// <param name="value">(optional) value to append, if null removes previously existing the inline</param>
        /// <returns>new line with inlines or <paramref name="lineFactory"/></returns>
        /// <exception cref="LineException">If key can't be inlined.</exception>
        public static ILine InlineCulture(this ILineFactory lineFactory, string culture, IString value)
        {
            ILineInlines inlines = lineFactory.Create <ILineInlines>(null);
            ILine        subkey  = lineFactory.Create <ILineNonCanonicalKey, string, string>(null, "Culture", culture);

            if (value != null)
            {
                subkey = subkey.String(value);
            }
            if (subkey != null)
            {
                inlines[subkey] = subkey;
            }
            return(inlines);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create new parameter part as <see cref="ILineParameter"/>, as <see cref="ILineCanonicalKey"/>, or as <see cref="ILineNonCanonicalKey"/> depending
        /// on parameter name and policy in <paramref name="parameterInfos"/>.
        /// </summary>
        /// <param name="lineFactory"></param>
        /// <param name="parameterName">parameter name</param>
        /// <param name="parameterValue">parameter value</param>
        /// <param name="parameterInfos">(optional) instructions on whether to instantiate as parameter or key. See ParameterInfos.Default for default configuration</param>
        /// <returns>new parameter part</returns>
        /// <exception cref="LineException">If part could not be appended</exception>
        /// <returns>new part</returns>
        public static ILine Parameter(this ILineFactory lineFactory, string parameterName, string parameterValue, IParameterInfos parameterInfos)
        {
            IParameterInfo info = null;

            if (parameterInfos != null && parameterInfos.TryGetValue(parameterName, out info))
            {
                if (info.InterfaceType == typeof(ILineHint))
                {
                    return(lineFactory.Create <ILineHint, string, string>(null, parameterName, parameterValue));
                }
                if (info.InterfaceType == typeof(ILineCanonicalKey))
                {
                    return(lineFactory.Create <ILineCanonicalKey, string, string>(null, parameterName, parameterValue));
                }
                if (info.InterfaceType == typeof(ILineNonCanonicalKey))
                {
                    return(lineFactory.Create <ILineNonCanonicalKey, string, string>(null, parameterName, parameterValue));
                }
            }
            return(lineFactory.Create <ILineParameter, string, string>(null, parameterName, parameterValue));
        }
Ejemplo n.º 5
0
        public void ParseTokensOnDifferentLinesShouldParseAsDifferentLines()
        {
            IList <TokenBase> firstLine = new List <TokenBase>();

            firstLine.Add(TokenCreator.Create <IdentifierToken>("test1"));

            TokenCreator.NewLine(1);

            IList <TokenBase> secondLine = new List <TokenBase>();

            secondLine.Add(TokenCreator.Create <IdentifierToken>("test2"));

            ILineFactory factory = Mocker.StrictMock <ILineFactory>();

            Expect.Call(factory.Create(firstLine)).Return(new Line(firstLine)).Repeat.Once();
            Expect.Call(factory.Create(secondLine)).Return(new Line(secondLine)).Repeat.Once();

            StubLineFactoryProvider provider = new StubLineFactoryProvider(factory);
            CalidusLineParser       parser   = new CalidusLineParser(provider);

            IList <LineBase> expected = new List <LineBase>();

            expected.Add(new Line(firstLine));
            expected.Add(new Line(secondLine));

            IList <TokenBase> toParse = new List <TokenBase>();

            toParse.Add(firstLine[0]);
            toParse.Add(secondLine[0]);

            Mocker.ReplayAll();

            IEnumerable <LineBase> actual = parser.Parse(toParse);

            CollectionAssert.AreEquivalent(expected, actual);

            Mocker.VerifyAll();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create inlined <paramref name="subkey"/> resource.
        /// </summary>
        /// <param name="lineFactory"></param>
        /// <param name="subkey">subkey in parametrized format, e.g. "Culture:en"</param>
        /// <param name="value">(optional) value to append, if null removes previously existing the inline</param>
        /// <returns>new line with inlines or <paramref name="lineFactory"/></returns>
        /// <exception cref="LineException">If key can't be inlined.</exception>
        public static ILine Inline(this ILineFactory lineFactory, ILine subkey, byte[] value)
        {
            ILineInlines inlines = lineFactory.Create <ILineInlines>(null);

            if (value != null)
            {
                subkey = subkey.Resource(value);
            }
            if (subkey != null)
            {
                inlines[subkey] = subkey;
            }
            return(inlines);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a clone of <paramref name="previous"/>'s appender, and add new components to it.
        /// </summary>
        /// <param name="previous">previous part</param>
        /// <param name="appender">appender to add</param>
        /// <param name="policy">add policy</param>
        /// <returns>part with another appender</returns>
        public static ILine AddAppender(this ILine previous, ILineFactory appender, LineFactoryAddPolicy policy = LineFactoryAddPolicy.OverwriteIfExists)
        {
            ILineFactory previousAppender;

            if (previous.TryGetAppender(out previousAppender))
            {
                ILineFactory newAppender = previousAppender == null ? appender : (ILineFactory) new LineFactoryComposition().Add(previousAppender, policy).Add(appender, policy);
                return(newAppender.Create <ILinePart>(previous));
            }
            else
            {
                return(appender.Create <ILinePart>(previous));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Append enumeration of parameters.
        /// </summary>
        /// <param name="part"></param>
        /// <param name="parameters">enumeration of parameters to append</param>
        /// <returns>new key that is appended to this key</returns>
        /// <exception cref="LineException">If key doesn't implement ILineParameterAssignable, or append failed</exception>
        public static ILine Parameters(this ILine part, IEnumerable <KeyValuePair <string, string> > parameters)
        {
            ILineFactory appender = part.GetAppender();

            if (appender == null)
            {
                throw new LineException(part, "Appender is not found.");
            }
            foreach (var parameter in parameters)
            {
                part = appender.Create <ILineParameter, string, string>(part, parameter.Key, parameter.Value);
            }
            return(part);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Parse string into key.
 /// </summary>
 /// <param name="lineFormat"></param>
 /// <param name="str">key as string</param>
 /// <param name="prevPart">(optional) previous part to append to</param>
 /// <param name="appender">(optional) line appender to append with. If null, uses appender from <paramref name="prevPart"/>. If null, uses default appender.</param>
 /// <returns>key result or null if contained no content</returns>
 /// <exception cref="LineException">If parse failed</exception>
 /// <exception cref="LineException">If <paramref name="lineFormat"/> doesn't implement <see cref="ILineFormatParser"/>.</exception>
 /// <exception cref="LineException">Error if appender is not available</exception>
 public static ILine Parse(this ILineFormat lineFormat, string str, ILine prevPart = default, ILineFactory appender = default)
 {
     if (lineFormat is ILineFormatAppendParser appendParser)
     {
         return appendParser.Parse(str, prevPart, appender);
     }
     if (lineFormat is ILineFormatParser parser)
     {
         if (appender == null) appender = prevPart.GetAppender();
         foreach (ILineArgument arg in parser.ParseArgs(str))
             prevPart = appender.Create(prevPart, arg);
         return prevPart;
     }
     else throw new LineException(prevPart, $"Cannot parse strings to {nameof(ILine)} with {lineFormat.GetType().FullName}. {lineFormat} doesn't implement {nameof(ILineFormatParser)}.");
 }
Ejemplo n.º 10
0
        private void DrawLocks()
        {
            canvas.RemoveAll <Line>();

            foreach (var sessionCircle in sessionCircles.Where(x => x.Session.BlockedBy.HasValue))
            {
                var blocking = sessionCircles.FirstOrDefault(x => x.Session.SPID == sessionCircle.Session.BlockedBy);
                if (blocking != null)
                {
                    var line = lineFactory.Create(
                        sessionCircle.X + sessionCircle.Size / 2,
                        sessionCircle.Y + sessionCircle.Size / 2,
                        blocking.X + blocking.Size / 2,
                        blocking.Y + blocking.Size / 2,
                        color: Colors.Red
                        );
                    canvas.Add(line, 2);
                }
            }
        }
 /// <summary>
 /// Create localization resolver.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="stringResolver">Assembly qualified class name to <see cref="IStringResolver"/></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If part append fails</exception>
 public static ILineHint StringResolver(this ILineFactory lineFactory, string stringResolver)
 => lineFactory.Create <ILineHint, string, string>(null, "StringResolver", stringResolver);
 /// <summary>
 /// Create localization resolver.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="stringResolver"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If part append fails</exception>
 public static ILineStringResolver StringResolver(this ILineFactory lineFactory, IStringResolver stringResolver)
 => lineFactory.Create <ILineStringResolver, IStringResolver>(null, stringResolver);
Ejemplo n.º 13
0
 /// <summary>
 /// Append format provider key.
 ///
 /// Format provider is requested for following interfaces:
 /// <list type="bullet">
 /// <item><see cref="ICustomFormatter"/></item>
 /// </list>
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="formatProvider">assembly qualified class name to <see cref="IFormatProvider"/></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If <see cref="ILineFormatProvider"/> could not be appended</exception>
 public static ILineHint FormatProvider(this ILineFactory lineFactory, string formatProvider)
 => lineFactory.Create <ILineHint, string, string>(null, "FormatProvider", formatProvider);
Ejemplo n.º 14
0
 /// <summary>
 /// Create <see cref="ILineString"/> part.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static ILineString String(this ILineFactory lineFactory, IString value)
 => lineFactory.Create <ILineString, IString>(null, value);
Ejemplo n.º 15
0
 /// <summary>
 /// Append localizatoin asset.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="asset"></param>
 /// <returns>part with asset</returns>
 public static ILineAsset Asset(this ILineFactory lineFactory, IAsset asset)
 => lineFactory.Create <ILineAsset, IAsset>(null, asset);
Ejemplo n.º 16
0
 /// <summary>
 /// Assign a specific instance of rules.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="rules"></param>
 /// <returns>new key with rules</returns>
 public static ILinePluralRules PluralRules(this ILineFactory lineFactory, IPluralRules rules)
 => lineFactory.Create <ILinePluralRules, IPluralRules>(null, rules);
Ejemplo n.º 17
0
 /// <summary>
 /// Append string format.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="stringFormat"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If could not be appended</exception>
 public static ILineStringFormat StringFormat(this ILineFactory lineFactory, IStringFormat stringFormat)
 => lineFactory.Create <ILineStringFormat, IStringFormat>(null, stringFormat);
Ejemplo n.º 18
0
 /// <summary>
 /// Append culture policy
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="culturePolicy"></param>
 /// <returns></returns>
 public static ILineCulturePolicy CulturePolicy(this ILineFactory lineFactory, ICulturePolicy culturePolicy)
 => lineFactory.Create <ILineCulturePolicy, ICulturePolicy>(null, culturePolicy);
Ejemplo n.º 19
0
 /// <summary>
 /// Create localization resolver.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="resourceResolver"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If part append fails</exception>
 public static ILineResourceResolver ResourceResolver(this ILineFactory lineFactory, IResourceResolver resourceResolver)
 => lineFactory.Create <ILineResourceResolver, IResourceResolver>(null, resourceResolver);
Ejemplo n.º 20
0
 /// <summary>
 /// Create parameter part.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="parameterName">parameter name</param>
 /// <param name="parameterValue">(optional) parameter value</param>
 /// <returns>new parameter part</returns>
 /// <exception cref="LineException">If part could not be appended</exception>
 /// <returns>new part</returns>
 public static ILine Parameter(this ILineFactory lineFactory, string parameterName, string parameterValue)
 => lineFactory.Create <ILineParameter, string, string>(null, parameterName, parameterValue);
Ejemplo n.º 21
0
 /// <summary>
 /// Create localization resolver.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="resourceResolver">Assembly qualified class name to <see cref="IResourceResolver"/></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If part append fails</exception>
 public static ILineHint ResourceResolver(this ILineFactory lineFactory, string resourceResolver)
 => lineFactory.Create <ILineHint, string, string>(null, "ResourceResolver", resourceResolver);
Ejemplo n.º 22
0
 /// <summary>
 /// Append format arguments. Format arguments
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 /// <exception cref="LineException">If key can't be formatted</exception>
 public static ILineValue Value(this ILineFactory lineFactory, params object[] args)
 => lineFactory.Create <ILineValue, Object[]>(null, args);
Ejemplo n.º 23
0
 /// <summary>
 /// Append observer that monitors resolving of localization strings.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="logger"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">Append logger</exception>
 public static ILineLogger Logger(this ILineFactory lineFactory, ILogger logger)
 => lineFactory.Create <ILineLogger, ILogger>(null, logger);
Ejemplo n.º 24
0
 /// <summary>
 /// Create "Type" as <see cref="ILineNonCanonicalKey"/> key.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="typeName"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If key doesn't implement <see cref="ILineNonCanonicalKey"/></exception>
 public static ILineNonCanonicalKey Type(this ILineFactory lineFactory, string typeName)
 => lineFactory.Create <ILineNonCanonicalKey, string, string>(null, "Type", typeName);
Ejemplo n.º 25
0
 /// <summary>
 /// Append string format.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="stringFormat"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If could not be appended</exception>
 public static ILineHint StringFormat(this ILineFactory lineFactory, string stringFormat)
 => lineFactory.Create <ILineHint, string, string>(null, "StringFormat", stringFormat);
Ejemplo n.º 26
0
 /// <summary>
 /// Create <see cref="ILineType"/> key.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="type"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If key doesn't implement <see cref="ILineType"/></exception>
 public static ILineType Type(this ILineFactory lineFactory, Type type)
 => lineFactory.Create <ILineType, Type>(null, type);
Ejemplo n.º 27
0
 /// <summary>
 /// Set new appender by appending a dummy <see cref="ILinePart"/> with the new <paramref name="appender"/>.
 /// </summary>
 /// <param name="previous"></param>
 /// <param name="appender"></param>
 /// <returns>part with another appender</returns>
 public static ILine SetAppender(this ILine previous, ILineFactory appender)
 => appender.Create <ILinePart>(previous);
Ejemplo n.º 28
0
 /// <summary>
 /// Create <see cref="ILine{T}"/> key.
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <returns>new key</returns>
 /// <typeparam name="T"></typeparam>
 /// <exception cref="LineException">If key cannot be appended</exception>
 public static ILine <T> Type <T>(this ILineFactory lineFactory)
 => (ILine <T>)lineFactory.Create <ILineType, Type>(null, typeof(T));
Ejemplo n.º 29
0
 /// <summary>
 /// Create "String" hint.
 ///
 /// StringResolver will parse the hint using the active StringFormat.
 /// If there is no active string format, then CSharp format is used
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static ILineHint String(this ILineFactory lineFactory, String value)
 => lineFactory.Create <ILineHint, string, string>(null, "String", value);
Ejemplo n.º 30
0
 /// <summary>
 /// Append format provider key.
 ///
 /// Format provider is requested for following interfaces:
 /// <list type="bullet">
 /// <item><see cref="ICustomFormatter"/></item>
 /// </list>
 /// </summary>
 /// <param name="lineFactory"></param>
 /// <param name="formatProvider"></param>
 /// <returns>new key</returns>
 /// <exception cref="LineException">If <see cref="ILineFormatProvider"/> could not be appended</exception>
 public static ILineFormatProvider FormatProvider(this ILineFactory lineFactory, IFormatProvider formatProvider)
 => lineFactory.Create <ILineFormatProvider, IFormatProvider>(null, formatProvider);