//Config file parser public static Config Parse(string filePath, Config currentConfig) { // refactoring needed List <string> inputLines = new List <string>(); List <string> sceneNodeLines = new List <string>(); List <string> screenLines = new List <string>(); List <string> viewportLines = new List <string>(); List <string> clusterNodeLines = new List <string>(); List <string> cameraLines = new List <string>(); List <string> generalLines = new List <string>(); List <string> stereoLines = new List <string>(); List <string> debugLines = new List <string>(); try { foreach (string line in File.ReadLines(filePath)) { if (line == string.Empty || line.First() == '#') { //Do nothing } else { if (line.Contains("[input]")) { inputLines.Add(line); } if (line.Contains("[scene_node]")) { sceneNodeLines.Add(line); } if (line.Contains("[screen]")) { screenLines.Add(line); } if (line.Contains("[viewport]")) { viewportLines.Add(line); } if (line.Contains("[cluster_node]")) { clusterNodeLines.Add(line); } if (line.Contains("[camera]")) { cameraLines.Add(line); } if (line.Contains("[general]")) { generalLines.Add(line); } if (line.Contains("[stereo]")) { stereoLines.Add(line); } if (line.Contains("[debug]")) { debugLines.Add(line); } if (line.Contains("[render]")) { //todo } if (line.Contains("[custom]")) { //todo } } } foreach (string line in viewportLines) { currentConfig.ViewportParse(line); } foreach (string line in generalLines) { currentConfig.GeneralParse(line); } foreach (string line in stereoLines) { currentConfig.StereoParse(line); } foreach (string line in debugLines) { currentConfig.DebugParse(line); } foreach (string line in inputLines) { currentConfig.InputsParse(line); } foreach (string line in cameraLines) { currentConfig.CameraParse(line); } foreach (string line in sceneNodeLines) { currentConfig.SceneNodeParse(line); } foreach (string line in screenLines) { currentConfig.ScreenParse(line); } foreach (string line in clusterNodeLines) { currentConfig.ClusterNodeParse(line); } currentConfig.sceneNodesView = currentConfig.ConvertSceneNodeList(currentConfig.sceneNodes); currentConfig.name = Path.GetFileNameWithoutExtension(filePath); AppLogger.Add("Config " + currentConfig.name + " loaded"); RegistrySaver.AddRegistryValue(RegistrySaver.configName, filePath); } catch (FileNotFoundException e) { AppLogger.Add("ERROR! Config " + currentConfig.name + "not found!"); } catch (System.ArgumentException e) { AppLogger.Add("ERROR! Config " + currentConfig.name + "not found!"); } return(currentConfig); }
//Implementation IDataErrorInfo methods for validation public string this[string columnName] { get { string error = String.Empty; if (columnName == "id" || columnName == validationName) { if (!ValidationRules.IsName(id)) { error = "Input ID should contain only letters, numbers and _"; AppLogger.Add("ERROR! " + error); } } if (columnName == "address" || columnName == validationName) { if (!ValidationRules.IsAddress(address)) { error = "Input Address in format [email protected]"; AppLogger.Add("ERROR! " + error); } } if (columnName == "locationX" || columnName == validationName) { if (!ValidationRules.IsFloat(locationX.ToString())) { error = "Location X should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "locationY" || columnName == validationName) { if (!ValidationRules.IsFloat(locationY.ToString())) { error = "Location Y should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "locationZ" || columnName == validationName) { if (!ValidationRules.IsFloat(locationZ.ToString())) { error = "Location Z should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "rotationP" || columnName == validationName) { if (!ValidationRules.IsFloat(rotationP.ToString())) { error = "Pitch should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "rotationY" || columnName == validationName) { if (!ValidationRules.IsFloat(rotationY.ToString())) { error = "Yaw should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "rotationR" || columnName == validationName) { if (!ValidationRules.IsFloat(rotationR.ToString())) { error = "Roll should be a floating point number"; AppLogger.Add("ERROR! " + error); } } MainWindow.ConfigModifyIndicator(); return(error); } }
private void CollectLogFiles(List <ClusterNode> nodes) { //List<string> nodes = GetNodes(); FolderBrowserDialog fbDialog = new FolderBrowserDialog(); //fbDialog.Description = "Select a folder for save log files from nodes :"; if (fbDialog.ShowDialog() != DialogResult.OK || nodes.Count == 0) { return; } // clean all files except *.zip, *.rar // list of new files List <string> fileList = new List <string>(); // copy + rename foreach (ClusterNode node in nodes) { string logFilename = logFile; string logFilenameSep = (logFilename == string.Empty) ? "" : ("_"); string srcLogPath = GetLogFolder(node.address) + Path.GetFileNameWithoutExtension(selectedApplication) + ".log"; string dstLogPath = fbDialog.SelectedPath + @"\" + logFilenamePrefix + node.id + logFilenameSep + logFilename; string logMsg = "[" + srcLogPath + "] to [" + dstLogPath + "]"; // add to list fileList.Add(dstLogPath); try { File.Copy(srcLogPath, dstLogPath); AppLogger.Add("Copied file from " + logMsg); } catch (Exception exception) { AppLogger.Add("Can't copy file from " + logMsg + ". EXCEPTION: " + exception.Message); } } // create archive if (!isLogZip) { return; } string currentTime = DateTime.Now.ToString("HHmmss"); string currentDate = DateTime.Now.ToString("yyyyMMdd"); string zipFilename = fbDialog.SelectedPath + @"\" + logFilenamePrefix + currentDate + "_" + currentTime + ".zip"; CreateZipLogs(zipFilename, fileList); // clean *.log-files if (isLogRemove) { RemoveListOfFiles(fileList); } }
//Implementation IDataErrorInfo methods for validation public string this[string columnName] { get { string error = String.Empty; if (columnName == "id" || columnName == validationName) { if (!ValidationRules.IsName(id)) { error = "Viewport ID should contain only letters, numbers and _"; AppLogger.Add("ERROR! " + error); } } if (columnName == "x" || columnName == validationName) { if (!ValidationRules.IsInt(x.ToString())) { error = "x should be an integer"; AppLogger.Add("ERROR! " + error); } } if (columnName == "y" || columnName == validationName) { if (!ValidationRules.IsInt(y.ToString())) { error = "y should be an integer"; AppLogger.Add("ERROR! " + error); } } if (columnName == "width" || columnName == validationName) { if (!ValidationRules.IsInt(width.ToString()) || Convert.ToInt32(width) < 0) { error = "Width should be an integer"; AppLogger.Add("ERROR! " + error); } } if (columnName == "height" || columnName == validationName) { if (!ValidationRules.IsInt(height.ToString()) || Convert.ToInt32(height) < 0) { error = "Height should be an integer"; AppLogger.Add("ERROR! " + error); } } //switch (columnName) //{ // case "id": // if (!ValidationRules.IsName(id)) // { // error = "Viewport ID should contain only letters, numbers and _"; // } // break; // case "x": // if (!ValidationRules.IsInt(x.ToString())) // { // error = "x should be an integer"; // } // break; // case "y": // if (!ValidationRules.IsInt(y.ToString())) // { // error = "y should be an integer"; // } // break; // case "width": // if (!ValidationRules.IsInt(width.ToString())) // { // error = "Width should be an integer"; // } // break; // case "height": // if (!ValidationRules.IsInt(height.ToString())) // { // error = "Height should be an integer"; // } // break; //} //if (!string.IsNullOrEmpty(error)) //{ // AppLogger.Add("ERROR! " + error); //} return(error); } }
//Implementation IDataErrorInfo methods for validation public string this[string columnName] { get { string error = String.Empty; if (columnName == "id" || columnName == validationName) { if (!ValidationRules.IsName(id)) { error = "Scene Nodes ID should contain only letters, numbers and _"; AppLogger.Add("ERROR! " + error); } } if (columnName == "locationX" || columnName == validationName) { if (!ValidationRules.IsFloatNullable(locationX.ToString())) { error = "Location X should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "locationY" || columnName == validationName) { if (!ValidationRules.IsFloatNullable(locationY.ToString())) { error = "Location Y should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "locationZ" || columnName == validationName) { if (!ValidationRules.IsFloatNullable(locationZ.ToString())) { error = "Location Z should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "rotationP" || columnName == validationName) { if (!ValidationRules.IsFloatNullable(rotationP.ToString())) { error = "Pitch should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "rotationY" || columnName == validationName) { if (!ValidationRules.IsFloatNullable(rotationY.ToString())) { error = "Yaw should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "rotationR" || columnName == validationName) { if (!ValidationRules.IsFloatNullable(rotationR.ToString())) { error = "Roll should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "trackerCh" || columnName == validationName) { if (!ValidationRules.IsIntNullable(trackerCh)) { error = "Tracker channel should be a positive integer"; AppLogger.Add("ERROR! " + error); } } MainWindow.ConfigModifyIndicator(); return(error); } }
//Implementation IDataErrorInfo methods public string this[string columnName] { get { string error = String.Empty; if (columnName == "cameraLocationX" || columnName == validationName) { if (!ValidationRules.IsFloat(cameraLocationX.ToString())) { error = "Camera location X should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "cameraLocationY" || columnName == validationName) { if (!ValidationRules.IsFloat(cameraLocationY.ToString())) { error = "Camera location Y should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "cameraLocationZ" || columnName == validationName) { if (!ValidationRules.IsFloat(cameraLocationZ.ToString())) { error = "Camera location Z should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "cameraTrackerCh" || columnName == validationName) { if (!ValidationRules.IsIntNullable(cameraTrackerCh)) { error = "Camera tracker channel should be an integer"; AppLogger.Add("ERROR! " + error); } } if (columnName == "eyeDist" || columnName == validationName) { if (!ValidationRules.IsFloat(eyeDist.ToString())) { error = "Eye distance should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "lagMaxTime" || columnName == validationName) { if (!ValidationRules.IsFloat(lagMaxTime.ToString())) { error = "Maximum delay time should be a floating point number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "portCs" || columnName == validationName) { if (!(ValidationRules.IsInt(portCs) || Convert.ToInt32(portCs) > 0)) { error = "Client port should be a positive number"; AppLogger.Add("ERROR! " + error); } } if (columnName == "portSs" || columnName == validationName) { if (!(ValidationRules.IsInt(portSs) || Convert.ToInt32(portSs) > 0)) { error = "Server port should be a positive number"; AppLogger.Add("ERROR! " + error); } } MainWindow.ConfigModifyIndicator(); return(error); } }
//Implementation IDataErrorInfo methods for validation public string this[string columnName] { get { string error = String.Empty; if (columnName == "id" || columnName == validationName) { if (!ValidationRules.IsName(id)) { error = "Cluster node ID should contain only letters, numbers and _"; AppLogger.Add("ERROR! " + error); } } if (columnName == "address" || columnName == validationName) { if (!ValidationRules.IsIp(address)) { error = "Cluster node address should be IP address"; AppLogger.Add("ERROR! " + error); } } if (columnName == "winX" || columnName == validationName) { if (isWindowed == true) { if (!ValidationRules.IsInt(winX.ToString())) { error = "x should be an integer"; AppLogger.Add("ERROR! " + error); } } } if (columnName == "winY" || columnName == validationName) { if (isWindowed == true) { if (!ValidationRules.IsInt(winY.ToString())) { error = "y should be an integer"; AppLogger.Add("ERROR! " + error); } } } if (columnName == "resX" || columnName == validationName) { if (isWindowed == true) { if (!ValidationRules.IsInt(resX.ToString()) || Convert.ToInt32(resX) < 0) { error = "Width should be an integer"; AppLogger.Add("ERROR! " + error); } } } if (columnName == "resY" || columnName == validationName) { if (isWindowed == true) { if (!ValidationRules.IsInt(resY.ToString()) || Convert.ToInt32(resY) < 0) { error = "Height should be an integer"; AppLogger.Add("ERROR! " + error); } } } MainWindow.ConfigModifyIndicator(); return(error); } }
private void cleanAppLogBtn_Click(object sender, RoutedEventArgs e) { AppLogger.CleanLog(); }
//Config file parser private void ConfigFileParser(string filePath) { // refactoring needed CreateConfig(); List <string> inputLines = new List <string>(); List <string> sceneNodeLines = new List <string>(); List <string> screenLines = new List <string>(); List <string> viewportLines = new List <string>(); List <string> clusterNodeLines = new List <string>(); List <string> cameraLines = new List <string>(); List <string> generalLines = new List <string>(); List <string> stereoLines = new List <string>(); List <string> debugLines = new List <string>(); try { foreach (string line in File.ReadLines(filePath)) { if (line == string.Empty || line.First() == '#') { //Do nothing } else { if (line.Contains("[input]")) { inputLines.Add(line); } if (line.Contains("[scene_node]")) { sceneNodeLines.Add(line); } if (line.Contains("[screen]")) { screenLines.Add(line); } if (line.Contains("[viewport]")) { viewportLines.Add(line); } if (line.Contains("[cluster_node]")) { clusterNodeLines.Add(line); } if (line.Contains("[camera]")) { cameraLines.Add(line); } if (line.Contains("[general]")) { generalLines.Add(line); } if (line.Contains("[stereo]")) { stereoLines.Add(line); } if (line.Contains("[debug]")) { debugLines.Add(line); } if (line.Contains("[render]")) { //todo } if (line.Contains("[custom]")) { //todo } } } foreach (string line in viewportLines) { currentConfig.ViewportParse(line); } foreach (string line in generalLines) { currentConfig.GeneralParse(line); } foreach (string line in stereoLines) { currentConfig.StereoParse(line); } foreach (string line in debugLines) { currentConfig.DebugParse(line); } foreach (string line in inputLines) { currentConfig.InputsParse(line); } foreach (string line in cameraLines) { currentConfig.CameraParse(line); } foreach (string line in sceneNodeLines) { currentConfig.SceneNodeParse(line); } foreach (string line in screenLines) { currentConfig.ScreenParse(line); } foreach (string line in clusterNodeLines) { currentConfig.ClusterNodeParse(line); } currentConfig.sceneNodesView = currentConfig.ConvertSceneNodeList(currentConfig.sceneNodes); currentConfig.name = Path.GetFileNameWithoutExtension(filePath); AppLogger.Add("Config " + currentConfig.name + " loaded"); RegistrySaver.AddRegistryValue(RegistrySaver.configName, filePath); //Set first items in listboxes and treeview as default if existed currentConfig.SelectFirstItems(); RefreshUiControls(); try { ((CollectionViewSource)this.Resources["cvsInputTrackers"]).View.Refresh(); } catch (NullReferenceException) { } //sceneNodeTrackerCb.SelectedIndex = -1; SetTitle(); } catch (FileNotFoundException e) { AppLogger.Add("ERROR! Config " + currentConfig.name + "not found!"); } }