Esempio n. 1
0
        public static void Run()
        {
            CodeBuilderConfiguration configuration = CodeBuilderConfiguration.Instance;

            for (int i = 0; i < configuration.Tasks.Count; i++)
            {
                TemplateGenerator generator = TemplateFactory.CreateObject(
                    configuration.Tasks[i].Name,
                    configuration.Tasks[i].Generator,
                    configuration);

                ITemplateObserver observer;

                foreach (TaskObserver item in configuration.Tasks[i].Observeres)
                {
                    switch (item.Type)
                    {
                    case "Console":
                        observer = new ConsoleObserver();
                        generator.AddObserver(observer);
                        break;

                    case "File":
                        observer = new FileObserver(configuration.Tasks[i]);
                        generator.AddObserver(observer);
                        break;

                    default:
                        break;
                    }
                }

                generator.Generate();
            }
        }
Esempio n. 2
0
 public HearthstoneEventObserver(IHearthstoneFactory factory)
 {
     this.factory = factory;
     currentState = new HearthInternalStateOff(this);
     fileObserver = new FileObserver("C:\\Program Files (x86)\\Hearthstone\\Logs\\Power.log", true);
     new Timer(TimeSpan.FromSeconds(10), DelayedObserving).Start();
 }
Esempio n. 3
0
 public static Assembly BuildAssemblyFromHbm(string assemblyName,params string[] mappings)
 {
     //uses hbm2net to create classes files.
     FileInfo configFile = new FileInfo(Path.GetTempFileName());
     List<string> hbms = new List<string>();
     // the mapping file needs to be written to the same
     // directory as the config file for this test
     foreach (var hbm in mappings)
     {
         FileInfo mappingFile = new FileInfo(Path.Combine(configFile.DirectoryName, hbm));
         if (mappingFile.Exists)
             mappingFile.Delete();
         ResourceHelper.WriteToFileFromResource(mappingFile, hbm);
         hbms.Add(mappingFile.FullName);
     }
     TestHelper.CreateConfigFile(configFile, T4DefaultTemplate, T4Renderer, "unused", "clazz.GeneratedName+\".generated.cs\"");
     List<string> args = new List<string>();
     args.Add("--config=" + configFile.FullName);
     args.AddRange(hbms);
     FileObserver fo = new FileObserver();
     CodeGenerator.Generate(args.ToArray(), fo);
     CSharpCodeProvider provider = new CSharpCodeProvider();
     CompilerParameters options = new CompilerParameters();
     options.GenerateInMemory = true;
     options.ReferencedAssemblies.Add(typeof(ISet).Assembly.Location);
     options.OutputAssembly = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyName + ".dll");
     options.GenerateInMemory = false;
     CompilerResults res = provider.CompileAssemblyFromFile(options, fo.Files);
     foreach (var e in res.Errors)
         Console.WriteLine("Compiler Error:" + e);
     Assert.AreEqual(0, res.Errors.Count);
     return res.CompiledAssembly;
 }
Esempio n. 4
0
 /// <summary>
 /// Cleanup OS handles for <see cref="_fileStreamReader"/>
 /// and <see cref="FileObserver"/>.
 /// </summary>
 protected override void PostStop()
 {
     _observer.Dispose();
     _observer = null;
     _fileStreamReader.Close();
     _fileStreamReader.Dispose();
     base.PostStop();
 }
Esempio n. 5
0
 /// <summary>
 /// The post stop.
 /// </summary>
 protected override void PostStop()
 {
     this.observer.Dispose();
     this.observer = null;
     this.fileStreamReader.Close();
     this.fileStreamReader.Dispose();
     base.PostStop();
 }
Esempio n. 6
0
 protected override void PostStop()
 {
     _observer.Dispose();
     _observer = null;
     _fileStreamReader.Close();
     _fileStreamReader.Dispose();
     base.PostStop();
 }
Esempio n. 7
0
        static void Main(string[] args)
        {
            var subject          = new ConcreteSubject();
            var fileObserver     = new FileObserver(subject);
            var insightsObserver = new InsightsObserver(subject);

            subject.Value = "Change this value";
            subject.Notify();
        }
Esempio n. 8
0
        private void Initialize()
        {
            modInstaller = new ModInstaller();

            game = new Game(this);

            fileObserver = new FileObserver(game);

            BuildLabel.Text = GameClient.Build;
        }
Esempio n. 9
0
        public void Show_NotifyTailActor_When_Change_Is_Made_To_File()
        {
            string fullFilePath = @"c:\temp\AkkaTest.txt";
            FileObserver fileObserver = new FileObserver(TestActor, fullFilePath);
            fileObserver.Start();
            File.WriteAllText(fullFilePath, "A test message from TailActorTests" +
                DateTime.Now.ToString());

            ExpectMsg<TailActor.FileWrite>(x => fullFilePath.Contains(x.FileName));
        }
Esempio n. 10
0
        public void Show_NotifyTailActor_When_Change_Is_Made_To_File()
        {
            string       fullFilePath = @"c:\temp\AkkaTest.txt";
            FileObserver fileObserver = new FileObserver(TestActor, fullFilePath);

            fileObserver.Start();
            File.WriteAllText(fullFilePath, "A test message from TailActorTests" +
                              DateTime.Now.ToString());

            ExpectMsg <TailActor.FileWrite>(x => fullFilePath.Contains(x.FileName));
        }
Esempio n. 11
0
        /// <summary>
        /// Initialization logic for actor that will tail changes to a file.
        /// </summary>
        protected override void PreStart()
        {
            // start watching file for changes
            _observer = new FileObserver(Self, Path.GetFullPath(_filePath));
            _observer.Start();

            // read the initial contents of the file and send it to console as first message
            var text = lastReadText = ReadFile();

            Self.Tell(new InitialRead(_filePath, text));
        }
Esempio n. 12
0
        public FileBacked(string file)
        {
            string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

            _path = Path.Combine(documentsPath, file);

            var observer = new FileObserver(_path, this);

            observer.StartWatching();

            if (File.Exists(_path))
            {
                FileChanged(File.ReadAllText(_path));
            }
        }
Esempio n. 13
0
        // we moved all the initialization logic from the constructor
        // down below to PreStart!
        /// <summary>
        /// Initialization logic for actor that will tail changes to a file.
        /// </summary>
        protected override void PreStart()
        {
            // start watching file for changes
            _observer = new FileObserver(Self, Path.GetFullPath(_filePath));
            _observer.Start();

            // open the file stream with shared read/write permissions (so file can be written to while open)
            _fileStream = new FileStream(Path.GetFullPath(_filePath), FileMode.Open, FileAccess.Read,
                FileShare.ReadWrite);
            _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8);

            // read the initial contents of the file and send it to console as first message
            var text = _fileStreamReader.ReadToEnd();
            Self.Tell(new InitialReadMessage(_filePath, text));
        }
Esempio n. 14
0
            protected override void PreStart()
            {
                // start watching file for changes
                _observer = new FileObserver(Self, Path.GetFullPath(_filePath));
                _observer.Start();

                // open the file stream with shared read/write permissions
                // (so file can be written to while open)
                _fileStream = new FileStream(Path.GetFullPath(_filePath),
                                             FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                _fileStreamReader = new StreamReader(_fileStream, Encoding.UTF8);

                // read the initial contents of the file and send it to console as first msg
                var text = _fileStreamReader.ReadToEnd();

                Self.Tell(new InitialRead(_filePath, text));
            }
Esempio n. 15
0
        /// <summary>生成SQL脚本</summary>
        /// <param name="options"></param>
        static void GenerateCode(Options options)
        {
            try
            {
                Console.WriteLine("loading configuration ...");

                string[] taskNames = options.TaskName.Split(',');

                foreach (string taskName in taskNames)
                {
                    var config = CodeBuilderEngine.GetTaskConfiguration(taskName);

                    if (config == null)
                    {
                        Console.WriteLine("未找到相关任务配置信息. [{\"task\":{\"name\":\"" + taskName + "\"}}]");
                        return;
                    }

                    Console.WriteLine();

                    Console.WriteLine("task name : {0}", config.Name);

                    foreach (TaskProperty property in config.Properties)
                    {
                        Console.WriteLine("\t{0} => {1}", property.Name, property.Value);
                    }

                    Console.WriteLine("\r\ngenerating code ...");

                    CodeBuilderEngine.Run(taskName);
                }

                Console.WriteLine("\r\nfinished.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());

                FileObserver file = new FileObserver("\\error_" + DateTime.Now.ToString("yyyy_MM_dd") + ".log");
                file.Generate(ex.ToString());
            }
        }
Esempio n. 16
0
        public static Assembly BuildAssemblyFromHbm(string assemblyName, params string[] mappings)
        {
            //uses hbm2net to create classes files.
            FileInfo      configFile = new FileInfo(Path.GetTempFileName());
            List <string> hbms       = new List <string>();

            // the mapping file needs to be written to the same
            // directory as the config file for this test
            foreach (var hbm in mappings)
            {
                FileInfo mappingFile = new FileInfo(Path.Combine(configFile.DirectoryName, hbm));
                if (mappingFile.Exists)
                {
                    mappingFile.Delete();
                }
                ResourceHelper.WriteToFileFromResource(mappingFile, hbm);
                hbms.Add(mappingFile.FullName);
            }
            TestHelper.CreateConfigFile(configFile, T4DefaultTemplate, T4Renderer, "unused", "clazz.GeneratedName+\".generated.cs\"");
            List <string> args = new List <string>();

            args.Add("--config=" + configFile.FullName);
            args.AddRange(hbms);
            FileObserver fo = new FileObserver();

            CodeGenerator.Generate(args.ToArray(), fo);
            CSharpCodeProvider provider = new CSharpCodeProvider();
            CompilerParameters options  = new CompilerParameters();

            options.GenerateInMemory = true;
            options.ReferencedAssemblies.Add(typeof(ISet).Assembly.Location);
            options.OutputAssembly   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyName + ".dll");
            options.GenerateInMemory = false;
            CompilerResults res = provider.CompileAssemblyFromFile(options, fo.Files);

            foreach (var e in res.Errors)
            {
                Console.WriteLine("Compiler Error:" + e);
            }
            Assert.AreEqual(0, res.Errors.Count);
            return(res.CompiledAssembly);
        }
        /// <summary>
        /// Attach an <paramref name="observer"/> on to a single file or directory.
        /// Observing a directory will observe the whole subtree.
        ///
        /// WARNING: The Observe implementation browses the subtree of the watched directory path in order to create delta of changes.
        /// </summary>
        /// <param name="filter">path to file or directory. The directory separator is "/". The root is without preceding slash "", e.g. "dir/dir2"</param>
        /// <param name="observer"></param>
        /// <param name="state">(optional) </param>
        /// <param name="eventDispatcher">(optional) event dispatcher</param>
        /// <param name="option">(optional) operation specific option; capability constraint, a session, security token or credential. Used for authenticating, authorizing or restricting the operation.</param>
        /// <returns>dispose handle</returns>
        /// <exception cref="IOException">On unexpected IO error</exception>
        /// <exception cref="SecurityException">If caller did not have permission</exception>
        /// <exception cref="ArgumentNullException"><paramref name="filter"/> is null</exception>
        /// <exception cref="ArgumentException"><paramref name="filter"/> contains only white space, or contains one or more invalid characters</exception>
        /// <exception cref="NotSupportedException">The <see cref="IFileSystem"/> doesn't support observe</exception>
        /// <exception cref="UnauthorizedAccessException">The access requested is not permitted by the operating system for the specified path.</exception>
        /// <exception cref="PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.</exception>
        /// <exception cref="InvalidOperationException">If <paramref name="filter"/> refers to a non-file device, such as "con:", "com1:", "lpt1:", etc.</exception>
        /// <exception cref="ObjectDisposedException"/>
        public virtual IFileSystemObserver Observe(string filter, IObserver <IEvent> observer, object state = null, IEventDispatcher eventDispatcher = default, IOption option = null)
        {
            // Assert observe is enabled.
            if (!CanObserve || !option.CanObserve(true))
            {
                throw new NotSupportedException(nameof(Observe));
            }
            // Assert not diposed
            IFileProvider fp = fileProvider;

            if (fp == null)
            {
                return(new DummyObserver(this, filter, observer, state, eventDispatcher));
            }
            // Parse filter
            GlobPatternInfo patternInfo = new GlobPatternInfo(filter);

            // Monitor single file (or dir, we don't know "dir")
            if (patternInfo.SuffixDepth == 0)
            {
                // Create observer that watches one file
                FileObserver handle = new FileObserver(this, filter, observer, state, eventDispatcher, option.OptionIntersection(this.options));
                // Send handle
                observer.OnNext(new StartEvent(handle, DateTimeOffset.UtcNow));
                // Return handle
                return(handle);
            }
            else
            // Has wildcards, e.g. "**/file.txt"
            {
                // Create handle
                PatternObserver handle = new PatternObserver(this, patternInfo, observer, state, eventDispatcher);
                // Send handle
                observer.OnNext(new StartEvent(handle, DateTimeOffset.UtcNow));
                // Return handle
                return(handle);
            }
        }
 public StartWatchingFileObserver(string path, FileObserver fileObserver) : base(path)
 {
     this.fileObserver = fileObserver;
 }
Esempio n. 19
0
        public static void Main(string[] args)
        {
            var fileObserver = new FileObserver();

            fileObserver.HandlerEvents();
        }
Esempio n. 20
0
 /// <summary>
 /// Cleanup OS handles for <see cref="FileObserver"/>.
 /// </summary>
 protected override void PostStop()
 {
     _observer.Dispose();
     _observer = null;
     base.PostStop();
 }
Esempio n. 21
0
 static void Main(string[] args)
 {
     fileObserver = new FileObserver("C:\\Users\\Public\\MirzabaevaHacker");
 }