private void SaveChangeList() { using (ChangeList change = new ChangeList(true)) { change.FromDate = FromDate; change.Todate = ToDate; if (ChangeListID == 0) { ChangeListID = change.Add(); } change.Clear(ChangeListID); foreach (ChangeListToolstriptItem RmenuItem in contextMenuStrip1.Items) { if (RmenuItem.asapuChangeListItem != null) { foreach (ChangeListItemBhikku bhikku in RmenuItem.asapuChangeListItem.bhikkuList) { change.AddBhikkuAsapuwa(ChangeListID, RmenuItem.asapuChangeListItem.asapuwaID, bhikku.bInfo.ID, bhikku.bInfo.Post, bhikku.bInfo.ChangeType); } } } } }
public void WriteCell(int x, int y, int val) { if (x >= 0 && x < Width && y >= 0 && y < Height) { ChangeList.Add(new Change(x, y, val)); } }
/// <summary> /// Compares the specified results. /// </summary> /// <param name="results">The results.</param> /// <param name="originalElement">The original element.</param> /// <param name="finalElement">The final element.</param> private void Compare(ChangeList results, ObjectGraphCapture.ValueElement originalElement, ObjectGraphCapture.ValueElement finalElement) { bool areEqual; if ((originalElement.Value == null) ^ (finalElement.Value == null)) { areEqual = false; } else if ((originalElement.Value == null) && (finalElement.Value == null)) { areEqual = true; } else { // ReSharper disable once PossibleNullReferenceException areEqual = originalElement.Value.Equals(finalElement.Value); } if (!areEqual) { var diff = new ValueGraphChange { Path = originalElement.Path, DeclaredType = originalElement.DeclaredType, OldValue = originalElement.Value, NewValue = finalElement.Value }; results.Add(diff); } }
public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply, Runner runner) { Change change = new Change(Variable, Variable.Value, Value); changes.Add(change, apply, runner); }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> /// <param name="runner"></param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply, Runner runner) { IVariable var = VariableIdentification.GetVariable(context); if (var != null) { IValue value = Expression.GetExpressionValue(context, explanation); if (value != null) { value = value.RightSide(var, true, true); } Range range = var.Type as Range; Collection collection = var.Type as Collection; if (range != null && range.convert(value) == null) { AddError("Value " + value + " is outside range", RuleChecksEnum.ExecutionFailed); } else if (collection != null && collection.convert(value) == null) { AddError("Value " + value + " cannot be assigned to variable", RuleChecksEnum.ExecutionFailed); } else { Change change = new Change(var, var.Value, value); changes.Add(change, apply, runner); ExplanationPart.CreateSubExplanation(explanation, Root, change); } } else { AddError("Cannot find variable " + VariableIdentification, RuleChecksEnum.ExecutionFailed); } }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> /// <param name="runner"></param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply, Runner runner) { IVariable variable = ListExpression.GetVariable(context); // ReSharper disable once ConditionIsAlwaysTrueOrFalse changes.Add(new InsertInListChange(context, this, variable, explanation), apply, runner); }
public void WriteCell(int x, int y, int val) { if (x >= 0 && x < Width && y >= 0 && y < Height) { PushPixel(new Pixel(x, y, ColorPalette[val])); ChangeList.Add(new Change(x, y, val)); } }
public void WriteCell(int x, int y, int val) { if (x >= 0 && x < Width && y >= 0 && y < Height) { PushPixel(new Pixel(x, y, val >= 0 && val < MaxStates ? ColorPalette[val * Delta] : EmptyColor)); ChangeList.Add(new Change(x, y, val)); } }
public void WriteCell(int x, int y, int val) { if (x >= 0 && x < Width && y >= 0 && y < Height) { PushPixel(new Pixel(x, y, val > 0 ? ColonyColor : EmptyColor)); ChangeList.Add(new Change(x, y, val > 0 ? 1 : 0)); } }
public int AddDeleteChangeItem(int bhikkuChangeListID, int asapuwaID, int bhikkuID, DBCore.BhikkuPost post, DBCore.BhikkuChangeType changeType, bool isUpasampanna) { using (ChangeList change = new ChangeList(true)) { saveHistrybtn.Enabled = true; if (ChangeListID == 0) { change.FromDate = FromDate; change.Todate = ToDate; ChangeListID = change.Add(); } if (bhikkuChangeListID == 0) { if (isUpasampanna) { upasampadaChangeCount++; } else { samaneraChangeCount++; } setSummaryCounts(); return(change.AddBhikkuAsapuwa(ChangeListID, asapuwaID, bhikkuID, post, changeType)); } else { // delete bhikku if (asapuwaID == -1) { if (isUpasampanna) { upasampadaChangeCount--; } else { samaneraChangeCount--; } change.DeleteBhikkuAsapuwa(bhikkuChangeListID); setSummaryCounts(); return(0); } else { change.UpdateBhikkuAsapuwa(bhikkuChangeListID, post, changeType); return(bhikkuChangeListID); } } } }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply) { Variables.IVariable variable = ListExpression.GetVariable(context); if (variable != null) { // HacK : ensure that the value is a correct rigth side // and keep the result of the right side operation Values.ListValue listValue = variable.Value.RightSide(variable, false) as Values.ListValue; variable.Value = listValue; if (listValue != null) { Values.ListValue newListValue = new Values.ListValue(listValue); int i = 0; foreach (Values.IValue current in newListValue.Val) { IteratorVariable.Value = current; if (conditionSatisfied(context)) { break; } i += 1; } if (i < newListValue.Val.Count) { Values.IValue value = Value.GetValue(context); if (value != null) { newListValue.Val[i] = value; Rules.Change change = new Rules.Change(variable, variable.Value, newListValue); changes.Add(change, apply); explanation.SubExplanations.Add(new ExplanationPart(Root, change)); } else { Root.AddError("Cannot find value for " + Value.ToString()); } } else { Root.AddError("Cannot find value in " + ListExpression.ToString() + " which satisfies " + Condition.ToString()); } } else { Root.AddError("Variable " + ListExpression.ToString() + " does not contain a list value"); } } else { Root.AddError("Cannot find variable for " + ListExpression.ToString()); } }
/// <summary> Fires Changed event if some conditions are met </summary> public void FireChange(BGCurveChangedArgs change, bool ignoreEventsGrouping = false) { if (eventMode == EventModeEnum.NoEvents || Changed == null) return; if (transactionLevel > 0 || (eventMode != EventModeEnum.Immediate && !ignoreEventsGrouping)) { changed = true; if (UseEventsArgs && !ChangeList.Contains(change)) ChangeList.Add(change); return; } Changed(this, UseEventsArgs ? change : null); }
/// <summary> /// Compares the specified results. /// </summary> /// <param name="results">The results.</param> /// <param name="originalElement">The original element.</param> /// <param name="finalElement">The final element.</param> private void Compare(ChangeList results, ObjectGraphCapture.ReferenceElement originalElement, ObjectGraphCapture.ReferenceElement finalElement) { bool areEqual = ReferenceEquals(originalElement.Value, finalElement.Value); if (!areEqual) { var diff = new ReferenceGraphChange { Path = originalElement.Path, DeclaredType = originalElement.DeclaredType }; results.Add(diff); } }
private void Watcher_Event(Data.FileSystemWatcherEventArgs e) { if (platformType == Data.PlatformType.UWP) { Device.BeginInvokeOnMainThread(() => { ChangeList.Add(e); }); } else { ChangeList.Add(e); } }
/// <summary> /// Updates the change list /// </summary> public bool UpdateList(Denomination coin) { // Change must be greater than value if (coin.Value > Change) { return(false); } // Add change to the list ChangeList.Add(coin.Description); // decrement the change Change -= coin.Value; return(true); }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply) { Variables.IVariable var = VariableIdentification.GetVariable(context); if (var != null) { string tmp = var.FullName; Values.IValue value = Expression.GetValue(context); if (value != null) { value = value.RightSide(var, true); } Rules.Change change = new Rules.Change(var, var.Value, value); changes.Add(change, apply); explanation.SubExplanations.Add(new ExplanationPart(Root, change)); } else { AddError("Cannot find variable " + VariableIdentification.ToString()); } }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> /// <param name="runner"></param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply, Runner runner) { // Explain what happens in this statement explanation = ExplanationPart.CreateSubExplanation(explanation, this); IVariable variable = ListExpression.GetVariable(context); if (variable != null) { // HacK : ensure that the value is a correct rigth side // and keep the result of the right side operation ListValue listValue = variable.Value.RightSide(variable, false, false) as ListValue; variable.Value = listValue; if (listValue != null) { // Provide the state of the list before removing elements from it ExplanationPart.CreateSubExplanation(explanation, "Input data = ", listValue); ListValue newListValue = new ListValue(listValue.CollectionType, new List <IValue>()); int token = context.LocalScope.PushContext(); context.LocalScope.SetVariable(IteratorVariable); int index = 0; if (Position == PositionEnum.Last) { index = listValue.Val.Count - 1; } // Remove the element while required to do so while (index >= 0 && index < listValue.Val.Count) { IValue value = listValue.Val[index]; index = NextIndex(index); IteratorVariable.Value = value; if (ConditionSatisfied(context, explanation)) { if (Position != PositionEnum.All) { break; } } else { InsertInResult(newListValue, value); } } // Complete the list while (index >= 0 && index < listValue.Val.Count) { IValue value = listValue.Val[index]; InsertInResult(newListValue, value); index = NextIndex(index); } Change change = new Change(variable, variable.Value, newListValue); changes.Add(change, apply, runner); ExplanationPart.CreateSubExplanation(explanation, Root, change); context.LocalScope.PopContext(token); } } }
/// <summary> /// Checks the compatibility of all updates /// </summary> /// <param name="variableUpdates"></param> public void CheckUpdatesCompatibility(IEnumerable <VariableUpdate> variableUpdates) { if (CheckForCompatibleChanges) { // Holds all changes that have already been processed Dictionary <IVariable, Change> changes = new Dictionary <IVariable, Change>(); Dictionary <Change, VariableUpdate> traceBack = new Dictionary <Change, VariableUpdate>(); foreach (VariableUpdate variableUpdate in variableUpdates) { Action action = variableUpdate.Action; ChangeList actionChanges = variableUpdate.Changes; if (variableUpdate.Action.Statement is ProcedureCallStatement) { Dictionary <IVariable, Change> procedureChanges = new Dictionary <IVariable, Change>(); foreach (Change change in variableUpdate.Changes.Changes) { procedureChanges[change.Variable] = change; } actionChanges = new ChangeList(); foreach (Change change in procedureChanges.Values) { actionChanges.Add(change, false, this); } } foreach (Change change in actionChanges.Changes) { IVariable variable = change.Variable; if (changes.ContainsKey(change.Variable)) { Change otherChange = changes[change.Variable]; Action otherAction = traceBack[otherChange].Action; if (!variable.Type.CompareForEquality(otherChange.NewValue, change.NewValue)) { if (change.CheckForCompatibility() || otherChange.CheckForCompatibility()) { string action1 = ((INamable)action.Enclosing).FullName + " : " + variableUpdate.Action.FullName; string action2 = ((INamable)otherAction.Enclosing).FullName + " : " + traceBack[otherChange].Action.FullName; variableUpdate.Action.AddError( "Simultaneous change of the variable " + variable.FullName + " with different values. Conflit between\n" + action1 + "\n and \n" + action2); action.AddError("Conflicting change"); otherAction.AddError("Conflicting change"); } } } else { changes.Add(change.Variable, change); traceBack.Add(change, variableUpdate); } } } } }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> /// <param name="runner"></param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply, Runner runner) { // Explain what happens in this statement explanation = ExplanationPart.CreateSubExplanation(explanation, this); int index = context.LocalScope.PushContext(); context.LocalScope.SetVariable(IteratorVariable); IVariable variable = ListExpression.GetVariable(context); if (variable != null) { // HacK : ensure that the value is a correct rigth side // and keep the result of the right side operation ListValue listValue = variable.Value.RightSide(variable, false, false) as ListValue; variable.Value = listValue; if (listValue != null) { // Provide the state of the list before removing elements from it ExplanationPart.CreateSubExplanation(explanation, "Input data = ", listValue); ListValue newListValue = new ListValue(listValue); int i = 0; foreach (IValue current in newListValue.Val) { IteratorVariable.Value = current; if (ConditionSatisfied(context, explanation)) { break; } i += 1; } if (i < newListValue.Val.Count) { IValue value = Value.GetExpressionValue(context, explanation); if (value != null) { newListValue.Val[i] = value; Change change = new Change(variable, variable.Value, newListValue); changes.Add(change, apply, runner); ExplanationPart.CreateSubExplanation(explanation, Root, change); } else { Root.AddError("Cannot find value for " + Value); } } else { Root.AddError("Cannot find value in " + ListExpression + " which satisfies " + Condition); } } else { Root.AddError("Variable " + ListExpression + " does not contain a list value"); } } else { Root.AddError("Cannot find variable for " + ListExpression); } context.LocalScope.PopContext(index); }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply) { Variables.IVariable variable = ListExpression.GetVariable(context); if (variable != null) { // HacK : ensure that the value is a correct rigth side // and keep the result of the right side operation Values.ListValue listValue = variable.Value.RightSide(variable, false) as Values.ListValue; variable.Value = listValue; if (listValue != null) { Values.IValue value = Value.GetValue(context); if (value != null) { Values.ListValue newListValue = new Values.ListValue(listValue); int index = newListValue.Val.IndexOf(EFSSystem.EmptyValue); if (index >= 0) { newListValue.Val[index] = value; } else { // List is full, try to remove an element before inserting the new element if (ReplaceElement != null) { Values.IValue removeValue = ReplaceElement.GetValue(context); index = newListValue.Val.IndexOf(removeValue); if (index >= 0) { newListValue.Val[index] = value; } else { Root.AddError("Cannot remove replacing element " + removeValue.Name); } } else { Root.AddError("Cannot add new element in list value : list is full"); } } Rules.Change change = new Rules.Change(variable, variable.Value, newListValue); changes.Add(change, apply); explanation.SubExplanations.Add(new ExplanationPart(Root, change)); } else { Root.AddError("Cannot find value for " + Value.ToString()); } } else { Root.AddError("Variable " + ListExpression.ToString() + " does not contain a list value"); } } else { Root.AddError("Cannot find variable for " + ListExpression.ToString()); } }
/// <summary> /// Executes the specified initial graph. /// </summary> /// <param name="initialGraph">The initial graph.</param> /// <param name="finalGraph">The final graph.</param> /// <returns>ChangeList.</returns> /// <exception cref="System.Exception"></exception> private ChangeList Execute(CaptureResults initialGraph, CaptureResults finalGraph) { var retVal = new ChangeList(); var unusedOriginalKeys = new List <string>(initialGraph.Elements.Keys); var unusedFinalKeys = new List <string>(finalGraph.Elements.Keys); foreach (KeyValuePair <string, Element> pair in initialGraph.Elements) { Element originalElement = pair.Value; Element finalElement; if (finalGraph.Elements.TryGetValue(pair.Key, out finalElement)) { unusedOriginalKeys.Remove(pair.Key); unusedFinalKeys.Remove(pair.Key); if (originalElement.GetType() != finalElement.GetType()) { throw new Exception(); } if (originalElement is ObjectGraphCapture.ReferenceElement) { if (originalElement.DeclaredType.IsArray) { ArrayCompare(retVal, (ObjectGraphCapture.ReferenceElement)originalElement, (ObjectGraphCapture.ReferenceElement)finalElement); } else { Compare(retVal, (ObjectGraphCapture.ReferenceElement)originalElement, (ObjectGraphCapture.ReferenceElement)finalElement); } } else { Compare(retVal, (ObjectGraphCapture.ValueElement)originalElement, (ObjectGraphCapture.ValueElement)finalElement); } } } foreach (string key in unusedOriginalKeys) { Element item = initialGraph.Elements[key]; var diff = new MissingGraphChange { Path = item.Path, DeclaredType = item.DeclaredType, }; var asValueChange = item as ObjectGraphCapture.ValueElement; if (asValueChange != null) { diff.OldValue = asValueChange.Value; } retVal.Add(diff); } foreach (string key in unusedFinalKeys) { Element item = finalGraph.Elements[key]; var diff = new AddedGraphChange { Path = item.Path, DeclaredType = item.DeclaredType, }; var asValueChange = item as ObjectGraphCapture.ValueElement; if (asValueChange != null) { diff.NewValue = asValueChange.Value; } retVal.Add(diff); } return(retVal); }
/// <summary> /// Arrays the compare. /// </summary> /// <param name="retVal">The ret value.</param> /// <param name="originalElement">The original element.</param> /// <param name="finalElement">The final element.</param> private void ArrayCompare(ChangeList retVal, ObjectGraphCapture.ReferenceElement originalElement, ObjectGraphCapture.ReferenceElement finalElement) { Compare(retVal, originalElement, finalElement); var originalArray = (Array)originalElement.Value; var finalArray = (Array)finalElement.Value; if ((originalArray == null) || (finalArray == null)) { return; } var finalList = new List <Tuple <object, int> >(); var originalList = new List <Tuple <object, int> >(); for (int index = 0; index < Math.Min(originalArray.Length, finalArray.Length); ++index) { object originalItem = originalArray.GetValue(index); object finalItem = finalArray.GetValue(index); if (originalItem != null) { if (finalItem != null) { // Both Live! if (!CheckSame(originalItem, finalItem)) { originalList.Add(new Tuple <object, int>(originalItem, index)); finalList.Add(new Tuple <object, int>(finalItem, index)); } } else { //! Original Only originalList.Add(new Tuple <object, int>(originalItem, index)); } } else { if (finalItem != null) { // Final Only finalList.Add(new Tuple <object, int>(finalItem, index)); } } } var match = new List <Tuple <Tuple <object, int>, Tuple <object, int> > >(); foreach (Tuple <object, int> originalItem in originalList) { foreach (Tuple <object, int> finalItem in finalList) { if (CheckSame(originalItem.Item1, finalItem.Item1)) { match.Add(new Tuple <Tuple <object, int>, Tuple <object, int> >(originalItem, finalItem)); } } } foreach (Tuple <Tuple <object, int>, Tuple <object, int> > item in match) { if (item.Item1.Item2 != item.Item2.Item2) { retVal.Add(new MiscGraphChange("ArrayIndewx,{0}=>{1})", item.Item1.Item2 != item.Item2.Item2)); } originalList.Remove(item.Item1); finalList.Remove(item.Item2); } if (originalList.Count > 0) { foreach (Tuple <object, int> pair in originalList) { object item = pair.Item1; retVal.Add(new MiscGraphChange("ArrayRemove,{0}@{1})", (item != null) ? item.GetType().Name : "{null}", IndexOf(originalArray, item))); } } if (finalList.Count > 0) { foreach (Tuple <object, int> pair in finalList) { object item = pair.Item1; retVal.Add(new MiscGraphChange("ArrayAdd,{0}@{1})", (item != null) ? item.GetType().Name : "{null}", IndexOf(finalArray, item))); } } }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply) { Variables.IVariable variable = ListExpression.GetVariable(context); if (variable != null) { // HacK : ensure that the value is a correct rigth side // and keep the result of the right side operation Values.ListValue listValue = variable.Value.RightSide(variable, false) as Values.ListValue; variable.Value = listValue; if (listValue != null) { Values.ListValue newListValue = new Values.ListValue(listValue.CollectionType, new List <Values.IValue>()); int token = context.LocalScope.PushContext(); context.LocalScope.setVariable(IteratorVariable); int index = 0; if (Position == PositionEnum.Last) { index = listValue.Val.Count - 1; } // Remove the element while required to do so while (index >= 0 && index < listValue.Val.Count) { Values.IValue value = listValue.Val[index]; index = nextIndex(index); if (value == EFSSystem.EmptyValue) { InsertInResult(newListValue, value); } else { IteratorVariable.Value = value; if (conditionSatisfied(context)) { if (Position != PositionEnum.All) { break; } } else { InsertInResult(newListValue, value); } } } // Complete the list while (index >= 0 && index < listValue.Val.Count) { Values.IValue value = listValue.Val[index]; InsertInResult(newListValue, value); index = nextIndex(index); } // Fill the gap while (newListValue.Val.Count < listValue.Val.Count) { newListValue.Val.Add(EFSSystem.EmptyValue); } Rules.Change change = new Rules.Change(variable, variable.Value, newListValue); changes.Add(change, apply); explanation.SubExplanations.Add(new ExplanationPart(Root, change)); context.LocalScope.PopContext(token); } } }