Пример #1
0
        public NfTypeName(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }

            _ctorString = name;

            var parseItem = TypeNameParseTree.ParseIl(name);

            if (parseItem == null)
            {
                return;
            }
            _className      = NfReflect.GetTypeNameWithoutNamespace(parseItem.FullName);
            _namespace      = NfReflect.GetNamespaceWithoutTypeName(parseItem.FullName);
            _publicKeyToken = parseItem.PublicKeyTokenValue;
            if (!string.IsNullOrWhiteSpace(parseItem.AssemblyFullName))
            {
                _asmName = new AssemblyName(parseItem.AssemblyFullName);
            }

            if (parseItem.GenericItems == null || !parseItem.GenericItems.Any())
            {
                return;
            }

            foreach (var gi in parseItem.GenericItems)
            {
                _genericArgs.Add(new NfTypeName(gi));
            }
        }
Пример #2
0
        /// <summary>
        /// Returns a node definition with just the type name's header.
        /// This is specific to graph-viz (ver. 2.38+)
        /// </summary>
        /// <param name="typeFullName"></param>
        /// <param name="enumValues">Optional values to be listed as line items with no type specifiers nor .gv port ids.</param>
        /// <returns></returns>
        public static string EmptyGraphVizClassNode(string typeFullName, string[] enumValues)
        {
            var className = NfReflect.GetTypeNameWithoutNamespace(typeFullName);
            var ns        = NfReflect.GetNamespaceWithoutTypeName(typeFullName);
            var fullName  = string.Format("{0}{1}", string.IsNullOrWhiteSpace(ns) ? string.Empty : ns + ".", className);
            var graphViz  = new StringBuilder();

            graphViz.Append(NfString.SafeDotNetIdentifier(fullName));
            graphViz.AppendLine(" [shape=Mrecord, label=<<table bgcolor=\"white\" border=\"0\" >");
            graphViz.AppendLine("<th>");
            graphViz.AppendLine("<td bgcolor=\"grey\" align=\"center\">");
            graphViz.Append("<font color=\"white\">");
            graphViz.AppendFormat("{0} :: {1}", className, string.IsNullOrWhiteSpace(ns) ? "global" : ns);
            graphViz.AppendLine("</font></td></th>");
            if (enumValues != null && enumValues.Length > 0)
            {
                foreach (var enumVal in enumValues)
                {
                    graphViz.Append("<tr><td><font color=\"blue\">");
                    graphViz.Append(enumVal);
                    graphViz.AppendLine("</font></td></tr>");
                }
            }
            else
            {
                graphViz.AppendLine("<tr><td></td></tr>");
                graphViz.AppendLine("<tr><td></td></tr>");
            }
            graphViz.AppendLine("</table>> ];");

            return(graphViz.ToString());
        }
Пример #3
0
        public void TestGetTypeNameWithoutNamespace()
        {
            var testResult = NfReflect.GetTypeNameWithoutNamespace("NoFuture.Asm.Fii.MyType");

            Console.WriteLine(testResult);
            Assert.AreEqual("MyType", testResult);

            testResult = NfReflect.GetTypeNameWithoutNamespace("My_SillyName_NoNamespace_Pos_Class");
            Console.WriteLine(testResult);
            Assert.AreEqual("My_SillyName_NoNamespace_Pos_Class", testResult);

            testResult =
                NfReflect.GetNamespaceWithoutTypeName(
                    "Wanker.DCF.UI.Controller.Operator.OperatorUIController::set_OperatorContacts(Wanker.DCF.DTO.WankerContact)");
        }
Пример #4
0
        public void TestGetNamespaceWithoutTypeName()
        {
            var testResult = NfReflect.GetNamespaceWithoutTypeName("NoFuture.Asm.Fii.MyType");

            Console.WriteLine(testResult);
            Assert.AreEqual("NoFuture.Asm.Fii", testResult);

            var testResult2 = NfReflect.GetNamespaceWithoutTypeName("My_SillyName_NoNamespace_Pos_Class");

            Assert.IsNull(testResult2);

            testResult =
                NfReflect.GetNamespaceWithoutTypeName(
                    "global::Wanker.DCF.UI.Controller.Operator.OperatorUIController::set_OperatorContacts(Wanker.DCF.DTO.WankerContact)");
            Console.WriteLine(testResult);
            Assert.AreEqual("Wanker.DCF.UI.Controller.Operator", testResult);

            testResult = NfReflect.GetNamespaceWithoutTypeName("NeedItInIl.DomainAdapterBase`2[[AThirdDll.Whatever, AThirdDll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]," +
                                                               "[System.Tuple`3[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]," +
                                                               "[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]," +
                                                               "[System.Collections.Generic.IEnumerable`1[[MoreBinaries.DomainObject+MyInnerType, MoreBinaries, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]," +
                                                               " mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], " +
                                                               "NeedItInIl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");


            Console.WriteLine(testResult);
            Assert.AreEqual("NeedItInIl", testResult);

            testResult =
                NfReflect.GetNamespaceWithoutTypeName(
                    "Wanker.DCF.UI.Controller.Operator.OperatorUIController::set_OperatorContacts(Wanker.DCF.DTO.WankerContact)");

            Console.WriteLine(testResult);
            Assert.AreEqual(testResult, "Wanker.DCF.UI.Controller.Operator");

            testResult =
                NfReflect.GetNamespaceWithoutTypeName(
                    ".Controller.Operator.OperatorUIController::set_OperatorContacts(Wanker.DCF.DTO.WankerContact)");

            Console.WriteLine(testResult);
            Assert.AreEqual(testResult, "Controller.Operator");
        }
Пример #5
0
        /// <summary>
        /// Parses a hbm.xml file into this runtime equiv.
        /// being intended for code generation.
        /// </summary>
        /// <param name="hbmXmlFilePath"></param>
        public HbmFileContent(string hbmXmlFilePath)
        {
            _simpleProperties       = new Dictionary <string, string>();
            _fkProperties           = new Dictionary <string, string>();
            _listProperties         = new Dictionary <string, string>();
            _compositeKeyProperties = new Dictionary <string, string>();

            _keyColumns    = new Dictionary <string, ColumnMetadata>();
            _simpleColumns = new Dictionary <string, ColumnMetadata>();
            _fkColumns     = new Dictionary <string, List <ColumnMetadata> >();
            _listColumns   = new Dictionary <string, List <ColumnMetadata> >();

            _spConstNames = new List <HbmStoredProxNames>();
            _keyManyToOnePropertyNames = new List <string>();
            _allPkColumns = new Dictionary <string, string>();

            if (!File.Exists(hbmXmlFilePath))
            {
                throw new ItsDeadJim(string.Format("There isn't any xml file at '{0}'", hbmXmlFilePath));
            }

            _fileNamePath = hbmXmlFilePath;
            _hbmXml       = new XmlDocument();
            _hbmXml.LoadXml(File.ReadAllText(_fileNamePath));
            _nsMgr = new XmlNamespaceManager(_hbmXml.NameTable);
            _nsMgr.AddNamespace(NS, Globals.HBM_XML_NS);

            _classNode =
                _hbmXml.SelectSingleNode(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS), _nsMgr) as
                XmlElement;
            if (_classNode == null)
            {
                throw new ItsDeadJim(string.Format("The top-level 'class' node is missing from the xml file at '{0}'", hbmXmlFilePath));
            }

            IsCompositeKey =
                _hbmXml.SelectSingleNode(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS, HbmXmlNames.COMPOSITE_ID), _nsMgr) != null;

            var tableNameAttr = _classNode.Attributes[HbmXmlNames.TABLE];

            if (tableNameAttr != null)
            {
                _tableName = tableNameAttr.Value;
            }

            var attrTypeName = GetAttrVal(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS), HbmXmlNames.NAME);

            if (NfReflect.IsFullAssemblyQualTypeName(attrTypeName))
            {
                _asmQualTypeName = attrTypeName;
                var nfName = new NfTypeName(attrTypeName);
                _className = nfName.ClassName;
                _namespace = nfName.Namespace;
            }
            else
            {
                _className       = NfReflect.GetTypeNameWithoutNamespace(attrTypeName);
                _namespace       = NfReflect.GetNamespaceWithoutTypeName(attrTypeName);
                _asmQualTypeName = Compose.ClassName(_className, _namespace);
            }

            _dbSchema = GetAttrVal(CreateXpath(HbmXmlNames.HIBERNATE_MAPPING, HbmXmlNames.CLASS), HbmXmlNames.SCHEMA);

            //the stored prox will not have a schema qualifier so try to derive it from the file name
            if (string.IsNullOrWhiteSpace(_dbSchema))
            {
                var ff = Path.GetFileName(_fileNamePath);
                if (!string.IsNullOrWhiteSpace(ff) && ff.Split('.').Length > 3)
                {
                    _dbSchema = ff.Split('.')[0];
                }
                else
                {
                    _dbSchema = "Dbo";
                }
            }

            //get id/composite-id node
            GetIdNode();

            //get id's name and type
            GetIdName();

            //get flat-data's names and types
            GetFlatProperties();

            //get FKs names and types
            GetFkProperties();

            //get IList names and types
            GetListProperties();

            //get stored proc names
            GetStoredProcNames();

            //get composite key's properties
            GetCompositeKeyProperties();

            //condense a list of what is just on this table
            GetAllPkColumns();
        }