private void DoTaskInternal() { Debug.Assert(_taskDoneEvent != null); Action finalAction; if (!IsDisposed) { object result = null; try { result = _taskAction(); } catch (Exception ex) { Debug.Fail(String.Format(CultureInfo.CurrentCulture, "Background task exception: {0}.\nInner exception: {1}\nInner exception callstack: {2}", ex.Message, ex.InnerException != null ? ex.InnerException.Message : "(none)", ex.InnerException != null ? ex.InnerException.StackTrace : "(none)")); result = ex; } finally { finalAction = () => UIThreadCompletedCallback(result); } } else { finalAction = () => UIThreadCanceledCallback(null); } _taskDoneEvent.Set(); EditorShell.DispatchOnUIThread(finalAction); }
public static void DockerComposeUp() { ZOSettings settings = ZOSettings.GetOrCreateSettings(); // Navigate to parent directories where the docker and dockercompose files are located var options = new EditorShell.Options() { workDirectory = settings.ComposeWorkingDirectory, environmentVars = new Dictionary <string, string>() { } }; // need to set environment variable so that we execute container as current user in host machine string command = "CURRENT_UID=$(id -u):$(id -g) docker-compose up"; // Execute docker command var task = EditorShell.Execute(command, options); DockerLog($"Starting docker container, please wait..."); task.onLog += (EditorShell.LogType logType, string log) => { DockerLog(log); }; task.onExit += (exitCode) => { if (exitCode == 0) { // we won't get this until the server is stopped } DockerLog($"Docker compose up exit: {exitCode}", forceDisplay: true); }; // TODO: poll to check if the server was started successfully // here we assume it will isRunning = true; }
public Editor(EditorShell shell) : base(shell) { InitializeComponent(); SetupKeyboard(); }
private async Task <int> ExecuteShellAsync(string cmd) { var task = EditorShell.Execute(cmd, new EditorShell.Options()); int code = await task; return(code); }
public static Task <bool> IsZODockerRunning() { ZOSettings settings = ZOSettings.GetOrCreateSettings(); var options = new EditorShell.Options() { workDirectory = settings.ComposeWorkingDirectory, environmentVars = new Dictionary <string, string>() { } }; // Create a task and return it so clients can use async/await // Use TaskCompletionSource so that we can manually fulfill the task when // the shell script executes the onExit callback TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>(); string command = "if [ $(docker inspect -f '{{.State.Running}}' zosim) = \"true\" ]; then exit 0; else exit 1; fi"; // Execute docker command var shellTask = EditorShell.Execute(command, options); DockerLog($"Checking if docker running..."); shellTask.onLog += (EditorShell.LogType logType, string log) => { DockerLog(log); }; shellTask.onExit += (exitCode) => { UnityEngine.Debug.Log("Check if docker running exit code: " + exitCode); isRunning = exitCode == 0; taskCompletionSource.SetResult(isRunning); }; return(taskCompletionSource.Task); }
/// <summary> /// Determine if docker is installed. /// </summary> /// <returns></returns> public static Task <bool> IsZODockerInstalled() { var options = new EditorShell.Options() { workDirectory = Application.dataPath }; // Create a task and return it so clients can use async/await // Use TaskCompletionSource so that we can manually fulfill the task when // the shell script executes the onExit callback TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>(); string command = "docker --version && docker-compose --version"; // Execute docker command var shellTask = EditorShell.Execute(command, options); DockerLog($"Checking if docker installed..."); shellTask.onLog += (EditorShell.LogType logType, string log) => { //DockerLog(log); }; shellTask.onExit += (exitCode) => { //DockerLog("Check if docker installed exit code: " + exitCode); isInstalled = exitCode == 0; taskCompletionSource.SetResult(isInstalled); }; return(taskCompletionSource.Task); }
public static void DockerComposeDown() { ZOSettings settings = ZOSettings.GetOrCreateSettings(); // Navigate to parent directories where the docker and dockercompose files are located var options = new EditorShell.Options() { workDirectory = settings.ComposeWorkingDirectory, environmentVars = new Dictionary <string, string>() { } }; string command = "docker-compose down"; // Execute docker command var task = EditorShell.Execute(command, options); DockerLog($"Stopping Docker, please wait...", forceDisplay: true); task.onLog += (EditorShell.LogType logType, string log) => { DockerLog(log); }; task.onExit += (exitCode) => { DockerLog($"Docker compose down exit: {exitCode}", forceDisplay: true); }; isRunning = false; }
public IEnumerator KillAsyncOperation() { var operation = EditorShell.Execute("sleep 5", new EditorShell.Options()); KillAfter1Second(operation); var task = GetOperationTask(operation); yield return(new TaskYieldable <int>(task)); Debug.Log("exit with code = " + task.Result); Assert.True(task.Result == 137); }
public IEnumerator EchoHelloWorld() { var task = EditorShell.Execute("echo hello world", new EditorShell.Options()); task.onLog += (logType, log) => { Debug.Log(log); LogAssert.Expect(LogType.Log, "hello world"); }; task.onExit += (code) => { Debug.Log("Exit with code = " + code); Assert.True(code == 0); }; yield return(new ShellOperationYieldable(task)); }
private async Task InsertFunctionBraces(SnapshotPoint position, string name) { bool function = await IsFunction(name); if (function) { EditorShell.DispatchOnUIThread(() => { if (TextView.TextBuffer.CurrentSnapshot.Version.VersionNumber == position.Snapshot.Version.VersionNumber) { TextView.TextBuffer.Insert(position.Position, "()"); TextView.Caret.MoveTo(new SnapshotPoint(TextView.TextBuffer.CurrentSnapshot, position.Position + 1)); EditorShell.DispatchOnUIThread(() => TriggerSignatureHelp()); } }); } }
public EditorDockContent(EditorShell shell) { // Stash the Shell instance for later use Shell = shell; if (shell == null) { return; } // Register to watch for the document changed event and just call to the virtual // function so it can easily be handled. Shell.ActiveDocumentChanged += (object sender, ActiveDocumentEventArgs args) => { OnActiveDocumentChanged(args.Document); }; }
protected void SubmitToInteractive(string command, CancellationToken cancellationToken) { var sessionProvider = EditorShell.Current.ExportProvider.GetExportedValue <IRSessionProvider>(); var session = sessionProvider.GetOrCreate(GuidList.InteractiveWindowRSessionGuid); if (session != null && session.IsHostRunning) { _runningAction = Task.Run(async() => { try { using (var eval = await session.BeginInteractionAsync(isVisible: true, cancellationToken: cancellationToken)) { await eval.RespondAsync(command); } } finally { EditorShell.DispatchOnUIThread(() => _runningAction = null); } }); _runningAction.SilenceException <OperationCanceledException>() .SilenceException <MessageTransportException>(); } }
public static void Main(string[] argv) { Program app = new Program("sampleapp", "0.0.1", Modules.UI, argv); Glade.XML gxml = new Glade.XML(null, "sample.glade", "preferences_dialog", null); gxml.Autoconnect(new X()); Settings.Changed += new NotifyEventHandler(Changed); EditorShell shell = new EditorShell(gxml); shell.Add(SettingKeys.Enable, "enable"); shell.Add(SettingKeys.TheFilename, "fileentry"); shell.Add(SettingKeys.TheInteger, "spinbutton_int"); shell.Add(SettingKeys.TheFloat, "spinbutton_float"); shell.Add(SettingKeys.TheFirstEnum, "optionmenu", typeof(Names)); shell.Add(SettingKeys.TheSecondEnum, "radiobutton", typeof(Direction)); shell.Add(SettingKeys.TheText, "entry"); shell.AddGuard(SettingKeys.Enable, "table1"); app.Run(); }
/// <summary> /// Install Docker. Note: Probably only works for Linux. /// </summary> public static void DockerInstall() { // Find Docker install script string[] installScriptAssets = AssetDatabase.FindAssets(installScriptAssetName); if (installScriptAssets.Length == 0) { EditorUtility.DisplayDialog("Error", "Couldn't find docker_install.sh among your assets. Have you imported ZeroSim samples already?", "Ok"); return; } string scriptPath = AssetDatabase.GUIDToAssetPath(installScriptAssets[0]); string directory = System.IO.Path.GetDirectoryName(scriptPath); UnityEngine.Debug.Log(directory); // Navigate to parent directories where the docker and dockercompose files are located var options = new EditorShell.Options() { workDirectory = directory }; string command = "./" + installScriptName; // Execute docker command var task = EditorShell.Execute(command, options); task.onLog += (EditorShell.LogType logType, string log) => { DockerLog(log); }; task.onExit += (exitCode) => { if (exitCode == 0) { isRunning = true; } DockerLog($"Install script exit code: {exitCode}", forceDisplay: true); }; }
/// <summary> /// Fetches help on the function from R asynchronously. /// When function data is obtained, parsed and the function /// index is updated, method invokes <see cref="infoReadyCallback"/> /// callback passing the specified parameter. Callback method can now /// fetch function information from the index. /// </summary> private static void GetFunctionInfoFromEngineAsync(string functionName, string packageName, Action <object> infoReadyCallback = null, object parameter = null) { _functionRdDataProvider.GetFunctionRdData( functionName, packageName, (string rdData) => { IReadOnlyList <IFunctionInfo> functionInfos = GetFunctionInfosFromRd(rdData); foreach (IFunctionInfo info in functionInfos) { _functionToInfoMap[info.Name] = info; } if (!_functionToInfoMap.ContainsKey(functionName)) { if (functionInfos.Count > 0) { // RD doesn't contain the requested function. // e.g. as.Date.character has RD for as.Date but not itself // without its own named info, this will request indefinitely many times // as workaround, add the first info with functionName _functionToInfoMap[functionName] = functionInfos[0]; } else { // TODO: add some stub function info here to prevent subsequent calls for the same function as we already know the call will fail. } } if (infoReadyCallback != null) { EditorShell.DispatchOnUIThread(() => { infoReadyCallback(parameter); }); } }); }
public EntityList(EditorShell shell) : base(shell) { InitializeComponent(); }
//string[] papersize = {"letter", "legal", "a4"}; //string[] modemType = {@"-j\Q4",@"-j\Q1",@"-j*F1",@"-j&H2&I0&R1&D3I4",@"-or"}; /* # FCINIT='-j\Q4' # AT&T (Dataport, Paradyne) # FCINIT='-j\Q1' # Motorola (Power Modem, 3400 Pro,...) # FCINIT='-j*F1' # QuickComm (Spirit II) # FCINIT='-j&H2&I0&R1&D3I4' # USR (Courier, Sportster) # FCINIT='-or' # Multi-Tech (for bit reversal) */ public GfaxPrefs() { gxml = new Glade.XML(null, "gfax.glade", "PrefsDialog", null); //GConf.PropertEditors EditorShell shell = new EditorShell(gxml); gxml.Autoconnect(this); // System Tab if (Settings.TransmitAgent == "hylafax") { HylafaxRadioButton.Active = true; CoverPageCheckButton.Visible = false; PrefsNotebook.GetNthPage(EFAX_PAGE).Hide(); } else if (Settings.TransmitAgent == "efax") { EfaxRadioButton.Active = true; EmailNotifyCheckButton.Sensitive = false; EmailAddressEntry.Sensitive = false; Settings.SendNow = SendNowCheckButton.Active; FaxLogCheckButton.Visible = false; CoverPageCheckButton.Visible = false; Settings.HiResolution = HiResCheckButton.Active; PrefsNotebook.GetNthPage(HYLAFAX_PAGE).Hide(); } // Set these regardless so they are set if we need them switch (Settings.EfaxPapersize) { case "letter": EfaxPapersizeComboBox.Active = 0; break; case "legal": EfaxPapersizeComboBox.Active = 1; break; case "a4": EfaxPapersizeComboBox.Active = 2; break; default: EfaxPapersizeComboBox.Active = 0; break; } //"-j\\Q4","-j\\Q1","-j*F1","-j&H2&I0&R1&D3I4","-or" switch (Settings.EfaxModemFcinit) { case @"-j\Q4": EfaxModemTypeComboBox.Active = 0; break; case @"-j\Q1": EfaxModemTypeComboBox.Active = 1; break; case @"-j*F1": EfaxModemTypeComboBox.Active = 2; break; case @"-j&H2&I0&R1&D3I4": EfaxModemTypeComboBox.Active = 3; break; case @"-or": EfaxModemTypeComboBox.Active = 4; break; default: EfaxModemTypeComboBox.Active = 5; break; } EfaxModemSpeakerVolumeComboBox.Active = Settings.EfaxModemSpeakerVolume; // changes that happen automagically shell.Add(SettingKeys.FaxNumber, "FaxNumberEntry"); shell.Add(SettingKeys.PhonePrefix, "DialPrefixEntry"); shell.Add(SettingKeys.FaxViewer, "FaxViewerEntry"); // Hylafax Tab shell.Add(SettingKeys.Hostname, "HylafaxHostnameEntry"); shell.Add(SettingKeys.Port, "HylafaxPortEntry"); shell.Add(SettingKeys.Username, "HylafaxUsernameEntry"); // Efax Tab shell.Add(SettingKeys.EfaxModemDevice, "EfaxModemDeviceEntry"); // User tab shell.Add(SettingKeys.EmailNotify, "EmailNotifyCheckButton"); shell.Add(SettingKeys.EmailAddress, "EmailAddressEntry"); shell.Add(SettingKeys.SendNow, "SendNowCheckButton"); shell.Add(SettingKeys.LogEnabled, "FaxLogCheckButton"); shell.Add(SettingKeys.CoverPage, "CoverPageCheckButton"); shell.Add(SettingKeys.HiResolution, "HiResCheckButton"); eventsEnabled = true; }
public EditorLevelCustomInfoPane(EditorShell shell) : base(shell) { InitializeComponent(); }
public EditorEntitiesEditPane(EditorShell shell) : base(shell) { InitializeComponent(); }
public EditorTexturingPane(EditorShell shell) : base(shell) { InitializeComponent(); }
public EditorViewOptionsPane(EditorShell shell) : base(shell) { InitializeComponent(); }
private static bool LoadIndex() { ConcurrentDictionary <string, string> functionToPackageMap = new ConcurrentDictionary <string, string>(); ConcurrentDictionary <string, IFunctionInfo> functionToInfoMap = new ConcurrentDictionary <string, IFunctionInfo>(); ConcurrentDictionary <string, BlockingCollection <INamedItemInfo> > packageToFunctionsMap = new ConcurrentDictionary <string, BlockingCollection <INamedItemInfo> >(); bool loaded = false; // ~/Documents/R/RTVS/FunctionsIndex.dx -> function to package map, also contains function description // ~/Documents/R/RTVS/[PackageName]/[FunctionName].sig -> function signatures // Function index format: // Each line is a triplet of function name followed // by the package name followed by the function description // There are no tabs in the function description. try { if (File.Exists(IndexFilePath)) { using (StreamReader sr = new StreamReader(IndexFilePath)) { char[] separator = new char[] { '\t' }; while (true) { string line = sr.ReadLine(); if (line == null) { break; } string[] parts = line.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 3) { string functionName = parts[0]; string packageName = parts[1]; string functionDescription = parts[2]; if (functionName == "completed" && packageName == "completed" && functionDescription == "completed") { loaded = true; break; } functionToPackageMap[functionName] = packageName; BlockingCollection <INamedItemInfo> functions; if (!packageToFunctionsMap.TryGetValue(packageName, out functions)) { functions = new BlockingCollection <INamedItemInfo>(); packageToFunctionsMap[packageName] = functions; } functions.Add(new NamedItemInfo(functionName, functionDescription)); } } } } } catch (IOException) { } if (!loaded) { return(false); } if (LoadFunctions(functionToPackageMap)) { EditorShell.DispatchOnUIThread(() => { _functionToPackageMap = functionToPackageMap; _packageToFunctionsMap = packageToFunctionsMap; _functionToInfoMap = functionToInfoMap; }); } return(loaded); }
public EditorLevelGlobalPane(EditorShell shell) : base(shell) { InitializeComponent(); }
public EditorGeometryDecalsPane(EditorShell shell) : base(shell) { InitializeComponent(); }
/// <summary> /// Main asyncronous task body /// </summary> void ProcessTextChanges(TextChange changeToProcess, bool async, Func <bool> isCancelledCallback) { lock (_disposeLock) { if (_editorTree == null || _disposed || isCancelledCallback()) { return; } EditorTreeChangeCollection treeChanges = null; // Cache id since it can change if task is canceled long taskId = TaskId; try { AstRoot rootNode; // We only need read lock since changes will be applied // from the main thread if (async) { rootNode = _editorTree.AcquireReadLock(_treeUserId); } else { rootNode = _editorTree.GetAstRootUnsafe(); } treeChanges = new EditorTreeChangeCollection(changeToProcess.Version, changeToProcess.FullParseRequired); TextChangeProcessor changeProcessor = new TextChangeProcessor(_editorTree, rootNode, isCancelledCallback); bool fullParseRequired = changeToProcess.FullParseRequired; if (fullParseRequired) { changeProcessor.FullParse(treeChanges, changeToProcess.NewTextProvider); } else { changeProcessor.ProcessChange(changeToProcess, treeChanges); } } finally { if (async && _editorTree != null) { _editorTree.ReleaseReadLock(_treeUserId); } } // Lock should be released at this point since actual application // of tree changes is going to be happen from the main thread. if (!isCancelledCallback() && treeChanges != null) { // Queue results for the main thread application. This must be done before // signaling that the task is complete since if EnsureProcessingComplete // is waiting it will want to apply changes itself rather than wait for // the DispatchOnUIThread to go though and hence it will need all changes // stored and ready for application. _backgroundParsingResults.Enqueue(treeChanges); } // Signal task complete now so if main thread is waiting // it can proceed and appy the changes immediately. SignalTaskComplete(taskId); if (_backgroundParsingResults.Count > 0) { _uiThreadTransitionRequestTime = DateTime.UtcNow; // It is OK to post results while main thread might be working // on them since if if it does, by the time posted request comes // queue will already be empty. if (async) { // Post request to apply tree changes to the main thread. // This must NOT block or else task will never enter 'RanToCompletion' state. EditorShell.DispatchOnUIThread(() => ApplyBackgroundProcessingResults()); } else { // When processing is synchronous, apply changes and fire events right away. ApplyBackgroundProcessingResults(); } } } }
public EditorOutputPane(EditorShell shell) : base(shell) { InitializeComponent(); }