/// <summary> /// Restores persistent data to the given runtime entity. /// </summary> static public bool Restore(RSEnvironment inEnvironment, RSPersistEntityData inData, IRSRuntimeEntity inEntity, int inFlags) { if (inEntity == null) { return(false); } return(Restore(inEnvironment, inData, inEntity, null, inFlags)); }
public void RunTest(string filePath) { string source, target = String.Empty, actual; var stdout = new StringBuilder(); var env = new RSEnvironment(); env.Output = s => stdout.AppendLine((s ?? "(null)").ToString()); source = File.ReadAllText(fixtures + filePath); if (File.Exists(fixtures + filePath + ".out")) { target = File.ReadAllText(fixtures + filePath + ".out"); } actual = ""; try { var parser = new Parser(); var syntax = parser.Parse(source); var result = env.Evaluate(syntax); actual = stdout.ToString(); } catch (Exception ex) { actual = ex.Message; } Assert.Equal(target, actual); }
internal void Restore(IRSRuntimeComponent inComponent, RSPersistComponentData inData, RSEnvironment inEnvironment, int inFlags) { if (inData.NamedValues != null) { for (int i = 0; i < inData.NamedValues.Length; ++i) { string name = inData.NamedValues[i].Name; RSValue value = inData.NamedValues[i].Value; RSPersistFieldInfo fieldInfo; m_PersistFields.TryGetValue(name, out fieldInfo); if (fieldInfo != null) { fieldInfo.Restore(inComponent, value, inEnvironment); } } } if (m_UseCustomDataField) { ((IRSCustomPersistDataProvider)inComponent).RestoreCustomPersistData(inData.CustomData, inFlags, inEnvironment); } }
internal void Restore(IRSRuntimeComponent inComponent, RSValue inValue, RSEnvironment inEnvironment) { object restoreValue = RSInterop.ToObject(m_FieldType, inValue, inEnvironment.StaticScope); m_FieldInfo.SetValue(inComponent, restoreValue); }
/// <summary> /// Restores persistent data to the given runtime entity and its components. /// </summary> static public bool Restore(RSEnvironment inEnvironment, RSPersistEntityData inData, IRSRuntimeEntity inEntity, IReadOnlyList <IRSRuntimeComponent> inComponents, int inFlags) { if (inEntity == null) { return(false); } using (PooledList <IRSPersistListener> persistListeners = PooledList <IRSPersistListener> .Alloc()) { IRSPersistListener entityPersistListener = inEntity as IRSPersistListener; if (entityPersistListener != null) { entityPersistListener.OnPreRestore(inEnvironment); persistListeners.Add(entityPersistListener); } inEntity.SetActiveWithoutNotify(inData.Active); inEntity.RuleTable?.Restore(inData.TableData); for (int i = 0, length = inData.ComponentData.Length; i < length; ++i) { RSPersistComponentData componentData = inData.ComponentData[i]; RSComponentInfo componentInfo = inEnvironment.Library.GetComponent(componentData.ComponentType); if (componentInfo == null) { continue; } IRSRuntimeComponent component = inEntity.GetRSComponent(componentInfo.OwnerType); if (component == null) { continue; } if (inComponents != null) { bool bIncluded = false; for (int allCompIdx = 0, allCompLength = inComponents.Count; allCompIdx < allCompLength; ++allCompIdx) { IRSRuntimeComponent includedComponent = inComponents[allCompIdx]; if (includedComponent == component) { bIncluded = true; break; } } if (!bIncluded) { continue; } } IRSPersistListener componentListener = component as IRSPersistListener; if (componentListener != null) { componentListener.OnPreRestore(inEnvironment); persistListeners.Add(componentListener); } componentInfo.Restore(component, componentData, inEnvironment, inFlags); } IRSCustomPersistDataProvider customDataProvider = inEntity as IRSCustomPersistDataProvider; if (customDataProvider != null) { customDataProvider.RestoreCustomPersistData(inData.CustomData, inFlags, inEnvironment); } foreach (var listener in persistListeners) { listener.OnPostRestore(inEnvironment); } } return(true); }