Example #1
0
 /// <summary>
 /// 安装入口
 /// </summary>
 /// <param name="parameter">安装参数</param>
 /// <returns>是否安装成功</returns>
 public bool Run(auto.parameter parameter)
 {
     if (parameter != null)
     {
         if (parameter.IsFastCSharp && parameter.ProjectName == pub.fastCSharp)
         {
             subArray <definition> definitions = ui.CurrentAssembly.GetTypes().getArray(type => new definition {
                 Type = type, Auto = type.customAttribute <auto>(), Parameter = parameter
             })
                                                 .getFind(type => type.Auto != null && type.Auto.IsTemplate)// && type.Auto.DependType == typeof(cSharper)
                                                 .Sort((left, right) => string.CompareOrdinal(left.Type.FullName, right.Type.FullName));
             subArray <string> codes = new subArray <string>(definitions.Count);
             foreach (definition definition in definitions)
             {
                 codes.Add(definition.ToString());
                 if (error.IsError)
                 {
                     return(false);
                 }
             }
             string fileName = new DirectoryInfo(parameter.ProjectPath).Parent.fullName() + @"ui\{" + pub.fastCSharp + "}.cSharper.cs";
             if (WriteFile(fileName, WarningCode + string.Concat(codes) + FileEndCode))
             {
                 error.Add(fileName + " 被修改");
                 throw new Exception();
             }
         }
         return(true);
     }
     return(false);
 }
Example #2
0
        /// <summary>
        /// CSharp代码生成器
        /// </summary>
        /// <param name="parameter">安装参数</param>
        /// <param name="type">模板数据视图</param>
        /// <param name="language">语言</param>
        public coder(auto.parameter parameter, Type type, auto.language language)
            : base(type, error.Add, error.Message)
        {
            this.parameter = parameter;
            extensionName  = "." + Enum <auto.language, auto.languageAttribute> .Array((int)(byte)language).ExtensionName;

            creators[command.NOTE.ToString()]     = note;
            creators[command.LOOP.ToString()]     = creators[command.FOR.ToString()] = loop;
            creators[command.AT.ToString()]       = at;
            creators[command.PUSH.ToString()]     = push;
            creators[command.IF.ToString()]       = ifThen;
            creators[command.NOT.ToString()]      = not;
            creators[command.NAME.ToString()]     = name;
            creators[command.FROMNAME.ToString()] = fromName;
            creators[command.PART.ToString()]     = part;
        }
Example #3
0
 /// <summary>
 /// 安装入口
 /// </summary>
 /// <param name="parameter">安装参数</param>
 /// <returns>是否安装成功</returns>
 public bool Run(auto.parameter parameter)
 {
     if (parameter != null)
     {
         //bool isTest = true;
         foreach (Type type in parameter.Types)
         {
             if (!type.IsGenericType && !type.IsInterface && !type.IsEnum)
             {
                 foreach (code.methodInfo methodInfo in code.methodInfo.GetMethods <testCase>(type, memberFilters.Static, false, true, false, false))
                 {
                     MethodInfo method = methodInfo.Method;
                     if (method.IsGenericMethod)
                     {
                         //isTest = false;
                         error.Message("测试用例不能是泛型函数 " + method.fullName());
                     }
                     else
                     {
                         Type returnType = method.ReturnType;
                         if ((returnType == typeof(bool) || returnType == typeof(void)) && method.GetParameters().Length == 0)
                         {
                             try
                             {
                                 object returnValue = method.Invoke(null, null);
                                 if (method.ReturnType == typeof(bool) && !(bool)returnValue)
                                 {
                                     //isTest = false;
                                     error.Message("测试用例调用失败 " + method.fullName());
                                 }
                             }
                             catch (Exception error)
                             {
                                 code.error.Message(error.ToString());
                             }
                         }
                     }
                 }
             }
         }
         //return isTest;
     }
     //return false;
     return(true);
 }
Example #4
0
 /// <summary>
 /// 安装入口
 /// </summary>
 /// <param name="parameter">安装参数</param>
 /// <returns>是否安装成功</returns>
 public bool Run(auto.parameter parameter)
 {
     if (parameter != null)
     {
         string path = parameter.ProjectPath + DefaultTemplatePath.pathSuffix();
         if (Directory.Exists(path))
         {
             list <string>[] codes = Directory.GetFiles(path, "*.cs").getArray(name => code(name));
             if (!codes.any(code => code == null))
             {
                 coder.Add(string.Concat(codes.getArray(code => code.ToArray()).getArray()));
                 return(true);
             }
             return(false);
         }
         return(true);
     }
     return(false);
 }
Example #5
0
            /// <summary>
            /// 创建代码
            /// </summary>
            /// <param name="type"></param>
            /// <param name="methodIndexs"></param>
            public void Create(auto.parameter parameter, memberType type, methodIndex[] methodIndexs)
            {
                AutoParameter = parameter;
                this.type     = type;
                Methods       = methodIndexs;

                Namespace = type.Type.Namespace;
                if (Namespace == AutoParameter.DefaultNamespace)
                {
                    Namespace = fastCSharpAPI;
                }
                else
                {
                    Namespace = Namespace.StartsWith(AutoParameter.DefaultNamespace, StringComparison.Ordinal) && Namespace[AutoParameter.DefaultNamespace.Length] == '.' ? fastCSharpAPI + Namespace.Substring(AutoParameter.DefaultNamespace.Length) : Namespace;
                }

                _code_.Empty();
                create(false);
                code.Add(_code_);
            }
Example #6
0
        /// <summary>
        /// 安装
        /// </summary>
        /// <param name="autos">安装类型属性</param>
        /// <param name="parameter">安装参数</param>
        /// <returns>安装是否成功</returns>
        internal static bool Setup(keyValue <Type, auto>[] autos, auto.parameter parameter, bool isConfig)
        {
            bool isSetup = true;

            if (autos != null)
            {
                try
                {
                    autos = autos.sort((left, right) => string.CompareOrdinal(left.Key.FullName, right.Key.FullName));
                    HashSet <Type>          types   = autos.getHash(value => value.Key);
                    keyValue <Type, Type>[] depends = autos
                                                      .getFind(value => value.Value.DependType != null && types.Contains(value.Value.DependType))
                                                      .GetArray(value => new keyValue <Type, Type>(value.Key, value.Value.DependType));
                    foreach (Type type in algorithm.topologySort.Sort(depends, types, true))
                    {
                        //Stopwatch time = new Stopwatch();
                        //time.Start();
                        if (!(CurrentAssembly.CreateInstance(type.FullName) as IAuto)
                            .Run(isConfig ? config.pub.LoadConfig(parameter.Copy(), type.ToString()) : parameter))
                        {
                            error.Add(type.fullName() + " 安装失败");
                            isSetup = false;
                        }
                        //time.Stop();
                        //error.Message(parameter.ProjectName + " " + type.FullName + " : " + time.ElapsedMilliseconds.ToString() + "ms");
                    }
#if TESTCASE
                    new test().Run(isConfig ? config.pub.LoadConfig(parameter.Copy(), typeof(test).ToString()) : parameter);
#endif
                }
                catch (Exception exception)
                {
                    error.Add(exception);
                }
                finally
                {
                    coder.Output(parameter);
                }
            }
            return(isSetup);
        }
Example #7
0
 /// <summary>
 /// 自动安装
 /// </summary>
 /// <param name="parameter">安装参数</param>
 static void auto(auto.parameter parameter)
 {
     if (parameter.ProjectPath.length() != 0 && Directory.Exists(parameter.ProjectPath))
     {
         try
         {
             subArray <keyValue <Type, auto> > autos = code.ui.CurrentAssembly.GetTypes()
                                                       .getFind(type => !type.IsInterface && !type.IsAbstract && typeof(IAuto).IsAssignableFrom(type))
                                                       .GetArray(type => new keyValue <Type, auto>(type, type.customAttribute <auto>()))
                                                       .getFind(value => value.Value != null && value.Value.IsAuto);
             ui.Setup(autos.ToArray(), parameter, false);
         }
         catch (Exception error)
         {
             code.error.Add(error);
         }
     }
     else
     {
         code.error.Add("项目路径不存在 : " + parameter.ProjectPath);
     }
     code.error.Open(true);
 }
Example #8
0
        /// <summary>
        /// 输出代码
        /// </summary>
        public static void Output(auto.parameter parameter)
        {
            stringBuilder[] builders = new stringBuilder[codes.Length];
            for (int index = codes.Length; index != 0;)
            {
                stringBuilder builder = codes[--index];
                if (builder.Count != 0)
                {
                    builders[index] = builder;
                    codes[index]    = new stringBuilder();
                }
                auto.language language = (auto.language)(byte) index;
                switch (language)
                {
                case auto.language.JavaScript:
                case auto.language.TypeScript:
                    if (builders[index] != null)
                    {
                        error.Add("生成了未知的 " + language + " 代码。");
                    }
                    break;
                }
            }
            stringBuilder rememberCodeBuilder = null;

            if (rememberCodes.Count != 0)
            {
                rememberCodeBuilder = rememberCodes;
                rememberCodes       = new stringBuilder();
            }
            codeTypes.Clear();
            error.ThrowError();
            string message = string.Empty;

            for (int index = builders.Length; index != 0;)
            {
                stringBuilder builder = builders[--index];
                if (builder != null)
                {
                    switch (index)
                    {
                    case (int)auto.language.CSharp:
                        string code = builder.ToString(), fastCSharpFileName = null, rememberFileName = null;
                        bool   isFastCSharp = false, isRemember = false;
                        if (code.length() != 0)
                        {
                            string fileName = parameter.ProjectPath + (fastCSharpFileName = "{" + parameter.DefaultNamespace + "}." + pub.fastCSharp + ".cs");
                            if (WriteFile(fileName, WarningCode + code + FileEndCode))
                            {
                                isFastCSharp = true;
                                message      = fileName + " 被修改";
                            }
                        }
                        if (rememberCodeBuilder != null && (code = rememberCodeBuilder.ToString()).length() != 0)
                        {
                            string fileName = parameter.ProjectPath + (rememberFileName = "{" + parameter.DefaultNamespace + "}.remember." + pub.fastCSharp + ".cs");
                            if (WriteFile(fileName, WarningCode + code + FileEndCode))
                            {
                                isRemember = true;
                                message   += @"
" + fileName + " 被修改";
                            }
                        }
                        if (parameter.IsFastCSharp && (isFastCSharp | isRemember))
                        {
                            string projectFile = parameter.AssemblyPath + parameter.ProjectName + ".csproj";
                            if (File.Exists(projectFile))
                            {
                                string projectXml = File.ReadAllText(projectFile, System.Text.Encoding.UTF8);
                                if (isFastCSharp)
                                {
                                    fastCSharpFileName = @"<Compile Include=""" + fastCSharpFileName + @""" />";
                                }
                                if (isRemember)
                                {
                                    rememberFileName = @"<Compile Include=""" + rememberFileName + @""" />";
                                }
                                int fileIndex;
                                if (isFastCSharp && (fileIndex = projectXml.IndexOf(fastCSharpFileName)) != -1)
                                {
                                    if (isRemember && projectXml.IndexOf(rememberFileName) == -1)
                                    {
                                        projectXml = projectXml.Insert(fileIndex + fastCSharpFileName.Length, @"
    " + rememberFileName);
                                        MoveFile(projectFile, projectXml);
                                    }
                                    break;
                                }
                                if (isRemember && (fileIndex = projectXml.IndexOf(rememberFileName)) != -1)
                                {
                                    if (isFastCSharp && projectXml.IndexOf(fastCSharpFileName) == -1)
                                    {
                                        projectXml = projectXml.Insert(fileIndex + rememberFileName.Length, @"
    " + fastCSharpFileName);
                                        MoveFile(projectFile, projectXml);
                                    }
                                    break;
                                }
                                string csFileName = @".cs"" />
";
                                if ((fileIndex = projectXml.IndexOf(csFileName)) != -1)
                                {
                                    if (isFastCSharp)
                                    {
                                        fastCSharpFileName += @"
    ";
                                        if (isRemember)
                                        {
                                            fastCSharpFileName += rememberFileName + @"
    ";
                                        }
                                    }
                                    else
                                    {
                                        fastCSharpFileName = rememberFileName + @"
    ";
                                    }
                                    projectXml = projectXml.Insert(fileIndex + csFileName.Length, fastCSharpFileName);
                                    MoveFile(projectFile, projectXml);
                                }
                            }
                        }
                        break;
                    }
                }
            }
            if (message.Length != 0)
            {
                fastCSharp.log.Default.ThrowReal(message, new System.Diagnostics.StackFrame(), false);
            }
        }