Exemple #1
0
        public static string ConverTablenameToGetEntitiesStoredProcedureName(string tablename)
        {
            string entityName, prefix;

            GetEntitynameAndPrefixByTablename(tablename, out entityName, out prefix);
            return(string.Format("up_{0}{2}_Get{1}", prefix, PluralizerHelper.ToPlural(entityName), entityName));
        }
        public static string ToSingular(this string rawText)
        {
            if (string.IsNullOrEmpty(rawText))
            {
                return(rawText);
            }

            return(PluralizerHelper.ToSingular(rawText));
        }
    static DynamicWebServiceHelpers() {
        _webServiceHelper = new WebServiceHelper();
        _pluralizerHelper = new PluralizerHelper();
        _simpleXmlHelper = new SimpleXmlHelper();

        Ops.RegisterAttributesInjectorForType(typeof(XmlElement), new XmlElementAttributesInjector(), true);
        Ops.RegisterAttributesInjectorForType(typeof(WebServiceHelper), new WebServiceHelperAttributesInjector(), false);
        Ops.RegisterAttributesInjectorForType(typeof(string), new PluralizerAttributesInjector(), false);
    }
Exemple #4
0
        private static void GetEntitynameAndPrefixByTablename(string tablename, out string entityName, out string prefix)
        {
            prefix    = string.Empty;
            tablename = tablename.Replace("Fct_", "").Replace("Rel_", "").Replace("Dim_", "");
            int i = tablename.IndexOf('_');

            if (i > -1)
            {
                prefix    = tablename.Substring(0, i + 1);
                tablename = tablename.Substring(i + 1);
            }
            entityName = PluralizerHelper.ToSingular(tablename);
        }
 public GetEntitiesDAFunc(string entityClass, string storedProcedureName, Column idColumn, string FunName)
     : base(
         string.Format("Get{0}", PluralizerHelper.ToPlural(FunName))
         , "void", null)
 {
     this.entityClass         = entityClass;
     this.storedProcedureName = storedProcedureName;
     this.idColumn            = idColumn;
     paramIds        = idColumn.Name.ToFirstLower().ToPlural();
     paramEntities   = PluralizerHelper.ToPlural(entityClass.ToFirstLower());
     this.Parameters = new List <FunctionParameter>();
     this.Parameters.Add(new FunctionParameter(paramIds, string.Format("{0}[]", idColumn.CSTypeName)));
     this.Parameters.Add(new FunctionParameter(paramEntities, string.Format("ref Dictionary<{0}, {1}>", idColumn.CSTypeName, entityClass)));
 }
Exemple #6
0
        public static string GenerateKVStoreManagerCode(string entityClass, Column idColumn)
        {
            StringBuilder code          = new StringBuilder();
            string        paramEntities = PluralizerHelper.ToPlural(entityClass.ToFirstLower()) + "Cache";

            code.AppendLineFormatWithTabs("static KVStoreEntityTable<{0}, {1}> {2} = KVStoreManager.GetKVStoreEntityTable<{0}, {1}>(\"{2}\", 180, 10000);", 1
                                          , idColumn.CSTypeName, entityClass, paramEntities);
            code.AppendLineFormatWithTabs("public static KVStoreEntityTable<{0}, {1}> {2}", 1
                                          , idColumn.CSTypeName, entityClass, paramEntities.ToFirstUpper());
            code.AppendLineWithTabs("{", 1);
            code.AppendLineFormatWithTabs("get {{ return {0}; }}", 2, paramEntities);
            code.AppendLineFormatWithTabs("set {{ {0} = value; }}", 2, paramEntities);
            code.AppendLineWithTabs("}", 1);
            return(code.ToString());
        }
Exemple #7
0
        public static string GenerateDataAccessOfGetEntities(string entityClass, string storedProcedureName, Column idColumn)
        {
            string paramIds      = idColumn.Name.ToFirstLower().ToPlural();
            string paramEntities = PluralizerHelper.ToPlural(entityClass.ToFirstLower());

            StringBuilder code = new StringBuilder();

            //code.AppendLineWithTabs("/// <summary>", 0);
            //code.AppendLineFormatWithTabs("/// 填充{0}集合", 0, entityClass);
            //code.AppendLineWithTabs("/// </summary>", 0);
            //code.AppendLineFormatWithTabs("/// <param name=\"{0}\"></param>", 0, paramIds);
            //code.AppendLineFormatWithTabs("/// <param name=\"{0}\"></param>", 0, paramEntities);
            code.AppendLineFormatWithTabs("public void Get{0}({2}[] {1}, ref Dictionary<{2}, {3}> {4})", 0
                                          , PluralizerHelper.ToPlural(entityClass), paramIds
                                          , idColumn.CSTypeName, entityClass, paramEntities);
            code.AppendLineWithTabs("{", 0);

            code.AppendLineFormatWithTabs("if ({0} == null)", 1, paramEntities);
            code.AppendLineFormatWithTabs("{0} = new Dictionary<{1}, {2}>();", 2
                                          , paramEntities, idColumn.CSTypeName, entityClass);
            code.AppendLine();

            code.AppendLineWithTabs("using (SqlConnection conn = GetSqlConnection())", 1);
            code.AppendLineWithTabs("{", 1);
            code.AppendLineFormatWithTabs("using (SqlDataReader dr = SqlHelper.ExecuteReader(conn, \"{0}\",", 2, storedProcedureName);
            code.AppendLineFormatWithTabs("new SqlParameter(\"@Ids\", SqlHelper.ConvertIdsToXML<{0}>(\"e\", {1}))", 4, idColumn.CSTypeName, paramIds);
            code.AppendLineWithTabs("))", 3);
            code.AppendLineWithTabs("{", 2);
            code.AppendLineWithTabs("while (dr.Read())", 3);
            code.AppendLineWithTabs("{", 3);
            code.AppendLineFormatWithTabs("{0} {1} = new {0}(dr);", 4, entityClass, entityClass.ToFirstLower());
            code.AppendLineFormatWithTabs("{0}[{1}.{2}] = {1};", 4, paramEntities, entityClass.ToFirstLower(), idColumn.Name);
            code.AppendLineWithTabs("}", 3);
            code.AppendLineWithTabs("dr.Close();", 3);
            code.AppendLineWithTabs("conn.Close();", 3);
            code.AppendLineWithTabs("}", 2);
            code.AppendLineWithTabs("}", 1);

            code.AppendLineWithTabs("}", 0);

            return(code.ToString());
        }
 static DynamicWebServiceHelpers()
 {
     _webServiceHelper = new WebServiceHelper();
     _pluralizerHelper = new PluralizerHelper();
     _simpleXmlHelper = new SimpleXmlHelper();
 }
Exemple #9
0
 static DynamicWebServiceHelpers()
 {
     _webServiceHelper = new WebServiceHelper();
     _pluralizerHelper = new PluralizerHelper();
     _simpleXmlHelper  = new SimpleXmlHelper();
 }