public void Load(XPathNavigator nav, string profileMainNodeName, ProfileItemPrivacyType profileItemPrivacyType) { var navPointer = nav.Select("/" + profileMainNodeName + "/Variables/Variable"); while (navPointer.MoveNext()) { var type = navPointer.Current.GetAttribute("Type", navPointer.Current.NamespaceURI); IVariable variable = null; if (type == "FsuipcVariable") { variable = new FsuipcVariable(); } if (type == "MemoryPatchVariable") { variable = new MemoryPatchVariable(); } if (type == "FakeVariable") { variable = new FakeVariable(); } if (variable != null) { variable.Load(navPointer.Current); (variable as VariableBase).SetPrivacyType(profileItemPrivacyType); StoreVariable(variable); } } }
public void FakeWFTemplateMarkup_Validator(object o) { var loop = o as FakeForEach <int>; var global = new FakeVariable <string>() { Name = "global" }; global.SetValue(null, "Hello World"); var environment = new FakeEnvironment(); environment.Variables[global.Name] = global; loop.Invoke(environment); Assert.AreEqual("Hello World123", global.GetValue(null)); }
public void FakeWFTemplateImperative1() { // This is the semantically equivalent code to the markup example. // Any conditional logical in the construction of the activity // tree is not representable in xaml. // var iVar = new FakeVariable <int>() { Name = "i" }; var loop = new FakeForEach <int>() { LoopVariable = iVar, ItemsSource = new int[] { 1, 2, 3 }, Body = () => new FakeAppendIntToString() { Target = new FakeLookupVariable <string>("global"), Content = iVar } }; var global = new FakeVariable <string>() { Name = "global" }; global.SetValue(null, "Hello World"); var environment = new FakeEnvironment(); environment.Variables[global.Name] = global; loop.Invoke(environment); string globalFinalValue = global.GetValue(null); Assert.AreEqual("Hello World123", globalFinalValue); }
public void FakeWFTemplateImperative3() { // This is identical to #2, however using a factory method // to get better type infrencing. C# 3.0 doesn't do inferencing // based on the LHS, so you have to type all the expr variables. // var loop = new FakeForEach <int>() { LoopVariable = new FakeVariable <int>() { Name = "i" }, ItemsSource = new int[] { 1, 2, 3 }, Body = () => (FakeActivity) new FakeAppendIntToString() { Target = new FakeLookupVariable <string>("global"), Content = new FakeLookupVariable <int>("i") } }; var global = new FakeVariable <string>() { Name = "global" }; global.SetValue(null, "Hello World"); var environment = new FakeEnvironment(); environment.Variables[global.Name] = global; loop.Invoke(environment); string globalFinalValue = global.GetValue(null); Assert.AreEqual("Hello World123", globalFinalValue); }
public void FakeWFTemplateImperative2() { // This is the more natural C# developer intuition. // Notice that the string LoopVariableName is effectively // ignored. // var loop = new FakeForEach <int>() { LoopVariable = new FakeVariable <int>() { Name = "i" }, ItemsSource = new int[] { 1, 2, 3 }, Body = () => new FakeAppendIntToString() { Target = new FakeLookupVariable <string>("global"), Content = new FakeLookupVariable <int>("i") } }; var global = new FakeVariable <string>() { Name = "global" }; global.SetValue(null, "Hello World"); var environment = new FakeEnvironment(); environment.Variables[global.Name] = global; loop.Invoke(environment); string globalFinalValue = global.GetValue(null); Assert.AreEqual("Hello World123", globalFinalValue); }
public void PrepareProfile() { Profile.Clear(); // Создание трёх панелей var p1 = new Panel { Name = "Panel1" }; Profile.PanelStorage.StorePanel(p1); var panelId1 = p1.Id; var p2 = new Panel { Name = "Panel2" }; Profile.PanelStorage.StorePanel(p2); var panelId2 = p2.Id; var p3 = new Panel { Name = "Panel3" }; Profile.PanelStorage.StorePanel(p3); var panelId3 = p3.Id; // Создание трёх переменных. Одна в первой панели, вторая и третья во второй var firstTestVariable = new FakeVariable { Size = MemoryVariableSize.Byte, Name = "Var1", PanelId = panelId1, Description = "Тестовая переменная 1\nНовая строка" }; var firstTestVariableId = firstTestVariable.Id; Profile.VariableStorage.StoreVariable(firstTestVariable); var secondTestVariable = new FakeVariable { Size = MemoryVariableSize.EightByteFloat, Name = "Var2", PanelId = panelId2, Description = "Тестовая переменная 2\nНовая строка" }; var secondTestVariableId = secondTestVariable.Id; Profile.VariableStorage.StoreVariable(secondTestVariable); var thirdTestVariable = new FakeVariable { Size = MemoryVariableSize.FourBytesSigned, Name = "Var3", PanelId = panelId2, Description = "Тестовая переменная 3\nНовая строка" }; var thirdTestVariableId = thirdTestVariable.Id; Profile.VariableStorage.StoreVariable(thirdTestVariable); // Создание описателей доступа // Button var valueAccessDescriptor = new DescriptorValue(); var powerFormula = "[" + Profile.PanelStorage.GetPanelById(Profile.VariableStorage.GetVariableById(firstTestVariableId).PanelId).Name + "." + Profile.VariableStorage.GetVariableById(firstTestVariableId).Name + "]"; valueAccessDescriptor.SetPowerFormula(powerFormula); valueAccessDescriptor.AssignDefaultStateId(0); valueAccessDescriptor.AddConnector("Off"); valueAccessDescriptor.AddConnector("On"); // valueAccessDescriptor.AddVariable(firstTestVariableId); valueAccessDescriptor.AddVariable(secondTestVariableId); valueAccessDescriptor.AddVariable(thirdTestVariableId); // valueAccessDescriptor.SetFormula(0, 0, "0"); valueAccessDescriptor.SetFormula(0, secondTestVariableId, "0"); valueAccessDescriptor.SetFormula(0, thirdTestVariableId, "0"); // valueAccessDescriptor.SetFormula(1, 0, "1"); valueAccessDescriptor.SetFormula(1, secondTestVariableId, "2.58"); valueAccessDescriptor.SetFormula(1, thirdTestVariableId, "-3"); valueAccessDescriptor.AssignDefaultStateId(0); valueAccessDescriptor.SetAssignedPanelId(panelId3); valueAccessDescriptor.SetName("AccessDescriptor1"); var valueAccessDescriptorId = Profile.AccessDescriptor.RegisterAccessDescriptor(valueAccessDescriptor); // Encoder var rangeAccessDescriptor = new DescriptorRange(); rangeAccessDescriptor.SetReceiveValueFormula("[" + Profile.PanelStorage.GetPanelById(panelId2).Name + "." + Profile.VariableStorage.GetVariableById(secondTestVariableId).Name + "]"); rangeAccessDescriptor.AddVariable(secondTestVariableId); rangeAccessDescriptor.AddVariable(firstTestVariableId); rangeAccessDescriptor.SetAssignedPanelId(panelId3); rangeAccessDescriptor.SetName("AccessDescriptorRange"); rangeAccessDescriptor.SetFormula(0, secondTestVariableId, "[R]"); rangeAccessDescriptor.SetFormula(1, thirdTestVariableId, "[R]:1"); rangeAccessDescriptor.SetMinimumValueFormula("0"); rangeAccessDescriptor.SetMaximumValueFormula("4"); rangeAccessDescriptor.SetStepFormula("0.5"); // rangeAccessDescriptor.IsLooped = true; var rangeAccessDescriptorId = Profile.AccessDescriptor.RegisterAccessDescriptor(rangeAccessDescriptor); var tempFile = Path.GetTempFileName(); Profile.SaveAs(tempFile); Profile.Clear(); Profile.Load(tempFile, ProfileItemPrivacyType.Public); var valueDescriptor = (DescriptorValue)Profile.AccessDescriptor.GetAccessDesciptorById(valueAccessDescriptorId); Profile.VariableStorage.WriteValue(firstTestVariableId, 0); Profile.VariableStorage.WriteValue(secondTestVariableId, 0); Profile.VariableStorage.WriteValue(thirdTestVariableId, 0); Thread.Sleep(200); valueDescriptor.SetState(1); Thread.Sleep(200); Assert.AreEqual(0, Profile.VariableStorage.ReadValue(firstTestVariableId).Value); Assert.AreEqual(0, Profile.VariableStorage.ReadValue(secondTestVariableId).Value); Assert.AreEqual(0, Profile.VariableStorage.ReadValue(thirdTestVariableId).Value); Profile.VariableStorage.WriteValue(firstTestVariableId, 1); Thread.Sleep(200); valueDescriptor.SetState(1); Thread.Sleep(200); Assert.AreEqual(1, Profile.VariableStorage.ReadValue(firstTestVariableId).Value); Assert.AreEqual(2.58, Profile.VariableStorage.ReadValue(secondTestVariableId).Value); Assert.AreEqual(-3, Profile.VariableStorage.ReadValue(thirdTestVariableId).Value); valueAccessDescriptor.SetDefaultState(); Thread.Sleep(200); Assert.AreEqual(0, Profile.VariableStorage.ReadValue(firstTestVariableId).Value); Assert.AreEqual(0, Profile.VariableStorage.ReadValue(secondTestVariableId).Value); Assert.AreEqual(0, Profile.VariableStorage.ReadValue(thirdTestVariableId).Value); File.Delete(tempFile); }
private void SynchronizeFakeVariable(FakeVariable fakeVariable) { fakeVariable.SetValueInMemory(fakeVariable.GetValueToSet()); }