public Guid Add(XmlKey key)
 {
     using (var conn = Connection)
     {
         return(conn.ExecuteScalar <Guid>($"INSERT into {TableName}(Xml) values (@Xml) returning Id", key));
     }
 }
Esempio n. 2
0
        private Key CreateKeyWithBasicProps(XmlKey xmlKey)
        {
            // Add the core properties from XML to a new key
            Key newKey = new Key();

            if (xmlKey.ShiftDownLabel != null && xmlKey.ShiftUpLabel != null)
            {
                newKey.ShiftUpText   = xmlKey.ShiftUpLabel.ToStringWithValidNewlines();
                newKey.ShiftDownText = xmlKey.ShiftDownLabel.ToStringWithValidNewlines();
            }
            else if (xmlKey.Label != null)
            {
                newKey.Text = xmlKey.Label.ToStringWithValidNewlines();
            }

            if (xmlKey.Symbol != null)
            {
                Geometry geom = (Geometry)this.Resources[xmlKey.Symbol];
                if (geom != null)
                {
                    newKey.SymbolGeometry = geom;
                }
                else
                {
                    Log.ErrorFormat("Could not parse {0} as symbol geometry", xmlKey.Symbol);
                }
            }

            // Add same symbol margin to all keys
            if (keyboard.SymbolMargin.HasValue)
            {
                newKey.SymbolMargin = keyboard.SymbolMargin.Value;
            }

            // Set shared size group
            bool hasSymbol = newKey.SymbolGeometry != null;
            bool hasString = xmlKey.Label != null || xmlKey.ShiftUpLabel != null || xmlKey.ShiftDownLabel != null;

            if (hasSymbol && hasString)
            {
                newKey.SharedSizeGroup = "KeyWithSymbolAndText";
            }
            else if (hasSymbol)
            {
                newKey.SharedSizeGroup = "KeyWithSymbol";
            }
            else if (hasString)
            {
                newKey.SharedSizeGroup = !(newKey.Text != null && newKey.Text.Length > 1) &&
                                         !(newKey.ShiftDownText != null && newKey.ShiftDownText.Length > 1) &&
                                         !(newKey.ShiftUpText != null && newKey.ShiftUpText.Length > 1) ? "KeyWithSingleLetter" : "KeyWithText";
            }

            //Set width span and height span
            newKey.WidthSpan  = xmlKey.Width;
            newKey.HeightSpan = xmlKey.Height;

            return(newKey);
        }
Esempio n. 3
0
 public int Add(XmlKey key)
 {
     using (var conn = Connection)
     {
         var result = conn.ExecuteScalar <int>($"INSERT into {TableName}(Xml) values (@Xml)", key);
         return(result);
     }
 }
Esempio n. 4
0
        private Key CreateKeyWithBasicProps(XmlKey xmlKey)
        {
            // Add the core properties from XML to a new key
            Key newKey = new Key();

            if (null != xmlKey.ShiftDownLabel && null != xmlKey.ShiftUpLabel)
            {
                newKey.ShiftUpText   = xmlKey.ShiftUpLabel.ToStringWithValidNewlines();
                newKey.ShiftDownText = xmlKey.ShiftDownLabel.ToStringWithValidNewlines();
            }
            else if (null != xmlKey.Label)
            {
                newKey.Text = xmlKey.Label.ToStringWithValidNewlines();
            }


            if (null != xmlKey.Symbol)
            {
                Geometry geom = (Geometry)this.Resources[xmlKey.Symbol];
                if (null != geom)
                {
                    newKey.SymbolGeometry = geom;
                }
                else
                {
                    Log.ErrorFormat("Could not parse {0} as symbol geometry", xmlKey.Symbol);
                }
            }

            // Add same symbol margin to all keys
            if (keyboard.SymbolMargin.HasValue)
            {
                newKey.SymbolMargin = keyboard.SymbolMargin.Value;
            }

            // Set shared size group
            bool hasSymbol = null != newKey.SymbolGeometry;
            bool hasString = null != xmlKey.Label || null != xmlKey.ShiftUpLabel || null != xmlKey.ShiftDownLabel;

            if (hasSymbol && hasString)
            {
                newKey.SharedSizeGroup = "KeyWithSymbolAndText";
            }
            else if (hasSymbol)
            {
                newKey.SharedSizeGroup = "KeyWithSymbol";
            }
            else if (hasString)
            {
                newKey.SharedSizeGroup = "KeyWithText";
            }
            // Also group separately by row/col width/height
            newKey.SharedSizeGroup += xmlKey.Width;
            newKey.SharedSizeGroup += xmlKey.Height;

            return(newKey);
        }
Esempio n. 5
0
        private string GetKeyString(XmlKey xmlKey)
        {
            var textKey = xmlKey as XmlTextKey;

            if (textKey != null)
            {
                return(textKey.Text);
            }

            return(xmlKey.Label ?? xmlKey.Symbol);
        }
    public void StoreElement(XElement element, string friendlyName)
    {
        var key = new XmlKey
        {
            Xml = element.ToString(SaveOptions.DisableFormatting)
        };

        using (var scope = factory.CreateScope())
        {
            var context = scope.ServiceProvider.GetRequiredService <DataProtectionDbContext>();
            context.XmlKeys.Add(key);
            context.SaveChanges();
        }
    }
Esempio n. 7
0
        private Key CreateKeyWithBasicProps(XmlKey xmlKey)
        {
            // Add the core properties from XML to a new key
            Key newKey = new Key();

            newKey.Text = xmlKey.Label.ToStringWithValidNewlines();

            if (null != xmlKey.Symbol)
            {
                Geometry geom = (Geometry)this.Resources[xmlKey.Symbol];
                if (null != geom)
                {
                    newKey.SymbolGeometry = geom;
                }
                else
                {
                    Log.ErrorFormat("Could not parse {0} as symbol geometry", xmlKey.Symbol);
                }
            }

            // Add same symbol margin to all keys
            if (keyboard.SymbolMargin.HasValue)
            {
                newKey.SymbolMargin = keyboard.SymbolMargin.Value;
            }

            // Set shared size group : The fonts for these groups are sized equally among
            // keys with the same SharedSizeGroup property and the same width by height values.
            // To scale the fonts for better viewability we are breaking the SharedSizeGroup
            // labels into classes based on the text label length (if it is non-zero):
            newKey.SharedSizeGroup  = ClassifySharedSizeGroup(newKey, xmlKey.Label);
            newKey.SharedSizeGroup += xmlKey.Width;
            newKey.SharedSizeGroup += xmlKey.Height;

            return(newKey);
        }
Esempio n. 8
0
 public static T Find <T>(this XmlKey key, Predicate <T> match)
 {
     return(XmlFactory.Find(key.ToString()).Find(match));
 }
Esempio n. 9
0
 public static List <T> FindAll <T>(this XmlKey key)
 {
     return(XmlFactory.Find(key.ToString()).FindAll <T>());
 }
Esempio n. 10
0
        private Key CreateKeyWithBasicProps(XmlKey xmlKey, int minKeyWidth, int minKeyHeight)
        {
            // Add the core properties from XML to a new key
            Key newKey = new Key();

            if (xmlKey.ShiftDownLabel != null && xmlKey.ShiftUpLabel != null)
            {
                newKey.ShiftUpText   = xmlKey.ShiftUpLabel.ToStringWithValidNewlines();
                newKey.ShiftDownText = xmlKey.ShiftDownLabel.ToStringWithValidNewlines();
            }
            else if (xmlKey.Label != null)
            {
                string vLabel = xmlKey.Label.ToString();
                string vText;
                string vLookup;
                while (vLabel.Contains("{Resource:"))
                {
                    vText   = vLabel.Substring(vLabel.IndexOf("{Resource:"), vLabel.IndexOf("}", vLabel.IndexOf("{Resource:")) - vLabel.IndexOf("{Resource:") + 1);
                    vLookup = Properties.Resources.ResourceManager.GetString(vText.Substring(10, vText.Length - 11).Trim());
                    vLabel  = vLabel.Replace(vText, vLookup);
                }
                while (vLabel.Contains("{Setting:"))
                {
                    vText   = vLabel.Substring(vLabel.IndexOf("{Setting:"), vLabel.IndexOf("}", vLabel.IndexOf("{Setting:")) - vLabel.IndexOf("{Setting:") + 1);
                    vLookup = Properties.Settings.Default[vText.Substring(9, vText.Length - 10).Trim()].ToString();
                    vLabel  = vLabel.Replace(vText, vLookup);
                }

                newKey.Text = vLabel.ToStringWithValidNewlines();
            }
            else if (xmlKey.Label != null)
            {
                newKey.Text = xmlKey.Label.ToStringWithValidNewlines();
            }

            if (xmlKey.Symbol != null)
            {
                Geometry geom = (Geometry)this.Resources[xmlKey.Symbol];
                if (geom != null)
                {
                    newKey.SymbolGeometry = geom;
                }
                else
                {
                    Log.ErrorFormat("Could not parse {0} as symbol geometry", xmlKey.Symbol);
                }
            }

            // Add same symbol margin to all keys
            if (keyboard.SymbolMargin.HasValue)
            {
                newKey.SymbolMargin = keyboard.SymbolMargin.Value;
            }

            // Set shared size group
            if (!string.IsNullOrEmpty(xmlKey.SharedSizeGroup))
            {
                newKey.SharedSizeGroup = xmlKey.SharedSizeGroup;
            }
            else
            {
                bool hasSymbol = newKey.SymbolGeometry != null;
                bool hasString = xmlKey.Label != null || xmlKey.ShiftUpLabel != null || xmlKey.ShiftDownLabel != null;
                if (hasSymbol && hasString)
                {
                    newKey.SharedSizeGroup = "KeyWithSymbolAndText";
                }
                else if (hasSymbol)
                {
                    newKey.SharedSizeGroup = "KeyWithSymbol";
                }
                else if (hasString)
                {
                    var text = newKey.Text != null?newKey.Text.Compose()
                                   : newKey.ShiftDownText != null?newKey.ShiftDownText.Compose()
                                       : newKey.ShiftUpText?.Compose();

                    //Strip out circle character used to show diacritic marks
                    text = text?.Replace("\x25CC", string.Empty);

                    newKey.SharedSizeGroup = text != null && text.Length > 1 ? "KeyWithText" : "KeyWithSingleLetter";
                }
            }

            //Auto set width span and height span
            if (xmlKey.AutoScaleToOneKeyWidth)
            {
                newKey.WidthSpan = (double)xmlKey.Width / (double)minKeyWidth;
            }

            if (xmlKey.AutoScaleToOneKeyHeight)
            {
                newKey.HeightSpan = (double)xmlKey.Height / (double)minKeyHeight;
            }

            newKey.UsePersianCompatibilityFont = xmlKey.UsePersianCompatibilityFont;
            newKey.UseUnicodeCompatibilityFont = xmlKey.UseUnicodeCompatibilityFont;
            newKey.UseUrduCompatibilityFont    = xmlKey.UseUrduCompatibilityFont;

            if (!string.IsNullOrEmpty(xmlKey.BackgroundColor) &&
                (Regex.IsMatch(xmlKey.BackgroundColor, "^(#[0-9A-Fa-f]{3})$|^(#[0-9A-Fa-f]{6})$") ||
                 System.Drawing.Color.FromName(xmlKey.BackgroundColor).IsKnownColor))
            {
                newKey.BackgroundColourOverride = (SolidColorBrush) new BrushConverter().ConvertFrom(xmlKey.BackgroundColor);
            }

            return(newKey);
        }
Esempio n. 11
0
 public static List <T> FindAll <T>(this XmlKey key, Predicate <T> match)
 {
     return(XmlService.Find(key.ToString()).FindAll(match));
 }
Esempio n. 12
0
 public static List <T> FindAll <T>(this XmlKey key, IFormFile file, Xml xml)
 {
     return(file == null?key.FindAll <T>() : file.FindAll <T>(xml));
 }