diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/AkiragestuProject/AkiragestuProject.csproj b/AkiragestuProject/AkiragestuProject.csproj new file mode 100644 index 0000000..7123b2a --- /dev/null +++ b/AkiragestuProject/AkiragestuProject.csproj @@ -0,0 +1,149 @@ + + + + + Debug + AnyCPU + {A4E730CF-2197-46F7-9459-4025ED11327C} + WinExe + Properties + AkiragestuProject + AkiragestuProject + v4.0 + 512 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + true + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + ..\packages\EntityFramework.5.0.0\lib\net40\EntityFramework.dll + + + + + + + + + + + + + + + + + + + + + + Model1.tt + + + Model1.tt + + + Model1.tt + + + Model1.tt + + + Form + + + Form1.cs + + + True + True + Model1.Context.tt + + + True + True + Model1.tt + + + True + True + Model1.edmx + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + EntityModelCodeGenerator + Model1.Designer.cs + + + TextTemplatingFileGenerator + Model1.edmx + Model1.Context.cs + + + Model1.edmx + + + TextTemplatingFileGenerator + Model1.edmx + Model1.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/AkiragestuProject/App.Config b/AkiragestuProject/App.Config new file mode 100644 index 0000000..5120b32 --- /dev/null +++ b/AkiragestuProject/App.Config @@ -0,0 +1,13 @@ + + + + +
+ + + + + + + + diff --git a/AkiragestuProject/Form1.Designer.cs b/AkiragestuProject/Form1.Designer.cs new file mode 100644 index 0000000..db1fdf8 --- /dev/null +++ b/AkiragestuProject/Form1.Designer.cs @@ -0,0 +1,87 @@ +namespace AkiragestuProject +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.listBox1 = new System.Windows.Forms.ListBox(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // listBox1 + // + this.listBox1.BackColor = System.Drawing.SystemColors.InactiveCaptionText; + this.listBox1.ForeColor = System.Drawing.SystemColors.MenuHighlight; + this.listBox1.FormattingEnabled = true; + this.listBox1.ItemHeight = 12; + this.listBox1.Location = new System.Drawing.Point(12, 12); + this.listBox1.Name = "listBox1"; + this.listBox1.Size = new System.Drawing.Size(453, 220); + this.listBox1.TabIndex = 0; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(13, 239); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(371, 21); + this.textBox1.TabIndex = 1; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(390, 239); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 2; + this.button1.Text = "button1"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(477, 267); + this.Controls.Add(this.button1); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.listBox1); + this.Name = "Form1"; + this.Text = "皓月人格模拟 Akiragestu Project Ver.0.0.1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListBox listBox1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button button1; + } +} + diff --git a/AkiragestuProject/Form1.cs b/AkiragestuProject/Form1.cs new file mode 100644 index 0000000..2d057bd --- /dev/null +++ b/AkiragestuProject/Form1.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace AkiragestuProject +{ + + + + public partial class Form1 : Form + { + /// + /// 参数影响类 + /// + akMood akm = new akMood(); + /// + /// 内容语言识别 + /// + akLanguage akl = new akLanguage(); + /// + /// 运算类 + /// + akOperation ako = new akOperation(); + + public Form1() + { + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + LoadAkira(); + } + + #region 基本信息载入 + + /// + /// 基本人格载入 + /// + public void LoadAkira() + { + + try + { + AddMessage(1, "皓月人格模拟载入中……"); + AddMessage(1, "版本 Ver.0.0.1"); + AddMessage(1, "----------------"); + AddMessage(1, "皓月基本参数读取..."); + var ak = akm.GetMain(); + AddMessage(1, "心情:" + ak.Mood); + AddMessage(1, "精力:" + ak.Energy); + AddMessage(1, "饥饿:" + ak.Hungry); + AddMessage(1, "主要心理状态:" + ak.MentalityType); + AddMessage(1, "皓月模拟人格数据载入完毕"); + AddMessage(1, "----------------"); + AddMessage(1, "输入 /help 可以获得基本帮助 (~ ̄▽ ̄~)"); + } + catch (Exception ex) + { + AddMessage(2, ex.ToString()); + } + } + + private void button1_Click(object sender, EventArgs e) + { + + + var Msg = textBox1.Text; + textBox1.Text = null; + if (Msg != null) + { + AddMessage(Msg); + //识别内容 + int Type = akl.GetlanguageType(Msg); + if (Type == 2) + { + var Comstr = Msg.Substring(1); + if(Comstr != null && Comstr != "") + { + AddMessage(1,akl.GetCommand(Comstr)); + } + } + } + } + + + #endregion + + #region 显示控制 + + public void AddMessage(string str) + { + + var msgtype = "> UserMsg : "; + + listBox1.Items.Add(DateTime.Now.ToLongTimeString().ToString() + msgtype + str); + + + } + public void AddMessage(int messagetype,string str) + { + var msgtype = ""; + switch (messagetype) + { + case 1: + msgtype = "> Msg : "; + break; + case 2: + msgtype = "> Error :"; + break; + case 3: + msgtype = "> Wran :"; + break; + } + + listBox1.Items.Add(DateTime.Now.ToLongTimeString().ToString() + msgtype + str); + + + } + + #endregion + + + + } +} diff --git a/AkiragestuProject/Form1.resx b/AkiragestuProject/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AkiragestuProject/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AkiragestuProject/Model1.Context.cs b/AkiragestuProject/Model1.Context.cs new file mode 100644 index 0000000..0930505 --- /dev/null +++ b/AkiragestuProject/Model1.Context.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------ +// +// 此代码是根据模板生成的。 +// +// 手动更改此文件可能会导致应用程序中发生异常行为。 +// 如果重新生成代码,则将覆盖对此文件的手动更改。 +// +//------------------------------------------------------------------------------ + +namespace AkiragestuProject +{ + using System; + using System.Data.Entity; + using System.Data.Entity.Infrastructure; + + public partial class akiragetsuEntities : DbContext + { + public akiragetsuEntities() + : base("name=akiragetsuEntities") + { + } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + throw new UnintentionalCodeFirstException(); + } + + public DbSet ak_impression { get; set; } + public DbSet ak_mainperson { get; set; } + public DbSet ak_petphrase { get; set; } + public DbSet ak_qa { get; set; } + } +} diff --git a/AkiragestuProject/Model1.Context.tt b/AkiragestuProject/Model1.Context.tt new file mode 100644 index 0000000..008b4e4 --- /dev/null +++ b/AkiragestuProject/Model1.Context.tt @@ -0,0 +1,735 @@ +<#@ template language="C#" debug="false" hostspecific="true"#> +<#@ include file="EF.Utility.CS.ttinclude"#><#@ + output extension=".cs"#><# + +const string inputFile = @"Model1.edmx"; +var textTransform = DynamicTextTransformation.Create(this); +var code = new CodeGenerationTools(this); +var ef = new MetadataTools(this); +var typeMapper = new TypeMapper(code, ef, textTransform.Errors); +var loader = new EdmMetadataLoader(textTransform.Host, textTransform.Errors); +var itemCollection = loader.CreateEdmItemCollection(inputFile); +var modelNamespace = loader.GetModelNamespace(inputFile); +var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef); + +var container = itemCollection.OfType().FirstOrDefault(); +if (container == null) +{ + return string.Empty; +} +#> +//------------------------------------------------------------------------------ +// +// <#=GetResourceString("Template_GeneratedCodeCommentLine1")#> +// +// <#=GetResourceString("Template_GeneratedCodeCommentLine2")#> +// <#=GetResourceString("Template_GeneratedCodeCommentLine3")#> +// +//------------------------------------------------------------------------------ + +<# + +var codeNamespace = code.VsNamespaceSuggestion(); +if (!String.IsNullOrEmpty(codeNamespace)) +{ +#> +namespace <#=code.EscapeNamespace(codeNamespace)#> +{ +<# + PushIndent(" "); +} + +#> +using System; +using System.Data.Entity; +using System.Data.Entity.Infrastructure; +<# +if (container.FunctionImports.Any()) +{ +#> +using System.Data.Objects; +using System.Data.Objects.DataClasses; +using System.Linq; +<# +} +#> + +<#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : DbContext +{ + public <#=code.Escape(container)#>() + : base("name=<#=container.Name#>") + { +<# +if (!loader.IsLazyLoadingEnabled(container)) +{ +#> + this.Configuration.LazyLoadingEnabled = false; +<# +} +#> + } + + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + throw new UnintentionalCodeFirstException(); + } + +<# + foreach (var entitySet in container.BaseEntitySets.OfType()) + { +#> + <#=codeStringGenerator.DbSet(entitySet)#> +<# + } + + foreach (var edmFunction in container.FunctionImports) + { + WriteFunctionImport(typeMapper, codeStringGenerator, edmFunction, modelNamespace, includeMergeOption: false); + } +#> +} +<# + +if (!String.IsNullOrEmpty(codeNamespace)) +{ + PopIndent(); +#> +} +<# +} +#> +<#+ + +private void WriteFunctionImport(TypeMapper typeMapper, CodeStringGenerator codeStringGenerator, EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) +{ + if (typeMapper.IsComposable(edmFunction)) + { +#> + + [EdmFunction("<#=edmFunction.NamespaceName#>", "<#=edmFunction.Name#>")] + <#=codeStringGenerator.ComposableFunctionMethod(edmFunction, modelNamespace)#> + { +<#+ + codeStringGenerator.WriteFunctionParameters(edmFunction, WriteFunctionParameter); +#> + <#=codeStringGenerator.ComposableCreateQuery(edmFunction, modelNamespace)#> + } +<#+ + } + else + { +#> + + <#=codeStringGenerator.FunctionMethod(edmFunction, modelNamespace, includeMergeOption)#> + { +<#+ + codeStringGenerator.WriteFunctionParameters(edmFunction, WriteFunctionParameter); +#> + <#=codeStringGenerator.ExecuteFunction(edmFunction, modelNamespace, includeMergeOption)#> + } +<#+ + if (typeMapper.GenerateMergeOptionFunction(edmFunction, includeMergeOption)) + { + WriteFunctionImport(typeMapper, codeStringGenerator, edmFunction, modelNamespace, includeMergeOption: true); + } + } +} + +public void WriteFunctionParameter(string name, string isNotNull, string notNullInit, string nullInit) +{ +#> + var <#=name#> = <#=isNotNull#> ? + <#=notNullInit#> : + <#=nullInit#>; + +<#+ +} + +public const string TemplateId = "CSharp_DbContext_Context_EF5"; + +public class CodeStringGenerator +{ + private readonly CodeGenerationTools _code; + private readonly TypeMapper _typeMapper; + private readonly MetadataTools _ef; + + public CodeStringGenerator(CodeGenerationTools code, TypeMapper typeMapper, MetadataTools ef) + { + ArgumentNotNull(code, "code"); + ArgumentNotNull(typeMapper, "typeMapper"); + ArgumentNotNull(ef, "ef"); + + _code = code; + _typeMapper = typeMapper; + _ef = ef; + } + + public string Property(EdmProperty edmProperty) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2} {{ {3}get; {4}set; }}", + Accessibility.ForProperty(edmProperty), + _typeMapper.GetTypeName(edmProperty.TypeUsage), + _code.Escape(edmProperty), + _code.SpaceAfter(Accessibility.ForGetter(edmProperty)), + _code.SpaceAfter(Accessibility.ForSetter(edmProperty))); + } + + public string NavigationProperty(NavigationProperty navigationProperty) + { + var endType = _typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType()); + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2} {{ {3}get; {4}set; }}", + AccessibilityAndVirtual(Accessibility.ForProperty(navigationProperty)), + navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType, + _code.Escape(navigationProperty), + _code.SpaceAfter(Accessibility.ForGetter(navigationProperty)), + _code.SpaceAfter(Accessibility.ForSetter(navigationProperty))); + } + + public string AccessibilityAndVirtual(string accessibility) + { + return accessibility + (accessibility != "private" ? " virtual" : ""); + } + + public string EntityClassOpening(EntityType entity) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1}partial class {2}{3}", + Accessibility.ForType(entity), + _code.SpaceAfter(_code.AbstractOption(entity)), + _code.Escape(entity), + _code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType))); + } + + public string EnumOpening(SimpleType enumType) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} enum {1} : {2}", + Accessibility.ForType(enumType), + _code.Escape(enumType), + _code.Escape(_typeMapper.UnderlyingClrType(enumType))); + } + + public void WriteFunctionParameters(EdmFunction edmFunction, Action writeParameter) + { + var parameters = FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef); + foreach (var parameter in parameters.Where(p => p.NeedsLocalVariable)) + { + var isNotNull = parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null"; + var notNullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", " + parameter.FunctionParameterName + ")"; + var nullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", typeof(" + parameter.RawClrTypeName + "))"; + writeParameter(parameter.LocalVariableName, isNotNull, notNullInit, nullInit); + } + } + + public string ComposableFunctionMethod(EdmFunction edmFunction, string modelNamespace) + { + var parameters = _typeMapper.GetParameters(edmFunction); + + return string.Format( + CultureInfo.InvariantCulture, + "{0} IQueryable<{1}> {2}({3})", + AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)), + _typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace), + _code.Escape(edmFunction), + string.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray())); + } + + public string ComposableCreateQuery(EdmFunction edmFunction, string modelNamespace) + { + var parameters = _typeMapper.GetParameters(edmFunction); + + return string.Format( + CultureInfo.InvariantCulture, + "return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<{0}>(\"[{1}].[{2}]({3})\"{4});", + _typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace), + edmFunction.NamespaceName, + edmFunction.Name, + string.Join(", ", parameters.Select(p => "@" + p.EsqlParameterName).ToArray()), + _code.StringBefore(", ", string.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()))); + } + + public string FunctionMethod(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) + { + var parameters = _typeMapper.GetParameters(edmFunction); + var returnType = _typeMapper.GetReturnType(edmFunction); + + var paramList = String.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray()); + if (includeMergeOption) + { + paramList = _code.StringAfter(paramList, ", ") + "MergeOption mergeOption"; + } + + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2}({3})", + AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)), + returnType == null ? "int" : "ObjectResult<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">", + _code.Escape(edmFunction), + paramList); + } + + public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) + { + var parameters = _typeMapper.GetParameters(edmFunction); + var returnType = _typeMapper.GetReturnType(edmFunction); + + var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray())); + if (includeMergeOption) + { + callParams = ", mergeOption" + callParams; + } + + return string.Format( + CultureInfo.InvariantCulture, + "return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});", + returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">", + edmFunction.Name, + callParams); + } + + public string DbSet(EntitySet entitySet) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} DbSet<{1}> {2} {{ get; set; }}", + Accessibility.ForReadOnlyProperty(entitySet), + _typeMapper.GetTypeName(entitySet.ElementType), + _code.Escape(entitySet)); + } + + public string UsingDirectives(bool inHeader, bool includeCollections = true) + { + return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion()) + ? string.Format( + CultureInfo.InvariantCulture, + "{0}using System;{1}" + + "{2}", + inHeader ? Environment.NewLine : "", + includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "", + inHeader ? "" : Environment.NewLine) + : ""; + } +} + +public class TypeMapper +{ + private const string ExternalTypeNameAttributeName = @"http://schemas.microsoft.com/ado/2006/04/codegeneration:ExternalTypeName"; + + private readonly System.Collections.IList _errors; + private readonly CodeGenerationTools _code; + private readonly MetadataTools _ef; + + public TypeMapper(CodeGenerationTools code, MetadataTools ef, System.Collections.IList errors) + { + ArgumentNotNull(code, "code"); + ArgumentNotNull(ef, "ef"); + ArgumentNotNull(errors, "errors"); + + _code = code; + _ef = ef; + _errors = errors; + } + + public string GetTypeName(TypeUsage typeUsage) + { + return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace: null); + } + + public string GetTypeName(EdmType edmType) + { + return GetTypeName(edmType, isNullable: null, modelNamespace: null); + } + + public string GetTypeName(TypeUsage typeUsage, string modelNamespace) + { + return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace); + } + + public string GetTypeName(EdmType edmType, string modelNamespace) + { + return GetTypeName(edmType, isNullable: null, modelNamespace: modelNamespace); + } + + public string GetTypeName(EdmType edmType, bool? isNullable, string modelNamespace) + { + if (edmType == null) + { + return null; + } + + var collectionType = edmType as CollectionType; + if (collectionType != null) + { + return String.Format(CultureInfo.InvariantCulture, "ICollection<{0}>", GetTypeName(collectionType.TypeUsage, modelNamespace)); + } + + var typeName = _code.Escape(edmType.MetadataProperties + .Where(p => p.Name == ExternalTypeNameAttributeName) + .Select(p => (string)p.Value) + .FirstOrDefault()) + ?? (modelNamespace != null && edmType.NamespaceName != modelNamespace ? + _code.CreateFullName(_code.EscapeNamespace(edmType.NamespaceName), _code.Escape(edmType)) : + _code.Escape(edmType)); + + if (edmType is StructuralType) + { + return typeName; + } + + if (edmType is SimpleType) + { + var clrType = UnderlyingClrType(edmType); + if (!IsEnumType(edmType)) + { + typeName = _code.Escape(clrType); + } + + return clrType.IsValueType && isNullable == true ? + String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>", typeName) : + typeName; + } + + throw new ArgumentException("edmType"); + } + + public Type UnderlyingClrType(EdmType edmType) + { + ArgumentNotNull(edmType, "edmType"); + + var primitiveType = edmType as PrimitiveType; + if (primitiveType != null) + { + return primitiveType.ClrEquivalentType; + } + + if (IsEnumType(edmType)) + { + return GetEnumUnderlyingType(edmType).ClrEquivalentType; + } + + return typeof(object); + } + + public object GetEnumMemberValue(MetadataItem enumMember) + { + ArgumentNotNull(enumMember, "enumMember"); + + var valueProperty = enumMember.GetType().GetProperty("Value"); + return valueProperty == null ? null : valueProperty.GetValue(enumMember, null); + } + + public string GetEnumMemberName(MetadataItem enumMember) + { + ArgumentNotNull(enumMember, "enumMember"); + + var nameProperty = enumMember.GetType().GetProperty("Name"); + return nameProperty == null ? null : (string)nameProperty.GetValue(enumMember, null); + } + + public System.Collections.IEnumerable GetEnumMembers(EdmType enumType) + { + ArgumentNotNull(enumType, "enumType"); + + var membersProperty = enumType.GetType().GetProperty("Members"); + return membersProperty != null + ? (System.Collections.IEnumerable)membersProperty.GetValue(enumType, null) + : Enumerable.Empty(); + } + + public bool EnumIsFlags(EdmType enumType) + { + ArgumentNotNull(enumType, "enumType"); + + var isFlagsProperty = enumType.GetType().GetProperty("IsFlags"); + return isFlagsProperty != null && (bool)isFlagsProperty.GetValue(enumType, null); + } + + public bool IsEnumType(GlobalItem edmType) + { + ArgumentNotNull(edmType, "edmType"); + + return edmType.GetType().Name == "EnumType"; + } + + public PrimitiveType GetEnumUnderlyingType(EdmType enumType) + { + ArgumentNotNull(enumType, "enumType"); + + return (PrimitiveType)enumType.GetType().GetProperty("UnderlyingType").GetValue(enumType, null); + } + + public string CreateLiteral(object value) + { + if (value == null || value.GetType() != typeof(TimeSpan)) + { + return _code.CreateLiteral(value); + } + + return string.Format(CultureInfo.InvariantCulture, "new TimeSpan({0})", ((TimeSpan)value).Ticks); + } + + public bool VerifyCaseInsensitiveTypeUniqueness(IEnumerable types, string sourceFile) + { + ArgumentNotNull(types, "types"); + ArgumentNotNull(sourceFile, "sourceFile"); + + var hash = new HashSet(StringComparer.InvariantCultureIgnoreCase); + if (types.Any(item => !hash.Add(item))) + { + _errors.Add( + new CompilerError(sourceFile, -1, -1, "6023", + String.Format(CultureInfo.CurrentCulture, GetResourceString("Template_CaseInsensitiveTypeConflict")))); + return false; + } + return true; + } + + public IEnumerable GetEnumItemsToGenerate(IEnumerable itemCollection) + { + return GetItemsToGenerate(itemCollection) + .Where(e => IsEnumType(e)); + } + + public IEnumerable GetItemsToGenerate(IEnumerable itemCollection) where T: EdmType + { + return itemCollection + .OfType() + .Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName)) + .OrderBy(i => i.Name); + } + + public IEnumerable GetAllGlobalItems(IEnumerable itemCollection) + { + return itemCollection + .Where(i => i is EntityType || i is ComplexType || i is EntityContainer || IsEnumType(i)) + .Select(g => GetGlobalItemName(g)); + } + + public string GetGlobalItemName(GlobalItem item) + { + if (item is EdmType) + { + return ((EdmType)item).Name; + } + else + { + return ((EntityContainer)item).Name; + } + } + + public IEnumerable GetSimpleProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetSimpleProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetPropertiesWithDefaultValues(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetPropertiesWithDefaultValues(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetNavigationProperties(EntityType type) + { + return type.NavigationProperties.Where(np => np.DeclaringType == type); + } + + public IEnumerable GetCollectionNavigationProperties(EntityType type) + { + return type.NavigationProperties.Where(np => np.DeclaringType == type && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many); + } + + public FunctionParameter GetReturnParameter(EdmFunction edmFunction) + { + ArgumentNotNull(edmFunction, "edmFunction"); + + var returnParamsProperty = edmFunction.GetType().GetProperty("ReturnParameters"); + return returnParamsProperty == null + ? edmFunction.ReturnParameter + : ((IEnumerable)returnParamsProperty.GetValue(edmFunction, null)).FirstOrDefault(); + } + + public bool IsComposable(EdmFunction edmFunction) + { + ArgumentNotNull(edmFunction, "edmFunction"); + + var isComposableProperty = edmFunction.GetType().GetProperty("IsComposableAttribute"); + return isComposableProperty != null && (bool)isComposableProperty.GetValue(edmFunction, null); + } + + public IEnumerable GetParameters(EdmFunction edmFunction) + { + return FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef); + } + + public TypeUsage GetReturnType(EdmFunction edmFunction) + { + var returnParam = GetReturnParameter(edmFunction); + return returnParam == null ? null : _ef.GetElementType(returnParam.TypeUsage); + } + + public bool GenerateMergeOptionFunction(EdmFunction edmFunction, bool includeMergeOption) + { + var returnType = GetReturnType(edmFunction); + return !includeMergeOption && returnType != null && returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType; + } +} + +public class EdmMetadataLoader +{ + private readonly IDynamicHost _host; + private readonly System.Collections.IList _errors; + + public EdmMetadataLoader(IDynamicHost host, System.Collections.IList errors) + { + ArgumentNotNull(host, "host"); + ArgumentNotNull(errors, "errors"); + + _host = host; + _errors = errors; + } + + public IEnumerable CreateEdmItemCollection(string sourcePath) + { + ArgumentNotNull(sourcePath, "sourcePath"); + + if (!ValidateInputPath(sourcePath)) + { + return new EdmItemCollection(); + } + + var schemaElement = LoadRootElement(_host.ResolvePath(sourcePath)); + if (schemaElement != null) + { + using (var reader = schemaElement.CreateReader()) + { + IList errors; + var itemCollection = MetadataItemCollectionFactory.CreateEdmItemCollection(new[] { reader }, out errors); + + ProcessErrors(errors, sourcePath); + + return itemCollection; + } + } + return new EdmItemCollection(); + } + + public string GetModelNamespace(string sourcePath) + { + ArgumentNotNull(sourcePath, "sourcePath"); + + if (!ValidateInputPath(sourcePath)) + { + return string.Empty; + } + + var model = LoadRootElement(_host.ResolvePath(sourcePath)); + if (model == null) + { + return string.Empty; + } + + var attribute = model.Attribute("Namespace"); + return attribute != null ? attribute.Value : ""; + } + + private bool ValidateInputPath(string sourcePath) + { + if (sourcePath == "$" + "edmxInputFile" + "$") + { + _errors.Add( + new CompilerError(_host.TemplateFile ?? sourcePath, 0, 0, string.Empty, + GetResourceString("Template_ReplaceVsItemTemplateToken"))); + return false; + } + + return true; + } + + public XElement LoadRootElement(string sourcePath) + { + ArgumentNotNull(sourcePath, "sourcePath"); + + var root = XElement.Load(sourcePath, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo); + return root.Elements() + .Where(e => e.Name.LocalName == "Runtime") + .Elements() + .Where(e => e.Name.LocalName == "ConceptualModels") + .Elements() + .Where(e => e.Name.LocalName == "Schema") + .FirstOrDefault() + ?? root; + } + + private void ProcessErrors(IEnumerable errors, string sourceFilePath) + { + foreach (var error in errors) + { + _errors.Add( + new CompilerError( + error.SchemaLocation ?? sourceFilePath, + error.Line, + error.Column, + error.ErrorCode.ToString(CultureInfo.InvariantCulture), + error.Message) + { + IsWarning = error.Severity == EdmSchemaErrorSeverity.Warning + }); + } + } + + public bool IsLazyLoadingEnabled(EntityContainer container) + { + string lazyLoadingAttributeValue; + var lazyLoadingAttributeName = MetadataConstants.EDM_ANNOTATION_09_02 + ":LazyLoadingEnabled"; + bool isLazyLoading; + return !MetadataTools.TryGetStringMetadataPropertySetting(container, lazyLoadingAttributeName, out lazyLoadingAttributeValue) + || !bool.TryParse(lazyLoadingAttributeValue, out isLazyLoading) + || isLazyLoading; + } +} + +public static void ArgumentNotNull(T arg, string name) where T : class +{ + if (arg == null) + { + throw new ArgumentNullException(name); + } +} + +private static readonly Lazy ResourceManager = + new Lazy( + () => new System.Resources.ResourceManager("System.Data.Entity.Design", typeof(MetadataItemCollectionFactory).Assembly), isThreadSafe: true); + +public static string GetResourceString(string resourceName) +{ + ArgumentNotNull(resourceName, "resourceName"); + + return ResourceManager.Value.GetString(resourceName, null); +} + +#> \ No newline at end of file diff --git a/AkiragestuProject/Model1.Designer.cs b/AkiragestuProject/Model1.Designer.cs new file mode 100644 index 0000000..b314372 --- /dev/null +++ b/AkiragestuProject/Model1.Designer.cs @@ -0,0 +1,10 @@ +// 为模型“D:\AkiragestuProject\AkiragestuProject\AkiragestuProject\Model1.edmx”启用了 T4 代码生成。 +// 要启用旧代码生成功能,请将“代码生成策略”设计器属性的值 +// 更改为“旧的 ObjectContext”。当在设计器中打开该模型时,此属性会出现在 +// “属性”窗口中。 + +// 如果没有生成任何上下文和实体类,可能是因为您创建了空模型但是 +// 尚未选择要使用的实体框架版本。要为您的模型生成一个上下文类和实体 +// 类,请在设计器中打开该模型,右键单击设计器图面,然后 +// 选择“从数据库更新模型...”、“从模型生成数据库...”或“添加代码生成 +// 项...”。 \ No newline at end of file diff --git a/AkiragestuProject/Model1.cs b/AkiragestuProject/Model1.cs new file mode 100644 index 0000000..e19e0d8 --- /dev/null +++ b/AkiragestuProject/Model1.cs @@ -0,0 +1,9 @@ +//------------------------------------------------------------------------------ +// +// 此代码是根据模板生成的。 +// +// 手动更改此文件可能会导致应用程序中发生异常行为。 +// 如果重新生成代码,则将覆盖对此文件的手动更改。 +// +//------------------------------------------------------------------------------ + diff --git a/AkiragestuProject/Model1.edmx b/AkiragestuProject/Model1.edmx new file mode 100644 index 0000000..c67c02f --- /dev/null +++ b/AkiragestuProject/Model1.edmx @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT +`ak_qa`.`ID`, +`ak_qa`.`Q`, +`ak_qa`.`A`, +`ak_qa`.`CreateTime` +FROM `ak_qa` AS `ak_qa` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AkiragestuProject/Model1.edmx.diagram b/AkiragestuProject/Model1.edmx.diagram new file mode 100644 index 0000000..6b692e2 --- /dev/null +++ b/AkiragestuProject/Model1.edmx.diagram @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AkiragestuProject/Model1.tt b/AkiragestuProject/Model1.tt new file mode 100644 index 0000000..329b8c4 --- /dev/null +++ b/AkiragestuProject/Model1.tt @@ -0,0 +1,845 @@ +<#@ template language="C#" debug="false" hostspecific="true"#> +<#@ include file="EF.Utility.CS.ttinclude"#><#@ + output extension=".cs"#><# + +const string inputFile = @"Model1.edmx"; +var textTransform = DynamicTextTransformation.Create(this); +var code = new CodeGenerationTools(this); +var ef = new MetadataTools(this); +var typeMapper = new TypeMapper(code, ef, textTransform.Errors); +var fileManager = EntityFrameworkTemplateFileManager.Create(this); +var itemCollection = new EdmMetadataLoader(textTransform.Host, textTransform.Errors).CreateEdmItemCollection(inputFile); +var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef); + +if (!typeMapper.VerifyCaseInsensitiveTypeUniqueness(typeMapper.GetAllGlobalItems(itemCollection), inputFile)) +{ + return string.Empty; +} + +WriteHeader(codeStringGenerator, fileManager); + +foreach (var entity in typeMapper.GetItemsToGenerate(itemCollection)) +{ + fileManager.StartNewFile(entity.Name + ".cs"); + BeginNamespace(code); +#> +<#=codeStringGenerator.UsingDirectives(inHeader: false)#> +<#=codeStringGenerator.EntityClassOpening(entity)#> +{ +<# + var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(entity); + var collectionNavigationProperties = typeMapper.GetCollectionNavigationProperties(entity); + var complexProperties = typeMapper.GetComplexProperties(entity); + + if (propertiesWithDefaultValues.Any() || collectionNavigationProperties.Any() || complexProperties.Any()) + { +#> + public <#=code.Escape(entity)#>() + { +<# + foreach (var edmProperty in propertiesWithDefaultValues) + { +#> + this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>; +<# + } + + foreach (var navigationProperty in collectionNavigationProperties) + { +#> + this.<#=code.Escape(navigationProperty)#> = new HashSet<<#=typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType())#>>(); +<# + } + + foreach (var complexProperty in complexProperties) + { +#> + this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>(); +<# + } +#> + } + +<# + } + + var simpleProperties = typeMapper.GetSimpleProperties(entity); + if (simpleProperties.Any()) + { + foreach (var edmProperty in simpleProperties) + { +#> + <#=codeStringGenerator.Property(edmProperty)#> +<# + } + } + + if (complexProperties.Any()) + { +#> + +<# + foreach(var complexProperty in complexProperties) + { +#> + <#=codeStringGenerator.Property(complexProperty)#> +<# + } + } + + var navigationProperties = typeMapper.GetNavigationProperties(entity); + if (navigationProperties.Any()) + { +#> + +<# + foreach (var navigationProperty in navigationProperties) + { +#> + <#=codeStringGenerator.NavigationProperty(navigationProperty)#> +<# + } + } +#> +} +<# + EndNamespace(code); +} + +foreach (var complex in typeMapper.GetItemsToGenerate(itemCollection)) +{ + fileManager.StartNewFile(complex.Name + ".cs"); + BeginNamespace(code); +#> +<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#> +<#=Accessibility.ForType(complex)#> partial class <#=code.Escape(complex)#> +{ +<# + var complexProperties = typeMapper.GetComplexProperties(complex); + var propertiesWithDefaultValues = typeMapper.GetPropertiesWithDefaultValues(complex); + + if (propertiesWithDefaultValues.Any() || complexProperties.Any()) + { +#> + public <#=code.Escape(complex)#>() + { +<# + foreach (var edmProperty in propertiesWithDefaultValues) + { +#> + this.<#=code.Escape(edmProperty)#> = <#=typeMapper.CreateLiteral(edmProperty.DefaultValue)#>; +<# + } + + foreach (var complexProperty in complexProperties) + { +#> + this.<#=code.Escape(complexProperty)#> = new <#=typeMapper.GetTypeName(complexProperty.TypeUsage)#>(); +<# + } +#> + } + +<# + } + + var simpleProperties = typeMapper.GetSimpleProperties(complex); + if (simpleProperties.Any()) + { + foreach(var edmProperty in simpleProperties) + { +#> + <#=codeStringGenerator.Property(edmProperty)#> +<# + } + } + + if (complexProperties.Any()) + { +#> + +<# + foreach(var edmProperty in complexProperties) + { +#> + <#=codeStringGenerator.Property(edmProperty)#> +<# + } + } +#> +} +<# + EndNamespace(code); +} + +foreach (var enumType in typeMapper.GetEnumItemsToGenerate(itemCollection)) +{ + fileManager.StartNewFile(enumType.Name + ".cs"); + BeginNamespace(code); +#> +<#=codeStringGenerator.UsingDirectives(inHeader: false, includeCollections: false)#> +<# + if (typeMapper.EnumIsFlags(enumType)) + { +#> +[Flags] +<# + } +#> +<#=codeStringGenerator.EnumOpening(enumType)#> +{ +<# + var foundOne = false; + + foreach (MetadataItem member in typeMapper.GetEnumMembers(enumType)) + { + foundOne = true; +#> + <#=code.Escape(typeMapper.GetEnumMemberName(member))#> = <#=typeMapper.GetEnumMemberValue(member)#>, +<# + } + + if (foundOne) + { + this.GenerationEnvironment.Remove(this.GenerationEnvironment.Length - 3, 1); + } +#> +} +<# + EndNamespace(code); +} + +fileManager.Process(); + +#> +<#+ + +public void WriteHeader(CodeStringGenerator codeStringGenerator, EntityFrameworkTemplateFileManager fileManager) +{ + fileManager.StartHeader(); +#> +//------------------------------------------------------------------------------ +// +// <#=GetResourceString("Template_GeneratedCodeCommentLine1")#> +// +// <#=GetResourceString("Template_GeneratedCodeCommentLine2")#> +// <#=GetResourceString("Template_GeneratedCodeCommentLine3")#> +// +//------------------------------------------------------------------------------ +<#=codeStringGenerator.UsingDirectives(inHeader: true)#> +<#+ + fileManager.EndBlock(); +} + +public void BeginNamespace(CodeGenerationTools code) +{ + var codeNamespace = code.VsNamespaceSuggestion(); + if (!String.IsNullOrEmpty(codeNamespace)) + { +#> +namespace <#=code.EscapeNamespace(codeNamespace)#> +{ +<#+ + PushIndent(" "); + } +} + +public void EndNamespace(CodeGenerationTools code) +{ + if (!String.IsNullOrEmpty(code.VsNamespaceSuggestion())) + { + PopIndent(); +#> +} +<#+ + } +} + +public const string TemplateId = "CSharp_DbContext_Types_EF5"; + +public class CodeStringGenerator +{ + private readonly CodeGenerationTools _code; + private readonly TypeMapper _typeMapper; + private readonly MetadataTools _ef; + + public CodeStringGenerator(CodeGenerationTools code, TypeMapper typeMapper, MetadataTools ef) + { + ArgumentNotNull(code, "code"); + ArgumentNotNull(typeMapper, "typeMapper"); + ArgumentNotNull(ef, "ef"); + + _code = code; + _typeMapper = typeMapper; + _ef = ef; + } + + public string Property(EdmProperty edmProperty) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2} {{ {3}get; {4}set; }}", + Accessibility.ForProperty(edmProperty), + _typeMapper.GetTypeName(edmProperty.TypeUsage), + _code.Escape(edmProperty), + _code.SpaceAfter(Accessibility.ForGetter(edmProperty)), + _code.SpaceAfter(Accessibility.ForSetter(edmProperty))); + } + + public string NavigationProperty(NavigationProperty navigationProperty) + { + var endType = _typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType()); + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2} {{ {3}get; {4}set; }}", + AccessibilityAndVirtual(Accessibility.ForProperty(navigationProperty)), + navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection<" + endType + ">") : endType, + _code.Escape(navigationProperty), + _code.SpaceAfter(Accessibility.ForGetter(navigationProperty)), + _code.SpaceAfter(Accessibility.ForSetter(navigationProperty))); + } + + public string AccessibilityAndVirtual(string accessibility) + { + return accessibility + (accessibility != "private" ? " virtual" : ""); + } + + public string EntityClassOpening(EntityType entity) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1}partial class {2}{3}", + Accessibility.ForType(entity), + _code.SpaceAfter(_code.AbstractOption(entity)), + _code.Escape(entity), + _code.StringBefore(" : ", _typeMapper.GetTypeName(entity.BaseType))); + } + + public string EnumOpening(SimpleType enumType) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} enum {1} : {2}", + Accessibility.ForType(enumType), + _code.Escape(enumType), + _code.Escape(_typeMapper.UnderlyingClrType(enumType))); + } + + public void WriteFunctionParameters(EdmFunction edmFunction, Action writeParameter) + { + var parameters = FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef); + foreach (var parameter in parameters.Where(p => p.NeedsLocalVariable)) + { + var isNotNull = parameter.IsNullableOfT ? parameter.FunctionParameterName + ".HasValue" : parameter.FunctionParameterName + " != null"; + var notNullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", " + parameter.FunctionParameterName + ")"; + var nullInit = "new ObjectParameter(\"" + parameter.EsqlParameterName + "\", typeof(" + parameter.RawClrTypeName + "))"; + writeParameter(parameter.LocalVariableName, isNotNull, notNullInit, nullInit); + } + } + + public string ComposableFunctionMethod(EdmFunction edmFunction, string modelNamespace) + { + var parameters = _typeMapper.GetParameters(edmFunction); + + return string.Format( + CultureInfo.InvariantCulture, + "{0} IQueryable<{1}> {2}({3})", + AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)), + _typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace), + _code.Escape(edmFunction), + string.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray())); + } + + public string ComposableCreateQuery(EdmFunction edmFunction, string modelNamespace) + { + var parameters = _typeMapper.GetParameters(edmFunction); + + return string.Format( + CultureInfo.InvariantCulture, + "return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<{0}>(\"[{1}].[{2}]({3})\"{4});", + _typeMapper.GetTypeName(_typeMapper.GetReturnType(edmFunction), modelNamespace), + edmFunction.NamespaceName, + edmFunction.Name, + string.Join(", ", parameters.Select(p => "@" + p.EsqlParameterName).ToArray()), + _code.StringBefore(", ", string.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()))); + } + + public string FunctionMethod(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) + { + var parameters = _typeMapper.GetParameters(edmFunction); + var returnType = _typeMapper.GetReturnType(edmFunction); + + var paramList = String.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray()); + if (includeMergeOption) + { + paramList = _code.StringAfter(paramList, ", ") + "MergeOption mergeOption"; + } + + return string.Format( + CultureInfo.InvariantCulture, + "{0} {1} {2}({3})", + AccessibilityAndVirtual(Accessibility.ForMethod(edmFunction)), + returnType == null ? "int" : "ObjectResult<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">", + _code.Escape(edmFunction), + paramList); + } + + public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption) + { + var parameters = _typeMapper.GetParameters(edmFunction); + var returnType = _typeMapper.GetReturnType(edmFunction); + + var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray())); + if (includeMergeOption) + { + callParams = ", mergeOption" + callParams; + } + + return string.Format( + CultureInfo.InvariantCulture, + "return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});", + returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">", + edmFunction.Name, + callParams); + } + + public string DbSet(EntitySet entitySet) + { + return string.Format( + CultureInfo.InvariantCulture, + "{0} DbSet<{1}> {2} {{ get; set; }}", + Accessibility.ForReadOnlyProperty(entitySet), + _typeMapper.GetTypeName(entitySet.ElementType), + _code.Escape(entitySet)); + } + + public string UsingDirectives(bool inHeader, bool includeCollections = true) + { + return inHeader == string.IsNullOrEmpty(_code.VsNamespaceSuggestion()) + ? string.Format( + CultureInfo.InvariantCulture, + "{0}using System;{1}" + + "{2}", + inHeader ? Environment.NewLine : "", + includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "", + inHeader ? "" : Environment.NewLine) + : ""; + } +} + +public class TypeMapper +{ + private const string ExternalTypeNameAttributeName = @"http://schemas.microsoft.com/ado/2006/04/codegeneration:ExternalTypeName"; + + private readonly System.Collections.IList _errors; + private readonly CodeGenerationTools _code; + private readonly MetadataTools _ef; + + public TypeMapper(CodeGenerationTools code, MetadataTools ef, System.Collections.IList errors) + { + ArgumentNotNull(code, "code"); + ArgumentNotNull(ef, "ef"); + ArgumentNotNull(errors, "errors"); + + _code = code; + _ef = ef; + _errors = errors; + } + + public string GetTypeName(TypeUsage typeUsage) + { + return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace: null); + } + + public string GetTypeName(EdmType edmType) + { + return GetTypeName(edmType, isNullable: null, modelNamespace: null); + } + + public string GetTypeName(TypeUsage typeUsage, string modelNamespace) + { + return typeUsage == null ? null : GetTypeName(typeUsage.EdmType, _ef.IsNullable(typeUsage), modelNamespace); + } + + public string GetTypeName(EdmType edmType, string modelNamespace) + { + return GetTypeName(edmType, isNullable: null, modelNamespace: modelNamespace); + } + + public string GetTypeName(EdmType edmType, bool? isNullable, string modelNamespace) + { + if (edmType == null) + { + return null; + } + + var collectionType = edmType as CollectionType; + if (collectionType != null) + { + return String.Format(CultureInfo.InvariantCulture, "ICollection<{0}>", GetTypeName(collectionType.TypeUsage, modelNamespace)); + } + + var typeName = _code.Escape(edmType.MetadataProperties + .Where(p => p.Name == ExternalTypeNameAttributeName) + .Select(p => (string)p.Value) + .FirstOrDefault()) + ?? (modelNamespace != null && edmType.NamespaceName != modelNamespace ? + _code.CreateFullName(_code.EscapeNamespace(edmType.NamespaceName), _code.Escape(edmType)) : + _code.Escape(edmType)); + + if (edmType is StructuralType) + { + return typeName; + } + + if (edmType is SimpleType) + { + var clrType = UnderlyingClrType(edmType); + if (!IsEnumType(edmType)) + { + typeName = _code.Escape(clrType); + } + + return clrType.IsValueType && isNullable == true ? + String.Format(CultureInfo.InvariantCulture, "Nullable<{0}>", typeName) : + typeName; + } + + throw new ArgumentException("edmType"); + } + + public Type UnderlyingClrType(EdmType edmType) + { + ArgumentNotNull(edmType, "edmType"); + + var primitiveType = edmType as PrimitiveType; + if (primitiveType != null) + { + return primitiveType.ClrEquivalentType; + } + + if (IsEnumType(edmType)) + { + return GetEnumUnderlyingType(edmType).ClrEquivalentType; + } + + return typeof(object); + } + + public object GetEnumMemberValue(MetadataItem enumMember) + { + ArgumentNotNull(enumMember, "enumMember"); + + var valueProperty = enumMember.GetType().GetProperty("Value"); + return valueProperty == null ? null : valueProperty.GetValue(enumMember, null); + } + + public string GetEnumMemberName(MetadataItem enumMember) + { + ArgumentNotNull(enumMember, "enumMember"); + + var nameProperty = enumMember.GetType().GetProperty("Name"); + return nameProperty == null ? null : (string)nameProperty.GetValue(enumMember, null); + } + + public System.Collections.IEnumerable GetEnumMembers(EdmType enumType) + { + ArgumentNotNull(enumType, "enumType"); + + var membersProperty = enumType.GetType().GetProperty("Members"); + return membersProperty != null + ? (System.Collections.IEnumerable)membersProperty.GetValue(enumType, null) + : Enumerable.Empty(); + } + + public bool EnumIsFlags(EdmType enumType) + { + ArgumentNotNull(enumType, "enumType"); + + var isFlagsProperty = enumType.GetType().GetProperty("IsFlags"); + return isFlagsProperty != null && (bool)isFlagsProperty.GetValue(enumType, null); + } + + public bool IsEnumType(GlobalItem edmType) + { + ArgumentNotNull(edmType, "edmType"); + + return edmType.GetType().Name == "EnumType"; + } + + public PrimitiveType GetEnumUnderlyingType(EdmType enumType) + { + ArgumentNotNull(enumType, "enumType"); + + return (PrimitiveType)enumType.GetType().GetProperty("UnderlyingType").GetValue(enumType, null); + } + + public string CreateLiteral(object value) + { + if (value == null || value.GetType() != typeof(TimeSpan)) + { + return _code.CreateLiteral(value); + } + + return string.Format(CultureInfo.InvariantCulture, "new TimeSpan({0})", ((TimeSpan)value).Ticks); + } + + public bool VerifyCaseInsensitiveTypeUniqueness(IEnumerable types, string sourceFile) + { + ArgumentNotNull(types, "types"); + ArgumentNotNull(sourceFile, "sourceFile"); + + var hash = new HashSet(StringComparer.InvariantCultureIgnoreCase); + if (types.Any(item => !hash.Add(item))) + { + _errors.Add( + new CompilerError(sourceFile, -1, -1, "6023", + String.Format(CultureInfo.CurrentCulture, GetResourceString("Template_CaseInsensitiveTypeConflict")))); + return false; + } + return true; + } + + public IEnumerable GetEnumItemsToGenerate(IEnumerable itemCollection) + { + return GetItemsToGenerate(itemCollection) + .Where(e => IsEnumType(e)); + } + + public IEnumerable GetItemsToGenerate(IEnumerable itemCollection) where T: EdmType + { + return itemCollection + .OfType() + .Where(i => !i.MetadataProperties.Any(p => p.Name == ExternalTypeNameAttributeName)) + .OrderBy(i => i.Name); + } + + public IEnumerable GetAllGlobalItems(IEnumerable itemCollection) + { + return itemCollection + .Where(i => i is EntityType || i is ComplexType || i is EntityContainer || IsEnumType(i)) + .Select(g => GetGlobalItemName(g)); + } + + public string GetGlobalItemName(GlobalItem item) + { + if (item is EdmType) + { + return ((EdmType)item).Name; + } + else + { + return ((EntityContainer)item).Name; + } + } + + public IEnumerable GetSimpleProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetSimpleProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetComplexProperties(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is ComplexType && p.DeclaringType == type); + } + + public IEnumerable GetPropertiesWithDefaultValues(EntityType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetPropertiesWithDefaultValues(ComplexType type) + { + return type.Properties.Where(p => p.TypeUsage.EdmType is SimpleType && p.DeclaringType == type && p.DefaultValue != null); + } + + public IEnumerable GetNavigationProperties(EntityType type) + { + return type.NavigationProperties.Where(np => np.DeclaringType == type); + } + + public IEnumerable GetCollectionNavigationProperties(EntityType type) + { + return type.NavigationProperties.Where(np => np.DeclaringType == type && np.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many); + } + + public FunctionParameter GetReturnParameter(EdmFunction edmFunction) + { + ArgumentNotNull(edmFunction, "edmFunction"); + + var returnParamsProperty = edmFunction.GetType().GetProperty("ReturnParameters"); + return returnParamsProperty == null + ? edmFunction.ReturnParameter + : ((IEnumerable)returnParamsProperty.GetValue(edmFunction, null)).FirstOrDefault(); + } + + public bool IsComposable(EdmFunction edmFunction) + { + ArgumentNotNull(edmFunction, "edmFunction"); + + var isComposableProperty = edmFunction.GetType().GetProperty("IsComposableAttribute"); + return isComposableProperty != null && (bool)isComposableProperty.GetValue(edmFunction, null); + } + + public IEnumerable GetParameters(EdmFunction edmFunction) + { + return FunctionImportParameter.Create(edmFunction.Parameters, _code, _ef); + } + + public TypeUsage GetReturnType(EdmFunction edmFunction) + { + var returnParam = GetReturnParameter(edmFunction); + return returnParam == null ? null : _ef.GetElementType(returnParam.TypeUsage); + } + + public bool GenerateMergeOptionFunction(EdmFunction edmFunction, bool includeMergeOption) + { + var returnType = GetReturnType(edmFunction); + return !includeMergeOption && returnType != null && returnType.EdmType.BuiltInTypeKind == BuiltInTypeKind.EntityType; + } +} + +public class EdmMetadataLoader +{ + private readonly IDynamicHost _host; + private readonly System.Collections.IList _errors; + + public EdmMetadataLoader(IDynamicHost host, System.Collections.IList errors) + { + ArgumentNotNull(host, "host"); + ArgumentNotNull(errors, "errors"); + + _host = host; + _errors = errors; + } + + public IEnumerable CreateEdmItemCollection(string sourcePath) + { + ArgumentNotNull(sourcePath, "sourcePath"); + + if (!ValidateInputPath(sourcePath)) + { + return new EdmItemCollection(); + } + + var schemaElement = LoadRootElement(_host.ResolvePath(sourcePath)); + if (schemaElement != null) + { + using (var reader = schemaElement.CreateReader()) + { + IList errors; + var itemCollection = MetadataItemCollectionFactory.CreateEdmItemCollection(new[] { reader }, out errors); + + ProcessErrors(errors, sourcePath); + + return itemCollection; + } + } + return new EdmItemCollection(); + } + + public string GetModelNamespace(string sourcePath) + { + ArgumentNotNull(sourcePath, "sourcePath"); + + if (!ValidateInputPath(sourcePath)) + { + return string.Empty; + } + + var model = LoadRootElement(_host.ResolvePath(sourcePath)); + if (model == null) + { + return string.Empty; + } + + var attribute = model.Attribute("Namespace"); + return attribute != null ? attribute.Value : ""; + } + + private bool ValidateInputPath(string sourcePath) + { + if (sourcePath == "$" + "edmxInputFile" + "$") + { + _errors.Add( + new CompilerError(_host.TemplateFile ?? sourcePath, 0, 0, string.Empty, + GetResourceString("Template_ReplaceVsItemTemplateToken"))); + return false; + } + + return true; + } + + public XElement LoadRootElement(string sourcePath) + { + ArgumentNotNull(sourcePath, "sourcePath"); + + var root = XElement.Load(sourcePath, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo); + return root.Elements() + .Where(e => e.Name.LocalName == "Runtime") + .Elements() + .Where(e => e.Name.LocalName == "ConceptualModels") + .Elements() + .Where(e => e.Name.LocalName == "Schema") + .FirstOrDefault() + ?? root; + } + + private void ProcessErrors(IEnumerable errors, string sourceFilePath) + { + foreach (var error in errors) + { + _errors.Add( + new CompilerError( + error.SchemaLocation ?? sourceFilePath, + error.Line, + error.Column, + error.ErrorCode.ToString(CultureInfo.InvariantCulture), + error.Message) + { + IsWarning = error.Severity == EdmSchemaErrorSeverity.Warning + }); + } + } + + public bool IsLazyLoadingEnabled(EntityContainer container) + { + string lazyLoadingAttributeValue; + var lazyLoadingAttributeName = MetadataConstants.EDM_ANNOTATION_09_02 + ":LazyLoadingEnabled"; + bool isLazyLoading; + return !MetadataTools.TryGetStringMetadataPropertySetting(container, lazyLoadingAttributeName, out lazyLoadingAttributeValue) + || !bool.TryParse(lazyLoadingAttributeValue, out isLazyLoading) + || isLazyLoading; + } +} + +public static void ArgumentNotNull(T arg, string name) where T : class +{ + if (arg == null) + { + throw new ArgumentNullException(name); + } +} + +private static readonly Lazy ResourceManager = + new Lazy( + () => new System.Resources.ResourceManager("System.Data.Entity.Design", typeof(MetadataItemCollectionFactory).Assembly), isThreadSafe: true); + +public static string GetResourceString(string resourceName) +{ + ArgumentNotNull(resourceName, "resourceName"); + + return ResourceManager.Value.GetString(resourceName, null); +} + +#> \ No newline at end of file diff --git a/AkiragestuProject/Program.cs b/AkiragestuProject/Program.cs new file mode 100644 index 0000000..1538b07 --- /dev/null +++ b/AkiragestuProject/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace AkiragestuProject +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/AkiragestuProject/Properties/AssemblyInfo.cs b/AkiragestuProject/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bbd15f6 --- /dev/null +++ b/AkiragestuProject/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("AkiragestuProject")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("AkiragestuProject")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("9588301c-9ceb-48f4-a487-d5665aa0cb72")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/AkiragestuProject/Properties/Resources.Designer.cs b/AkiragestuProject/Properties/Resources.Designer.cs new file mode 100644 index 0000000..b854525 --- /dev/null +++ b/AkiragestuProject/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.34209 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace AkiragestuProject.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AkiragestuProject.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/AkiragestuProject/Properties/Resources.resx b/AkiragestuProject/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/AkiragestuProject/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AkiragestuProject/Properties/Settings.Designer.cs b/AkiragestuProject/Properties/Settings.Designer.cs new file mode 100644 index 0000000..cdeb695 --- /dev/null +++ b/AkiragestuProject/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.34209 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace AkiragestuProject.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/AkiragestuProject/Properties/Settings.settings b/AkiragestuProject/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/AkiragestuProject/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/AkiragestuProject/akLanguage.cs b/AkiragestuProject/akLanguage.cs new file mode 100644 index 0000000..847c806 --- /dev/null +++ b/AkiragestuProject/akLanguage.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace AkiragestuProject +{ + class akLanguage + { + + akMood akm = new akMood(); + //判读按语法先 + public int GetlanguageType(string MsgStr) + { + if (MsgStr.Substring(0, 1).Contains('/')) + { + //确定是命令 + return 2; + } + else + return 1; + } + + /// + /// 获取方法 + /// + public string GetCommand(string CommandStr) + { + int commHeadIndex = CommandStr.IndexOf(" "); + string CommFirst = CommandStr; + //空格多命令 + if (commHeadIndex > 0) + { + CommFirst = CommandStr.Substring(0, commHeadIndex); + } + switch (CommFirst.ToLower()) + { + case "help": + return com_help(); + break; + case "hentai": + return com_hentai(); + break; + case "addqa": + if (commHeadIndex > 0) + { + return com_AddQA(CommandStr.Substring(commHeadIndex)); + } + else + return "QA参数错误"; + break; + } + + return null; + } + public string com_help() + { + return "基本命令: /help /hentai /akiragatsu"; + } + + public string com_hentai() + { + return "变态有什么错"; + } + + public string com_AddQA(string QA) + { + try + { + string[] strArr = QA.Split('^'); + if (akm.AddQA(strArr[0], strArr[1])) + return "增加成功 o(^▽^)o"; + else + return "增加失败"; + + } + catch (Exception ex) + { + return ex.ToString(); + } + + } + + + + } +} diff --git a/AkiragestuProject/akMood.cs b/AkiragestuProject/akMood.cs new file mode 100644 index 0000000..64443a9 --- /dev/null +++ b/AkiragestuProject/akMood.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AkiragestuProject +{ + + /// + /// 参数影响类 + /// + class akMood + { + akiragetsuEntities akEn = new akiragetsuEntities(); + public ak_mainperson GetMain() + { + return akEn.ak_mainperson.FirstOrDefault(); + } + + + public bool AddQA(string Q, string A) + { + ak_qa qa = new ak_qa(); + qa.ID = Guid.NewGuid(); + qa.A = A; + qa.Q = Q; + akEn.ak_qa.Add(qa); + akEn.SaveChanges(); + return true; + } + } +} diff --git a/AkiragestuProject/akOperation.cs b/AkiragestuProject/akOperation.cs new file mode 100644 index 0000000..ca65fc6 --- /dev/null +++ b/AkiragestuProject/akOperation.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AkiragestuProject +{ + /// + /// 基本计算类 + /// + class akOperation + { + akMood akm = new akMood(); + /// + /// 加法 + /// + /// + /// + /// + public string Addition(string Addstr) + { + string[] Arr = Addstr.Split('+'); + + + int cstr = 0; + foreach(var a in Arr) + { + cstr+= Convert.ToInt32(a); + } + return cstr.ToString(); + } + + /// + /// 减法 + /// + /// + /// + /// + public string Subtraction(int f1, int f2) + { + + int c = f1 - f2; + + var cstr = c.ToString(); + return cstr; + } + + /// + /// 乘法 + /// + /// + /// + /// + public string Multiplication(int f1, int f2) + { + + int c = f1 * f2; + + var cstr = c.ToString(); + return cstr; + } + + /// + /// Division + /// + /// + /// + /// + public string Division(int f1, int f2) + { + + int c = f1 / f2; + + var cstr = c.ToString(); + return cstr; + } + } +} diff --git a/AkiragestuProject/ak_impression.cs b/AkiragestuProject/ak_impression.cs new file mode 100644 index 0000000..276752f --- /dev/null +++ b/AkiragestuProject/ak_impression.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// 此代码是根据模板生成的。 +// +// 手动更改此文件可能会导致应用程序中发生异常行为。 +// 如果重新生成代码,则将覆盖对此文件的手动更改。 +// +//------------------------------------------------------------------------------ + +namespace AkiragestuProject +{ + using System; + using System.Collections.Generic; + + public partial class ak_impression + { + public int ID { get; set; } + public string Content { get; set; } + public Nullable CreateTime { get; set; } + public Nullable Deep { get; set; } + } +} diff --git a/AkiragestuProject/ak_mainperson.cs b/AkiragestuProject/ak_mainperson.cs new file mode 100644 index 0000000..e22b84d --- /dev/null +++ b/AkiragestuProject/ak_mainperson.cs @@ -0,0 +1,23 @@ +//------------------------------------------------------------------------------ +// +// 此代码是根据模板生成的。 +// +// 手动更改此文件可能会导致应用程序中发生异常行为。 +// 如果重新生成代码,则将覆盖对此文件的手动更改。 +// +//------------------------------------------------------------------------------ + +namespace AkiragestuProject +{ + using System; + using System.Collections.Generic; + + public partial class ak_mainperson + { + public int ID { get; set; } + public Nullable Mood { get; set; } + public Nullable Energy { get; set; } + public Nullable Hungry { get; set; } + public Nullable MentalityType { get; set; } + } +} diff --git a/AkiragestuProject/ak_petphrase.cs b/AkiragestuProject/ak_petphrase.cs new file mode 100644 index 0000000..7afb0e3 --- /dev/null +++ b/AkiragestuProject/ak_petphrase.cs @@ -0,0 +1,23 @@ +//------------------------------------------------------------------------------ +// +// 此代码是根据模板生成的。 +// +// 手动更改此文件可能会导致应用程序中发生异常行为。 +// 如果重新生成代码,则将覆盖对此文件的手动更改。 +// +//------------------------------------------------------------------------------ + +namespace AkiragestuProject +{ + using System; + using System.Collections.Generic; + + public partial class ak_petphrase + { + public int ID { get; set; } + public string Petphrase { get; set; } + public Nullable AppearNumber { get; set; } + public Nullable CreateTime { get; set; } + public Nullable Deep { get; set; } + } +} diff --git a/AkiragestuProject/ak_qa.cs b/AkiragestuProject/ak_qa.cs new file mode 100644 index 0000000..75376e8 --- /dev/null +++ b/AkiragestuProject/ak_qa.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// 此代码是根据模板生成的。 +// +// 手动更改此文件可能会导致应用程序中发生异常行为。 +// 如果重新生成代码,则将覆盖对此文件的手动更改。 +// +//------------------------------------------------------------------------------ + +namespace AkiragestuProject +{ + using System; + using System.Collections.Generic; + + public partial class ak_qa + { + public System.Guid ID { get; set; } + public string Q { get; set; } + public string A { get; set; } + public Nullable CreateTime { get; set; } + } +} diff --git a/AkiragestuProject/packages.config b/AkiragestuProject/packages.config new file mode 100644 index 0000000..4392065 --- /dev/null +++ b/AkiragestuProject/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/HaoYue.Personality.sln b/HaoYue.Personality.sln new file mode 100644 index 0000000..3366e79 --- /dev/null +++ b/HaoYue.Personality.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26403.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AkiragestuProject", "AkiragestuProject\AkiragestuProject.csproj", "{A4E730CF-2197-46F7-9459-4025ED11327C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{45D79DC2-10AB-423E-AB7E-219DB563D631}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersonBLL", "PersonBLL\PersonBLL.csproj", "{CFAA33F3-D128-4D9F-98E0-EDF805D6B732}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A4E730CF-2197-46F7-9459-4025ED11327C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4E730CF-2197-46F7-9459-4025ED11327C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4E730CF-2197-46F7-9459-4025ED11327C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4E730CF-2197-46F7-9459-4025ED11327C}.Release|Any CPU.Build.0 = Release|Any CPU + {45D79DC2-10AB-423E-AB7E-219DB563D631}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {45D79DC2-10AB-423E-AB7E-219DB563D631}.Debug|Any CPU.Build.0 = Debug|Any CPU + {45D79DC2-10AB-423E-AB7E-219DB563D631}.Release|Any CPU.ActiveCfg = Release|Any CPU + {45D79DC2-10AB-423E-AB7E-219DB563D631}.Release|Any CPU.Build.0 = Release|Any CPU + {CFAA33F3-D128-4D9F-98E0-EDF805D6B732}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFAA33F3-D128-4D9F-98E0-EDF805D6B732}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFAA33F3-D128-4D9F-98E0-EDF805D6B732}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFAA33F3-D128-4D9F-98E0-EDF805D6B732}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Model/Model.csproj b/Model/Model.csproj new file mode 100644 index 0000000..765fdfc --- /dev/null +++ b/Model/Model.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + 45d79dc2-10ab-423e-ab7e-219db563d631 + Library + Properties + Model + Model + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Model/Properties/AssemblyInfo.cs b/Model/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..aa11e57 --- /dev/null +++ b/Model/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Model")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Model")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("45d79dc2-10ab-423e-ab7e-219db563d631")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PersonBLL/Class1.cs b/PersonBLL/Class1.cs new file mode 100644 index 0000000..b70b0ae --- /dev/null +++ b/PersonBLL/Class1.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace PersonBLL +{ + public class Class1 + { + } +} diff --git a/PersonBLL/PersonBLL.csproj b/PersonBLL/PersonBLL.csproj new file mode 100644 index 0000000..85814e9 --- /dev/null +++ b/PersonBLL/PersonBLL.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {CFAA33F3-D128-4D9F-98E0-EDF805D6B732} + Library + Properties + PersonBLL + PersonBLL + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PersonBLL/Properties/AssemblyInfo.cs b/PersonBLL/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c1bd917 --- /dev/null +++ b/PersonBLL/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("PersonBLL")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PersonBLL")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("aae10ddb-316d-4968-9edf-4d4f5ef20cac")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]