private void OpManager_OpStatusChanged(object sender, QuestomAssets.AssetOps.AssetOp e) { List <AssetOp> opCopy; lock (_trackedOps) { if (!_trackedOps.Any(x => x.ID == e.ID)) { _trackedOps.Add(e); } _trackedOps.RemoveAll(x => x.Status == OpStatus.Complete); opCopy = _trackedOps.ToList(); } HostOpStatus opstat = new HostOpStatus(); foreach (var op in opCopy) { string exmsg = null; //if (op.Exception != null) //{ // exmsg = $"{op.Exception.Message} {op.Exception.StackTrace}"; // var ex = op.Exception.InnerException; // while (ex != null) // { // exmsg += $"\nInnerException: {ex.Message} {ex.StackTrace}"; // ex = ex.InnerException; // } //} opstat.Ops.Add(new HostOp() { ID = op.ID, OpDescription = op.GetType().Name, Status = op.Status, Error = op.Exception?.Message }); } lock (_sendClientOpsChangedLock) { if (_sendClientOpsChanged == null) { _sendClientOpsChanged = new Debouncey <HostOpStatus>(400, false); _sendClientOpsChanged.Debounced += (e2, a) => { SendMessageToClient(a); }; } } if (e.Status == OpStatus.Complete && e.IsWriteOp) { CurrentConfig.IsCommitted = CurrentConfig.IsCommitted && (!Engine.HasChanges); SendConfigChangeMessage(); } _sendClientOpsChanged.EventRaised(this, opstat); }
private void SendConfigChangeMessage() { lock (_configChangeMsgDebounceLock) { if (_configChangeMsgDebounce == null) { _configChangeMsgDebounce = new Debouncey <object>(100, true); _configChangeMsgDebounce.Debounced += (e, a) => { if (!_suppressConfigChangeMessage) { _webServer.SendMessage(new HostConfigChangeEvent() { UpdatedConfig = CurrentConfig }); } }; } } //todo: see if this is needed or makes sense here. Could cause noise on the messages. CurrentConfig.IsCommitted = CurrentConfig.IsCommitted && (!Engine.HasChanges); _configChangeMsgDebounce.EventRaised(this, null); }
private void OpManager_OpStatusChanged(object sender, QuestomAssets.AssetOps.AssetOp e) { List <AssetOp> opCopy; lock (_trackedOps) { if (!_trackedOps.Any(x => x.ID == e.ID)) { _trackedOps.Add(e); } _trackedOps.RemoveAll(x => x.Status == OpStatus.Complete); opCopy = _trackedOps.ToList(); } HostOpStatus opstat = new HostOpStatus(); foreach (var op in opCopy) { string exmsg = null; //if (op.Exception != null) //{ // exmsg = $"{op.Exception.Message} {op.Exception.StackTrace}"; // var ex = op.Exception.InnerException; // while (ex != null) // { // exmsg += $"\nInnerException: {ex.Message} {ex.StackTrace}"; // ex = ex.InnerException; // } //} opstat.Ops.Add(new HostOp() { ID = op.ID, OpDescription = op.GetType().Name, Status = op.Status, Error = op.Exception?.Message }); } lock (_sendClientOpsChangedLock) { if (_sendClientOpsChanged == null) { _sendClientOpsChanged = new Debouncey <HostOpStatus>(400, false); _sendClientOpsChanged.Debounced += (e2, a) => { lock (lastSendOpsLock) { lastOpsSendHadOps = (a.Ops.Count > 0); SendMessageToClient(a); } }; } } if (e.Status == OpStatus.Complete && e.IsWriteOp) { CurrentConfig.IsCommitted = CurrentConfig.IsCommitted && (!Engine.HasChanges); SendConfigChangeMessage(); } //if the last send didn't have ops and this one does, send the message immediately in addition to debouncing it. // this will send a duplicate message because the debounce is called in addition to the message being sent, but it'll assure keeping things in sync with the client lock (lastSendOpsLock) { if ((opstat.Ops.Count > 0) && !lastOpsSendHadOps) { lastOpsSendHadOps = true; SendMessageToClient(opstat); } } _sendClientOpsChanged.EventRaised(this, opstat); }