/// <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 (setup.methodInfo methodInfo in setup.methodInfo.GetMethods<testCase>(type, memberFilter.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) { setup.error.Message(error.ToString()); } } } } } } return isTest; } return false; }
/// <summary> /// 预定义生成 /// </summary> /// <param name="parameter">安装参数</param> public static void Setup(auto.parameter parameter) { try { string csproj = parameter.ProjectPath + "fastCSharp.csproj"; if (File.Exists(csproj)) { list<htmlNode> nodes = new htmlNode(File.ReadAllText(csproj)).Path(@"TargetFrameworkVersion"); if (nodes != null) { string define = null; foreach (htmlNode node in nodes) { string version = nodes[0].Text.Trim(); if (version.Length > 1 && version[0] == 'v') { int leftVersion, dotIndex = version.IndexOf('.'); if (int.TryParse(dotIndex != -1 ? version.Substring(1, dotIndex - 1) : version.Substring(1), out leftVersion)) { define = @" "; if (leftVersion == 3 ? dotIndex != -1 && ++dotIndex != version.Length && version[dotIndex] >= '5' : leftVersion > 3) { define = @" #define DOTNET35 "; } break; } } error.Add("不可识别的 TargetFrameworkVersion : " + version); } if (define != null) { foreach (string file in Directory.GetFiles(parameter.ProjectPath, "*.cs", SearchOption.AllDirectories)) { if (file.IndexOf('@') == -1) { string code = File.ReadAllText(file); if (code.StartsWith(defineStart, StringComparison.Ordinal) && !new subString(code, defineStart.Length).StartsWith(define + defineEnd)) { int endIndex = code.IndexOf(defineEnd); if (endIndex != -1) { cSharp.coder.MoveFile(file, defineStart + define + defineEnd + code.Substring(endIndex + defineEnd.Length)); } else error.Add(file + " 没有找到结束符 " + defineEnd); } } } return; } } error.Add("没有找到 TargetFrameworkVersion"); } else error.Add("没有找到项目文件"); } catch (Exception error) { setup.error.Add(error); } finally { error.Open(true); } }
/// <summary> /// 安装 /// </summary> /// <param name="autos">安装类型属性</param> /// <param name="parameter">安装参数</param> /// <returns>安装是否成功</returns> internal static bool Setup(ICollection<keyValue<Type, auto>> autos, auto.parameter parameter, bool isConfig) { bool isSetup = true; if (autos != null) { try { 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.Default.LoadConfig(parameter.Copy(), type.ToString()) : parameter)) { error.Add(type.fullName() + " 安装失败"); isSetup = false; } //time.Stop(); //error.Message(parameter.ProjectName + " " + type.FullName + " : " + time.ElapsedMilliseconds.ToString() + "ms"); } } finally { cSharp.coder.Output(parameter); } } return isSetup; }