public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { object result; try { var extension = Path.GetExtension(value.ToString().ToLower()); if (!String.IsNullOrEmpty(extension)) { if (extension == ".src") { var bitmapImage = Utilities.LoadBitmap(Global.ImgSrc); result = bitmapImage; return result; } if (extension == ".dat") { result = Utilities.LoadBitmap(Global.ImgDat); return result; } if (extension == ".sub") { result = Utilities.LoadBitmap(Global.ImgSps); return result; } } } catch (Exception ex) { var msg = new ErrorMessage("Convert", ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); } return null; }
static ApplicationAttributes() { try { Title = string.Empty; CompanyName = string.Empty; Copyright = string.Empty; ProductName = string.Empty; Version = string.Empty; Assembly = Assembly.GetEntryAssembly(); if (Assembly != null) { var customAttributes = Assembly.GetCustomAttributes(false); var array = customAttributes; foreach (var obj in array) { var type = obj.GetType(); if (type == typeof (AssemblyTitleAttribute)) { _Title = (AssemblyTitleAttribute) obj; } if (type == typeof (AssemblyCompanyAttribute)) { _Company = (AssemblyCompanyAttribute) obj; } if (type == typeof (AssemblyCopyrightAttribute)) { _Copyright = (AssemblyCopyrightAttribute) obj; } if (type == typeof (AssemblyProductAttribute)) { _Product = (AssemblyProductAttribute) obj; } } _Version = Assembly.GetName().Version; } if (_Title != null) { Title = _Title.Title; } if (_Company != null) { CompanyName = _Company.Company; } if (_Copyright != null) { Copyright = _Copyright.Copyright; } if (_Product != null) { ProductName = _Product.Product; } if (_Version != null) { Version = _Version.ToString(); } } catch (Exception ex) { var msg = new ErrorMessage("RecentFileList.ApplicationAttributes", ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); } }
private IEnumerable<Item> getItems(string command, string itemType, int idx) { var result = new List<Item>(); var dbConnection = GetDBConnection(); if (dbConnection != null) { try { if (dbConnection.State != ConnectionState.Open) dbConnection.Open(); using (var cmd = new OleDbCommand(command, dbConnection)) { using (var reader = cmd.ExecuteReader()) { while (reader != null && reader.Read()) { var text = reader.GetValue(0).ToString(); var item = new Item(String.Format(itemType, text.Substring(idx)), reader.GetValue(1).ToString()); result.Add(item); } } } } catch(OleDbException ex) { var msg = new ErrorMessage("Error on Opening Db", ex); Messenger.Default.Send(msg); } } return result; }
public void FillTreeNode(TreeNode node, string root) { if (root == null) { throw new ArgumentNullException("root"); } try { Cursor = Cursors.WaitCursor; var text = node.FullPath; if (string.CompareOrdinal(text, "\\") == 0) { text = node.ToString(); } else { if (string.CompareOrdinal(text.Substring(1, 1), ":") != 0) { root = node.Text; text = root + text.Substring(text.IndexOf("\\", StringComparison.Ordinal)); } } var directoryInfo = new DirectoryInfo(text); var directories = directoryInfo.GetDirectories(); var comparer = new Comparer(CultureInfo.InvariantCulture); Array.Sort(directories, comparer); foreach (var current in from d in directories select new TreeNode(d.Name, 0, 1) { Tag = node.Tag.ToString() }) { node.Nodes.Add(current); current.Nodes.Add(""); } var files = Directory.GetFiles(text, FileExplorerControl.Instance.Filter); Array.Sort(files); var array = files; var array2 = array; foreach (var path in array2) { var treeNode = new TreeNode(Path.GetFileName(path)) { Tag = node.Tag.ToString() }; var extension = Path.GetExtension(path); if (extension != null) { var text2 = extension.ToLower(); var text3 = text2; // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (text3 == null) { goto IL_260; } if (text3 != ".src") { if (text3 != ".dat") { if (text3 != ".sub") { if (text3 != ".zip") { goto IL_260; } treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } else { treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } } else { treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } } else { treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } goto IL_275; IL_260: treeNode.SelectedImageIndex = 6; treeNode.ImageIndex = 6; } IL_275: node.Nodes.Add(treeNode); } Cursor = Cursors.Default; } catch (Exception ex) { var msg = new ErrorMessage("ExplorerClass.FillTreeNode", ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); Cursor = Cursors.Default; } }
public void ShowTree() { Nodes.Clear(); try { var drives = DriveInfo.GetDrives(); foreach (var driveInfo in drives) { switch (driveInfo.DriveType) { case DriveType.Unknown: AddNode(driveInfo.Name, 7, 7); break; case DriveType.Removable: { var name = driveInfo.Name; if (name == null) { goto IL_9E; } if (name != "A:\\" && name != "B:\\") { goto IL_9E; } AddNode(driveInfo.Name, 5, 5); break; IL_9E: AddNode(driveInfo.Name, 5, 5); break; } case DriveType.Fixed: AddNode(driveInfo.Name, 2, 2); break; case DriveType.Network: AddNode(driveInfo.Name, 7, 7); break; case DriveType.CDRom: AddNode(driveInfo.Name, 3, 3); break; } } } catch (Exception ex) { var msg = new ErrorMessage("ExplorerClass", ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); } }
private void AddTool(object parameter) { var text = parameter as string; ToolViewModel toolModel = null; var layoutAnchorable = new LayoutAnchorable(); var text2 = text; switch (text2) { case "Angle Converter": toolModel = new AngleConvertorViewModel(); layoutAnchorable.AutoHideMinWidth = 219.0; goto IL_1EE; case "Functions": toolModel = new FunctionViewModel(); layoutAnchorable.AutoHideMinWidth = 300.0; goto IL_1EE; case "Explorer": layoutAnchorable.Content = new FileExplorerWindow(); goto IL_1EE; case "Object Browser": toolModel = new ObjectBrowserViewModel(); goto IL_1EE; case "Output Window": toolModel = new MessageViewModel(); goto IL_1EE; case "Notes": toolModel = new NotesViewModel(); goto IL_1EE; case "ArchiveInfo": toolModel = new ArchiveInfoViewModel(); goto IL_1EE; case "Rename Positions": layoutAnchorable.Content = new RenamePositionWindow(); goto IL_1EE; case "Shift": layoutAnchorable.Content = new ShiftWindow(); goto IL_1EE; case "CleanDat": toolModel = new DatCleanHelper(); layoutAnchorable.AutoHideMinWidth = DatCleanHelper.Instance.Width; goto IL_1EE; } var msg = new ErrorMessage("Not Implemented", string.Format("Add Tool Parameter of {0} not Implemented", text), MessageType.Error); Messenger.Default.Send<IMessage>(msg); IL_1EE: if (toolModel != null) { layoutAnchorable.Title = toolModel.Title; layoutAnchorable.Content = toolModel; using (var enumerator = ( from t in Tools where t.Title == toolModel.Title select t).GetEnumerator()) { if (enumerator.MoveNext()) { var current = enumerator.Current; current.IsActive = true; return; } } toolModel.IsActive = true; _tools.Add(toolModel); } // ReSharper disable once ExplicitCallerInfoArgument RaisePropertyChanged("Tools"); }
private void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { var msg = new ErrorMessage("App", e.Exception, MessageType.Error); Messenger.Default.Send(msg); Console.Write(e); e.Handled = true; }
public static bool LoadSnippet(string file) { file = Path.GetFullPath(file); if (!File.Exists(file)) { return false; } bool result; try { var xElement = XElement.Load(file); if (xElement.Name != "CodeSnippets") { result = false; } else { if (!xElement.Elements("CodeSnippet").Any()) { result = false; } else { foreach (var current in xElement.Elements("CodeSnippet")) { var snippetInfo = BuildSnippet(current, file); foreach (var current2 in snippetInfo.Header.Shortcuts) { if (!Snippets.ContainsKey(current2)) { Snippets.Add(current2, snippetInfo); } else { var msg = new ErrorMessage(string.Format("Duplicate Shortcut :", file), null, MessageType.Error); Messenger.Default.Send(msg); } } foreach (var current3 in snippetInfo.Header.Extensions) { if (SnippetsByExtension.ContainsKey(current3)) { var list = SnippetsByExtension[current3]; if (!list.Contains(snippetInfo)) { list.Add(snippetInfo); } } else { SnippetsByExtension[current3] = new List<SnippetInfo> { snippetInfo }; } } } result = true; } } } catch (Exception ex2) { var msg = new ErrorMessage("ErrorOnLoadingSnippet", ex2, MessageType.Error); Messenger.Default.Send(msg); result = false; } return result; }
// ReSharper disable once MemberHidesStaticFromOuterClass public static string GetSystemFunctions() { var stringBuilder = new StringBuilder(); var systemFunctionsViewModel = new SystemFunctionsViewModel(); var window = new Window { Content = systemFunctionsViewModel }; string result; if (window.DialogResult.HasValue && window.DialogResult.Value) { var openFileDialog = new OpenFileDialog(); try { openFileDialog.Filter = "KUKA VxWorks _file (vxWorks.rt;VxWorks.Debug;*.*)|vxWorks.rt;vxWorks.debug;*.*"; openFileDialog.Title = "Select file for reading System Functions"; openFileDialog.InitialDirectory = "C:\\krc\\bin\\"; if (openFileDialog.ShowDialog() == true) { if (!File.Exists(openFileDialog.FileName)) { return null; } File.Copy(openFileDialog.FileName, "c:\\Temp.rt", true); _functionFile = "c:\\Temp.rt"; if (systemFunctionsViewModel.Structures) { stringBuilder.AppendFormat("{0}\r\n*** Structures ******************\r\n{0}\r\n", "************************************************"); stringBuilder.Append(GetStruc(_functionFile)); } if (systemFunctionsViewModel.Programs) { stringBuilder.AppendFormat("{0}\r\n*** Programs ******************\r\n{0}\r\n", "************************************************"); stringBuilder.Append(GetRegex(_functionFile, "(EXTFCTP|EXTDEF)([\\d\\w]*)([\\[\\]\\w\\d\\( :,]*\\))")); } if (systemFunctionsViewModel.Functions) { stringBuilder.AppendFormat("{0}\r\n*** Functions ******************\r\n{0}\r\n", "************************************************"); stringBuilder.Append(GetRegex(_functionFile, "(EXTFCTP|EXTDEF)([\\d\\w]*)([\\[\\]\\w\\d\\( :,]*\\))")); } if (systemFunctionsViewModel.Variables) { } } } catch (Exception ex) { var msg = new ErrorMessage("GetSystemFiles", ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); } } result = stringBuilder.ToString(); return result; }
private void GetRootFiles(string dir) { try { var newFiles = (from directory in Directory.GetDirectories(dir) let files = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories) from file in files select new FileInfo(file)).ToList(); foreach (var file in newFiles) { if (file.Name.Equals("kuka_con.mdb", StringComparison.OrdinalIgnoreCase)) _kukaCon = file.Name; _files.Add(file); } } catch (Exception ex) { var msg = new ErrorMessage("Error When Getting Files for Object Browser", ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); } }
private static IEnumerable<IVariable> FindMatches(Regex matchstring, string imgPath, string filepath) { var list = new List<IVariable>(); IEnumerable<IVariable> result; try { var input = File.ReadAllText(filepath); if (string.IsNullOrEmpty(matchstring.ToString())) { result = list; return result; } var match = matchstring.Match(input); while (match.Success) { list.Add(new Variable { Declaration = match.Groups[0].ToString(), Offset = match.Index, Type = match.Groups[1].ToString(), Name = match.Groups[2].ToString(), Value = match.Groups[3].ToString(), Path = filepath, Icon = Utilities.LoadBitmap(imgPath) }); match = match.NextMatch(); } } catch (Exception ex) { var msg = new ErrorMessage("Find Matches", ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); } result = list; return result; }
public void GetRootDirectory(string dir) { var directoryInfo = new DirectoryInfo(dir); if (directoryInfo.Name == directoryInfo.Root.Name) { _rootFound = true; } try { while (directoryInfo.Parent != null && !_rootFound && directoryInfo.Parent.Name != "KRC") { GetRootDirectory(directoryInfo.Parent.FullName); } if (!_rootFound) { if (directoryInfo.Parent != null && directoryInfo.Parent.Parent != null && directoryInfo.Parent.Parent.Parent != null) { _rootName = ((directoryInfo.Parent != null && directoryInfo.Parent.Parent.Name != "C") ? directoryInfo.Parent.Parent.FullName : directoryInfo.Parent.Parent.Parent.FullName); } var directoryInfo2 = new DirectoryInfo(_rootName); var directories = directoryInfo2.GetDirectories(); if (directories.Length >= 1) { if (directories[0].Name == "C" && directories[1].Name == "KRC") { _rootName = directoryInfo2.FullName; } _rootFound = true; GetRootFiles(_rootName); FileCount = Files.Count; GetVariables(); } } } catch (Exception ex) { var msg = new ErrorMessage("Get Root Directory", ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); } }
public static List<IVariable> GetVariables(string filename, Regex regex, string iconpath) { var list = new List<IVariable>(); var bitmapImage = Utilities.LoadBitmap(iconpath); var instance = ServiceLocator.Current.GetInstance<MainViewModel>(); var fileLanguage = instance.ActiveEditor.FileLanguage; var match = VariableHelper.FindMatches(regex, filename); var fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(bitmapImage.UriSource.AbsolutePath); var flag = fileNameWithoutExtension != null && fileNameWithoutExtension.Contains("XYZ"); List<IVariable> result; if (match == null) { var msg = new ErrorMessage("Variable for " + fileLanguage.RobotType, "Does not exist in VariableBase.GetVariables", MessageType.Error); Messenger.Default.Send<IMessage>(msg); result = null; } else { while (match.Success) { var item = new Variable { Icon = bitmapImage, Path = filename, Offset = match.Index, Type = match.Groups[1].ToString(), Name = match.Groups[2].ToString(), Value = flag ? fileLanguage.ExtractXYZ(match.ToString()) : match.Groups[3].ToString(), Comment = match.Groups[4].ToString() }; list.Add(item); match = match.NextMatch(); } result = list; } return result; }
public void SetHighlighting() { try { if (Filename != null) { SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(Filename)); } } catch (Exception ex) { var msg = new ErrorMessage(string.Format("Could not load Syntax Highlighting for {0}", Filename), ex, MessageType.Error); Messenger.Default.Send<IMessage>(msg); } }
private bool IsFileLocked(System.IO.FileInfo file) { FileStream fileStream = null; if (!File.Exists(file.FullName)) { } else { try { fileStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None); } catch (IOException ex) { var msg = new ErrorMessage("File is locked!", ex); Messenger.Default.Send<IMessage>(msg); return true; } finally { if (fileStream != null) { fileStream.Close(); } } } return false; }
private void ChangeIndent(object param) { try { var flag = Convert.ToBoolean(param); var lineByOffset = Document.GetLineByOffset(SelectionStart); var lineByOffset2 = Document.GetLineByOffset(SelectionStart + SelectionLength); var num = 0; using (Document.RunUpdate()) { var documentLine = lineByOffset; while (documentLine.LineNumber < lineByOffset2.LineNumber + 1) { var line = GetLine(documentLine.LineNumber); var regex = new Regex("(^[\\s]+)"); var match = regex.Match(line); if (match.Success) { num = match.Groups[1].Length; } if (flag) { Document.Insert(documentLine.Offset + num, " "); } else { num = ((num > 1) ? (num - 1) : num); if (num >= 1) { Document.Replace(documentLine.Offset, line.Length, line.Substring(1)); } } documentLine = documentLine.NextLine; } } } catch (Exception ex) { var msg = new ErrorMessage("Editor.ChangeIndent", ex); Messenger.Default.Send<IMessage>(msg); } }