Ejemplo n.º 1
0
		public void Start(FileInfo[] files, Template template, bool storeObjects)
		{
			this.files = files;
			this.template = template;
			this.storeObjects = storeObjects;
			this.state = EngineState.Running;
		}
Ejemplo n.º 2
0
		public void Startup()
		{
			if (_disposed)
			{
				throw new ObjectDisposedException(this.ToString());
			}
			
			_state = EngineState.Running;
		}
Ejemplo n.º 3
0
		public void Shutdown()
		{
			if (_disposed)
			{
				throw new ObjectDisposedException(this.ToString());
			}

			_state = EngineState.Stopped;
		}
Ejemplo n.º 4
0
		protected Engine()
		{
			this.state = EngineState.Stopped;
			this.clearedSeries = new Hashtable();
			new Thread(new ThreadStart(this.Run))
			{
				Name = "Import Engine"
			}.Start();
		}
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new instance of engine for the game
 /// </summary>
 private Engine()
 {
     engineState = new PlayState();
     TimerManager.RegisterTimer("Can Act", .25f);
     GameAction invoke = new GameAction(
         this,
          this.GetType().GetMethod("Select"),
          new object[0]);
     InputManager.AddToKeyboardMap(Keys.Enter, invoke);
     InputManager.AddToKeyboardMap(Keys.LeftShift, invoke);
 }
Ejemplo n.º 6
0
 protected Engine()
 {
   eX4XcIhHpDXt70u2x3N.k8isAcYzkUOGF();
   // ISSUE: explicit constructor call
   base.\u002Ector();
   this.wMOYKdjT8I = EngineState.Stopped;
   this.uESY0nGd5r = new Hashtable();
   new Thread(new ThreadStart(this.s6aY4lp6hS))
   {
     Name = RNaihRhYEl0wUmAftnB.aYu7exFQKN(5304)
   }.Start();
 }
Ejemplo n.º 7
0
 public RoomieEngine()
 {
     _engineState = EngineState.New;
     GlobalScope = new HierarchicalVariableScope();
     DataStore = new DataStore();
     StreamStore = new SafeWritingStreamStore(new BasicStreamStore());
     ThreadPools = new List<ThreadPool>();
     Threads = CreateThreadPool("Root Threads");
     CommandLibrary = new RoomieCommandLibrary();
     CommandLibrary.Message += CommandLibrary_Message;
     PrintCommandCalls = false;
     DevelopmentEnvironment = Environment.CurrentDirectory.EndsWith(@"\bin\Debug");
     ArgumentTypes = new ArgumentTypeCollection();
 }
Ejemplo n.º 8
0
		public void Dispose()
		{
			lock (this)
			{
				if (!_disposed)
				{
					_state = EngineState.Quit;
					_processThread = null;

					GC.SuppressFinalize(this);

					_disposed = true;
				}
			}
		}
Ejemplo n.º 9
0
 public void Pause()
 {
     this.wMOYKdjT8I = EngineState.Paused;
 }
Ejemplo n.º 10
0
        public void Start()
        {
            if (Global.IsRunningOnMono())
            {
                ThreadPool.SetMaxThreads(200, 50);
                ThreadPool.SetMinThreads(100, 50);
            }

            Logger.Info(@"
_________ _______ _________ ______   _______  _       
\__   __/(  ____ )\__   __/(  ___ \ (  ___  )( \      
   ) (   | (    )|   ) (   | (   ) )| (   ) || (      
   | |   | (____)|   | |   | (__/ / | (___) || |      
   | |   |     __)   | |   |  __ (  |  ___  || |      
   | |   | (\ (      | |   | (  \ \ | (   ) || |      
   | |   | ) \ \_____) (___| )___) )| )   ( || (____/\
   )_(   |/   \__/\_______/|/ \___/ |/     \|(_______/
                                                      
          _______  _______  _______ 
|\     /|(  ____ \(  ____ )(  ___  )
| )   ( || (    \/| (    )|| (   ) |
| (___) || (__    | (____)|| |   | |
|  ___  ||  __)   |     __)| |   | |
| (   ) || (      | (\ (   | |   | |
| )   ( || (____/\| ) \ \__| (___) |
|/     \|(_______/|/   \__/(_______)");

            if (State != EngineState.Stopped)
            {
                throw new Exception("Server is not stopped");
            }

            State = EngineState.Starting;

            // Load map
            using (var mapFile = new FileStream(Config.maps_folder + "map.dat", FileMode.Open))
                using (var map = new GZipStream(mapFile, CompressionMode.Decompress))
                {
                    // Create region changes file or open it depending on config settings
                    string regionChangesPath = Config.regions_folder + "region_changes.dat";

#if DEBUG
                    bool createRegionChanges = Config.database_empty || !File.Exists(regionChangesPath);
#else
                    bool createRegionChanges = !File.Exists(regionChangesPath);
#endif
                    FileStream regionChanges = File.Open(regionChangesPath,
                                                         createRegionChanges ? FileMode.Create : FileMode.Open,
                                                         FileAccess.ReadWrite);

                    // Load map
                    world.Regions.Load(map,
                                       regionChanges,
                                       createRegionChanges,
                                       Config.map_width,
                                       Config.map_height,
                                       Config.region_width,
                                       Config.region_height,
                                       Config.minimap_region_width,
                                       Config.minimap_region_height);
                }

#if DEBUG
            if (Config.server_production)
            {
                throw new Exception("Trying to run debug on production server");
            }
#endif

            // Empty database if specified
#if DEBUG
            if (Config.database_empty)
            {
                dbManager.EmptyDatabase();
            }
#endif

            // Initiate city channel
            cityChannel.Register(world.Cities);

            // Load database
            dbLoader.LoadFromDatabase();

            // Initialize stronghold
            if (Config.stronghold_generate > 0 && strongholdManager.Count == 0) // Only generate if there is none.
            {
                strongholdManager.Generate(Config.stronghold_generate);
            }

            strongholdActivationChecker.Start(TimeSpan.FromSeconds(Config.stronghold_activation_check_interval_in_sec));
            strongholdChecker.Start();
            strongholdManagerLogger.Listen(strongholdManager);

            // Initialize barbarian tribes
            barbarianTribeChecker.Start(TimeSpan.FromSeconds(Config.barbariantribe_idle_check_interval_in_sec));

            // Initialize game market
            Market.Init();

            // Start listening  for queue events
            if (!Config.queue_disabled)
            {
                queueListener.Start(Config.api_domain);
            }

            // Start store sync
            storeSync.Start();

            // Start command processor
            server.Start(Config.server_listen_address, Config.server_port);

            // Start policy server
            policyServer.Start(Config.server_listen_address, 843);

            // Start thrift server
            ThreadPool.QueueUserWorkItem(o => thriftServer.Serve());

            // Schedule player deletions
            if (Config.players_remove_idle)
            {
                playersRemoverFactory.CreatePlayersRemover(playerSelector.CreateNewbieIdleSelector()).Start();
            }

            // Start data export
            mapDataExport.Start(TimeSpan.FromMinutes(30));

            State = EngineState.Started;
        }
Ejemplo n.º 11
0
		private void WaitForState(EngineState[] expectedStates)
		{
			while (true)
			{
				foreach (EngineState engineState in expectedStates)
				{
					if (this.state == engineState)
						return;
				}
				Thread.Sleep(1);
			}
		}
Ejemplo n.º 12
0
        public static List <LogInfo> UserInput(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_UserInput));
            CodeInfo_UserInput info = cmd.Info as CodeInfo_UserInput;

            UserInputType type = info.Type;

            switch (type)
            {
            case UserInputType.DirPath:
            case UserInputType.FilePath:
            {
                Debug.Assert(info.SubInfo.GetType() == typeof(UserInputInfo_DirFile));
                UserInputInfo_DirFile subInfo = info.SubInfo as UserInputInfo_DirFile;

                System.Windows.Shell.TaskbarItemProgressState oldTaskbarItemProgressState = s.MainViewModel.TaskbarProgressState;         // Save our progress state
                s.MainViewModel.TaskbarProgressState = System.Windows.Shell.TaskbarItemProgressState.Paused;

                string initPath     = StringEscaper.Preprocess(s, subInfo.InitPath);
                string selectedPath = initPath;
                if (type == UserInputType.FilePath)
                {
                    string filter   = "All Files|*.*";
                    string initFile = Path.GetFileName(initPath);
                    if (initFile.StartsWith("*.", StringComparison.Ordinal) || initFile.Equals("*", StringComparison.Ordinal))
                    {         // If wildcard exists, apply to filter.
                        string ext = Path.GetExtension(initFile);
                        if (1 < ext.Length && ext.StartsWith(".", StringComparison.Ordinal))
                        {
                            ext = ext.Substring(1);
                        }
                        filter = $"{ext} Files|{initFile}";
                    }

                    Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog()
                    {
                        Filter           = filter,
                        InitialDirectory = Path.GetDirectoryName(initPath),
                    };

                    if (dialog.ShowDialog() == true)
                    {
                        selectedPath = dialog.FileName;
                        logs.Add(new LogInfo(LogState.Success, $"File path [{selectedPath}] was chosen by user"));
                    }
                    else
                    {
                        logs.Add(new LogInfo(LogState.Error, "File path was not chosen by user"));
                        return(logs);
                    }
                }
                else
                {
                    VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog()
                    {
                        SelectedPath = initPath,
                    };

                    bool failure = false;
                    Application.Current.Dispatcher.Invoke(() =>
                        {
                            MainWindow w = Application.Current.MainWindow as MainWindow;

                            if (dialog.ShowDialog(w) == true)
                            {
                                selectedPath = dialog.SelectedPath;
                                logs.Add(new LogInfo(LogState.Success, $"Directory path [{selectedPath}] was chosen by user"));
                            }
                            else
                            {
                                logs.Add(new LogInfo(LogState.Error, "Directory path was not chosen by user"));
                                failure = true;
                            }
                        });
                    if (failure)
                    {
                        return(logs);
                    }
                }

                s.MainViewModel.TaskbarProgressState = oldTaskbarItemProgressState;

                List <LogInfo> varLogs = Variables.SetVariable(s, subInfo.DestVar, selectedPath);
                logs.AddRange(varLogs);
            }
            break;

            default:     // Error
                throw new InvalidCodeCommandException($"Wrong UserInputType [{type}]");
            }

            return(logs);
        }
Ejemplo n.º 13
0
 public void Finish()
 {
     this.wMOYKdjT8I = EngineState.Finished;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// This is a variation of LogEngineHealthEvent api to make additionalInfo
 /// optional
 /// </summary>
 /// <param name="executionContext"></param>
 /// <param name="eventId"></param>
 /// <param name="exception"></param>
 /// <param name="severity"></param>
 /// <param name="newEngineState"></param>
 internal static void LogEngineHealthEvent(ExecutionContext executionContext,
                                         int eventId,
                                         Exception exception,
                                         Severity severity,
                                         EngineState newEngineState)
 {
     LogEngineHealthEvent(executionContext, eventId, exception, severity, null, newEngineState);
 }
Ejemplo n.º 15
0
        public bool IsEngineStateChangeAllowed(EngineState newState, EngineState oldState)
        {
            switch (newState)
            {
                case EngineState.PreparingSync:
                    return (this.CurrentState == PartnershipState.Idle);

                case EngineState.Syncing:
                    return ((this.CurrentState == PartnershipState.Idle) || (this.CurrentState == PartnershipState.PreparingSync));
            }
            return true;
        }
Ejemplo n.º 16
0
        public void FileDelete()
        {
            EngineState s       = EngineTests.CreateEngineState();
            string      destDir = FileHelper.GetTempDir();

            void SingleTemplate(string rawCode, string fileName, ErrorCheck check = ErrorCheck.Success)
            {
                string dirPath = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandFile"));

                string srcDir = Path.Combine(dirPath, SrcDirFile);

                string destFullPath = Path.Combine(destDir, fileName);

                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
                FileHelper.DirCopy(srcDir, destDir, new FileHelper.DirCopyOptions
                {
                    CopySubDirs = true,
                    Overwrite   = true,
                });
                try
                {
                    EngineTests.Eval(s, rawCode, CodeType.FileDelete, check);

                    if (check == ErrorCheck.Success)
                    {
                        Assert.IsFalse(File.Exists(destFullPath));
                    }
                }
                finally
                {
                    if (Directory.Exists(destDir))
                    {
                        Directory.Delete(destDir, true);
                    }
                }
            }

            void MultiTemplate(string rawCode, string wildCard, ErrorCheck check = ErrorCheck.Success, bool recursive = true)
            {
                string dirPath      = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandFile"));
                string srcDir       = Path.Combine(dirPath, SrcDirFile);
                string destFullPath = Path.Combine(destDir, wildCard);

                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
                FileHelper.DirCopy(srcDir, destDir, new FileHelper.DirCopyOptions
                {
                    CopySubDirs = true,
                    Overwrite   = true,
                });
                try
                {
                    string[] destFiles;
                    if (recursive)
                    {
                        destFiles = Directory.GetFiles(destDir, wildCard, SearchOption.AllDirectories);
                    }
                    else
                    {
                        destFiles = Directory.GetFiles(destDir, wildCard);
                    }

                    EngineTests.Eval(s, rawCode, CodeType.FileDelete, check);

                    if (check == ErrorCheck.Success)
                    {
                        for (int i = 0; i < destFiles.Length; i++)
                        {
                            Assert.IsFalse(File.Exists(destFullPath));
                        }
                    }
                }
                finally
                {
                    if (Directory.Exists(destDir))
                    {
                        Directory.Delete(destDir, true);
                    }
                }
            }

            SingleTemplate($@"FileDelete,{destDir}\A.txt", "A.txt");
            SingleTemplate($@"FileDelete,{destDir}\H.txt", "H.txt", ErrorCheck.Warning);
            SingleTemplate($@"FileDelete,{destDir}\H.txt,NOWARN", "H.txt", ErrorCheck.Success);
            MultiTemplate($@"FileDelete,{destDir}\*.ini", "*.ini", ErrorCheck.Success);
            MultiTemplate($@"FileDelete,{destDir}\*.ini,NOREC", "*.ini", ErrorCheck.Success, false);
        }
Ejemplo n.º 17
0
        public void DirCopy()
        {
            EngineState s         = EngineTests.CreateEngineState();
            string      pbDirPath = Path.Combine("%TestBench%", "CommandFile");
            string      pbSrcDir  = Path.Combine(pbDirPath, SrcDirDir);
            string      destDir   = FileHelper.GetTempDir();

            void Template(string rawCode, string dirName, ErrorCheck check = ErrorCheck.Success, bool wbBug = false)
            {
                string dirPath = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandFile"));
                string srcDir  = Path.Combine(dirPath, SrcDirDir);

                string srcFullPath  = Path.Combine(srcDir, dirName);
                string destFullPath = Path.Combine(destDir, dirName);

                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
                try
                {
                    EngineTests.Eval(s, rawCode, CodeType.DirCopy, check);

                    if (check == ErrorCheck.Success)
                    {
                        string wildcard = null;
                        if (dirName.IndexOfAny(new char[] { '*', '?' }) != -1)
                        {
                            wildcard = dirName;
                        }

                        if (wildcard == null)
                        {
                            Assert.IsTrue(Directory.Exists(destFullPath));

                            string[] srcDirs  = Directory.GetFiles(srcFullPath, "*", SearchOption.AllDirectories);
                            string[] destDirs = Directory.GetFiles(destFullPath, "*", SearchOption.AllDirectories);

                            Assert.IsTrue(srcDirs.Length == destDirs.Length);

                            for (int i = 0; i < srcDirs.Length; i++)
                            {
                                Assert.IsTrue(srcDirs[i].Substring(srcDir.Length).Equals(destDirs[i].Substring(destDir.Length), StringComparison.Ordinal));
                            }
                        }
                        else
                        {
                            if (wbBug)
                            {
                                string[] firstSrcFiles  = Directory.GetFiles(srcDir, wildcard);
                                string[] firstDestFiles = Directory.GetFiles(destDir, wildcard);
                                Assert.IsTrue(firstDestFiles.Length == firstSrcFiles.Length);
                            }
                            else
                            {
                                string[] firstDestFiles = Directory.GetFiles(destDir, wildcard);
                                Assert.IsTrue(firstDestFiles.Length == 0);
                            }

                            string[] firstSrcDirs  = Directory.GetDirectories(srcDir, wildcard);
                            string[] firstDestDirs = Directory.GetDirectories(destDir, wildcard);
                            Assert.IsTrue(firstSrcDirs.Length == firstDestDirs.Length);

                            for (int i = 0; i < firstSrcDirs.Length; i++)
                            {
                                string[] srcDirs  = Directory.GetFiles(firstSrcDirs[i], "*", SearchOption.AllDirectories);
                                string[] destDirs = Directory.GetFiles(firstDestDirs[i], "*", SearchOption.AllDirectories);
                                Assert.IsTrue(srcDirs.Length == destDirs.Length);
                                Assert.IsTrue(srcDirs[i].Substring(srcDir.Length).Equals(destDirs[i].Substring(destDir.Length), StringComparison.Ordinal));
                            }
                        }
                    }
                }
                finally
                {
                    if (Directory.Exists(destDir))
                    {
                        Directory.Delete(destDir, true);
                    }
                }
            }

            Template($@"DirCopy,{pbSrcDir}\ABCD,{destDir}", "ABCD");
            Template($@"DirCopy,{pbSrcDir}\ABDE,{destDir}", "ABDE");
            Template($@"DirCopy,{pbSrcDir}\AB*,{destDir}", "AB*");
            Template($@"DirCopy,{pbSrcDir}\*,{destDir}", "*");

            s.CompatDirCopyBug = true;
            Template($@"DirCopy,{pbSrcDir}\*,{destDir}", "*", ErrorCheck.Success, true);
        }
Ejemplo n.º 18
0
        public static List <LogInfo> DirCopy(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_DirCopy));
            CodeInfo_DirCopy info = cmd.Info as CodeInfo_DirCopy;

            string srcDir  = StringEscaper.Preprocess(s, info.SrcDir);
            string destDir = StringEscaper.Preprocess(s, info.DestDir);

            // Path Security Check
            if (StringEscaper.PathSecurityCheck(destDir, out string errorMsg) == false)
            {
                logs.Add(new LogInfo(LogState.Error, errorMsg));
                return(logs);
            }

            // DestPath must be directory
            if (File.Exists(destDir))
            {
                logs.Add(new LogInfo(LogState.Error, $"Cannot overwrite file [{destDir}] with directory [{srcDir}]"));
                return(logs);
            }

            // Check srcDir contains wildcard
            string wildcard = Path.GetFileName(srcDir);

            if (wildcard.IndexOfAny(new char[] { '*', '?' }) == -1)
            { // No Wildcard
                string destFullPath = Path.Combine(destDir, Path.GetFileName(srcDir));
                if (Directory.Exists(destFullPath))
                {
                    logs.Add(new LogInfo(LogState.Overwrite, $"Directory [{destFullPath}] will be overwritten with [{srcDir}]"));
                }
                else
                {
                    Directory.CreateDirectory(destFullPath);
                }

                FileHelper.DirectoryCopy(srcDir, destFullPath, true, true, null);
                logs.Add(new LogInfo(LogState.Success, $"Directory [{srcDir}] copied to [{destFullPath}]", cmd));
            }
            else
            { // With Wildcard
                if (Directory.Exists(destDir))
                {
                    logs.Add(new LogInfo(LogState.Overwrite, $"Directory [{destDir}] will be overwritten with [{srcDir}]"));
                }
                else
                {
                    Directory.CreateDirectory(destDir);
                }

                string srcParentDir = Path.GetDirectoryName(srcDir);

                DirectoryInfo dirInfo = new DirectoryInfo(srcParentDir);
                if (!dirInfo.Exists)
                {
                    throw new DirectoryNotFoundException($"Source directory does not exist or cannot be found: {srcDir}");
                }

                if (s.CompatDirCopyBug)
                { // Simulate WB082's [DirCopy,%SrcDir%\*,%DestDir%] filecopy bug
                    foreach (FileInfo f in dirInfo.GetFiles(wildcard))
                    {
                        File.Copy(f.FullName, Path.Combine(destDir, f.Name), true);
                    }
                }

                // Copy first sublevel directory with wildcard
                // Note that wildcard will not be applied to subdirectory copy
                foreach (DirectoryInfo subDir in dirInfo.GetDirectories(wildcard))
                {
                    FileHelper.DirectoryCopy(subDir.FullName, Path.Combine(destDir, subDir.Name), true, true, null);
                }

                logs.Add(new LogInfo(LogState.Success, $"Directory [{srcDir}] copied to [{destDir}]", cmd));
            }

            return(logs);
        }
Ejemplo n.º 19
0
        public static List <LogInfo> FileCopy(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_FileCopy));
            CodeInfo_FileCopy info = cmd.Info as CodeInfo_FileCopy;

            string srcFile  = StringEscaper.Preprocess(s, info.SrcFile);
            string destPath = StringEscaper.Preprocess(s, info.DestPath);

            // Path Security Check
            if (StringEscaper.PathSecurityCheck(destPath, out string errorMsg) == false)
            {
                logs.Add(new LogInfo(LogState.Error, errorMsg));
                return(logs);
            }

            // Check destPath is directory
            bool destPathExists = false;
            bool destPathIsDir  = false;

            if (Directory.Exists(destPath))
            {
                destPathExists = true;
                destPathIsDir  = true;
            }
            else if (File.Exists(destPath))
            {
                destPathExists = true;
            }

            // Check srcFileName contains wildcard
            string wildcard = Path.GetFileName(srcFile);

            if (wildcard.IndexOfAny(new char[] { '*', '?' }) == -1)
            {                      // No Wildcard
                if (destPathIsDir) // DestPath exists, and it is directory
                {
                    Directory.CreateDirectory(destPath);
                    string destFullPath = Path.Combine(destPath, Path.GetFileName(srcFile));
                    if (File.Exists(destFullPath))
                    {
                        if (info.Preserve)
                        {
                            logs.Add(new LogInfo(info.NoWarn ? LogState.Ignore : LogState.Overwrite, $"[{destFullPath}] will not be overwritten", cmd));
                            return(logs);
                        }
                        else
                        {
                            logs.Add(new LogInfo(info.NoWarn ? LogState.Ignore : LogState.Overwrite, $"File [{destFullPath}] will be overwritten", cmd));
                        }
                    }

                    File.Copy(srcFile, destFullPath, true);
                    logs.Add(new LogInfo(LogState.Success, $"[{srcFile}] copied to [{destFullPath}]", cmd));
                }
                else // DestPath not exist, or it is a file
                {
                    Directory.CreateDirectory(FileHelper.GetDirNameEx(destPath));
                    if (destPathExists)
                    {
                        if (info.Preserve)
                        {
                            logs.Add(new LogInfo(info.NoWarn ? LogState.Ignore : LogState.Overwrite, $"[{destPath}] will not be overwritten", cmd));
                            return(logs);
                        }
                        else
                        {
                            logs.Add(new LogInfo(info.NoWarn ? LogState.Ignore : LogState.Overwrite, $"File [{destPath}] will be overwritten", cmd));
                        }
                    }

                    File.Copy(srcFile, destPath, true);
                    logs.Add(new LogInfo(LogState.Success, $"[{srcFile}] copied to [{destPath}]", cmd));
                }
            }
            else
            { // With Wildcard
                // Use FileHelper.GetDirNameEx to prevent ArgumentException of Directory.GetFiles
                string srcDirToFind = Path.GetFullPath(FileHelper.GetDirNameEx(srcFile));

                string[] files;
                if (info.NoRec)
                {
                    files = FileHelper.GetFilesEx(srcDirToFind, wildcard);
                }
                else
                {
                    files = FileHelper.GetFilesEx(srcDirToFind, wildcard, SearchOption.AllDirectories);
                }

                if (0 < files.Length)
                { // One or more file will be copied
                    logs.Add(new LogInfo(LogState.Success, $"[{srcFile}] will be copied to [{destPath}]", cmd));

                    if (destPathIsDir || !destPathExists)
                    {
                        for (int i = 0; i < files.Length; i++)
                        {
                            string f            = files[i];
                            string destFullPath = Path.Combine(destPath, f.Substring(srcDirToFind.Length + 1));

                            if (File.Exists(destFullPath))
                            {
                                if (info.Preserve)
                                {
                                    logs.Add(new LogInfo(info.NoWarn ? LogState.Ignore : LogState.Overwrite, $"[{destFullPath}] will not be overwritten", cmd));
                                    continue;
                                }
                                else
                                {
                                    logs.Add(new LogInfo(info.NoWarn ? LogState.Ignore : LogState.Overwrite, $"[{destFullPath}] will be overwritten", cmd));
                                }
                            }

                            Directory.CreateDirectory(Path.GetDirectoryName(destFullPath));
                            File.Copy(f, destFullPath, true);

                            logs.Add(new LogInfo(LogState.Success, $"[{f}] copied to [{destFullPath}]", cmd));
                        }

                        logs.Add(new LogInfo(LogState.Success, $"[{files.Length}] files copied", cmd));
                    }
                    else
                    {
                        logs.Add(new LogInfo(LogState.Error, "<DestPath> must be directory when using wildcard in <SrcFile>", cmd));
                        return(logs);
                    }
                }
                else
                { // No file will be copied
                    logs.Add(new LogInfo(LogState.Ignore, $"Files matching wildcard [{srcFile}] were not found", cmd));
                }
            }

            return(logs);
        }
Ejemplo n.º 20
0
        public static List <LogInfo> FileRename(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_FileRename));
            CodeInfo_FileRename info = cmd.Info as CodeInfo_FileRename;

            string srcPath  = StringEscaper.Preprocess(s, info.SrcPath);
            string destPath = StringEscaper.Preprocess(s, info.DestPath);

            // Path Security Check
            if (StringEscaper.PathSecurityCheck(destPath, out string errorMsg) == false)
            {
                logs.Add(new LogInfo(LogState.Error, errorMsg));
                return(logs);
            }

            if (File.Exists(srcPath) == false)
            {
                // Check if srcPath is directory
                if (Directory.Exists(srcPath))
                {
                    if (s.CompatFileRenameCanMoveDir)
                    {
                        if (Directory.Exists(destPath))
                        {
                            string destFullPath = Path.Combine(destPath, Path.GetFileName(srcPath));

                            Directory.Move(srcPath, destFullPath);
                            logs.Add(new LogInfo(LogState.Success, $"Directory [{srcPath}] moved to [{destFullPath}]"));
                            return(logs);
                        }
                        else
                        {
                            Directory.Move(srcPath, destPath);
                            logs.Add(new LogInfo(LogState.Success, $"Directory [{srcPath}] moved to [{destPath}]"));
                            return(logs);
                        }
                    }
                    else
                    {
                        logs.Add(new LogInfo(LogState.Error, $"[{srcPath}] is a directory, not a file"));
                        return(logs);
                    }
                }
                else
                {
                    logs.Add(new LogInfo(LogState.Error, $"File [{srcPath}] does not exist"));
                    return(logs);
                }
            }

            File.SetAttributes(srcPath, FileAttributes.Normal);
            File.Move(srcPath, destPath);
            if (cmd.Type == CodeType.FileRename)
            {
                logs.Add(new LogInfo(LogState.Success, $"File [{srcPath}] renamed to [{destPath}]"));
            }
            else
            {
                logs.Add(new LogInfo(LogState.Success, $"File [{srcPath}] moved to [{destPath}]"));
            }

            return(logs);
        }
Ejemplo n.º 21
0
        public static List <LogInfo> FileDelete(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_FileDelete));
            CodeInfo_FileDelete info = cmd.Info as CodeInfo_FileDelete;

            string filePath = StringEscaper.Preprocess(s, info.FilePath);

            // Path Security Check
            if (StringEscaper.PathSecurityCheck(filePath, out string errorMsg) == false)
            {
                logs.Add(new LogInfo(LogState.Error, errorMsg));
                return(logs);
            }

            // Check srcFileName contains wildcard
            string wildcard = Path.GetFileName(filePath);

            if (wildcard.IndexOfAny(new char[] { '*', '?' }) == -1)
            {     // No Wildcard
                if (File.Exists(filePath))
                { // Delete File
                    File.SetAttributes(filePath, FileAttributes.Normal);
                    File.Delete(filePath);

                    logs.Add(new LogInfo(LogState.Success, $"Deleted file [{filePath}]"));
                }
                else
                {
                    logs.Add(new LogInfo(info.NoWarn ? LogState.Ignore : LogState.Warning, $"File [{filePath}] does not exist"));
                }
            }
            else
            { // With Wildcard
                // Use FileHelper.GetDirNameEx to prevent ArgumentException of Directory.GetFiles
                string srcDirToFind = FileHelper.GetDirNameEx(filePath);
                if (Directory.Exists(srcDirToFind) == false)
                {
                    logs.Add(new LogInfo(LogState.Error, $"Cannot find path [{srcDirToFind}]"));
                    return(logs);
                }

                string[] files;
                if (info.NoRec)
                {
                    files = FileHelper.GetFilesEx(srcDirToFind, wildcard);
                }
                else
                {
                    files = FileHelper.GetFilesEx(srcDirToFind, wildcard, SearchOption.AllDirectories);
                }

                if (0 < files.Length)
                { // One or more file will be deleted
                    foreach (string f in files)
                    {
                        File.SetAttributes(f, FileAttributes.Normal);
                        File.Delete(f);
                        logs.Add(new LogInfo(LogState.Success, $"File [{f}] deleted"));
                    }

                    logs.Add(new LogInfo(LogState.Success, $"[{files.Length}] files deleted"));
                }
                else
                { // No file will be deleted
                    logs.Add(new LogInfo(info.NoWarn ? LogState.Ignore : LogState.Warning, $"Files matching wildcard [{filePath}] were not found"));
                }
            }

            return(logs);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Provider interface function for logging engine lifecycle event
        /// </summary>
        /// <param name="logContext"></param>
        /// <param name="newState"></param>
        /// <param name="previousState"></param>
        internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
        {
            if (IsEnabled(PSLevel.Informational, PSKeyword.Cmdlets | PSKeyword.UseAlwaysAnalytic))
            {
                StringBuilder payload = PayloadBuilder;
                payload.Clear();

                payload.AppendLine(StringUtil.Format(EtwLoggingStrings.EngineStateChange, previousState.ToString(), newState.ToString()));

                PSTask task = PSTask.EngineStart;

                if (newState == EngineState.Stopped ||
                    newState == EngineState.OutOfService ||
                    newState == EngineState.None ||
                    newState == EngineState.Degraded)
                {
                    task = PSTask.EngineStop;
                }

                WriteEvent(PSEventId.Engine_Lifecycle, PSChannel.Analytic, PSOpcode.Method, task, logContext, payload.ToString());
            }
        }
Ejemplo n.º 23
0
		public void Stop()
		{
			this.state = EngineState.Stopped;
		}
Ejemplo n.º 24
0
 /// <summary>
 /// This is a variation of basic LogEngineLifeCycleEvent api which makes invocationInfo
 /// optional.
 /// </summary>
 /// <param name="executionContext"></param>
 /// <param name="engineState"></param>
 internal static void LogEngineLifecycleEvent(ExecutionContext executionContext,
                                              EngineState engineState)
 {
     LogEngineLifecycleEvent(executionContext, engineState, null);
 }
Ejemplo n.º 25
0
		public void Continue()
		{
			this.state = EngineState.Running;
		}
Ejemplo n.º 26
0
 public void Stop()
 {
   this.wMOYKdjT8I = EngineState.Stopped;
 }
Ejemplo n.º 27
0
 /// <summary>
 /// This is a variation of basic LogEngineLifeCycleEvent api which makes invocationInfo
 /// optional.
 /// </summary>
 /// <param name="executionContext"></param>
 /// <param name="engineState"></param>
 internal static void LogEngineLifecycleEvent(ExecutionContext executionContext,
                                         EngineState engineState)
 {
     LogEngineLifecycleEvent(executionContext, engineState, null);
 }
Ejemplo n.º 28
0
 public void Continue()
 {
   this.wMOYKdjT8I = EngineState.Running;
 }
Ejemplo n.º 29
0
 internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
 {
     int engineLifecycleEventId = GetEngineLifecycleEventId(newState);
     if (engineLifecycleEventId != -1)
     {
         Hashtable mapArgs = new Hashtable();
         mapArgs["NewEngineState"] = newState.ToString();
         mapArgs["PreviousEngineState"] = previousState.ToString();
         FillEventArgs(mapArgs, logContext);
         EventInstance entry = new EventInstance((long) engineLifecycleEventId, 4) {
             EntryType = EventLogEntryType.Information
         };
         string eventDetail = this.GetEventDetail("EngineLifecycleContext", mapArgs);
         this.LogEvent(entry, new object[] { newState, previousState, eventDetail });
     }
 }
Ejemplo n.º 30
0
 public void Continue()
 {
     this.wMOYKdjT8I = EngineState.Running;
 }
Ejemplo n.º 31
0
 public void Stop()
 {
     this.wMOYKdjT8I = EngineState.Stopped;
 }
Ejemplo n.º 32
0
 public void Finish()
 {
   this.wMOYKdjT8I = EngineState.Finished;
 }
Ejemplo n.º 33
0
        public void FileCopy()
        {
            EngineState s = EngineTests.CreateEngineState();

            string pbDirPath = Path.Combine("%TestBench%", "CommandFile");
            string pbSrcDir  = Path.Combine(pbDirPath, SrcDirFile);
            string destDir   = FileHelper.GetTempDir();

            void SingleTemplate(string rawCode, string srcFileName, string destFileName,
                                ErrorCheck check = ErrorCheck.Success, bool preserve = false, bool ignoreCompare = false)
            {
                if (destFileName == null)
                {
                    destFileName = srcFileName;
                }

                string dirPath = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandFile"));
                string srcDir  = Path.Combine(dirPath, SrcDirFile);

                string srcFullPath  = Path.Combine(srcDir, srcFileName);
                string destFullPath = Path.Combine(destDir, destFileName);

                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
                Directory.CreateDirectory(destDir);
                try
                {
                    if (preserve)
                    {
                        File.Create(destFullPath).Close();
                    }

                    EngineTests.Eval(s, rawCode, CodeType.FileCopy, check);

                    if (check == ErrorCheck.Success && !ignoreCompare)
                    {
                        Assert.IsTrue(File.Exists(destFullPath));

                        using (FileStream srcStream = new FileStream(srcFullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                            using (FileStream destStream = new FileStream(destFullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                            {
                                byte[] srcDigest  = HashHelper.GetHash(HashHelper.HashType.SHA256, srcStream);
                                byte[] destDigest = HashHelper.GetHash(HashHelper.HashType.SHA256, destStream);
                                Assert.IsTrue(srcDigest.SequenceEqual(destDigest));
                            }
                    }
                }
                finally
                {
                    if (Directory.Exists(destDir))
                    {
                        Directory.Delete(destDir, true);
                    }
                }
            }

            void MultiTemplate(string rawCode, string srcFileWildCard, bool recursive, ErrorCheck check = ErrorCheck.Success)
            {
                string dirPath = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandFile"));
                string srcDir  = Path.Combine(dirPath, SrcDirFile);

                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
                Directory.CreateDirectory(destDir);
                try
                {
                    EngineTests.Eval(s, rawCode, CodeType.FileCopy, check);

                    if (check == ErrorCheck.Success)
                    {
                        string[] srcFiles;
                        string[] destFiles;
                        if (recursive)
                        {
                            srcFiles  = Directory.GetFiles(srcDir, srcFileWildCard, SearchOption.AllDirectories);
                            destFiles = Directory.GetFiles(destDir, srcFileWildCard, SearchOption.AllDirectories);
                        }
                        else
                        {
                            srcFiles  = Directory.GetFiles(srcDir, srcFileWildCard);
                            destFiles = Directory.GetFiles(destDir, srcFileWildCard);
                        }

                        Assert.IsTrue(srcFiles.Length == destFiles.Length);

                        for (int i = 0; i < srcFiles.Length; i++)
                        {
                            using (FileStream srcStream = new FileStream(srcFiles[i], FileMode.Open, FileAccess.Read, FileShare.Read))
                                using (FileStream destStream = new FileStream(destFiles[i], FileMode.Open, FileAccess.Read, FileShare.Read))
                                {
                                    byte[] srcDigest  = HashHelper.GetHash(HashHelper.HashType.SHA256, srcStream);
                                    byte[] destDigest = HashHelper.GetHash(HashHelper.HashType.SHA256, destStream);
                                    Assert.IsTrue(srcDigest.SequenceEqual(destDigest));
                                }
                        }
                    }
                }
                finally
                {
                    if (Directory.Exists(destDir))
                    {
                        Directory.Delete(destDir, true);
                    }
                }
            }

            SingleTemplate($@"FileCopy,{pbSrcDir}\A.txt,{destDir}", "A.txt", null);
            SingleTemplate($@"FileCopy,{pbSrcDir}\A.txt,{destDir}\B.txt", "A.txt", "B.txt");
            SingleTemplate($@"FileCopy,{pbSrcDir}\Z\Y.ini,{destDir}", Path.Combine("Z", "Y.ini"), "Y.ini");
            MultiTemplate($@"FileCopy,{pbSrcDir}\*.txt,{destDir}", "*.txt", true);
            MultiTemplate($@"FileCopy,{pbSrcDir}\*.ini,{destDir},NOREC", "*.ini", false);

            SingleTemplate($@"FileCopy,{pbSrcDir}\P.txt,{destDir}", "P.txt", null, ErrorCheck.RuntimeError);
            SingleTemplate($@"FileCopy,{pbSrcDir}\C.txt,{destDir}", "C.txt", null, ErrorCheck.Overwrite, true);
            SingleTemplate($@"FileCopy,{pbSrcDir}\C.txt,{destDir},NOWARN", "C.txt", null, ErrorCheck.Success, true);
            SingleTemplate($@"FileCopy,{pbSrcDir}\C.txt,{destDir},PRESERVE", "C.txt", null, ErrorCheck.Overwrite, true);
            SingleTemplate($@"FileCopy,{pbSrcDir}\C.txt,{destDir},PRESERVE,NOWARN", "C.txt", null, ErrorCheck.Success, true, true);
        }
Ejemplo n.º 34
0
 /// <summary>
 /// Set current engine state for the engine instance corresponding to executionContext
 /// passed in.
 ///
 /// Engine state is stored in ExecutionContext.
 /// </summary>
 /// <param name="executionContext"></param>
 /// <param name="engineState"></param>
 private static void SetEngineState(ExecutionContext executionContext, EngineState engineState)
 {
     executionContext.EngineState = engineState;
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Provider interface function for logging engine lifecycle event
        /// </summary>
        /// <param name="logContext"></param>
        /// <param name="newState"></param>
        /// <param name="previousState"></param>
        /// 
        internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
        {
            if (IsEnabled(PSLevel.Informational, PSKeyword.Cmdlets | PSKeyword.UseAlwaysAnalytic))
            {
                StringBuilder payload = new StringBuilder();

                payload.AppendLine(StringUtil.Format(EtwLoggingStrings.EngineStateChange, previousState.ToString(), newState.ToString()));

                PSTask task = PSTask.EngineStart;

                if (newState == EngineState.Stopped ||
                    newState == EngineState.OutOfService ||
                    newState == EngineState.None ||
                    newState == EngineState.Degraded)
                {
                    task = PSTask.EngineStop;
                }

                WriteEvent(PSEventId.Engine_Lifecycle, PSChannel.Analytic, PSOpcode.Method, task, logContext, payload.ToString());
            }
        }
Ejemplo n.º 36
0
        public void PathMove()
        {
            EngineState s       = EngineTests.CreateEngineState();
            string      destDir = FileHelper.GetTempDir();

            void FileTemplate(string rawCode, string srcFileName, string destFileName, ErrorCheck check = ErrorCheck.Success)
            {
                string dirPath      = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandFile"));
                string srcDir       = Path.Combine(dirPath, SrcDirFile);
                string srcFullPath  = Path.Combine(destDir, srcFileName);
                string destFullPath = Path.Combine(destDir, destFileName);

                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
                FileHelper.DirCopy(srcDir, destDir, new FileHelper.DirCopyOptions
                {
                    CopySubDirs = true,
                    Overwrite   = true,
                });
                try
                {
                    EngineTests.Eval(s, rawCode, CodeType.PathMove, check);

                    if (check == ErrorCheck.Success)
                    {
                        Assert.IsFalse(File.Exists(srcFullPath));
                        Assert.IsTrue(File.Exists(destFullPath));
                    }
                }
                finally
                {
                    if (Directory.Exists(destDir))
                    {
                        Directory.Delete(destDir, true);
                    }
                }
            }

            void DirTemplate(string rawCode, string srcFileName, string destFileName, ErrorCheck check = ErrorCheck.Success)
            {
                string dirPath      = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandFile"));
                string srcDir       = Path.Combine(dirPath, SrcDirDir);
                string srcFullPath  = Path.Combine(destDir, srcFileName);
                string destFullPath = Path.Combine(destDir, destFileName);

                if (Directory.Exists(destDir))
                {
                    Directory.Delete(destDir, true);
                }
                FileHelper.DirCopy(srcDir, destDir, new FileHelper.DirCopyOptions
                {
                    CopySubDirs = true,
                    Overwrite   = true,
                });
                try
                {
                    EngineTests.Eval(s, rawCode, CodeType.PathMove, check);

                    if (check == ErrorCheck.Success)
                    {
                        Assert.IsFalse(Directory.Exists(srcFullPath));
                        Assert.IsTrue(Directory.Exists(destFullPath));
                    }
                }
                finally
                {
                    if (Directory.Exists(destDir))
                    {
                        Directory.Delete(destDir, true);
                    }
                }
            }

            FileTemplate($@"PathMove,{destDir}\A.txt,{destDir}\R.txt", "A.txt", "R.txt");
            DirTemplate($@"PathMove,{destDir}\ABCD,{destDir}\XYZ", "ABCD", "XYZ");
        }
Ejemplo n.º 37
0
 public void Pause()
 {
   this.wMOYKdjT8I = EngineState.Paused;
 }
Ejemplo n.º 38
0
 /// <summary>
 /// DummyLogProvider does nothing to Logging EngineLifecycleEvent.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="newState"></param>
 /// <param name="previousState"></param>
 internal override void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
 {
 }
Ejemplo n.º 39
0
 private void s6aY4lp6hS()
 {
   while (true)
   {
     this.kdRYU0k0L6(new EngineState[2]
     {
       EngineState.Running,
       EngineState.Finished
     });
     if (this.wMOYKdjT8I != EngineState.Finished)
     {
       this.RVDYrOBxap();
       this.LDcY85Y27P(0);
       this.uESY0nGd5r.Clear();
       for (int index = 0; index < this.toaYXwOc9v.Length; ++index)
       {
         if (this.wMOYKdjT8I == EngineState.Paused)
         {
           this.RVDYrOBxap();
           this.kdRYU0k0L6(new EngineState[2]
           {
             EngineState.Running,
             EngineState.Stopped
           });
           this.RVDYrOBxap();
         }
         if (this.wMOYKdjT8I != EngineState.Stopped)
         {
           this.wNkYI3uLB3(this.toaYXwOc9v[index]);
           this.LDcY85Y27P(index + 1);
         }
         else
           break;
       }
       DataManager.Server.Flush();
       this.wMOYKdjT8I = EngineState.Stopped;
       this.RVDYrOBxap();
     }
     else
       break;
   }
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Provider interface function for logging engine lifecycle event.
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="newState"></param>
 /// <param name="previousState"></param>
 internal abstract void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState);
Ejemplo n.º 41
0
 public void Start(FileInfo[] files, Template template, bool storeObjects)
 {
   this.toaYXwOc9v = files;
   this.template = template;
   this.UY6YNDKXaq = storeObjects;
   this.wMOYKdjT8I = EngineState.Running;
 }
Ejemplo n.º 42
0
        public static List <LogInfo> IniWriteOp(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_IniWriteOp infoOp = cmd.Info.Cast <CodeInfo_IniWriteOp>();

            string fileName = StringEscaper.Preprocess(s, infoOp.Infos[0].FileName);

            Debug.Assert(fileName != null, $"{nameof(fileName)} != null");

            if (!StringEscaper.PathSecurityCheck(fileName, out string errorMsg))
            {
                return(LogInfo.LogErrorMessage(logs, errorMsg));
            }

            IniKey[] keys = new IniKey[infoOp.Cmds.Count];
            for (int i = 0; i < keys.Length; i++)
            {
                CodeInfo_IniWrite info = infoOp.Infos[i];

                string sectionName = StringEscaper.Preprocess(s, info.Section);
                string key         = StringEscaper.Preprocess(s, info.Key);
                string value       = StringEscaper.Preprocess(s, info.Value);

                if (sectionName.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Section name cannot be empty"));
                }
                if (key.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Key name cannot be empty"));
                }

                keys[i] = new IniKey(sectionName, key, value);
            }

            string dirPath = Path.GetDirectoryName(fileName);

            if (dirPath == null)
            {
                throw new InternalException("Internal Logic Error at IniWriteOp");
            }
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            // If a dest file does not exist, create an empty file to force ANSI encoding as default in IniReadWriter.
            if (!File.Exists(fileName))
            {
                File.Create(fileName).Dispose();
            }

            bool result;

            if (s.CompatAutoCompactIniWriteCommand)
            {
                result = IniReadWriter.WriteCompactKeys(fileName, keys);
            }
            else
            {
                result = IniReadWriter.WriteKeys(fileName, keys);
            }

            if (result)
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    IniKey kv = keys[i];
                    logs.Add(new LogInfo(LogState.Success, $"Key [{kv.Key}] and it's value [{kv.Value}] written", infoOp.Cmds[i]));
                }
                logs.Add(new LogInfo(LogState.Success, $"Wrote [{keys.Length}] values to [{fileName}]", cmd));
            }
            else
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    IniKey kv = keys[i];
                    logs.Add(new LogInfo(LogState.Error, $"Could not write key [{kv.Key}] and it's value [{kv.Value}]", infoOp.Cmds[i]));
                }
                logs.Add(new LogInfo(LogState.Error, $"Could not write [{keys.Length}] values to [{fileName}]", cmd));
            }

            return(logs);
        }
Ejemplo n.º 43
0
		private void Run()
		{
			while (true)
			{
				this.WaitForState(new EngineState[2]
				{
					EngineState.Running,
					EngineState.Finished
				});
				if (this.state != EngineState.Finished)
				{
					this.EmitStateChanged();
					this.EmitTotalProgress(0);
					this.clearedSeries.Clear();
					for (int index = 0; index < this.files.Length; ++index)
					{
						if (this.state == EngineState.Paused)
						{
							this.EmitStateChanged();
							this.WaitForState(new EngineState[2]
							{
								EngineState.Running,
								EngineState.Stopped
							});
							this.EmitStateChanged();
						}
						if (this.state != EngineState.Stopped)
						{
							this.ProcessFile(this.files[index]);
							this.EmitTotalProgress(index + 1);
						}
						else
							break;
					}
					DataManager.Server.Flush();
					this.state = EngineState.Stopped;
					this.EmitStateChanged();
				}
				else
					break;
			}
		}
Ejemplo n.º 44
0
        public static List <LogInfo> IniDeleteOp(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_IniDeleteOp infoOp = cmd.Info.Cast <CodeInfo_IniDeleteOp>();

            string fileName = StringEscaper.Preprocess(s, infoOp.Infos[0].FileName);

            Debug.Assert(fileName != null, $"{nameof(fileName)} != null");

            if (!StringEscaper.PathSecurityCheck(fileName, out string errorMsg))
            {
                return(LogInfo.LogErrorMessage(logs, errorMsg));
            }

            IniKey[] keys = new IniKey[infoOp.Cmds.Count];
            for (int i = 0; i < keys.Length; i++)
            {
                CodeInfo_IniDelete info = infoOp.Infos[i];

                string sectionName = StringEscaper.Preprocess(s, info.Section);
                string key         = StringEscaper.Preprocess(s, info.Key);

                if (sectionName.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Section name cannot be empty"));
                }
                if (key.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Key name cannot be empty"));
                }

                keys[i] = new IniKey(sectionName, key);
            }

            bool[] result;
            if (s.CompatAutoCompactIniWriteCommand)
            {
                result = IniReadWriter.DeleteCompactKeys(fileName, keys);
            }
            else
            {
                result = IniReadWriter.DeleteKeys(fileName, keys);
            }

            int successCount = 0;

            for (int i = 0; i < keys.Length; i++)
            {
                IniKey kv = keys[i];
                if (result[i])
                {
                    successCount += 1;
                    logs.Add(new LogInfo(LogState.Success, $"Key [{kv.Key}] deleted", infoOp.Cmds[i]));
                }
                else
                {
                    logs.Add(new LogInfo(LogState.Ignore, $"Could not delete key [{kv.Key}]", infoOp.Cmds[i]));
                }
            }

            if (0 < successCount)
            {
                logs.Add(new LogInfo(LogState.Success, $"Deleted [{keys.Length}] values from [{fileName}]", cmd));
            }
            if (0 < keys.Length - successCount)
            {
                logs.Add(new LogInfo(LogState.Ignore, $"Could not delete [{keys.Length}] values from [{fileName}]", cmd));
            }

            return(logs);
        }
Ejemplo n.º 45
0
        public static List <LogInfo> IniReadSectionOp(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_IniReadSectionOp infoOp = cmd.Info.Cast <CodeInfo_IniReadSectionOp>();

            string fileName = StringEscaper.Preprocess(s, infoOp.Infos[0].FileName);

            Debug.Assert(fileName != null, $"{nameof(fileName)} != null");

            string[] sections = new string[infoOp.Cmds.Count];
            string[] destVars = new string[infoOp.Cmds.Count];
            string[] delims   = new string[infoOp.Cmds.Count];
            for (int i = 0; i < sections.Length; i++)
            {
                CodeInfo_IniReadSection info = infoOp.Infos[i];

                string section = StringEscaper.Preprocess(s, info.Section);
                if (section.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Section name cannot be empty"));
                }

                sections[i] = section;
                destVars[i] = info.DestVar;
                delims[i]   = "|";
                if (info.Delim != null)
                {
                    delims[i] = StringEscaper.Preprocess(s, info.Delim);
                }
            }

            Dictionary <string, IniKey[]> keyDict = IniReadWriter.ReadSections(fileName, sections);

            int successCount = 0;

            for (int i = 0; i < sections.Length; i++)
            {
                string      section = sections[i];
                string      delim   = delims[i];
                IniKey[]    keys    = keyDict[section];
                CodeCommand subCmd  = infoOp.Cmds[i];

                if (keys != null)
                {
                    List <string> kvList = new List <string>(keys.Length * 2);
                    foreach (IniKey k in keys)
                    {
                        kvList.Add(k.Key);
                        kvList.Add(k.Value);
                    }
                    string destStr = StringEscaper.PackListStr(kvList, delim);
                    logs.Add(new LogInfo(LogState.Success, $"Section [{section}] read", subCmd));

                    string         escapedValue = StringEscaper.Escape(destStr, false, true);
                    List <LogInfo> varLogs      = Variables.SetVariable(s, destVars[i], escapedValue, false, false, false);
                    LogInfo.AddCommand(varLogs, subCmd);
                    logs.AddRange(varLogs);
                }
                else
                {
                    logs.Add(new LogInfo(LogState.Ignore, $"Section [{section}] does not exist", subCmd));

                    List <LogInfo> varLogs = Variables.SetVariable(s, destVars[i], string.Empty, false, false, false);
                    LogInfo.AddCommand(varLogs, subCmd);
                    logs.AddRange(varLogs);
                }
            }
            logs.Add(new LogInfo(LogState.Success, $"Read [{successCount}] sections from [{fileName}]", cmd));

            return(logs);
        }
Ejemplo n.º 46
0
        public static List <LogInfo> IniAddSectionOp(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_IniAddSectionOp infoOp = cmd.Info.Cast <CodeInfo_IniAddSectionOp>();

            string fileName = StringEscaper.Preprocess(s, infoOp.Infos[0].FileName);

            Debug.Assert(fileName != null, $"{nameof(fileName)} != null");

            if (!StringEscaper.PathSecurityCheck(fileName, out string errorMsg))
            {
                return(LogInfo.LogErrorMessage(logs, errorMsg));
            }

            string[] sections = new string[infoOp.Cmds.Count];
            for (int i = 0; i < sections.Length; i++)
            {
                CodeInfo_IniAddSection info = infoOp.Infos[i];

                string sectionName = StringEscaper.Preprocess(s, info.Section);
                if (sectionName.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Section name cannot be empty"));
                }

                sections[i] = sectionName;
            }

            string dirPath = Path.GetDirectoryName(fileName);

            if (dirPath == null)
            {
                throw new InternalException("Internal Logic Error at IniAddSectionOp");
            }
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            // If a dest file does not exist, create an empty file to force ANSI encoding as default in IniReadWriter.
            if (!File.Exists(fileName))
            {
                File.Create(fileName).Dispose();
            }

            bool result = IniReadWriter.AddSections(fileName, sections);

            if (result)
            {
                for (int i = 0; i < sections.Length; i++)
                {
                    logs.Add(new LogInfo(LogState.Success, $"Section [{sections[i]}] added", infoOp.Cmds[i]));
                }
                logs.Add(new LogInfo(LogState.Success, $"Added [{sections.Length}] sections to [{fileName}]", cmd));
            }
            else
            {
                for (int i = 0; i < sections.Length; i++)
                {
                    logs.Add(new LogInfo(LogState.Error, $"Could not add section [{sections[i]}]", infoOp.Cmds[i]));
                }
                logs.Add(new LogInfo(LogState.Error, $"Could not add [{sections.Length}] sections to [{fileName}]", cmd));
            }

            return(logs);
        }
Ejemplo n.º 47
0
		public void Finish()
		{
			this.state = EngineState.Finished;
		}
Ejemplo n.º 48
0
        public static List <LogInfo> IniWriteTextLineOp(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_IniWriteTextLineOp infoOp = cmd.Info.Cast <CodeInfo_IniWriteTextLineOp>();

            string fileName = StringEscaper.Preprocess(s, infoOp.Infos[0].FileName);

            Debug.Assert(fileName != null, $"{nameof(fileName)} != null");

            bool append = infoOp.Infos[0].Append;

            if (!StringEscaper.PathSecurityCheck(fileName, out string errorMsg))
            {
                return(LogInfo.LogErrorMessage(logs, errorMsg));
            }

            List <IniKey> keyList = new List <IniKey>(infoOp.Infos.Count);

            foreach (CodeInfo_IniWriteTextLine info in infoOp.Infos)
            {
                string sectionName = StringEscaper.Preprocess(s, info.Section);
                string line        = StringEscaper.Preprocess(s, info.Line);

                if (append)
                {
                    keyList.Add(new IniKey(sectionName, line));
                }
                else // prepend
                {
                    keyList.Insert(0, new IniKey(sectionName, line));
                }
            }
            IniKey[] keys = keyList.ToArray();

            string dirPath = Path.GetDirectoryName(fileName);

            if (dirPath == null)
            {
                throw new InternalException("Internal Logic Error at IniWriteTextLineOp");
            }
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            // If a dest file does not exist, create an empty file to force ANSI encoding as default in IniReadWriter.
            if (!File.Exists(fileName))
            {
                File.Create(fileName).Dispose();
            }

            bool result = IniReadWriter.WriteRawLines(fileName, keyList, append);

            if (result)
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    IniKey kv = keyList[i];
                    logs.Add(new LogInfo(LogState.Success, $"Line [{kv.Key}] written", infoOp.Cmds[i]));
                }
                logs.Add(new LogInfo(LogState.Success, $"Wrote [{keys.Length}] lines to [{fileName}]", cmd));
            }
            else
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    IniKey kv = keyList[i];
                    logs.Add(new LogInfo(LogState.Error, $"Could not write line [{kv.Key}]", infoOp.Cmds[i]));
                }
                logs.Add(new LogInfo(LogState.Error, $"Could not write [{keys.Length}] lines to [{fileName}]", cmd));
            }

            return(logs);
        }
Ejemplo n.º 49
0
		public void Pause()
		{
			this.state = EngineState.Paused;
		}
Ejemplo n.º 50
0
        public static List <LogInfo> IniReadOp(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            CodeInfo_IniReadOp infoOp = cmd.Info.Cast <CodeInfo_IniReadOp>();

            string fileName = StringEscaper.Preprocess(s, infoOp.Infos[0].FileName);

            Debug.Assert(fileName != null, $"{nameof(fileName)} != null");

            if (!StringEscaper.PathSecurityCheck(fileName, out string errorMsg))
            {
                return(LogInfo.LogErrorMessage(logs, errorMsg));
            }

            IniKey[] keys = new IniKey[infoOp.Cmds.Count];
            for (int i = 0; i < keys.Length; i++)
            {
                CodeInfo_IniRead info = infoOp.Infos[i];

                string sectionName = StringEscaper.Preprocess(s, info.Section);
                string key         = StringEscaper.Preprocess(s, info.Key);

                if (sectionName.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Section name cannot be empty"));
                }
                if (key.Length == 0)
                {
                    return(LogInfo.LogErrorMessage(logs, "Key name cannot be empty"));
                }

                keys[i] = new IniKey(sectionName, key);
            }

            keys = IniReadWriter.ReadKeys(fileName, keys);

            int successCount = 0;

            for (int i = 0; i < keys.Length; i++)
            {
                IniKey      kv     = keys[i];
                CodeCommand subCmd = infoOp.Cmds[i];

                if (kv.Value != null)
                {
                    logs.Add(new LogInfo(LogState.Success, $"Key [{kv.Key}] and it's value [{kv.Value}] successfully read", subCmd));

                    string         escapedValue = StringEscaper.Escape(kv.Value, false, true);
                    List <LogInfo> varLogs      = Variables.SetVariable(s, infoOp.Infos[i].DestVar, escapedValue, false, false, false);
                    LogInfo.AddCommand(varLogs, subCmd);
                    logs.AddRange(varLogs);

                    successCount += 1;
                }
                else
                {
                    if (infoOp.Infos[i].DefaultValue != null)
                    {
                        logs.Add(new LogInfo(LogState.Ignore, $"Key [{kv.Key}] does not exist. Assigning default value [{infoOp.Infos[i].DefaultValue}]"));

                        List <LogInfo> varLogs = Variables.SetVariable(s, infoOp.Infos[i].DestVar, infoOp.Infos[i].DefaultValue, false, false, false);
                        logs.AddRange(varLogs);
                    }
                    else
                    {
                        logs.Add(new LogInfo(LogState.Ignore, $"Key [{kv.Key}] does not exist", subCmd));

                        List <LogInfo> varLogs = Variables.SetVariable(s, infoOp.Infos[i].DestVar, string.Empty, false, false, false);
                        logs.AddRange(varLogs);
                    }
                }
            }
            logs.Add(new LogInfo(LogState.Success, $"Read [{successCount}] values from [{fileName}]", cmd));

            return(logs);
        }
Ejemplo n.º 51
0
        /// <summary>
        /// LogEngineHealthEvent: Log an engine health event. If engine state is changed, a engine 
        /// lifecycle event will be logged also.
        /// 
        /// This is the basic form of EngineHealthEvent logging api, in which all parameters are provided.
        /// 
        /// Variant form of this function is defined below, which will make parameters additionalInfo 
        /// and newEngineState optional.
        /// </summary>
        /// <param name="executionContext">Execution context for the engine that is running</param>
        /// <param name="eventId">EventId for the event to be logged</param>
        /// <param name="exception">Exception associated with this event</param>
        /// <param name="severity">Severity of this event</param>
        /// <param name="additionalInfo">Additional information for this event</param>
        /// <param name="newEngineState">New engine state</param>
        internal static void LogEngineHealthEvent(ExecutionContext executionContext,
                                                int eventId,
                                                Exception exception,
                                                Severity severity,
                                                Dictionary<String, String> additionalInfo,
                                                EngineState newEngineState)
        {
            if (executionContext == null)
            {
                PSTraceSource.NewArgumentNullException("executionContext");
                return;
            }

            if (exception == null)
            {
                PSTraceSource.NewArgumentNullException("exception");
                return;
            }

            InvocationInfo invocationInfo = null;
            IContainsErrorRecord icer = exception as IContainsErrorRecord;
            if (null != icer && null != icer.ErrorRecord)
                invocationInfo = icer.ErrorRecord.InvocationInfo;
            foreach (LogProvider provider in GetLogProvider(executionContext))
            {
                if (NeedToLogEngineHealthEvent(provider, executionContext))
                {
                    provider.LogEngineHealthEvent(GetLogContext(executionContext, invocationInfo, severity), eventId, exception, additionalInfo);
                }
            }

            if (newEngineState != EngineState.None)
            {
                LogEngineLifecycleEvent(executionContext, newEngineState, invocationInfo);
            }
        }
Ejemplo n.º 52
0
        private async void CodeBoxRunCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            CodeBoxRunButton.Focus();

            _m.CanExecuteCommand = false;
            try
            {
                // Save CodeBox first
                _m.SaveCodeBox();

                // Run Engine
                if (Engine.TryEnterLock())
                {
                    try
                    {
                        Project project = _m.CurrentProject;
                        Script  sc      = project.LoadScriptRuntime(_m.CodeFile, new LoadScriptRuntimeOptions {
                            IgnoreMain = true
                        });

                        MainViewModel mainModel = Global.MainViewModel;
                        mainModel.BuildTreeItems.Clear();
                        mainModel.SwitchNormalBuildInterface = false;
                        mainModel.WorkInProgress             = true;

                        EngineState s = new EngineState(sc.Project, Global.Logger, mainModel, EngineMode.RunMainAndOne, sc);
                        s.SetOptions(Global.Setting);
                        s.SetCompat(sc.Project.Compat);

                        Engine.WorkingEngine = new Engine(s);

                        // Set StatusBar Text
                        using (CancellationTokenSource ct = new CancellationTokenSource())
                        {
                            Task printStatus = MainViewModel.PrintBuildElapsedStatus("Running CodeBox...", s, ct.Token);

                            await Engine.WorkingEngine.Run($"CodeBox - {project.ProjectName}");

                            // Cancel and Wait until PrintBuildElapsedStatus stops
                            ct.Cancel();
                            await printStatus;
                        }

                        // Turn off progress ring
                        mainModel.WorkInProgress = false;

                        // Build ended, Switch to Normal View
                        mainModel.SwitchNormalBuildInterface = true;
                        mainModel.BuildTreeItems.Clear();

                        // Report elapsed build time
                        string haltReason = s.RunResultReport();
                        if (haltReason != null)
                        {
                            mainModel.StatusBarText = $"CodeBox took {s.Elapsed:h\\:mm\\:ss}, stopped by {haltReason}";
                        }
                        else
                        {
                            mainModel.StatusBarText = $"CodeBox took {s.Elapsed:h\\:mm\\:ss}";
                        }

                        s.MainViewModel.DisplayScript(mainModel.CurMainTree.Script);
                        if (Global.Setting.General.ShowLogAfterBuild && LogWindow.Count == 0)
                        { // Open BuildLogWindow
                            Application.Current?.Dispatcher?.Invoke(() =>
                            {
                                if (!(Application.Current.MainWindow is MainWindow w))
                                {
                                    return;
                                }

                                w.LogDialog = new LogWindow(1);
                                w.LogDialog.Show();
                            });
                        }
                    }
                    finally
                    {
                        Engine.WorkingEngine = null;
                        Engine.ExitLock();
                    }
                }
            }
            finally
            {
                _m.CanExecuteCommand = true;
                CommandManager.InvalidateRequerySuggested();

                CodeBoxInputTextBox.Focus();
            }
        }
Ejemplo n.º 53
0
        /// <summary>
        /// LogEngineLifecycleEvent: Log an engine lifecycle event. 
        /// 
        /// This is the basic form of EngineLifecycleEvent logging api, in which all parameters are provided.
        /// 
        /// Variant form of this function is defined below, which will make parameter additionalInfo 
        /// optional.
        /// </summary>
        /// <param name="executionContext">execution context for current engine instance</param>
        /// <param name="engineState">new engine state</param>
        /// <param name="invocationInfo">invocationInfo for current command that is running</param>
        internal static void LogEngineLifecycleEvent(ExecutionContext executionContext,
                                                EngineState engineState,
                                                InvocationInfo invocationInfo)
        {
            if (executionContext == null)
            {
                PSTraceSource.NewArgumentNullException("executionContext");
                return;
            }

            EngineState previousState = GetEngineState(executionContext);
            if (engineState == previousState)
                return;

            foreach (LogProvider provider in GetLogProvider(executionContext))
            {
                if (NeedToLogEngineLifecycleEvent(provider, executionContext))
                {
                    provider.LogEngineLifecycleEvent(GetLogContext(executionContext, invocationInfo), engineState, previousState);
                }
            }

            SetEngineState(executionContext, engineState);
        }
Ejemplo n.º 54
0
 public void Math_Template_Error(EngineState s, string rawCode, ErrorCheck check)
 {
     EngineTests.Eval(s, rawCode, CodeType.Math, check);
 }
Ejemplo n.º 55
0
 /// <summary>
 /// Set current engine state for the engine instance corresponding to executionContext
 /// passed in. 
 /// 
 /// Engine state is stored in ExecutionContext.
 /// </summary>
 /// <param name="executionContext"></param>
 /// <param name="engineState"></param>
 private static void SetEngineState(ExecutionContext executionContext, EngineState engineState)
 {
     executionContext.EngineState = engineState;
 }
Ejemplo n.º 56
0
 public void OnStateChanged(EngineState state)
 {
     AnalysisStateChanged?.Invoke(this, new AnalysisStateEventArgs(state));
 }
Ejemplo n.º 57
0
        private static int GetEngineLifecycleEventId(EngineState engineState)
        {
            switch (engineState)
            {
                case EngineState.None:
                    return -1;

                case EngineState.Available:
                    return 400;

                case EngineState.Degraded:
                    return 0x191;

                case EngineState.OutOfService:
                    return 0x192;

                case EngineState.Stopped:
                    return 0x193;
            }
            return -1;
        }
Ejemplo n.º 58
0
 /// <summary>
 /// Provider interface function for logging engine lifecycle event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="newState"></param>
 /// <param name="previousState"></param>
 internal static void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
 {
     provider.LogEngineLifecycleEvent(logContext, newState, previousState);
 }
Ejemplo n.º 59
0
 /// <summary>
 /// Provider interface function for logging engine lifecycle event
 /// </summary>
 /// <param name="logContext"></param>
 /// <param name="newState"></param>
 /// <param name="previousState"></param>
 /// 
 internal static void LogEngineLifecycleEvent(LogContext logContext, EngineState newState, EngineState previousState)
 {
     provider.LogEngineLifecycleEvent(logContext, newState, previousState);
 }
Ejemplo n.º 60
0
        public static List <LogInfo> EchoFile(EngineState s, CodeCommand cmd)
        {
            List <LogInfo> logs = new List <LogInfo>();

            Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_EchoFile));
            CodeInfo_EchoFile info = cmd.Info as CodeInfo_EchoFile;

            string srcFile = StringEscaper.Preprocess(s, info.SrcFile);

            if (!File.Exists(srcFile))
            {
                logs.Add(new LogInfo(LogState.Warning, $"File [{srcFile}] does not exist", cmd));
                return(logs);
            }

            if (info.Encode)
            { // Binary Mode -> encode files into log database
                string tempFile = Path.GetRandomFileName();
                try
                {
                    // Create dummy script instance
                    FileHelper.WriteTextBOM(tempFile, Encoding.UTF8);
                    Script p = cmd.Addr.Project.LoadScript(tempFile, true, false);

                    // Encode binary file into script instance
                    string fileName = Path.GetFileName(srcFile);
                    EncodedFile.AttachFile(p, "Folder", fileName, srcFile, EncodedFile.EncodeMode.ZLib);

                    // Remove Script instance
                    p = null;

                    // Read encoded text strings into memory
                    string   txtStr;
                    Encoding encoding = FileHelper.DetectTextEncoding(tempFile);
                    using (StreamReader r = new StreamReader(tempFile, encoding))
                    {
                        txtStr = r.ReadToEnd();
                    }

                    string logStr;
                    if (txtStr.EndsWith("\r\n", StringComparison.Ordinal))
                    {
                        logStr = $"Encoded File [{srcFile}]\r\n{txtStr}";
                    }
                    else
                    {
                        logStr = $"Encoded File [{srcFile}]\r\n{txtStr}\r\n";
                    }

                    s.MainViewModel.BuildEchoMessage = logStr;
                    logs.Add(new LogInfo(info.Warn ? LogState.Warning : LogState.Success, logStr, cmd));
                }
                finally
                {
                    File.Delete(tempFile);
                }
            }
            else
            { // Text Mode -> Just read with StreamReader
                string   txtStr;
                Encoding encoding = FileHelper.DetectTextEncoding(srcFile);
                using (StreamReader r = new StreamReader(srcFile, encoding))
                {
                    txtStr = r.ReadToEnd();
                }

                string logStr;
                if (txtStr.EndsWith("\r\n", StringComparison.Ordinal))
                {
                    logStr = $"File [{srcFile}]\r\n{txtStr}";
                }
                else
                {
                    logStr = $"File [{srcFile}]\r\n{txtStr}\r\n";
                }

                s.MainViewModel.BuildEchoMessage = logStr;
                logs.Add(new LogInfo(info.Warn ? LogState.Warning : LogState.Success, logStr, cmd));
            }

            return(logs);
        }