private JMXSchema creaateTestSchema() { JMXSchema s = new JMXSchema("SysSchema") { DbObjectName = new JMXObjectName("SysCat", "SysSchemas") }; JMXAttribute a = new JMXAttribute("ID") { DataType = MdbType.@int }; s.Attributes.Add(new JMXAttribute("ID") { DataType = MdbType.@int, Caption = "Identifier", IsNullable = false }); s.Attributes.Add(new JMXAttribute("Name") { DataType = MdbType.@string, Caption = "Name of SysSchema" }); s.PrimaryKey = new JMXPrimaryKey("PK_SysSchemas", "ID"); s.Indexes.Add(new JMXIndex("IE1_SysSchemas", "Name")); var fk = new JMXForeignKey("FK1") { RefObjectName = "SysCat.SysArea", RefDbObjectName = new JMXObjectName("SysCat", "SysAreas") }; fk.AddKeyMember("AreaID"); fk.AddRefKeyMember("ID"); s.ForeignKeys.Add(fk); return(s); }
public Color4VM(string Name, Color4 Color) : base(Name, true) { var red = new JMXAttribute("Red", Color.Red); var green = new JMXAttribute("Green", Color.Green); var blue = new JMXAttribute("Blue", Color.Blue); // Add nodes Childs.Add(red); Childs.Add(green); Childs.Add(blue); Childs.Add(new JMXAttribute("Alpha", Color.Alpha)); // Add handlers to update color brush void OnColorChange(object s, PropertyChangedEventArgs e) { DemoBrush = new SolidColorBrush(new Color() { R = (byte)((float)red.Value * 255), G = (byte)((float)green.Value * 255), B = (byte)((float)blue.Value * 255), A = 255 }); ; OnPropertyChanged(nameof(DemoBrush)); }; red.PropertyChanged += OnColorChange; green.PropertyChanged += OnColorChange; blue.PropertyChanged += OnColorChange; // Update it OnColorChange(null, null); }
private static void SetAttrType(JMXAttribute att, string source) { string s = source.Between('(', ')'); if (!s.IsEmpty()) { if (s.Contains(',')) { var a = s.Split(','); att.DataSize = new JMXDataSize(a[0].ToIntOrDefault(), a[1].ToIntOrDefault()); } else { att.DataSize = new JMXDataSize(s.ToIntOrDefault()); } } var serverType = source.GetToken(0, " ") .RemoveChar("[]".ToCharArray()); att.ServerDataType = serverType; if (SQLiteHelper.TypeInfo.ContainsKey(serverType)) { att.DataType = SQLiteHelper.TypeInfo[serverType].MdbType; } else { att.DataType = MdbType.@string; } }
public override async Task <JMXSchema> GetObjectSchemaAsync(string objectName) { ///!!! костыль с именем таблицы JMXSchema schema = new JMXSchema(objectName.Left(objectName.Length - 1)) { DbObjectType = DbObjectTypes.Table, DbObjectName = objectName, SchemaRepo = _schemaRepo }; var drs = await Factory .GetMdbContext() .GetReadersAsync(SQLite.GetTableSchema, new MdbParameter("@table_name", objectName)); var dr = drs[0]; string sql = string.Empty; if (dr.Read()) { sql = (string)dr["sql"]; } else { return(null); } var s = sql.Split(new string[] { "CONSTRAINT ", " PRIMARY KEY" }, StringSplitOptions.RemoveEmptyEntries) .First(str => !str.Contains(' ')); if (!s.IsEmpty()) { schema.PrimaryKey = new JMXPrimaryKey(s); } dr = drs[1]; for (; dr.Read();) { JMXAttribute att = new JMXAttribute((string)dr["name"]); att.FieldName = att.AttribName; att.IsFK = dr["pk"].Equals(1); att.Required = dr["notnull"].Equals(1); if (att.IsFK) { schema.PrimaryKey.AddKeyMember(att.FieldName); } SetAttrType(att, (string)dr["type"]); schema.Attributes.Add(att); } //Костыль!!! доделать return(null); }
private static async Task NormalizeDetailsAsync(MdbContext mdb, JMXSchema schema) { foreach (var att in schema.Attributes.Where(a => a.DataType == MdbType.@object)) { if (att.ObjectSchema == null) { //For an object type attribute, you must specify a schema throw new InvalidOperationException(Properties.Strings.S031_MetaStack_Core_ORM_JMXSchemaProviderDB_normalize_2); } att.ObjectSchema = await NormalizeSchemaAsync(mdb, att.ObjectSchema); att.ServerDataType = "varchar"; att.DataSize = new JMXDataSize(1); att.FieldName = $"{JMXFactory.DETAIL_FIELD_PREFIX}{att.ObjectSchema.DbObjectName.AreaName}_{att.ObjectSchema.DbObjectName.ObjectName}"; //check indexes fo FK if (!att.ObjectSchema.ForeignKeys.Any(fk => fk.RefDbObjectName.AreaName == schema.DbObjectName.AreaName && fk.RefDbObjectName.ObjectName == schema.DbObjectName.ObjectName)) { var fk = new JMXForeignKey($"FK_{att.ObjectSchema.DbObjectName.AreaName}_{att.ObjectSchema.DbObjectName.ObjectName}_{schema.DbObjectName.ObjectName}") { RefDbObjectName = schema.DbObjectName.ToString(), RefObjectName = schema.ObjectName.ToString() }; foreach (var m in schema.PrimaryKey.KeyMembers) { string fieldName = $"{schema.ObjectName}{m.FieldName}"; if (!att.ObjectSchema.Attributes.Any(a => a.FieldName == fieldName)) { var refAtt = schema.Attributes.FirstOrDefault(a => a.FieldName == m.FieldName); var newAtt = new JMXAttribute(fieldName) { DataType = refAtt.DataType, ServerDataType = refAtt.ServerDataType, Required = true, FieldName = fieldName, IsFK = true, DataSize = refAtt.DataSize }; att.ObjectSchema.Attributes.Add(newAtt); } } //check for exists attribute $"{schema.ObjectName}{m.FieldName}" in att.ObjectSchema fk.AddKeyMember(schema.PrimaryKey.KeyMembers.Select(m => $"{schema.ObjectName}{m.FieldName}").ToArray()); fk.AddRefKeyMember(schema.PrimaryKey.KeyMembers.Select(m => m.FieldName).ToArray()); att.ObjectSchema.ForeignKeys.Add(fk); } } }
private void MnuTotal_Click(object sender, EventArgs e) { ToolStripMenuItem mi = (sender as ToolStripMenuItem); ContextMenuStrip ms = (mi.Owner as ContextMenuStrip); DataGridViewColumn col = (DataGridViewColumn)((ms.SourceControl as Label).Tag); string totalFunc = string.Empty; switch (mi.Name) { case "mnuTotalSum": totalFunc = "sum"; break; case "mnuTotalAverage": totalFunc = "ave"; break; case "mnuTotalCount": totalFunc = "rcnt"; break; case "mnuTotalMin": totalFunc = "min"; break; case "mnuTotalMax": totalFunc = "max"; break; case "mnuTotalCopy": string fText = this.FooterText(col.Index).Replace( System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyGroupSeparator, ""); if (!string.IsNullOrEmpty(fText)) { Clipboard.SetText(fText); } return; } JMXAttribute att = _xc.Attributes[col.Index]; if (TotalValid(GetMacroType(att.DataType), totalFunc)) { att.Agregate = totalFunc; _xcOriginal.Attributes[col.Index].Agregate = totalFunc; MakeTotals(); ShowTotals(); } }
public SchemaManager(JMXSchema schema) { _schema = schema; if (_schema.PrimaryKey.KeyMembers.Count == 1) { var key = _schema.PrimaryKey.KeyMembers[0].FieldName; var att = _schema.Attributes.FirstOrDefault(a => a.FieldName == key); if (att == null) { ///!!! To Resources throw new InvalidOperationException($"Attribute with FieldName that equals {key} not found"); } else if (att.DataType == MdbType.@int || att.DataType == MdbType.@long) { _identityAttribute = att; } } if (_identityAttribute == null) { _identityAttribute = schema.Attributes.FirstOrDefault(a => a.Identity.IsIdentity); } if (_identityAttribute == null) { foreach (var ak in schema.Indexes.Where(idx => idx.IsUnique && idx.KeyMembers.Count == 1)) { var key = ak.KeyMembers[0].FieldName; var att = _schema.Attributes.FirstOrDefault(a => a.FieldName == key); if (att == null) { ///!!! To Resources throw new InvalidOperationException($"Attribute with FieldName that equals {key} not found"); } else if (att.DataType == MdbType.@int || att.DataType == MdbType.@long) { _identityAttribute = att; } } } }
public void SerializeTest() { using (FileLog _logger = new FileLog("ORMSchemaTest", new FileLogSettings() { DateFolderMask = "yyyy-MM-dd" })) { JMXAttribute a = new JMXAttribute("ID") { DataType = MdbType.@int, IsNullable = false }; string sa = a.ToString(); //_logger.Debug(sa); a = JsonConvert.DeserializeObject <JMXAttribute>(sa); //_logger.Debug(a.ToString()); Assert.AreEqual(sa, a.ToString()); JMXPrimaryKey pk = new JMXPrimaryKey("PK_SomeObjects", "SomeAtt", "NextAtt"); string spk = pk.ToString(); //_logger.Debug(spk); pk = JsonConvert.DeserializeObject <JMXPrimaryKey>(spk); Assert.AreEqual(spk, pk.ToString()); JMXSchema s = new JMXSchema("SysSchemas") { DbObjectName = new JMXObjectName("SysCat", "SysSchemas") }; s.Attributes.Add(a); s.PrimaryKey = pk; s.Indexes.Add(new JMXIndex("IE1_SysSchemas", "ID")); var fk = new JMXForeignKey("FK1") { RefObjectName = "SysCat.SysArea", RefDbObjectName = new JMXObjectName("SysCat", "SysAreas") }; fk.AddKeyMember("AreaID"); fk.AddRefKeyMember("ID"); s.ForeignKeys.Add(fk); string ss = s.ToString(); _logger.Debug(ss); s = JsonConvert.DeserializeObject <JMXSchema>(ss); Assert.AreEqual(ss, s.ToString()); _logger.Debug("Start speed test fo JMXObject parse from json string"); JMXSchemaProviderFactory.RegisterProvider <JMXSchemaProviderMemory>(); JMXSchemaProviderFactory.SetDefault(JMXSchemaProviderFactory.GetProvider <JMXSchemaProviderMemory>()); JMXSchemaProviderFactory.Default.SaveSchema(creaateTestSchema()); JMXObject o = new JMXObject("SysCat.SysSchema"); for (int i = 0; i < 1000; i++) { o.ParseJson(ss, null); } _logger.Debug("Finish speed test"); _logger.Debug(o.ToString()); _logger.Debug("Start speed test fo JMXSchema serialize to json string"); for (int i = 0; i < 1000; i++) { ss = JsonConvert.SerializeObject(s); } _logger.Debug("Finish speed test"); _logger.Debug("Start speed test fo JMXSchema ToString method to json string"); for (int i = 0; i < 1000; i++) { ss = s.ToString(); } _logger.Debug("Finish speed test"); _logger.Debug("Start speed test fo JMXSchema parse from json string"); for (int i = 0; i < 1000; i++) { s = JsonConvert.DeserializeObject <JMXSchema>(ss); } _logger.Debug("Finish speed test"); //JMXObject o = new JMXObject(JObject.Parse(ss)); //_logger.Debug((o as JObject).ToString()); //JsonSerializer serializer = new JsonSerializer(); //JMXObject o = (JMXObject)serializer.Deserialize(new JTokenReader(JObject.Parse(ss)), typeof(JMXObject)); //JMXObject o = new JMXObject("Test"); } }