/// <summary> /// Takes the current text position input value, updates the current defifinition with it and invokes the change events. /// </summary> private void UpdateTextPosition() { var newPos = new TPoint(this.txtTextPosition.X, this.txtTextPosition.Y); this.currentDefinition = this.currentDefinition.ModifyMouse(textPosition: newPos); this.DefinitionChanged?.Invoke(this.currentDefinition); }
private static X509KeyStorageFlags GetStorageFlags(KeyDefinition key) { var defaultFlags = OperatingSystem.IsLinux() ? UnsafeEphemeralKeySet : (OperatingSystem.IsMacOS() ? X509KeyStorageFlags.PersistKeySet : X509KeyStorageFlags.DefaultKeySet); if (key.StorageFlags == null) { return(defaultFlags); } var flagsList = key.StorageFlags.Split(' ', StringSplitOptions.RemoveEmptyEntries); if (flagsList.Length == 0) { return(defaultFlags); } var result = ParseCurrentFlag(flagsList[0]); foreach (var flag in flagsList.Skip(1)) { result |= ParseCurrentFlag(flag); } return(result);
/// <summary> /// Initializes a new instance of the <see cref="MouseElementPropertiesForm" /> class. /// </summary> /// <param name="initialDefinition">The definition to show the properties for.</param> public MouseElementPropertiesForm(KeyDefinition initialDefinition) { if (initialDefinition is KeyboardKeyDefinition) { throw new Exception("A MouseElementePropertiesForm cannot be used for keyboard keys."); } this.initialDefinition = initialDefinition; this.currentDefinition = (KeyDefinition)initialDefinition.Clone(); this.InitializeComponent(); if (initialDefinition is MouseKeyDefinition) { this.Text = "Mouse Key Properties"; this.cmbKeyCode.Items.Clear(); this.cmbKeyCode.Items.Add(MouseKeyCode.LeftButton); this.cmbKeyCode.Items.Add(MouseKeyCode.MiddleButton); this.cmbKeyCode.Items.Add(MouseKeyCode.RightButton); this.cmbKeyCode.Items.Add(MouseKeyCode.X1Button); this.cmbKeyCode.Items.Add(MouseKeyCode.X2Button); } if (initialDefinition is MouseScrollDefinition) { this.Text = "Mouse Scroll Properties"; this.cmbKeyCode.Items.Clear(); this.cmbKeyCode.Items.Add(MouseScrollKeyCode.ScrollUp); this.cmbKeyCode.Items.Add(MouseScrollKeyCode.ScrollRight); this.cmbKeyCode.Items.Add(MouseScrollKeyCode.ScrollDown); this.cmbKeyCode.Items.Add(MouseScrollKeyCode.ScrollLeft); } }
private List <KeyDefinition> ToEZKeyDefinitions(List <ConfiguratorKeyDefinition> keyCodesOrigin) { List <KeyDefinition> keyDefinitions = new List <KeyDefinition>(); foreach (var configKeyDef in keyCodesOrigin) { var(label, isGlyph) = ChooseLabel(configKeyDef); var keyDefinition = new KeyDefinition { Label = label, Description = configKeyDef.Description, IsGlyph = isGlyph, KeyCode = configKeyDef.KeyCode, KeyCategory = (KeyCategory)Enum.Parse(typeof(KeyCategory), configKeyDef.Category, true), SecondaryCommand = configKeyDef.Command }; if (configKeyDef.PrecedingKey.HasValue) { keyDefinition.PrecedingKey = configKeyDef.PrecedingKey.Value; } keyDefinitions.Add(keyDefinition); } return(keyDefinitions); }
public SigningCredentials LoadKey() { // We can't know for sure if there was a configuration section explicitly defined. // Check if the current configuration has any children and avoid failing if that's the case. // This will avoid failing when no configuration has been specified but will still fail if partial data // was defined. if (!_configuration.GetChildren().Any()) { return(null); } var key = new KeyDefinition() { Type = _configuration[nameof(KeyDefinition.Type)], FilePath = _configuration[nameof(KeyDefinition.FilePath)], Password = _configuration[nameof(KeyDefinition.Password)], Name = _configuration[nameof(KeyDefinition.Name)], StoreLocation = _configuration[nameof(KeyDefinition.StoreLocation)], StoreName = _configuration[nameof(KeyDefinition.StoreName)], StorageFlags = _configuration[nameof(KeyDefinition.StorageFlags)] }; if (bool.TryParse(_configuration[nameof(KeyDefinition.Persisted)], out var value)) { key.Persisted = value; } switch (key.Type) { case KeySources.Development: var developmentKeyPath = Path.Combine(Directory.GetCurrentDirectory(), key.FilePath ?? DefaultTempKeyRelativePath); var createIfMissing = key.Persisted ?? true; _logger.LogInformation($"Loading development key at '{developmentKeyPath}'."); var developmentKey = new RsaSecurityKey(SigningKeysLoader.LoadDevelopment(developmentKeyPath, createIfMissing)) { KeyId = "Development" }; return(new SigningCredentials(developmentKey, "RS256")); case KeySources.File: var pfxPath = Path.Combine(Directory.GetCurrentDirectory(), key.FilePath); var pfxPassword = key.Password; var storageFlags = GetStorageFlags(key); _logger.LogInformation($"Loading certificate file at '{pfxPath}' with storage flags '{key.StorageFlags}'."); return(new SigningCredentials(new X509SecurityKey(SigningKeysLoader.LoadFromFile(pfxPath, key.Password, storageFlags)), "RS256")); case KeySources.Store: if (!Enum.TryParse <StoreLocation>(key.StoreLocation, out var storeLocation)) { throw new InvalidOperationException($"Invalid certificate store location '{key.StoreLocation}'."); } _logger.LogInformation($"Loading certificate with subject '{key.Name}' in '{key.StoreLocation}\\{key.StoreName}'."); return(new SigningCredentials(new X509SecurityKey(SigningKeysLoader.LoadFromStoreCert(key.Name, key.StoreName, storeLocation, GetCurrentTime())), "RS256")); default: throw new InvalidOperationException($"Invalid key type '{key.Type ?? "(null)"}'."); } }
/// <summary> /// Called when the user clicks "Apply" in the rectangle dialog. Sets the new boundaries and invokes the changed event. /// </summary> private void OnRectangleDimensionsSet(TRectangle rectangle) { this.lstBoundaries.Items.Clear(); this.lstBoundaries.Items.Add(rectangle.TopLeft); this.lstBoundaries.Items.Add(rectangle.TopRight); this.lstBoundaries.Items.Add(rectangle.BottomRight); this.lstBoundaries.Items.Add(rectangle.BottomLeft); this.currentDefinition = this.currentDefinition.ModifyMouse(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList()); this.DefinitionChanged?.Invoke(this.currentDefinition); }
public XElement SerializeKeyDefinition(KeyDefinition keyDef) { XElement xkeyDef = new XElement("keydefinition", new XElement("keyfields", keyDef.Fields.Select(cmd => new XElement("field", new XAttribute("name", cmd.Name), new XAttribute("generator", cmd.Generator.Name), new XAttribute("maxlength", cmd.Generator.MaxLength) ) )), new XElement("targetkeyfield", new XAttribute("name", keyDef.TargetKeyField) ) ); return(xkeyDef); }
/// <summary> /// Handles changing the key-code, sets the new text and invokes the changed event. /// </summary> private void cmbKeyCode_SelectedIndexChanged(object sender, EventArgs e) { if (this.initialDefinition is MouseKeyDefinition) { this.currentDefinition = this.currentDefinition .ModifyMouse(keyCode: (int)(MouseKeyCode)this.cmbKeyCode.SelectedItem); } if (this.initialDefinition is MouseScrollDefinition) { this.currentDefinition = this.currentDefinition .ModifyMouse(keyCode: (int)(MouseScrollKeyCode)this.cmbKeyCode.SelectedItem); } this.DefinitionChanged?.Invoke(this.currentDefinition); }
/// <summary> /// Handles removing a boundary, sets the new boundaries and invokes the changed event. /// </summary> private void btnRemoveBoundary_Click(object sender, EventArgs e) { if (this.lstBoundaries.SelectedItem == null) { return; } var index = this.lstBoundaries.SelectedIndex; this.lstBoundaries.Items.Remove(this.lstBoundaries.SelectedItem); this.lstBoundaries.SelectedIndex = Math.Min(this.lstBoundaries.Items.Count - 1, index); this.currentDefinition = this.currentDefinition.ModifyMouse(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList()); this.DefinitionChanged?.Invoke(this.currentDefinition); }
/// <summary> /// Handles moving a boundary down in the list, sets the new boundaries and invokes the changed event. /// </summary> private void btnBoundaryDown_Click(object sender, EventArgs e) { var item = this.lstBoundaries.SelectedItem; var index = this.lstBoundaries.SelectedIndex; if (item == null || index == this.lstBoundaries.Items.Count - 1) { return; } this.lstBoundaries.Items.Remove(item); this.lstBoundaries.Items.Insert(index + 1, item); this.lstBoundaries.SelectedIndex = index + 1; this.currentDefinition = this.currentDefinition.ModifyMouse(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList()); this.DefinitionChanged?.Invoke(this.currentDefinition); }
/// <summary> /// Handles adding a boundary, sets the new boundaries and invokes the changed event. /// </summary> private void btnAddBoundary_Click(object sender, EventArgs e) { var newBoundary = new TPoint(this.txtBoundaries.X, this.txtBoundaries.Y); if (this.lstBoundaries.Items.Cast <TPoint>().Any(p => p.X == newBoundary.X && p.Y == newBoundary.Y)) { return; } var newIndex = Math.Max(0, this.lstBoundaries.SelectedIndex); this.lstBoundaries.Items.Insert(newIndex, newBoundary); this.lstBoundaries.SelectedIndex = newIndex; this.currentDefinition = this.currentDefinition.ModifyMouse(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList()); this.DefinitionChanged?.Invoke(this.currentDefinition); }
public KeyDefinition DeserializeKeyDefinition(XElement xKeyDef) { try { var keyDef = new KeyDefinition(); if (xKeyDef == null) { return(keyDef); } // KeyFields foreach (XElement xField in xKeyDef.Element("keyfields").Elements()) { var keyField = new KeyField(); keyField.Name = xField.Attribute(XName.Get("name")).Value; // Keygenerator string keyGeneratorName = xField.Attribute(XName.Get("generator")).Value; if (!string.IsNullOrEmpty(keyGeneratorName)) { keyField.Generator = StringPhoneticKeyBuilderFactory.GetInstance(keyGeneratorName); keyField.Generator.MaxLength = (int)xField.Attribute(XName.Get("maxlength")); } keyDef.Fields.Add(keyField); } // Target Field keyDef.TargetKeyField = xKeyDef.Element("targetkeyfield") .Attribute(XName.Get("name")) .Value; return(keyDef); } catch (Exception ex) { throw new ArgumentException("Fehler in " + this.GetType().FullName + " Method: [" + System.Reflection.MethodBase.GetCurrentMethod() + "] Data: " + xKeyDef.ToString(), ex); } }
public SigningCredentials LoadKey() { var key = new KeyDefinition(); _configuration.Bind(key); switch (key.Type) { case KeySources.Development: var developmentKeyPath = Path.Combine(Directory.GetCurrentDirectory(), key.FilePath ?? DefaultTempKeyRelativePath); var createIfMissing = key.Persisted ?? true; _logger.LogInformation($"Loading development key at '{developmentKeyPath}'."); var developmentKey = new RsaSecurityKey(SigningKeysLoader.LoadDevelopment(developmentKeyPath, createIfMissing)) { KeyId = "Development" }; return(new SigningCredentials(developmentKey, "RS256")); case KeySources.File: var pfxPath = Path.Combine(Directory.GetCurrentDirectory(), key.FilePath); var pfxPassword = key.Password; var storageFlags = GetStorageFlags(key); _logger.LogInformation($"Loading certificate file at '{pfxPath}' with storage flags '{key.StorageFlags}'."); return(new SigningCredentials(new X509SecurityKey(SigningKeysLoader.LoadFromFile(pfxPath, key.Password, storageFlags)), "RS256")); case KeySources.Store: if (!Enum.TryParse <StoreLocation>(key.StoreLocation, out var storeLocation)) { throw new InvalidOperationException($"Invalid certificate store location '{key.StoreLocation}'."); } _logger.LogInformation($"Loading certificate with subject '{key.Name}' in '{key.StoreLocation}\\{key.StoreName}'."); return(new SigningCredentials(new X509SecurityKey(SigningKeysLoader.LoadFromStoreCert(key.Name, key.StoreName, storeLocation, GetCurrentTime())), "RS256")); case null: throw new InvalidOperationException($"Key type not specified."); default: throw new InvalidOperationException($"Invalid key type '{key.Type ?? "(null)"}'."); } }
private X509KeyStorageFlags GetStorageFlags(KeyDefinition key) { var defaultFlags = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? UnsafeEphemeralKeySet : (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? X509KeyStorageFlags.PersistKeySet : X509KeyStorageFlags.DefaultKeySet); if (key.StorageFlags == null) { return(defaultFlags); } var flagsList = key.StorageFlags.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (flagsList.Length == 0) { return(defaultFlags); } var result = ParseCurrentFlag(flagsList[0]); foreach (var flag in flagsList.Skip(1)) { result |= ParseCurrentFlag(flag); } return(result); X509KeyStorageFlags ParseCurrentFlag(string candidate) { if (Enum.TryParse <X509KeyStorageFlags>(candidate, out var flag)) { return(flag); } else { throw new InvalidOperationException($"Invalid storage flag '{candidate}'"); } } }
/// <summary> /// Handles updating a boundary, sets the new boundaries and invokes the changed event. /// </summary> private void btnUpdateBoundary_Click(object sender, EventArgs e) { if (this.lstBoundaries.SelectedItem == null) { return; } var updateIndex = this.lstBoundaries.SelectedIndex; var newBoundary = new TPoint(this.txtBoundaries.X, this.txtBoundaries.Y); if (this.lstBoundaries.Items.Cast <TPoint>().Any(p => p.X == newBoundary.X && p.Y == newBoundary.Y)) { return; } this.lstBoundaries.Items.RemoveAt(updateIndex); this.lstBoundaries.Items.Insert(updateIndex, newBoundary); this.lstBoundaries.SelectedIndex = updateIndex; this.currentDefinition = this.currentDefinition.ModifyMouse(boundaries: this.lstBoundaries.Items.Cast <TPoint>().ToList()); this.DefinitionChanged?.Invoke(this.currentDefinition); }
public Schema.Order StringToOrder(string order) { if (order.IndexOf(Keywords.Key) >= 0) { KeyDefinition keyDefinition = _parser.ParseKeyDefinition(order); Schema.Order localOrder = new Schema.Order(); foreach (KeyColumnDefinition column in keyDefinition.Columns) { localOrder.Columns.Add(new Schema.OrderColumn(TableVar.Columns[column.ColumnName], true)); } return(localOrder); } else { OrderDefinition orderDefinition = _parser.ParseOrderDefinition(order); Schema.Order localOrder = new Schema.Order(); foreach (OrderColumnDefinition column in orderDefinition.Columns) { localOrder.Columns.Add(new Schema.OrderColumn(TableVar.Columns[column.ColumnName], column.Ascending, column.IncludeNils)); } return(localOrder); } }
/// <summary> /// Handles changing the text position, sets the new text position and invokes the changed event. /// </summary> private void txtTextPosition_ValueChanged(Controls.VectorTextBox sender, TPoint newValue) { this.currentDefinition = this.currentDefinition.ModifyMouse(textPosition: newValue); this.DefinitionChanged?.Invoke(this.currentDefinition); }
/// <summary> /// Handles changing the text, sets the new text and invokes the changed event. /// </summary> private void txtText_TextChanged(object sender, EventArgs e) { this.currentDefinition = this.currentDefinition.ModifyMouse(text: this.txtText.Text); this.DefinitionChanged?.Invoke(this.currentDefinition); }