コード例 #1
0
        public ChangeStreamTests()
        {
            _path = Path.Combine(Path.GetTempPath(), "LightningStore", Guid.NewGuid().ToString("N"));
            Directory.CreateDirectory(_path);

            _changeStream = new ChangeStream(_path);
        }
コード例 #2
0
        public SimpleEventStore(string baseDirectory)
        {
            var directoryName = Path.Combine(baseDirectory, "EventStore");

            Directory.CreateDirectory(directoryName);
            _allStream = new ChangeStream(directoryName);
            _notifier  = new PollingNotifier(ReadHead);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: LexouDuck/Event-Assembler
        private static void Assemble(ILog log)
        {
            TextReader input;
            bool       inputIsFile;

            if (Program.RunConfig.inputFile != null)
            {
                input       = File.OpenText(Program.RunConfig.inputFile);
                inputIsFile = false;
            }
            else
            {
                input       = Console.In;
                inputIsFile = true;
            }

            using (IDirectivePreprocessor preprocessor = new Preprocessor(log)) {
                // preprocessor.AddReserved (eaCodeLanguage.GetCodeNames ());
                preprocessor.AddDefined(new string[] { "_" + Program.RunConfig.language + "_", "_EA_" });

                DependencyMakingIncludeListener depMaker = null;

                if (Program.RunConfig.ppDepEnable)
                {
                    depMaker = new DependencyMakingIncludeListener();
                    preprocessor.IncludeListener = depMaker;
                }

                using (IInputStream inputStream = new PreprocessingInputStream(input, preprocessor)) {
                    if (Program.RunConfig.ppSimulation)
                    {
                        // preprocess to null output
                        while (inputStream.ReadLine() != null)
                        {
                            ;
                        }
                    }
                    else
                    {
                        if (Program.RunConfig.outputFile == null)
                        {
                            log.AddError("No output file specified for assembly.");
                            return;
                        }

                        string outFile = Program.RunConfig.outputFile;

                        if (File.Exists(outFile) && File.GetAttributes(outFile).HasFlag((Enum)FileAttributes.ReadOnly))
                        {
                            log.AddError("File `{0}` exists and cannot be written to.", outFile);
                            return;
                        }

                        ChangeStream changeStream = new ChangeStream();

                        using (BinaryWriter output = new BinaryWriter((Stream)changeStream)) {
                            if (!Program.CodesLoaded)
                            {
                                LoadCodes(false);
                            }

                            EACodeLanguage language = Program.Languages [Program.RunConfig.language];

                            EAExpressionAssembler assembler = new EAExpressionAssembler(language.CodeStorage, new TokenParser <int> (new Func <string, int> (StringExtensions.GetValue)));
                            assembler.Assemble(inputStream, output, log);

                            if (Program.RunConfig.symbolOutputFile != null)
                            {
                                // Outputting global symbols to another file

                                try {
                                    if (File.Exists(Program.RunConfig.symbolOutputFile))
                                    {
                                        File.Delete(Program.RunConfig.symbolOutputFile);
                                    }

                                    using (FileStream fileStream = File.OpenWrite(Program.RunConfig.symbolOutputFile))
                                        using (StreamWriter symOut = new StreamWriter(fileStream))
                                            foreach (KeyValuePair <string, int> symbol in assembler.GetGlobalSymbols())
                                            {
                                                symOut.WriteLine("{0}={1}", symbol.Key, symbol.Value.ToHexString("$"));
                                            }
                                } catch (Exception e) {
                                    log.AddError(e.ToString());
                                }
                            }
                        }

                        if (log.ErrorCount == 0)
                        {
                            using (Stream stream = (Stream)File.OpenWrite(outFile))
                                changeStream.WriteToFile(stream);
                        }
                    }
                }

                if (depMaker != null)
                {
                    try {
                        depMaker.GenerateMakeDependencies(log);
                    } catch (Exception e) {
                        log.AddError(e.ToString());
                    }
                }
            }

            if (inputIsFile)
            {
                input.Close();
            }
        }