Esempio n. 1
0
    public async Task ExecuteAotSparqlAction(AotSparqlOptions options)
    {
        if (options == null)
        {
            throw new ArgumentNullException(nameof(options));
        }
        using (var namespaceMap = new NamespaceMapper())
        {
            foreach (var entry in options.NamespaceMapping)
            {
                namespaceMap.AddNamespace(entry.Key, new Uri(entry.Value));
            }
            using (var moduleFactory = await OptionUtility.CreateExportModuleFactoryAsync(options.ExportModulePrefix, mwSiteProvider, logger))
                using (var executor = new AotSparqlExecutor(options.DataSource, namespaceMap, uri =>
                {
                    // Blank node.
                    if (uri == null)
                    {
                        return("_:");
                    }
                    // One.
                    if (uri == Utility.WikibaseRdfUnityEntity)
                    {
                        return("1");
                    }
                    if (namespaceMap.ReduceToQName(uri.ToString(), out var qname))
                    {
                        // Remove prefix for local entities.
                        if (qname.StartsWith("wd:", StringComparison.OrdinalIgnoreCase))
                        {
                            return(qname.Substring(3));
                        }
                        return(qname);
                    }
                    throw new InvalidOperationException($"Cannot reduce {uri} into its QName.");
                }, logger.ForContext <AotSparqlExecutor>()))
                {
                    var exporter = new AotSparqlModuleExporter(logger, moduleFactory, executor);
                    {
                        var(configSite, configModule) = await OptionUtility.ResolveSiteAndTitleAsync(options.ConfigModule, mwSiteProvider);

                        await exporter.LoadConfigFromModuleAsync(configSite, configModule);

                        logger.Information("Loaded config from {Module}.", options.ConfigModule);
                    }
                    await exporter.ExportModulesAsync();
                }
        }
    }
Esempio n. 2
0
        public override object Build(BuilderContext context)
        {
            Builtin         builtin       = context.Builtin;
            IOptionProvider provider      = null;
            string          providerValue = builtin.Properties.GetRawValue("provider");

            var node = new OptionNode(builtin.Name,
                                      builtin.Properties.GetValue <string>("title"),
                                      builtin.Properties.GetValue <string>("description"));

            if (string.IsNullOrWhiteSpace(providerValue))
            {
                return(node);
            }

            switch (providerValue.Trim().ToLower())
            {
            case ".":
            case "plugin":
                provider = OptionUtility.GetConfiguration(builtin.Plugin);
                break;

            case "/":
            case "application":
                provider = context.PluginContext.ApplicationContext.Configuration;
                break;

            default:
                provider = builtin.Properties.GetValue <IOptionProvider>("provider");
                break;
            }

            if (provider == null)
            {
                throw new PluginException(string.Format("Cann't obtain OptionProvider with '{0}'.", providerValue));
            }

            node.Option = new Option(node, provider)
            {
                View        = context.Builtin.Properties.GetValue <IOptionView>("view"),
                ViewBuilder = context.Builtin.Properties.GetValue <IOptionViewBuilder>("viewBuilder"),
            };

            return(node);
        }
        public object GetOptionValue(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentNullException(nameof(text));
            }

            //解析层次结构表达式
            var expression = Collections.HierarchicalExpression.Parse(text);

            string sectionPath, elementName;

            //拆解路径文本中的Section和Element部分
            OptionUtility.ResolveOptionPath(expression.Path, out sectionPath, out elementName);

            //获取指定路径的配置节
            var section = this.GetSection(sectionPath);

            if (section == null)
            {
                throw new ArgumentException($"Not found '{sectionPath}' configuration option section in the '{this.FilePath}' file.");
            }

            //获取指定配置节下面的配置元素
            var element = section.Children[elementName];

            if (element == null)
            {
                throw new ArgumentException($"Not found '{elementName}' configuration element in the '{this.FilePath}' file.");
            }

            if (expression.Members.Length > 0)
            {
                return(Reflection.MemberAccess.GetMemberValue <object>(element, expression.Members));
            }

            return(element);
        }
        public object GetOptionObject(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            string sectionPath, nodeName;

            if (!OptionUtility.ResolveOptionPath(path, out sectionPath, out nodeName))
            {
                return(null);
            }

            var section = this.GetSection(sectionPath);

            if (section == null)
            {
                return(null);
            }

            return(section.Children[nodeName]);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            try
            {
                ClothesFactory clothesFactory = new ClothesFactory();
                IClothes       shirt          = null;
                // User make choice.

                Console.WriteLine("Please choose clothing you want to trading:");
                Console.WriteLine("1: TShirt, 2: DShirt");

                switch (int.Parse(Console.ReadLine().ToString()))
                {
                case 1:
                    shirt = clothesFactory.GetClothes(ClothesType.TShirt);
                    break;

                case 2:
                    shirt = clothesFactory.GetClothes(ClothesType.TShirt);
                    break;

                default:

                    break;
                }

                // Execute action.
                Console.WriteLine("Please choose action you want to trading:");
                Console.WriteLine("1: Sell, 2: Buy");
                var tradetype = int.Parse(Console.ReadLine().ToString());

                // User make a number to trade.
                Console.WriteLine("Please choose number of item you want to trading:");
                var tradeNo = int.Parse(Console.ReadLine().ToString());

                // User make a number to trade.
                Console.WriteLine("Please choose option for item you want to trading:");
                var opts = OptionUtility.GetOption(shirt.Options);

                switch (tradetype)
                {
                case 1:
                    Console.WriteLine(shirt.Trade(TradeType.Sell, tradeNo, opts));
                    break;

                case 2:
                    Console.WriteLine(shirt.Trade(TradeType.Buy, tradeNo, opts));
                    break;

                default:

                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.Read();
        }
Esempio n. 6
0
 /// <summary>
 /// Execute action.
 /// </summary>
 /// <param name="rate">Sell or Buy rate</param>
 /// <param name="number">NUmber of sell or buy</param>
 /// <returns>Result string</returns>
 public string Execute(int rate, int number, List <IOption> options)
 {
     return(string.Format(notify, number, rate) + "\r\n" + OptionUtility.PrintOption(options));
 }
Esempio n. 7
0
        protected internal virtual void ExecuteCommand(OptionItem optionItem, Option systemOption, Out @out)

        {
            OptionItem nameItem = OptionUtility.GetItemByName(optionItem, systemOption, false);

            if (CheckOption(nameItem, "-b:b") == true)

            {
                this.baseOpt_ = 1;
            }
            else if (CheckOption(nameItem, "-b:c") == true)

            {
                this.baseOpt_ = 2;
            }
            else if (CheckOption(nameItem, "-b:e") == true)

            {
                this.baseOpt_ = 3;
            }
            else if (CheckOption(nameItem, "-b:ex") == true)

            {
                this.baseOpt_ = 4;
            }
            else if (CheckOption(nameItem, "-c:a") == true)

            {
                this.category_ |= Category.ToValue("adj");
            }
            else if (CheckOption(nameItem, "-c:all") == true)

            {
                this.category_ |= 0x7FF;
            }
            else if (CheckOption(nameItem, "-c:b") == true)

            {
                this.category_ |= Category.ToValue("adv");
            }
            else if (CheckOption(nameItem, "-c:c") == true)

            {
                this.category_ |= Category.ToValue("compl");
            }
            else if (CheckOption(nameItem, "-c:d") == true)

            {
                this.category_ |= Category.ToValue("det");
            }
            else if (CheckOption(nameItem, "-c:h") == true)

            {
                LexAccessHelp.CategoryHelp(this.outWriter_, this.fileOutput_, @out);
                this.runFlag_ = false;
            }
            else if (CheckOption(nameItem, "-c:j") == true)

            {
                this.category_ |= Category.ToValue("conj");
            }
            else if (CheckOption(nameItem, "-c:m") == true)

            {
                this.category_ |= Category.ToValue("modal");
            }
            else if (CheckOption(nameItem, "-c:n") == true)

            {
                this.category_ |= Category.ToValue("noun");
            }
            else if (CheckOption(nameItem, "-c:p") == true)

            {
                this.category_ |= Category.ToValue("prep");
            }
            else if (CheckOption(nameItem, "-c:r") == true)

            {
                this.category_ |= Category.ToValue("pron");
            }
            else if (CheckOption(nameItem, "-c:v") == true)

            {
                this.category_ |= Category.ToValue("verb");
            }
            else if (CheckOption(nameItem, "-c:x") == true)

            {
                this.category_ |= Category.ToValue("aux");
            }
            else if (CheckOption(nameItem, "-ci") == true)

            {
                try

                {
                    bool   useClassPath = false;
                    string configFile   = this.configFile_;
                    if (string.ReferenceEquals(configFile, null))

                    {
                        useClassPath = true;
                        configFile   = "data.config.lexAccess";
                    }

                    Configuration conf = new Configuration(configFile, useClassPath);


                    if (this.properties_ != null)

                    {
                        conf.OverwriteProperties(this.properties_);
                    }

                    @out.Println(this.outWriter_, conf.GetInformation(), this.fileOutput_, false);
                }
                catch (IOException)
                {
                }

                this.runFlag_ = false;
            }
            else if (CheckOption(nameItem, "-cn:LONG") == true)

            {
                long cat = long.Parse(nameItem.GetOptionArgument());
                if ((cat <= 0L) || (cat > 2047L))

                {
                    string temp = "*** Error: Illegal value for category (" + cat + ").";

                    try

                    {
                        @out.Println(this.outWriter_, temp, this.fileOutput_, false);
                    }
                    catch (IOException)
                    {
                    }

                    this.runFlag_ = false;
                }
                else

                {
                    this.category_ = long.Parse(nameItem.GetOptionArgument());
                }
            }
            else if (CheckOption(nameItem, "-cnf:LONG") == true)

            {
                this.outCat_ = long.Parse(nameItem.GetOptionArgument());
            }
            else if (CheckOption(nameItem, "-f:b") == true)

            {
                this.formatOpt_ = 3;
            }
            else if (CheckOption(nameItem, "-f:bd") == true)

            {
                this.formatOpt_ = 4;
            }
            else if (CheckOption(nameItem, "-f:h") == true)

            {
                LexAccessHelp.FormatHelp(this.outWriter_, this.fileOutput_, @out);
                this.runFlag_ = false;
            }
            else if (CheckOption(nameItem, "-f:i") == true)

            {
                this.formatOpt_ = 7;
            }
            else if (CheckOption(nameItem, "-f:id") == true)

            {
                this.formatOpt_ = 8;
            }
            else if (CheckOption(nameItem, "-f:s") == true)

            {
                this.formatOpt_ = 5;
            }
            else if (CheckOption(nameItem, "-f:sd") == true)

            {
                this.formatOpt_ = 6;
            }
            else if (CheckOption(nameItem, "-f:t") == true)

            {
                this.formatOpt_ = 0;
            }
            else if (CheckOption(nameItem, "-f:tx") == true)

            {
                this.formatOpt_ = 2;
            }
            else if (CheckOption(nameItem, "-f:x") == true)

            {
                this.formatOpt_ = 1;
            }
            else if (CheckOption(nameItem, "-h") == true)

            {
                LexAccessHelp.LexAccessHelp(this.outWriter_, this.fileOutput_, @out);
                this.runFlag_ = false;
            }
            else if (CheckOption(nameItem, "-hs") == true)

            {
                systemOption.PrintOptionHierachy();
                this.runFlag_ = false;
            }
            else if (CheckOption(nameItem, "-i:STR") == true)

            {
                string inFile = nameItem.GetOptionArgument();
                if (!string.ReferenceEquals(inFile, null))

                {
                    try

                    {
                        this.inReader_ = new System.IO.StreamReader(
                            new System.IO.FileStream(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read),
                            Encoding.UTF8);
                    }
                    catch (IOException)

                    {
                        this.runFlag_ = false;
                        Console.Error.WriteLine("**Error: problem of opening/reading file " + inFile);
                    }
                }
            }
            else if (CheckOption(nameItem, "-n") == true)

            {
                this.noOutputFlag_ = true;
            }
            else if (CheckOption(nameItem, "-o:STR") == true)

            {
                string outFile = nameItem.GetOptionArgument();
                if (!string.ReferenceEquals(outFile, null))

                {
                    try

                    {
                        this.outWriter_ = new System.IO.StreamWriter(
                            new System.IO.FileStream(outFile, System.IO.FileMode.Create, System.IO.FileAccess.Write),
                            Encoding.UTF8);

                        this.fileOutput_ = true;
                    }
                    catch (IOException)

                    {
                        this.runFlag_ = false;
                        Console.Error.WriteLine("**Error: problem of opening/writing file " + outFile);
                    }
                }
            }
            else if (CheckOption(nameItem, "-p") == true)

            {
                this.promptFlag_ = true;
            }
            else if (CheckOption(nameItem, "-q") == true)

            {
                this.query_     = this.option_.GetOptionStr();
                this.showQuery_ = true;
            }
            else if (CheckOption(nameItem, "-rv:STR") == true)

            {
                this.version_ = nameItem.GetOptionArgument();
                if (!SetVersionInConfig(this.version_))

                {
                    Console.Error.WriteLine("**Err@LexAccessCmdApi(): Illegal version setting (" + this.version_ + ")");


                    this.runFlag_ = false;
                }
            }
            else if (CheckOption(nameItem, "-s:STR") == true)

            {
                string separator = nameItem.GetOptionArgument();

                if (separator.Equals("\\t"))

                {
                    separator = (new char?('\t')).ToString();
                }

                GlobalBehavior.GetInstance().SetFieldSeparator(separator);
            }
            else if (CheckOption(nameItem, "-t") == true)

            {
                this.showTotalRecNum_ = true;
            }
            else if (CheckOption(nameItem, "-v") == true)

            {
                try

                {
                    string releaseStr = "lexAccess.2016";
                    @out.Println(this.outWriter_, releaseStr, this.fileOutput_, false);
                }
                catch (IOException)
                {
                }

                this.runFlag_ = false;
            }
            else if (CheckOption(nameItem, "-x:STR") == true)

            {
                this.configFile_ = nameItem.GetOptionArgument();
            }
        }
Esempio n. 8
0
        protected internal virtual void ExecuteCommand(OptionItem optionItem, Option systemOption, Out @out)

        {
            OptionItem nameItem = OptionUtility.GetItemByName(optionItem, systemOption, false);

            if (CheckOption(nameItem, "-d") == true)

            {
                debugFlag_ = true;
            }
            else if (CheckOption(nameItem, "-f:r") == true)

            {
                format_ = 4;
            }
            else if (CheckOption(nameItem, "-f:t") == true)

            {
                format_ = 0;
            }
            else if (CheckOption(nameItem, "-f:tx") == true)

            {
                format_ = 3;
            }
            else if (CheckOption(nameItem, "-f:x") == true)

            {
                format_ = 1;
            }
            else if (CheckOption(nameItem, "-f:nxh") == true)

            {
                printXmlHeader_ = false;
            }
            else if (CheckOption(nameItem, "-h") == true)

            {
                helpMenu(@out);
                runFlag_ = false;
            }
            else if (CheckOption(nameItem, "-hs") == true)

            {
                systemOption.PrintOptionHierachy();
                runFlag_ = false;
            }
            else if (CheckOption(nameItem, "-i:STR") == true)

            {
                string inFile = nameItem.GetOptionArgument();
                if (!string.ReferenceEquals(inFile, null))

                {
                    try

                    {
                        inReader_ = new System.IO.StreamReader(
                            new System.IO.FileStream(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read),
                            Encoding.UTF8);
                    }
                    catch (IOException)

                    {
                        runFlag_ = false;
                        Console.Error.WriteLine("**Error: problem of opening/reading file " + inFile);
                    }
                }
            }
            else if (CheckOption(nameItem, "-o:STR") == true)

            {
                string outFile = nameItem.GetOptionArgument();
                try

                {
                    outWriter_ = new System.IO.StreamWriter(
                        new System.IO.FileStream(outFile, System.IO.FileMode.Create, System.IO.FileAccess.Write),
                        Encoding.UTF8);

                    fileOutput_ = true;
                }
                catch (Exception)

                {
                    runFlag_ = false;
                    Console.Error.WriteLine("**Error: problem of opening/writing file " + outFile);
                }
            }
            else if (CheckOption(nameItem, "-v") == true)

            {
                try

                {
                    string releaseStr = "lexCheck.2016";
                    @out.Println(outWriter_, releaseStr, fileOutput_, false);
                }
                catch (Exception)
                {
                }

                runFlag_ = false;
            }
            else if (CheckOption(nameItem, "-x:STR") == true)

            {
                configFile_ = nameItem.GetOptionArgument();
            }
        }