private void RunTaskOutProcess(TaskPlugin plugin, string taskToken) { string waitHandleId = Guid.NewGuid().ToString(); EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, waitHandleId); Task.Factory.StartNew(() => { string address = string.Format(longRunningTaskAddressBase, taskToken); #if GISEditorUnitTest string exePath = Assembly.GetExecutingAssembly().Location; #else string exePath = Assembly.GetEntryAssembly().Location; #endif string exeDirectory = Path.GetDirectoryName(exePath); ProcessStartInfo info = new ProcessStartInfo { CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, Arguments = string.Format(CultureInfo.InvariantCulture, argumentFormatString, waitHandleId, address, callBackReceiverAddress, taskToken), WorkingDirectory = exeDirectory, FileName = "GisEditorTaskHost" }; Process hostProcess = Process.Start(info); waitHandle.WaitOne(); EndpointAddress endpointAddress = new EndpointAddress(string.Format(CultureInfo.InvariantCulture, longRunningTaskAddressBase, taskToken)); NetNamedPipeBinding binding = new NetNamedPipeBinding(); binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue; binding.ReaderQuotas.MaxDepth = int.MaxValue; binding.ReaderQuotas.MaxStringContentLength = int.MaxValue; binding.ReaderQuotas.MaxArrayLength = int.MaxValue; binding.ReceiveTimeout = TimeSpan.MaxValue; binding.MaxReceivedMessageSize = int.MaxValue; ITaskHost host = ChannelFactory <ITaskHost> .CreateChannel(binding, endpointAddress); IContextChannel channel = (IContextChannel)host; channel.OperationTimeout = TimeSpan.MaxValue; try { string tempParameterPathFileName = Path.Combine(GisEditor.InfrastructureManager.TemporaryPath, "TaskParameters", taskToken + ".setting"); string tempParameterPathName = Path.GetDirectoryName(tempParameterPathFileName); if (File.Exists(tempParameterPathFileName)) { File.Delete(tempParameterPathFileName); } else if (!Directory.Exists(tempParameterPathName)) { Directory.CreateDirectory(tempParameterPathName); } using (var pluginStream = new MemoryStream()) { BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(pluginStream, plugin); File.WriteAllBytes(tempParameterPathFileName, pluginStream.ToArray()); } if (File.Exists(tempParameterPathFileName)) { host.RunTask(Encoding.UTF8.GetBytes(tempParameterPathFileName)); } } catch (Exception e) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, e.Message, new ExceptionInfo(e)); } }); }
public InProcessTaskInfo(TaskPlugin taskPlugin, string taskToken, TaskCommand taskCommand) { TaskCommand = taskCommand; TaskToken = taskToken; TaskPlugin = taskPlugin; }
/// <summary> /// Runs the task. /// </summary> /// <param name="taskPlugin">The task plugin.</param> /// <returns></returns> public string RunTask(TaskPlugin taskPlugin) { StartCallBackReceiverService(); return(RunTaskCore(taskPlugin)); }