Пример #1
0
        public CClass Convert(CTableType tableType)
        {
            if (string.IsNullOrEmpty(tableType.TableName))
            {
                throw new Exception("cannot create CClass without a class name");
            }

            var @class = new CClass(tableType.TableName);

            @class.Namespace = new CNamespace {
                NamespaceName = tableType.Schema.SchemaName
            };

            @class.NamespaceRef.Add(new CNamespaceRef("System"));

            if (!string.IsNullOrEmpty(tableType.TableName))
            {
                foreach (var column in tableType.Column)
                {
                    var prop = new CProperty();
                    prop.PropertyName = column.ColumnName;
                    prop.Type         = column.ColumnType.ToClrTypeName();
                    prop.MaxLength    = column.ColumnLength;

                    @class.Property.Add(prop);
                }
            }

            return(@class);
        }
Пример #2
0
        private CProtoMessageField FindProtoMessageField(CProtoMessage protoMessage, CProperty property)
        {
            foreach (var protoField in protoMessage.ProtoField)
            {
                if (protoField.DerivedFrom is CColumn)
                {
                    var column = protoField.DerivedFrom as CColumn;
                    if (column.ColumnName == property.PropertyName)
                    {
                        return(protoField);
                    }
                }
                if (protoField.DerivedFrom is CStoredProcedureParameter)
                {
                    var parameter = protoField.DerivedFrom as CStoredProcedureParameter;
                    if (parameter.SourceColumn.ColumnName == property.PropertyName)
                    {
                        return(protoField);
                    }
                }

                if (protoField.FieldName == property.PropertyName)
                {
                    return(protoField);
                }
            }
            return(null);
        }
Пример #3
0
        public void EnumPropertyTest()
        {
            var prop = new CProperty <EDispatchMode>();

            Assert.AreEqual(EDispatchMode.NotAssigned, prop.Value, "Default Value");

            prop.Value = EDispatchMode.Inline;
            Assert.AreEqual <EDispatchMode>(EDispatchMode.Inline, prop, "After Assignment");
        }
Пример #4
0
        public void BasicConstructionTest()
        {
            var prop = new CProperty <int>();

            Assert.AreEqual <int>(0, prop, "Default Value");

            prop = 5;
            Assert.AreEqual(5, prop.Value, "Error Message");

            Assert.AreEqual("5", prop.ToString(), "ToString on property");
        }
        private Entity ToEntity(string status, CProperty duration, CProperty meters)
        {
            var e = new Entity("organization");

            e["status"] = status;
            if (status.ToUpper() == "OK")
            {
                e["miles"]    = meters.Value * 0.000621371d;   // Convert to miles
                e["duration"] = duration.Value;
            }
            else
            {                                        // either NOT_FOUND or ZERO_RESULTS
                e["miles"]    = 0d;
                e["duration"] = 0d;
            }
            return(e);
        }
Пример #6
0
        public void UserClassPropertyTest()
        {
            var prop = new CProperty <CTestObject>();

            var obj = new CTestObject()
            {
                X = 11, m_string = "hello"
            };

            prop.Value = obj;

            Assert.AreEqual(11, prop.Value.X, "X should equal 11");
            Assert.AreEqual("hello", prop.Value.m_string, "String should be hello");

            obj.X++;
            Assert.AreEqual(12, prop.Value.X, "X should be 12");
        }
Пример #7
0
        private CProperty ConverterToNodeProperty(JValue value)
        {
            if (value == null)
            {
                return(null);
            }

            CProperty result = new CProperty
            {
                Value = value.Value
            };
            bool ok = Enum.TryParse(value.Type.ToString(), out CPropertyType Type);

            if (ok)
            {
                result.CType = Type;
            }
            return(result);
        }
Пример #8
0
        public CClass Convert(CView view)
        {
            var @class = new CClass(view.ViewName);

            @class.Namespace = new CNamespace {
                NamespaceName = view.Schema.SchemaName
            };


            foreach (var column in view.Column)
            {
                var prop = new CProperty();
                prop.PropertyName = column.ColumnName;
                prop.Type         = column.ColumnType.ToClrTypeName();
                @class.Property.Add(prop);
            }

            return(@class);
        }
Пример #9
0
        /// <summary>
        /// When the selection changes this sets the PropertyGrid's selected component
        /// </summary>
        private void selectionService_SelectionChanged(object sender, EventArgs e)
        {
            if (_selectionService != null)
            {
                ICollection selectedComponents = _selectionService.GetSelectedComponents();
                // Now, we only support single selected object
                if (selectedComponents == null || selectedComponents.Count != 1)
                {
                    return;
                }

                PropertyGrid propertyGrid = (PropertyGrid)this.GetService(typeof(PropertyGrid));

                object[] comps = new object[selectedComponents.Count];
                int      i     = 0;

                foreach (Object o in selectedComponents)
                {
                    comps[i] = o;
                    i++;
                }

                XmlNode   tmpXNode       = null;
                CProperty cp             = null;
                string    compTypeName   = comps[0].GetType().Name;
                string    singleNodePath = "Components/Component[@Name=\""
                                           + compTypeName
                                           + "\"]";

                tmpXNode = _xDoc.SelectSingleNode(singleNodePath);

                if (tmpXNode != null)
                {
                    XmlNodeList tmpXPropLst = tmpXNode.SelectNodes("Propertys/Property");
                    cp = new CProperty(comps[0], tmpXPropLst);
                    propertyGrid.SelectedObject = cp;
                }
                else
                {
                    propertyGrid.SelectedObjects = comps;
                }
            }
        }
Пример #10
0
        public void Visit(CProperty property)
        {
            if (property.Type == null)
            {
                throw new ArgumentException("Type not set");
            }
            var staticString = property.IsStatic ? "static " : string.Empty;

            _codeWriter.Write(
                $"{property.AccessModifier.GetString()} {staticString}{property.Type} {property.PropertyName}");
            _codeWriter.Write(" {");
            _codeWriter.Write(" get;");
            _codeWriter.Write(" set;");

            if (property.DefaultValue != null)
            {
                _codeWriter.Write(" } ");
                _codeWriter.WriteLine($" = {property.DefaultValue};");
            }
            else
            {
                _codeWriter.WriteLine(" } ");
            }
        }
Пример #11
0
        private void GenerateDef(CDBM db, CSharpProject p, string namespaceName, TextWriter mensajes)
        {
            string className = DefName(db.Name);

            p.AddCSharpFile(className + ".generated", namespaceName);
            CClass c = p.AddClass(className, isStatic: true);

            c.lUsing.Add(CSharpStandarUsing.System);
            c.lUsing.Add(new CUsing("IvanCruz.Util.UtilBD"));
            foreach (CTableM t in db.lTable)
            {
                c.AddField(new CField(t.Name, new TextualType(ClassDefName(t.Name)), CSharpVisibility.cvPublic, isStatic: true, InitialValue: " new " + ClassDefName(t.Name) + "()"));

                //CConstructor consVacio = new CConstructor(c, CSharpVisibility.cvPublic);
                //CConstructor cons = new CConstructor(c, CSharpVisibility.cvPublic);
                ////Se añaden al final por estética de la clase generada
                //foreach (CFieldM f in t.lFieldAll) {
                //	CType aux = CGenerator.SqlServerTD2CSharp(f.Td, f.IsNullable);
                //	if (aux.Equals(CSharpPrimitiveType.cDateTime)) {
                //		c.lUsing.Add(CSharpStandarUsing.System);
                //	}
                //	c.AddField(new CField(f.Name, aux, CSharpVisibility.cvPublic));
                //	cons.AddParam(SUtil.LowerFirst(f.Name), CGenerator.SqlServerTD2CSharp(f.Td, f.IsNullable));
                //	cons.AddSentence(new CTextualSentence($"this.{f.Name} = {SUtil.LowerFirst(f.Name)};"));
                //}
                //c.AddConstructor(consVacio);
                //c.AddConstructor(cons);
                CClass cTable = p.AddClass(ClassDefName(t.Name), isStatic: false);
                cTable.ParentClassName = "CTableDef";
                CProperty prop;
                prop          = new CProperty("TableName", CSharpVisibility.cvPublic, new TextualType("string"), hasGet: true, hasSet: false);
                prop.Override = true;
                prop.lSentenceGet.Add(new CTextualSentence("return " + SUtil.DoubleQuote(t.Name) + ";"));
                cTable.AddProperty(prop);
                prop          = new CProperty("SingularTitle", CSharpVisibility.cvPublic, new TextualType("string"), hasGet: true, hasSet: false);
                prop.Override = true;
                prop.lSentenceGet.Add(new CTextualSentence("return " + SUtil.DoubleQuote(t.SingularTitle) + ";"));
                cTable.AddProperty(prop);
                CField        auxField;
                StringBuilder sb = new StringBuilder();
                prop          = new CProperty("Fields", CSharpVisibility.cvPublic, new TextualType("System.Collections.Generic.IEnumerable<CFieldDef>"), hasGet: true, hasSet: false);
                prop.Override = true;
                foreach (CFieldM f in t.lFieldAll)
                {
                    auxField = new CField(f.Name, new TextualType("CFieldDef"), CSharpVisibility.cvPublic, isStatic: false);
                    sb.Clear();
                    sb.Append("new CFieldDef");
                    sb.Append("(");
                    sb.Append(SUtil.DoubleQuote(f.Name));
                    if (!string.IsNullOrWhiteSpace(f.Title))
                    {
                        sb.Append(",");
                        sb.Append(SUtil.DoubleQuote(f.Title));
                    }
                    sb.Append(")");
                    auxField.InitialValue = sb.ToString();
                    cTable.AddField(auxField);
                    prop.lSentenceGet.Add(new CTextualSentence("yield return " + f.Name + ";"));
                }
                cTable.AddProperty(prop);


                //public override System.Collections.Generic.IEnumerable<CFieldDef> Fields {
                //	get {
                //		yield return Id;
                //		yield return CodigoMedico;
                //		yield return Nomb;
                //	}
                //}
            }
            mensajes.WriteLine("Definición generada en: " + p.RootDirectory.ActualDirectory.FullName);
        }
Пример #12
0
 public void Visit(CProperty property)
 {
     _propertyVisitor.Visit(property);
 }
Пример #13
0
        private (ObservableCollection <CNode> Nodes, ObservableCollection <CProperty> Properties) ResolveJson(JObject data, JObject descObj)
        {
            var childNodes = new ObservableCollection <CNode>();
            var properties = new ObservableCollection <CProperty>();

            if (data == null)
            {
                return(childNodes, properties);
            }

            dynamic descInfo = null;

            foreach (var x in data)
            {
                if (descObj != null)
                {
                    descInfo = descObj[x.Key];
                }

                descInfo = ConveterJnjectData(descInfo);

                if (x.Value is JValue)
                {
                    var       value    = x.Value as JValue;
                    CProperty property = ConverterToNodeProperty(value);
                    if (property == null)
                    {
                        continue;
                    }

                    if (descInfo != null)
                    {
                        bool ok = Enum.TryParse(descInfo.type.ToString(), true, out CPropertyType cType);
                        if (ok)
                        {
                            property.CType = cType;
                        }

                        FillObj(property, descInfo);

                        if (descInfo.cbItems != null)
                        {
                            var tempList = new List <CProperty>();
                            foreach (var item in descInfo.cbItems)
                            {
                                var tmp = new CProperty();
                                FillObj(tmp, item);
                                tmp.Value = item.value.ToString();
                                tempList.Add(tmp);
                            }
                            property.ItemsSource = tempList;
                            property.Selected    = tempList.FirstOrDefault
                                                       (m => m.Value != null && property.Value != null &&
                                                       m.Value.ToString() == property.Value.ToString());
                        }
                    }

                    property.Name = x.Key;

                    if (property != null)
                    {
                        properties.Add(property);
                    }
                }
                else
                {
                    var node = new CNode();
                    if (descInfo != null)
                    {
                        FillObj(node, descInfo);
                    }
                    node.Name = x.Key;

                    var(Nodes, Properties) = ResolveJson(x.Value as JObject, descInfo as JObject);
                    node.Children          = Nodes;
                    node.Properties        = Properties;
                    childNodes.Add(node);
                }
            }

            return(childNodes, properties);
        }
Пример #14
0
        private void LoadData()
        {
            if (this.data != null)
            {
                return;
            }

            this.data = new Dictionary <String, CR2WVariant>();

            // Read variants
            {
                this.stream.Seek(this.entry.Offset, SeekOrigin.Begin);
                BinaryReader reader = new BinaryReader(this.stream);

                if (reader.ReadByte() != 0)
                {
                    return;
                }

                while (true)
                {
                    CR2WVariant variant = CR2WVariant.FromStream(this.file, this.stream);
                    if (variant == null)
                    {
                        break;
                    }

                    this.data.Add(variant.Name, variant);
                }
            }

            // Read new variants
            try {
                this.newData = new Dictionary <string, CProperty>();

                this.stream.Seek(this.entry.Offset, SeekOrigin.Begin);
                BinaryReader reader = new BinaryReader(this.stream);

                if (reader.ReadByte() != 0)
                {
                    return;
                }

                while (this.stream.Position < (this.entry.Offset + this.entry.Size))
                {
                    try {
                        CProperty prop = CR2WValue.ReadValue(this.file, reader);
                        if (prop.Name == null)
                        {
                            break;
                        }

                        this.newData.Add(prop.Name, prop);
                    } catch (Exception e) {
                        continue;
                    }
                }
            } catch (Exception e) {
                Console.Error.Write(e);
            }
        }
Пример #15
0
        public CClass Convert(CTable table, IEnumerable <CTable> allTables, bool convertForeignKeysToObjects)
        {
            var @class = new CClass(table.TableName);

            @class.DerivedFrom = table;
            @class.Namespace   = new CNamespace {
                NamespaceName = table.Schema.SchemaName
            };

            @class.NamespaceRef.Add(new CNamespaceRef()
            {
                ReferenceTo = new CNamespace()
                {
                    NamespaceName = "System"
                }
            });
            @class.NamespaceRef.Add(new CNamespaceRef()
            {
                ReferenceTo = new CNamespace()
                {
                    NamespaceName = "System.Collections.Generic"
                }
            });

            foreach (var column in table.Column)
            {
                if (!convertForeignKeysToObjects || !column.ForeignKeyColumn.Any())
                {
                    var prop = new CProperty();
                    prop.PropertyName = column.ColumnName;
                    prop.Type         = column.ColumnType.ToClrTypeName();
                    @class.Property.Add(prop);
                }
                else
                {
                    //we add foreign keys later, as objects
                }
            }

            if (convertForeignKeysToObjects && allTables != null)
            {
                //add foreign keys as objects
                //todo: put this core logic into extension method
                foreach (var allTable in allTables)
                {
                    foreach (var allTableColumn in allTable.Column)
                    {
                        foreach (var allTableColumnFK in allTableColumn.ForeignKeyColumn)
                        {
                            if (allTableColumnFK.Table.Schema.SchemaName == table.Schema.SchemaName &&
                                allTableColumnFK.Table.TableName == table.TableName) //todo: use a fancy compare method
                            {
                                var prop = new CProperty();
                                var s    = new Inflector.Inflector(CultureInfo.CurrentCulture);

                                prop.PropertyName = s.Pluralize(allTable.TableName);
                                prop.Type         = $"IEnumerable<{allTable.TableName}>"; //todo: how can we determine if is a collection or not? may be able to use DerivedFrom
                                @class.Property.Add(prop);
                            }
                        }
                    }
                }
            }



            return(@class);
        }
Пример #16
0
        public CClass ConvertByResultSet(CStoredProcedure storedProcedure)
        {
            if (string.IsNullOrEmpty(storedProcedure.ResultSetName))
            {
                throw new Exception("cannot create CClass without a class name");
            }

            var @class = new CClass(storedProcedure.ResultSetName)
            {
                DerivedFrom = storedProcedure,
                Namespace   = new CNamespace {
                    NamespaceName = storedProcedure.Schema.SchemaName
                }
            };

            if (storedProcedure.ResultSet.Exists(r => r.ColumnType == DbType.DateTime2))
            {
                @class.NamespaceRef.Add(new CNamespaceRef()
                {
                    ReferenceTo = new CNamespace()
                    {
                        NamespaceName = "System"
                    }
                });
            }

            if (!string.IsNullOrEmpty(storedProcedure.ResultSetName))
            {
                foreach (var column in storedProcedure.ResultSet)
                {
                    var prop = new CProperty
                    {
                        PropertyName = column.ColumnName,
                        Type         = column.ColumnType.ToClrTypeName(),
                        MaxLength    = column.ColumnLength
                    };
                    @class.Property.Add(prop);
                }
            }


            return(@class);

            /*
             * var view = new SView
             * {
             *  Schema = new SSchema {  SchemaName = storedProcedure.Schema.SchemaName},
             *  ViewName = storedProcedure.StoredProcedureName
             * };
             * view.Column = new List<SColumn>();
             *
             * foreach (var col in storedProcedure.ResultSet)
             * {
             *  var column = new SColumn(view)
             *  {
             *      ColumnName = col.ColumnName,
             *      ColumnTypeRaw = col.ColumnTypeRaw,
             *      ColumnSqlDbType = col.ColumnSqlDbType,
             *      ColumnType = col.ColumnType,
             *      ColumnLength = col.ColumnLength
             *  };
             *  view.Column.Add(column);
             * }
             * return view;
             */
        }