public static RdTask <T> ToRdTask <T>(this IRdTask <T> task, Lifetime lifetime) { if (task is RdTask <T> rdTask) { return(rdTask); } var newRdTask = new RdTask <T>(); task.Result.Advise(lifetime, result => { switch (result.Status) { case RdTaskStatus.Success: newRdTask.Set(result.Result); break; case RdTaskStatus.Canceled: newRdTask.SetCancelled(); break; case RdTaskStatus.Faulted: newRdTask.Set(result.Error); break; } }); return(newRdTask); }
private static void AdviseRunMethod(EditorPluginModel model) { model.RunMethodInUnity.Set((lifetime, data) => { var task = new RdTask <RunMethodResult>(); MainThreadDispatcher.Instance.Queue(() => { if (!lifetime.IsAlive) { task.SetCancelled(); return; } try { ourLogger.Verbose($"Attempt to execute {data.MethodName}"); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); var assembly = assemblies .FirstOrDefault(a => a.GetName().Name.Equals(data.AssemblyName)); if (assembly == null) { throw new Exception($"Could not find {data.AssemblyName} assembly in current AppDomain"); } var type = assembly.GetType(data.TypeName); if (type == null) { throw new Exception($"Could not find {data.TypeName} in assembly {data.AssemblyName}."); } var method = type.GetMethod(data.MethodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (method == null) { throw new Exception($"Could not find {data.MethodName} in type {data.TypeName}"); } try { method.Invoke(null, null); } catch (Exception e) { Debug.LogException(e); } task.Set(new RunMethodResult(true, string.Empty, string.Empty)); } catch (Exception e) { ourLogger.Log(LoggingLevel.WARN, $"Execute {data.MethodName} failed.", e); task.Set(new RunMethodResult(false, e.Message, e.StackTrace)); } }); return(task); }); }
public AwsProjectHost(ISolution solution) { var model = solution.GetProtocolSolution().GetAwsProjectModel(); model.GetProjectOutput.Set((lifetime, request) => { var task = new RdTask <AwsProjectOutput>(); var assemblyPathPrefix = FileSystemPath.Parse(request.ProjectPath); using (ReadLockCookie.Create()) { var allProjects = solution.GetAllProjects(); foreach (var project in allProjects) { var targetFrameworks = project.GetAllTargetFrameworks(); foreach (var targetFramework in targetFrameworks) { var assembly = project.GetOutputAssemblyInfo(targetFramework.FrameworkId); if (assembly == null) { continue; } if (assembly.Location.FullPath.StartsWith(assemblyPathPrefix.FullPath)) { task.Set(new AwsProjectOutput(assembly.AssemblyNameInfo.Name, assembly.Location.FullPath)); return(task); } } } task.SetCancelled(); return(task); } }); }