/// <summary> /// 注册处理Item的Process /// </summary> /// <param name="serviceName"></param> /// <param name="itemName"></param> /// <param name="process"></param> public void RegisterRelation(string serviceName, string itemName, IProcess process) { processes.Add(process); if (serviceName != null || serviceName.Trim().Length != 0) { relations.Add(serviceName, itemName, process.Name); } }
public IDataProcess GetOneInstance(string name, bool isAddToList = true, bool newOne = false, bool isAddUI = false) { if (newOne) { var process = PluginProvider.GetObjectByType <IDataProcess>(name); if (process != null) { if (isAddToList) { ProcessCollection.Add(process); process.SysDataManager = dataManager; process.SysProcessManager = this; var rc4 = process as AbstractProcessMethod; if (rc4 != null) { rc4.MainPluginLocation = MainFrmUI.MainPluginLocation; rc4.MainFrm = MainFrmUI; } XLogSys.Print.Info("已经成功添加" + process.TypeName + "到当前列表"); } if (isAddUI) { ControlExtended.UIInvoke(() => LoadProcessView(process)); ControlExtended.UIInvoke(() => ShowConfigUI(process)); } return(process); } } return(ProcessCollection.Get(name, isAddToList)); }
public static void RefreshProcessCollection() { foreach (Process process in Process.GetProcesses()) { if (!IsProcessIDInCollection(process.Id) && (process.MainWindowHandle != IntPtr.Zero)) { ProcessItem item = new ProcessItem(process); _processList.Add(item); if (ProcessItemAdded != null) { ProcessItemAdded(null, new ProcessManagerEventArgs(item)); } } } for (int i = 0; i < _processList.Count; i++) { ProcessItem item = _processList[i]; try { item.Process.Refresh(); if (item.Process.HasExited) { _processList.Remove(item); if (ProcessItemRemoved != null) { ProcessItemRemoved(null, new ProcessManagerEventArgs(item)); } item.Dispose(); } } catch (Exception) { } } }
protected override void AddProcess(Message message) { if (message != null) { String[] dataArray = message.Text.Split(';'); int processID; if (dataArray.Count() >= 2 && Int32.TryParse(dataArray[0], out processID)) { ProcessPrototype process = ProcessCollection.FirstOrDefault(x => x.ID == processID); if (process == null) { process = new ProcessPrototype(processID, dataArray[1]); Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(() => { ProcessCollection.Add(process); })); Connection.Send(Connection.Socket, new Message(MessageTypes.REQUEST_NEXT_PROCESS, process.ID.ToString())); } } } }
private void OnProcessEnum(string rsp) { var list = JsonConvert.DeserializeObject <List <WinProcessModel> >(rsp); if (ProcessCollection != null) { ProcessCollection.Clear(); foreach (var obj in list) { var process = Tuple.Create <uint, string>(obj.ProcessId, obj.Name); ProcessCollection.Add(process); } } }
private void OnProcessEnum(CommandMessageRsp rsp) { if (rsp.RspType == CommandMessageRsp.StringDataType) { var list = JsonConvert.DeserializeObject <List <WinProcessModel> >(rsp.StringCommandRsp); if (ProcessCollection != null) { ProcessCollection.Clear(); foreach (var obj in list) { var process = Tuple.Create <uint, string>(obj.ProcessId, obj.Name); ProcessCollection.Add(process); } } } }
public void Analysis_Abutment() { string ana_file = Path.Combine(Get_Project_Folder(), "Abutment_Analysis_Input.txt"); string kStr = ""; List <string> list = new List <string>(); int i = 0; list.Add("ASTRA FLOOR RCC T GIRDER BRIDGE DECK ANALYSIS"); list.Add("UNIT METER MTON"); list.Add("JOINT COORDINATES"); List <JointNode> Joints = new List <JointNode>(); List <Member> MemColls = new List <Member>(); double L = MyList.StringToDouble(txt_Ana_L.Text, 0.0); double og = MyList.StringToDouble(txt_Ana_og.Text, 0.0); double inc = (L - og * 2) / 4.0; double ws = 2.0 - og; JointNode jn = new JointNode(); jn.NodeNo = 1; jn.X = 0.0; Joints.Add(jn); jn = new JointNode(); jn.NodeNo = 2; jn.X = og + og; Joints.Add(jn); jn = new JointNode(); jn.NodeNo = 3; jn.X = og + ws; Joints.Add(jn); jn = new JointNode(); jn.NodeNo = 4; jn.X = og + inc; Joints.Add(jn); jn = new JointNode(); jn.NodeNo = 5; jn.X = og + 2 * inc; Joints.Add(jn); jn = new JointNode(); jn.NodeNo = 6; jn.X = og + 3 * inc; Joints.Add(jn); jn = new JointNode(); jn.NodeNo = 7; jn.X = L - (og + ws); Joints.Add(jn); jn = new JointNode(); jn.NodeNo = 8; jn.X = og + 4 * inc; Joints.Add(jn); jn = new JointNode(); jn.NodeNo = 9; jn.X = L; Joints.Add(jn); Member mbr = new Member(); mbr.MemberNo = 1; mbr.StartNode = Joints[0]; mbr.EndNode = Joints[1]; MemColls.Add(mbr); for (i = 2; i < Joints.Count; i++) { mbr = new Member(); mbr.MemberNo = i; mbr.StartNode = Joints[i - 1]; mbr.EndNode = Joints[i]; MemColls.Add(mbr); } for (i = 0; i < Joints.Count; i++) { list.Add(Joints[i].ToString()); } list.Add("MEMBER INCIDENCES"); for (i = 0; i < MemColls.Count; i++) { list.Add(MemColls[i].ToString()); } list.Add("SECTION PROPERTIES"); ////list.Add("1 2 5 6 AX"); ////list.Add(string.Format("1 2 6 7 PRIS AX 0.036212 IX 0.00001 IY 0.000697 IZ 0.001", //list.Add(string.Format("1 2 7 8 PRIS AX {0} IX 0.00001 IY {1} IZ 0.001", // txt_smp_i_a_sup.Text, // txt_smp_i_Ix_sup.Text // )); //list.Add(string.Format("3 TO 6 PRIS AX {0} IX 0.00001 IY {1} IZ 0.001", // txt_smp_i_a_mid.Text, // txt_smp_i_ix_mid.Text // )); list.Add(string.Format("MATERIAL CONSTANT")); list.Add(string.Format("E 2.85E6 ALL")); list.Add(string.Format("DENSITY CONCRETE ALL")); list.Add(string.Format("POISSON CONCRETE ALL")); list.Add(string.Format("SUPPORT")); //list.Add(string.Format("2 6 PINNED")); list.Add(string.Format("2 8 FIXED BUT FX MZ")); //list.Add(string.Format("99 100 101 102 FIXED BUT FX MZ")); //list.Add(string.Format("LOAD 1 DEAD LOAD")); //list.Add(string.Format("MEMBER LOAD")); //list.Add(string.Format("1 2 7 8 UNI GY -{0:f4}", MyList.StringToDouble(txt_Ana_DL_supp.Text, 0.0)/10.0)); //list.Add(string.Format("3 TO 6 UNI GY -{0}", MyList.StringToDouble(txt_Ana_DL_mid.Text, 0.0)/10.0)); //list.Add(string.Format("LOAD 2 SIDL")); //list.Add(string.Format("MEMBER LOAD")); //list.Add(string.Format("1 TO 8 UNI GY -{0}", MyList.StringToDouble(txt_Ana_SIDL.Text, 0.0) / 10.0)); //list.Add(string.Format("LOAD 3 FPLL")); //list.Add(string.Format("MEMBER LOAD")); //list.Add(string.Format("1 TO 8 UNI GY -{0}", MyList.StringToDouble(txt_Ana_FPLL.Text, 0.0)/10.0)); //list.Add(string.Format("PRINT SUPPORT REACTIONS")); //list.Add(string.Format("PERFORM ANALYSIS")); //list.Add(string.Format("FINISH")); File.WriteAllLines(ana_file, list.ToArray()); MessageBox.Show("Input Data Created as " + ana_file, "ASTRA"); #region Process try { #region Process //int i = 0; ProcessCollection pcol = new ProcessCollection(); ProcessData pd = new ProcessData(); string flPath = ana_file; iapp.Progress_Works.Clear(); if (File.Exists(flPath)) { pd = new ProcessData(); pd.Process_File_Name = flPath; pd.Process_Text = "PROCESS ANALYSIS FOR " + Path.GetFileNameWithoutExtension(flPath).ToUpper(); pcol.Add(pd); iapp.Progress_Works.Add("Reading Analysis Data from " + Path.GetFileNameWithoutExtension(flPath).ToUpper() + " (ANALYSIS_REP.TXT)"); } i++; string ana_rep_file = Path.Combine(Path.GetDirectoryName(flPath), "ANALYSIS_REP"); if (iapp.Show_and_Run_Process_List(pcol)) { BridgeMemberAnalysis DeadLoad_Analysis = new BridgeMemberAnalysis(iapp, ana_rep_file); } #endregion Process } catch (Exception ex) { } #endregion Process }
public override bool Execute() { if (System.Type.GetType("Mono.Runtime") != null) // Don't execute under Mono. { Log.LogMessage(MessageImportance.High, "The GenerateWebProxies task doesn't run under Mono."); return(true); } if ((Files == null || (Urls == null && Sources == null)) && SourceProject == null) { return(true); } var tool = ToolExe; if (tool == null) { Log.LogError("GenerateWebProxies: Cannot find " + (WCF ? "svcutil.exe" : "wsdl.exe") + ", please install Windows SDK."); } var projTime = string.IsNullOrEmpty(Project) ? DateTime.MinValue : File.GetLastWriteTimeUtc(Project); DateTime[] sourceTimes = null; IisExpress.SSL = SSL; var iisport = IisExpress.RandomPort; var useIisExpress = Urls == null; var newiis = false; if (Urls == null || AutoRest || Swagger) { var site = Path.GetFullPath(SourceProject).Trim('\\'); newiis = IisExpress.SiteFolder != site || !IisExpress.IsStarted; if (newiis) { IisExpress.SiteFolder = site; } } if (!newiis) { iisport = IisExpress.Port.Value; } var ServerUrl = (SSL ? "https" : "http") + "://localhost:" + iisport.ToString() + "/"; if (Urls == null) { if (!AutoRest && !Swagger) { Sources = Sources ?? Directory.EnumerateFiles(SourceProject, WCF ? "*.svc" : "*.asmx", SearchOption.AllDirectories) .Where(p => !(Exclude?.Any(x => x.ItemSpec == p) ?? false)) .Select(path => new TaskItem(path)).ToArray(); Urls = Sources.Select(src => new TaskItem(ServerUrl + src.ItemSpec.Substring(SourceProject.Length).Trim('\\', '/', ' ').Replace('\\', '/') /*+ (WCF ? "?wsdl" : "") */)) .ToArray(); var files = Sources.Select(src => new TaskItem(Path.ChangeExtension(src.ItemSpec.Substring(SourceProject.Length), (FileSuffix ?? Type.ToString()) + "." + Language.ToLower()))) .ToDictionary(src => src.ItemSpec); if (Files == null) { Files = files.Values.ToArray(); } else { var items = Files.ToDictionary(f => f.ItemSpec); Files = files.Values.Select(f => items.ContainsKey(f.ItemSpec) ? items[f.ItemSpec] : f).ToArray(); } var regex = new Regex(@"<%@ (?:WebService|ServiceHost).*?(?:CodeBehind|CodeFile)\s*=\s*(?:(?:""(?<code>[^""]*)"")|(?:'(?<code>[^']*)')).*?%>"); sourceTimes = Sources.Select(src => { // get times of svc or asmx C# source files var sourceInfo = new FileInfo(src.ItemSpec); if (sourceInfo.Exists) { var m = regex.Match(File.ReadAllText(src.ItemSpec)); var t = sourceInfo.LastWriteTimeUtc; if (m.Success) { var codeInfo = new FileInfo(Path.Combine(Path.GetDirectoryName(src.ItemSpec), m.Groups["code"].Value)); var codet = codeInfo.Exists ? codeInfo.LastWriteTimeUtc : DateTime.MinValue; return(codet > t ? codet : t); } } return(DateTime.MinValue); }).ToArray(); } } var output = new List <TaskItem>(); var processes = new ProcessCollection(); var startTime = DateTime.UtcNow; var wait = new ManualResetEvent(false); var iisstarted = false; var anyprocesses = false; System.Net.ServicePointManager.DefaultConnectionLimit = 9999; var serverError = false; if (!AutoRest && !Swagger) { System.Threading.Tasks.Parallel.For(0, Urls.Length, i => { //for (int i = 0; i < Urls.Length; i++) { try { var meta = Files[i].GetMetadata(Meta); if (!string.IsNullOrEmpty(Meta) && !string.IsNullOrEmpty(meta) && meta != "false") { return; } var url = Urls[i].ItemSpec; var file = Files[i].ItemSpec; var src = Sources?[i].ItemSpec; var ns = Files[i].GetMetadata("Namespace"); if (string.IsNullOrEmpty(ns)) { ns = Namespace; } var config = Config != null ? $"/config:{Config} /mergeConfig " : ""; var serializer = Serializer != null ? $"/serializer:{Serializer} " : ""; var useSerializerForFaults = Serializer != null && UseSerializerForFaults ? $"/useSerializerForFaults " : ""; var async = Async ? "/async " : "/syncOnly "; string reference = ""; if (Reference != null) { var refs = Reference.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()); var str = new StringBuilder(); foreach (var r in refs) { str.Append("\"/r:"); str.Append(Path.GetFullPath(r)); str.Append("\" "); } reference = str.ToString(); } var targetVersion = TargetClientVersion != null ? $"/targetClientVersion:{TargetClientVersion} " : ""; var importXmlTypes = ImportXmlTypes ? "/importXmlTypes " : ""; var dataContractOnly = DataContractOnly ? "/dataContractOnly " : ""; var serviceContract = ServiceContract ? "/serviceContract " : ""; var enableDataBinding = EnableDataBinding ? "/enableDataBinding " : ""; string excludeType = ""; if (ExcludeType != null) { var types = ExcludeType.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()); var str = new StringBuilder(); foreach (var t in types) { str.Append("\"/et:"); str.Append(Path.GetFullPath(t)); str.Append("\" "); } excludeType = str.ToString(); } var _internal = Internal ? "/internal " : ""; var mergeConfig = MergeConfig ? "/mergeConfig " : ""; var noConfig = NoConfig ? "/noConfig " : ""; var noStdLib = NoStdLib ? "/noStdLib " : ""; var arg = WCF ? $"/t:code /out:{file} /namespace:{ns} /language:{Language} {config}{serializer}{useSerializerForFaults}{async}{targetVersion}{importXmlTypes}{reference}{dataContractOnly}{serviceContract}{enableDataBinding}{excludeType}{_internal}{mergeConfig}{noConfig}{noStdLib}{url}" : $"/out:{file} /namespace:{ns} /language:{Language} /protocol:{Protocol}" + (WSE ? " /type:" + (type == Types.WseSoapClient ? "soapClient" : "webClient") : (type == Types.Client ? "" : (type == Types.Server ? " /server" : " /serverInterface"))) + (Sharetypes ? " /sharetypes" : "") + " " + url; var fileInfo = new FileInfo(file); var fileTime = fileInfo.LastWriteTimeUtc; var sourceTime = sourceTimes[i]; if (src == null || !fileInfo.Exists || fileTime < projTime || fileTime < sourceTime) { lock (this) { if (useIisExpress && !iisstarted) { iisstarted = true; if (newiis) { IisExpress.Stop(); IisExpress.Start(iisport); var web = new WebClient(); try { serverError = (web.DownloadString(url) == null); } catch (Exception ex) { serverError = true; } } } } if (serverError) { Log.LogError("Server still has errors."); return; } var wsdlstart = new ProcessStartInfo(tool) { UseShellExecute = false, WorkingDirectory = Environment.CurrentDirectory, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardOutput = true, Arguments = arg }; var p = new Process(); p.StartInfo = wsdlstart; p.EnableRaisingEvents = true; p.Exited += (sender, a) => { var any = !Terminated(p, processes, false); ProcessInfo[] infos; lock (processes) infos = processes.ToArray(); foreach (var info in infos) { any |= !Terminated(info.Process, processes, false); } if (!any) { wait.Set(); } }; lock (processes) processes.Add(new ProcessInfo { Process = p, File = file, Url = url, Args = arg }); lock (output) output.Add(new TaskItem(Files[i])); anyprocesses = true; p.Start(); } } catch (Exception ex) { Log.LogErrorFromException(ex); } }); //foreach (var p in processes.ToArray()) p.Start(); if (anyprocesses && !wait.WaitOne(Timeout * 1000)) { ProcessInfo[] infos; lock (processes) infos = processes.ToArray(); foreach (var info in infos) { if (!info.Process.HasExited) { info.Process.Kill(); } Terminated(info.Process, processes, true); } } } else { var swaggerdocsurl = SwaggerUrl ?? (ServerUrl + "/swagger/docs/" + (ApiVersion ?? "v1")); serverError = false; if (AutoRest || SwaggerUrl == null) { if (newiis) { IisExpress.Stop(); IisExpress.Start(iisport); iisstarted = true; var web = new WebClient(); try { serverError = (web.DownloadString(ServerUrl) == null); } catch { serverError = true; } if (serverError) { Log.LogError($"Server still has errors: {ServerUrl}."); return(false); } } } var swaggerjson = new WebClient().DownloadString(swaggerdocsurl); var jsonfile = Path.Combine(OutputDirectory, "swagger.json"); if (!File.Exists(jsonfile) || File.ReadAllText(jsonfile) != swaggerjson) { if (Directory.Exists(OutputDirectory)) { Directory.Delete(OutputDirectory, true); } Directory.CreateDirectory(OutputDirectory); File.WriteAllText(jsonfile, swaggerjson); if (AutoRest) { // AutoRest var outdir = OutputDirectory != null ? $"-OutputDirectory \"{OutputDirectory}\" " : ""; var codegen = CodeGenerator != null ? $"-CodeGenerator {CodeGenerator} " : ""; var modeler = Modeler != null ? $"-Modeler {Modeler} " : ""; var clientname = ClientName != null ? $"-ClientName {ClientName} " : ""; var payloadthrs = PayloadFlatteningTreshold != null ? $"-PayloadFlatteningThreshold {PayloadFlatteningTreshold} " : ""; var header = Header != null ? $"-Header \"{Header}\" " : ""; var credentials = AddCredentials != null ? $"-AddCredentials {AddCredentials} " : ""; var outfile = OutputFileName != null ? $"-OutputFileName \"{OutputFileName}\" " : ""; var verbose = Verbose ? $"-Verbose " : ""; var settings = CodeGenSettings != null ? $"-CodeGenSettings \"{CodeGenSettings}\"" : ""; var args = $"{outdir}{codegen}{modeler}{clientname}{payloadthrs}{header}{credentials}{outfile}{verbose}{settings}".Trim(); Process.Start(ToolExe, args); } else if (Swagger) { try { var codegenurl = "http://generator.swagger.io/api/gen/clients/" + (Language ?? "typescript-angular2"); var body = new StringWriter(); body.Write("{\"spec\": "); body.Write(swaggerjson); body.Write(",\"swaggerUrl\":null"); if (Options != null) { body.Write($",\"options\":{Options}"); } if (Authorization != null) { body.Write($",\"authorizationValue\":{Authorization}"); } if (Security != null) { body.Write($",\"securityDefinition\": {Security}"); } body.Write("}"); var gen = (HttpWebRequest)WebRequest.Create(codegenurl); gen.Method = "POST"; gen.ContentType = "application/json"; gen.Accept = "application/json"; gen.ProtocolVersion = HttpVersion.Version11; var buf = Encoding.UTF8.GetBytes(body.ToString()); gen.ContentLength = buf.Length; var w = gen.GetRequestStream(); w.Write(buf, 0, buf.Length); w.Close(); var res = (HttpWebResponse)gen.GetResponse(); var r = new StreamReader(res.GetResponseStream(), Encoding.UTF8); dynamic result = SimpleJson.DeserializeObject(r.ReadToEnd()); var rawzip = new WebClient().DownloadData(result.link); var zipfile = Path.Combine(OutputDirectory, "swagger.zip"); File.WriteAllBytes(zipfile, rawzip); var zip = new Ionic.Zip.ZipFile(zipfile); zip.ExtractAll(OutputDirectory); } catch (Exception ex) { Log.LogErrorFromException(ex); return(false); } } var odir = Path.Combine(Environment.CurrentDirectory, OutputDirectory); output.AddRange( Directory.EnumerateFiles(OutputDirectory) .Select(file => new TaskItem { ItemSpec = file.StartsWith(odir) ? file.Substring(odir.Length).Trim('\\') : file })); } } //if (iisstarted) IisExpress.Stop(); Output = output.ToArray(); return(!Log.HasLoggedErrors); }