Esempio n. 1
0
        private void button6_Click(object sender, EventArgs e)
        {
            this.Text = "测试中,请稍候";
            CardsReader    mReader         = new LuceneReader();
            CardLibrary    cardLibrary     = new CardLibrary(mReader.Read("CardIndex"));
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter           = "中中版查卡器数据文件 (ocg.yxwp)|ocg.yxwp|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 0;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllText("test.txt", "", Encoding.GetEncoding("GB2312"));
                int          i  = 0;
                StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.GetEncoding("GB2312"));
                while (!sr.EndOfStream)
                {
                    string   s  = sr.ReadLine();
                    string[] ss = s.Split('^');
                    string   n  = ss[1];
                    i++;
                    if (cardLibrary.GetCardByName(n) == null && cardLibrary.GetCardByOldName(n) == null)
                    {
                        File.AppendAllText("test.txt", string.Format("{0}   {1}\r\n", i, n), Encoding.GetEncoding("GB2312"));
                    }
                }
                sr.Close();
            }
            this.Text = "辅助转换工具";
            MessageBox.Show("测试完成!");
        }
Esempio n. 2
0
 public static CardLibrary GetInstance()
 {
     if (instance == null)
     {
         CLConfig config = CLConfig.GetInstance();
         Path         = System.AppDomain.CurrentDomain.BaseDirectory;
         KeepInMemory = string.Equals(config.GetSetting("KeepInMemory"), "true", StringComparison.OrdinalIgnoreCase);
         if (KeepInMemory)
         {
             ramdir = new Lucene.Net.Store.RAMDirectory(Path + "CardIndex");
             CardsReader Reader = new LuceneReader();
             instance = new CardLibrary(Reader.Read(ramdir));
             if (Directory.Exists(Path + "DIYCardIndex"))
             {
                 ramdiydir = new Lucene.Net.Store.RAMDirectory(Path + "DIYCardIndex");
                 instance.AddDIYCards(Reader.Read(ramdiydir));
             }
         }
         else
         {
             CardsReader Reader = new LuceneReader();
             instance = new CardLibrary(Reader.Read(Path + "CardIndex"));
             if (Directory.Exists(Path + "DIYCardIndex"))
             {
                 instance.AddDIYCards(Reader.Read(Path + "DIYCardIndex"));
             }
         }
     }
     return(instance);
 }
Esempio n. 3
0
        private void button5_Click(object sender, EventArgs e)
        {
            this.Text = "转换中,请稍候";
            CardsReader mReader     = new LuceneReader();
            CardLibrary cardLibrary = new CardLibrary(mReader.Read("CardIndex"));
            CardsSaver  aSaver      = new AllCardsSaver();

            aSaver.Save("allcards.dll", cardLibrary.GetCards());
            this.Text = "辅助转换工具";
            MessageBox.Show("导出完成!");
        }
Esempio n. 4
0
        protected override void Load(ContainerBuilder builder)
        {
            if (_process == null)
            {
                return;
            }

            // Connections
            foreach (var c in _process.Connections.Where(cn => cn.Provider == "lucene"))
            {
                switch (c.Provider)
                {
                case "lucene":
                    // Analyzers
                    builder.Register <Analyzer>(ctx => new KeywordAnalyzer()).Named <Analyzer>(DefaultAnalyzer);
                    foreach (var analyzer in _process.SearchTypes.Where(st => st.Analyzer != string.Empty && st.Analyzer != DefaultAnalyzer).Select(st => st.Analyzer).Distinct())
                    {
                        switch (analyzer)
                        {
                        case "simple":
                            builder.Register <Analyzer>(ctx => new SimpleAnalyzer()).Named <Analyzer>(analyzer);
                            break;

                        case "whitespace":
                            builder.Register <Analyzer>(ctx => new WhitespaceAnalyzer()).Named <Analyzer>(analyzer);
                            break;

                        case "standard":
                            builder.Register <Analyzer>(ctx => new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)).Named <Analyzer>(analyzer);
                            break;

                        default:
                            builder.Register <Analyzer>(ctx => new KeywordAnalyzer()).Named <Analyzer>(analyzer);
                            break;
                        }
                    }

                    // entity index writers
                    foreach (var e in _process.Entities)
                    {
                        // Directory
                        builder.Register(ctx => new DirectoryFactory(Path.Combine(c.Folder, e.Alias))).Named <DirectoryFactory>(e.Key);

                        // Per Field Analyzer
                        builder.Register <Analyzer>(ctx => {
                            var analyzers = new PerFieldAnalyzerWrapper(ctx.ResolveNamed <Analyzer>(DefaultAnalyzer));
                            var context   = ctx.ResolveNamed <OutputContext>(e.Key);
                            foreach (var field in new FieldSearchTypes(context.Process, context.OutputFields))
                            {
                                if (field.SearchType.Name != "none")
                                {
                                    analyzers.AddAnalyzer(field.Alias, ctx.ResolveNamed <Analyzer>(field.SearchType.Analyzer == string.Empty ? DefaultAnalyzer : field.SearchType.Analyzer));
                                }
                            }
                            return(analyzers);
                        }).Named <Analyzer>(e.Key + ReadFrom.Output);

                        builder.Register <Analyzer>(ctx => {
                            var analyzers = new PerFieldAnalyzerWrapper(ctx.ResolveNamed <Analyzer>(DefaultAnalyzer));
                            var context   = ctx.ResolveNamed <InputContext>(e.Key);
                            foreach (var field in new FieldSearchTypes(context.Process, context.InputFields))
                            {
                                if (field.SearchType.Name != "none")
                                {
                                    analyzers.AddAnalyzer(field.Field.Name, ctx.ResolveNamed <Analyzer>(field.SearchType.Analyzer == string.Empty ? DefaultAnalyzer : field.SearchType.Analyzer));
                                }
                            }
                            return(analyzers);
                        }).Named <Analyzer>(e.Key + ReadFrom.Input);

                        // Index Writer Factory
                        builder.Register(ctx => new IndexWriterFactory(ctx.ResolveNamed <DirectoryFactory>(e.Key), ctx.ResolveNamed <Analyzer>(e.Key + ReadFrom.Output))).Named <IndexWriterFactory>(e.Key);

                        // Index Reader Factory
                        builder.Register(ctx => new IndexReaderFactory(ctx.ResolveNamed <DirectoryFactory>(e.Key), ctx.ResolveNamed <IndexWriterFactory>(e.Key))).Named <IndexReaderFactory>(e.Key);

                        // Index Searcher Factory
                        builder.Register(ctx => new SearcherFactory(ctx.ResolveNamed <IndexReaderFactory>(e.Key))).Named <SearcherFactory>(e.Key);
                    }

                    break;
                }
            }

            // entity input
            foreach (var entity in _process.Entities.Where(e => _process.Connections.First(c => c.Name == e.Connection).Provider == "lucene"))
            {
                // INPUT VERSION DETECTOR
                builder.Register <IInputVersionDetector>(ctx => {
                    var input = ctx.ResolveNamed <InputContext>(entity.Key);
                    switch (input.Connection.Provider)
                    {
                    case "lucene":
                        return(new LuceneInputVersionDetector(input, ctx.ResolveNamed <SearcherFactory>(entity.Key)));

                    default:
                        return(new NullVersionDetector());
                    }
                }).Named <IInputVersionDetector>(entity.Key);

                // INPUT READER
                builder.Register <IRead>(ctx => {
                    var input      = ctx.ResolveNamed <InputContext>(entity.Key);
                    var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity));

                    switch (input.Connection.Provider)
                    {
                    case "lucene":
                        return(new LuceneReader(input, input.InputFields, ctx.ResolveNamed <SearcherFactory>(entity.Key), ctx.ResolveNamed <Analyzer>(entity.Key + ReadFrom.Input), ctx.ResolveNamed <IndexReaderFactory>(entity.Key), rowFactory, ReadFrom.Input));

                    default:
                        return(new NullReader(input, false));
                    }
                }).Named <IRead>(entity.Key);
            }

            // entity output
            if (_process.Output().Provider == "lucene")
            {
                // PROCESS OUTPUT CONTROLLER
                builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>();

                // PROCESS INITIALIZER
                builder.Register <IInitializer>(ctx => {
                    var output = ctx.Resolve <OutputContext>();
                    return(new LuceneInitializer(output));
                }).As <IInitializer>();

                foreach (var entity in _process.Entities)
                {
                    // UPDATER
                    builder.Register <IUpdate>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);
                        output.Warn($"{output.Connection.Provider} does not denormalize.");
                        return(new NullMasterUpdater());
                    }).Named <IUpdate>(entity.Key);

                    // OUTPUT
                    builder.Register <IOutputController>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);

                        switch (output.Connection.Provider)
                        {
                        case "lucene":
                            return(new LuceneOutputController(
                                       output,
                                       new NullInitializer(),
                                       ctx.ResolveNamed <IInputVersionDetector>(entity.Key),
                                       new LuceneOutputVersionDetector(output, ctx.ResolveNamed <SearcherFactory>(entity.Key)),
                                       ctx.ResolveNamed <SearcherFactory>(entity.Key),
                                       ctx.ResolveNamed <IndexReaderFactory>(entity.Key)
                                       ));

                        default:
                            return(new NullOutputController());
                        }
                    }).Named <IOutputController>(entity.Key);

                    // WRITER
                    builder.Register <IWrite>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);

                        switch (output.Connection.Provider)
                        {
                        case "lucene":
                            return(new LuceneWriter(output, ctx.ResolveNamed <IndexWriterFactory>(entity.Key), ctx.ResolveNamed <SearcherFactory>(entity.Key)));

                        default:
                            return(new NullWriter(output));
                        }
                    }).Named <IWrite>(entity.Key);

                    // DELETE HANDLER
                    if (entity.Delete)
                    {
                        builder.Register <IEntityDeleteHandler>(ctx => {
                            var context      = ctx.ResolveNamed <IContext>(entity.Key);
                            var inputContext = ctx.ResolveNamed <InputContext>(entity.Key);
                            var rowFactory   = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", inputContext.RowCapacity));
                            IRead input      = new NullReader(context);
                            var primaryKey   = entity.GetPrimaryKey();

                            switch (inputContext.Connection.Provider)
                            {
                            case "lucene":
                                input = new LuceneReader(
                                    inputContext,
                                    primaryKey,
                                    ctx.ResolveNamed <SearcherFactory>(entity.Key),
                                    ctx.ResolveNamed <Analyzer>(entity.Key + ReadFrom.Input),
                                    ctx.ResolveNamed <IndexReaderFactory>(entity.Key),
                                    rowFactory,
                                    ReadFrom.Input);
                                break;
                            }

                            IRead output         = new NullReader(context);
                            IDelete deleter      = new NullDeleter(context);
                            var outputConnection = _process.Output();
                            var outputContext    = ctx.ResolveNamed <OutputContext>(entity.Key);

                            switch (outputConnection.Provider)
                            {
                            case "lucene":
                                output = new LuceneReader(
                                    outputContext,
                                    primaryKey,
                                    ctx.ResolveNamed <SearcherFactory>(entity.Key),
                                    ctx.ResolveNamed <Analyzer>(entity.Key + ReadFrom.Output),
                                    ctx.ResolveNamed <IndexReaderFactory>(entity.Key),
                                    rowFactory,
                                    ReadFrom.Output
                                    );
                                //TODO: need LuceneUpdater (update TflDeleted to true)
                                break;
                            }

                            var handler = new DefaultDeleteHandler(context, input, output, deleter);

                            // since the primary keys from the input may have been transformed into the output, you have to transform before comparing
                            // feels a lot like entity pipeline on just the primary keys... may look at consolidating
                            handler.Register(new DefaultTransform(context, entity.GetPrimaryKey().ToArray()));
                            handler.Register(TransformFactory.GetTransforms(ctx, _process, entity, primaryKey));
                            handler.Register(new StringTruncateTransfom(context, primaryKey));

                            return(new ParallelDeleteHandler(handler));
                        }).Named <IEntityDeleteHandler>(entity.Key);
                    }
                }
            }
        }
Esempio n. 5
0
        public static CardLibrary GetInstance()
        {
            //单实例
            if (instance == null)
            {
                //读取配置
                CLConfig config = CLConfig.GetInstance();

                //获取路径
                path = Global.GetPath();

                //清除多余索引文件
                if (File.Exists(path + "CardIndex\\list.txt"))
                {
                    string[] files = File.ReadAllLines(path + "CardIndex\\list.txt", Encoding.UTF8);

                    foreach (string s in Directory.GetFiles(path + "CardIndex"))
                    {
                        string ss     = s.Substring(s.LastIndexOf('\\') + 1);
                        bool   inlist = false;
                        foreach (string s2 in files)
                        {
                            if (string.Equals(ss, s2, StringComparison.OrdinalIgnoreCase))
                            {
                                inlist = true;
                                break;
                            }
                        }

                        if (!(inlist || string.Equals(ss, "list.txt", StringComparison.OrdinalIgnoreCase)))
                        {
                            File.Delete(s);
                        }
                    }
                }

                //读取主索引
                indexdir = new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(path + "CardIndex"), new Lucene.Net.Store.SimpleFSLockFactory());

                //读取DIY索引
                if (Directory.Exists(path + "DIYCardIndex"))
                {
                    diydir = new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(path + "DIYCardIndex"), new Lucene.Net.Store.SimpleFSLockFactory());
                }

                //是否使用内存索引
                KeepInMemory = string.Equals(config.GetSetting("KeepInMemory"), "true", StringComparison.OrdinalIgnoreCase);
                if (KeepInMemory)
                {
                    indexdir = new Lucene.Net.Store.RAMDirectory(indexdir);

                    if (diydir != null)
                    {
                        diydir = new Lucene.Net.Store.RAMDirectory(diydir);
                    }
                }

                //读取所有卡片信息,建立卡片数据库实例
                LuceneReader Reader = new LuceneReader();
                instance = new CardLibrary(Reader.Read(indexdir));
                if (diydir != null)
                {
                    instance.AddDIYCards(Reader.Read(diydir));
                }

                //建立搜索器实例
                instance.BuildSearcher();
            }

            return(instance);
        }