void Iterate(IGH_DataAccess DA, Document doc, CommitAction action) { var element = PreviousStructureEnumerator?.MoveNext() ?? false ? ( PreviousStructureEnumerator.Current is Types.Element x && doc.Equals(x.Document) ? doc.GetElement(x.Id) : null ) : null; if (element?.Pinned != false) { var previous = element; try { action(doc, ref element); } catch (System.ComponentModel.WarningException e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, e.Message.Replace("\r\n", " ")); element = null; } catch (System.ArgumentNullException) { // Grasshopper components use to send a Null when they receive a Null without throwing any error element = null; } catch (System.ArgumentException e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message.Replace("\r\n", " ")); element = null; } catch (Autodesk.Revit.Exceptions.ArgumentException e) { var message = e.Message.Split("\r\n".ToCharArray()).First().Replace("Application.ShortCurveTolerance", "Revit.ShortCurveTolerance"); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message); element = null; } catch (System.Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message); DA.AbortComponentSolution(); } finally { if (previous is object && !ReferenceEquals(previous, element) && previous.IsValidObject) { previous.Document.Delete(previous.Id); } if (element?.IsValidObject == true) { element.Pinned = true; } } } DA.SetData(0, element); }
private async Task <bool> Commit <T>(string dataPath, Func <List <T>, bool> commitOperation, bool isOperationAsync, Func <JToken, T> readConvert) { var commitAction = new CommitAction(); commitAction.HandleAction = new Func <JObject, (bool success, string json)>(currentJson => { var updatedJson = string.Empty; var selectedData = currentJson[dataPath]? .Children() .Select(e => readConvert(e)) .ToList() ?? new List <T>(); var success = commitOperation(selectedData); if (success) { currentJson[dataPath] = JArray.FromObject(selectedData); updatedJson = _toJsonFunc(currentJson); } return(success, updatedJson); }); bool waitFlag = true; bool actionSuccess = false; Exception actionException = null; commitAction.Ready = new Action <bool, Exception>((isSuccess, exception) => { actionSuccess = isSuccess; actionException = exception; waitFlag = false; }); _updates.Add(commitAction); while (waitFlag) { if (isOperationAsync) { await Task.Delay(5).ConfigureAwait(false); } else { Task.Delay(5).Wait(); } } if (actionException != null) { throw actionException; } return(actionSuccess); }
public _IClosure4_170(BooleanByRef shallListen, CommitAction action, IObjectContainer clientA, IObjectContainer clientB, Lock4 lockObject) { this.shallListen = shallListen; this.action = action; this.clientA = clientA; this.clientB = clientB; this.lockObject = lockObject; }
private bool WaitStepWithExpBackoff(CommitAction action) { int retry = 0; int sleeptime = expBackoff; bool isStepComplete = false; action(); while (!(isStepComplete = this.stepWaitEvent.WaitOne(stepTimeout)) && retry < maxRetry) { Thread.Sleep(sleeptime); sleeptime *= 2; retry++; string outstring = string.Format("Sleep and retry {0}\r", retry); this.Message += outstring; Console.Write(outstring); action(); } return(isStepComplete); }
private bool WaitStepWithExpBackoff(CommitAction action) { int retry = 0; int sleeptime = expBackoff; bool isStepComplete = false; action(); while (!(isStepComplete = this.stepWaitEvent.WaitOne(stepTimeout)) && retry < maxRetry) { Thread.Sleep(sleeptime); sleeptime *= 2; retry++; string outstring = string.Format("Sleep and retry {0}\r", retry); this.Message += outstring; Console.Write(outstring); action(); } return isStepComplete; }
public CommitResult(IEntity entity, CommitAction commitAction) : this() { this.CommitActions.Add(entity, commitAction); }
public void AddCommitAction(CommitAction commitAction) { this.commitActions.Add(commitAction); }