public IActionResult RenderLayerIcon(string deviceId, string layerId, int keyId) { Bitmap icon; try { DeviceModel device = _deviceManager.GetDevice(deviceId); KeyMap keyMap = device.Layers.GetLayerById(layerId).Keys; if (keyMap.ContainsKey(keyId)) { KeyModel key = keyMap[keyId]; icon = _deviceManager.GenerateKeyIcon(key, deviceId); } else { icon = IconHelpers.DrawBlankKeyIcon(244, 244); } } catch (Exception e) { icon = IconHelpers.DrawBlankKeyIcon(244, 244); } return(File(icon.ToMemoryStream(), "image/png", "key.png")); }
public static List <FileModel> GetDrives() { List <FileModel> drives = new List <FileModel>(); try { foreach (string drive in Directory.GetLogicalDrives()) { DriveInfo dInfo = new DriveInfo(drive); FileModel dModel = new FileModel() { Icon = IconHelpers.GetIconOfFile(drive, true, true), Name = dInfo.Name, Path = dInfo.Name, DateModified = DateTime.Now, Type = FileType.Drive, SizeBytes = dInfo.TotalSize }; drives.Add(dModel); } return(drives); } catch (IOException io) { MessageBox.Show($"IO Exception getting drives: {io.Message}", "Exception getting drives"); } catch (UnauthorizedAccessException noAccess) { MessageBox.Show($"No access for a hard drive: {noAccess.Message}", ""); } return(drives); }
/// <summary> /// Creates a simple icon. /// </summary> public static HelperResult Icon(this HtmlHelper helper, string icon, bool doubleSize = false) { if (doubleSize) { return(IconHelpers.SimpleIcon2X(icon)); } return(IconHelpers.SimpleIcon(icon)); }
public static List <FileModel> GetFiles(string directory) { List <FileModel> files = new List <FileModel>(); if (!directory.IsDirectory()) { return(files); } string currentFile = ""; try { foreach (string file in Directory.GetFiles(directory)) { currentFile = file; if (Path.GetExtension(file) != ".lnk") { FileInfo fInfo = new FileInfo(file); FileModel fModel = new FileModel() { Icon = IconHelpers.GetIconOfFile(file, true, false), Name = fInfo.Name, Path = fInfo.FullName, DateCreated = fInfo.CreationTime, DateModified = fInfo.LastWriteTime, Type = FileType.File, SizeBytes = fInfo.Length }; files.Add(fModel); } } return(files); } catch (IOException io) { MessageBox.Show( $"IO Exception getting files in directory: {io.Message}", "Exception getting files in directory"); } catch (UnauthorizedAccessException noAccess) { MessageBox.Show( $"No access for a file: {noAccess.Message}", "Exception getting files in directory"); } catch (Exception e) { MessageBox.Show( $"Failed to get files in '{directory}' || " + $"Something to do with '{currentFile}'\n" + $"Exception: {e.Message}", "Error"); } return(files); }
protected override void DrawIcon(KeyModel keyModel) { string svgPath = Path.Combine(@"C:\Source\Resources\fa\solid\", PropertyRule.GetProperty(keyModel, GraphicPath)); AddGraphic("__micon_glyph", svgPath, IconHelpers.GetColorFromHex(PropertyRule.GetProperty(keyModel, GraphicColor))); SetElementText("__micon_text", PropertyRule.GetProperty(keyModel, Text)); SetFill("__micon_background", IconHelpers.GetColorFromHex(PropertyRule.GetProperty(keyModel, BackgroundColor))); }
public IActionResult RenderLiveStateIcon(string deviceId, int keyId) { Bitmap icon; try { KeyModel keyInput = null; if (_deviceManager.GetDevice(deviceId).KeyStates.IsKeyMapped(keyId)) { keyInput = _deviceManager.GetDevice(deviceId).KeyStates[keyId]; } icon = _deviceManager.GenerateKeyIcon(keyInput, deviceId); } catch (Exception e) { icon = IconHelpers.DrawBlankKeyIcon(244, 244); } return(File(icon.ToMemoryStream(), "image/png", "key.png")); }
public async void TryNavigateToPath(string path) { if (path == string.Empty) { ClearFiles(); foreach (FileModel drive in Fetcher.GetDrives()) { FilesControl fc = CreateFileControl(drive); AddFile(fc); } } else if (path.IsFile()) { MessageBox.Show($"Opening {path}"); } else if (path.IsDirectory()) { ClearFiles(); string backPath = path.Substring(0, path.LastIndexOf('\\')); if (!backPath.Contains('\\')) { backPath += "\\"; DriveInfo dInfo = new DriveInfo(backPath); FileModel dModel = new FileModel() { Icon = IconHelpers.GetIconOfFile(backPath, true, true), Name = dInfo.Name, Path = dInfo.Name, DateModified = DateTime.Now, Type = FileType.Drive, SizeBytes = dInfo.TotalSize }; FilesControl back = CreateFileControl(dModel); AddFile(back); } else { DirectoryInfo dInfo = new DirectoryInfo(backPath); FileModel dModel = new FileModel() { Icon = IconHelpers.GetIconOfFile(backPath, true, true), Name = dInfo.Name, Path = dInfo.FullName, DateCreated = dInfo.CreationTime, DateModified = dInfo.LastWriteTime, Type = FileType.Folder, SizeBytes = Fetcher.DirSize(new DirectoryInfo(backPath), 1) }; FilesControl back = CreateFileControl(dModel); AddFile(back); } List <FileModel> directories = new List <FileModel>(); await Fetcher.GetDirectories(path, directories); foreach (FileModel dir in directories) { FilesControl fc = CreateFileControl(dir); AddFile(fc); } foreach (FileModel file in Fetcher.GetFiles(path)) { FilesControl fc = CreateFileControl(file); AddFile(fc); } } else { MessageBox.Show("Something get wrong"); } }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is Symbol symbol) { return(new SymbolIcon { Symbol = symbol }); } else if (value is IconSource ico) { if (ico is FontIconSource fis) { return(IconHelpers.CreateFontIconFromFontIconSource(fis)); } else if (ico is SymbolIconSource sis) { return(IconHelpers.CreateSymbolIconFromSymbolIconSource(sis)); } else if (ico is PathIconSource pis) { return(IconHelpers.CreatePathIconFromPathIconSource(pis)); } else if (ico is BitmapIconSource bis) { return(IconHelpers.CreateBitmapIconFromBitmapIconSource(bis)); } } else if (value is string val) { //First we try if the text is a valid Symbol if (Enum.TryParse(typeof(Symbol), val, out object sym)) { return(new SymbolIcon() { Symbol = (Symbol)sym }); } //Try a PathIcon if (PathIcon.IsDataValid(val, out Geometry g)) { return(new PathIcon() { Data = g }); } try { if (Uri.TryCreate(val, UriKind.RelativeOrAbsolute, out Uri result)) { return(new BitmapIcon() { UriSource = result }); } } catch { } //If we've reached this point, we'll make a FontIcon //Glyph can be anything (sort of), so we don't need to Try/Catch return(new FontIconSource() { Glyph = val }); } return(base.ConvertFrom(context, culture, value)); }
public static async Task GetDirectories(string directory, List <FileModel> directories) { await Task.Run(() => { if (!directory.IsDirectory()) { return(directories); } string currentDirectory = ""; try { foreach (string dir in Directory.GetDirectories(directory)) { currentDirectory = dir; DirectoryInfo dInfo = new DirectoryInfo(dir); FileModel dModel = new FileModel() { Icon = IconHelpers.GetIconOfFile(dir, true, true), Name = dInfo.Name, Path = dInfo.FullName, DateCreated = dInfo.CreationTime, DateModified = dInfo.LastWriteTime, Type = FileType.Folder, SizeBytes = DirSize(new DirectoryInfo(dir), 1) }; directories.Add(dModel); } foreach (string file in Directory.GetFiles(directory)) { if (Path.GetExtension(file) == ".lnk") { string realDirPath = ExplorerHelper.GetShortcutTargetFolder(file); FileInfo dInfo = new FileInfo(realDirPath); FileModel dModel = new FileModel() { Icon = IconHelpers.GetIconOfFile(realDirPath, true, true), Name = dInfo.Name, Path = dInfo.FullName, DateCreated = dInfo.CreationTime, DateModified = dInfo.LastWriteTime, Type = FileType.File, SizeBytes = 0 }; directories.Add(dModel); } } return(directories); } catch (IOException io) { MessageBox.Show( $"IO Exception getting folders in directory: {io.Message}", "Exception getting folders in directory"); } catch (UnauthorizedAccessException noAccess) { MessageBox.Show( $"No access for a directory: {noAccess.Message}", "Exception getting folders in directory"); } catch (Exception e) { MessageBox.Show( $"Failed to get directories in '{directory}' || " + $"Something to do with '{currentDirectory}'\n" + $"Exception: {e.Message}", "Error"); } return(directories); }); }
/// <summary> /// Creates an icon follewed by an 8 px margin. /// </summary> public static HelperResult IconMargin(this HtmlHelper helper, string icon) { return(IconHelpers.IconMargin(icon)); }
/// <summary> /// Creates an icon followed by an 8 px margin and text. /// </summary> public static HelperResult IconText(this HtmlHelper helper, string icon, IHtmlString text) { return(IconHelpers.IconText(icon, text)); }