Пример #1
0
        public bool Deserialize(IStorage storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            uint signature = storage.ReadUnsignedInteger(FieldCode.RuntimeStatesSignature);

            if (signature != Configurations.RuntimeStatesSignature)
            {
                throw new InvalidOperationException("Invalid input data");
            }

            try
            {
                // Here we attempt to take a snapshot of what variables are currently
                // defined in the system, and which is the node defining it.
                //
                Dictionary <string, uint> oldDefinitions = null;
                if (null != this.undefinedVarsTracker)
                {
                    oldDefinitions = new Dictionary <string, uint>();
                    foreach (KeyValuePair <string, List <uint> > kvp in variableNodesMap)
                    {
                        List <uint> definingNodes = kvp.Value;
                        if (null != definingNodes && (definingNodes.Count > 0))
                        {
                            oldDefinitions.Add(kvp.Key, definingNodes[0]);
                        }
                    }
                }

                this.version    = (RuntimeStates.Version)storage.ReadInteger(FieldCode.RuntimeStatesVersion);
                this.IsModified = storage.ReadBoolean(FieldCode.IsModified);

                int variableNodesMapCount = storage.ReadInteger(FieldCode.VariableNodesMapCount);
                this.variableNodesMap.Clear();
                for (int i = 0; i < variableNodesMapCount; i++)
                {
                    string      key        = storage.ReadString(FieldCode.VariableNodesMapKey);
                    List <uint> value      = new List <uint>();
                    int         valueCount = storage.ReadInteger(FieldCode.VariableNodesMapValueCount);
                    for (int j = 0; j < valueCount; j++)
                    {
                        value.Add(storage.ReadUnsignedInteger(FieldCode.VariableNodesMapValue));
                    }
                    this.variableNodesMap.Add(key, value);
                }

                // After deserialization is done, we'll move all the previously defined variables
                // into the "undefinedVarsTracker". Note that we copy ALL of them into the tracker,
                // but some of them may still be defined after the "variableNodesMap" got updated.
                // This is because eventually these variables which are still in the system will
                // be removed in the final pass in "EndDefinitionMonitor" call.
                //
                if (null != oldDefinitions && (oldDefinitions.Count > 0))
                {
                    foreach (KeyValuePair <string, uint> oldDefinition in oldDefinitions)
                    {
                        string name   = oldDefinition.Key;
                        uint   nodeId = oldDefinition.Value;
                        if (!undefinedVarsTracker.ContainsKey(nodeId))
                        {
                            undefinedVarsTracker[nodeId] = new List <string>();
                        }

                        List <string> variables = undefinedVarsTracker[nodeId];
                        if (!variables.Contains(name))
                        {
                            variables.Add(name);
                        }
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n RuntimeStates deserialization failed.");
                return(false);
            }
        }
Пример #2
0
        public bool Deserialize(IStorage storage)
        {
            if (storage == null)
                throw new ArgumentNullException("storage");

            uint signature = storage.ReadUnsignedInteger(FieldCode.RuntimeStatesSignature);
            if (signature != Configurations.RuntimeStatesSignature)
                throw new InvalidOperationException("Invalid input data");

            try
            {
                // Here we attempt to take a snapshot of what variables are currently
                // defined in the system, and which is the node defining it.
                //
                Dictionary<string, uint> oldDefinitions = null;
                if (null != this.undefinedVarsTracker)
                {
                    oldDefinitions = new Dictionary<string, uint>();
                    foreach (KeyValuePair<string, List<uint>> kvp in variableNodesMap)
                    {
                        List<uint> definingNodes = kvp.Value;
                        if (null != definingNodes && (definingNodes.Count > 0))
                            oldDefinitions.Add(kvp.Key, definingNodes[0]);
                    }
                }

                this.version = (RuntimeStates.Version)storage.ReadInteger(FieldCode.RuntimeStatesVersion);
                this.IsModified = storage.ReadBoolean(FieldCode.IsModified);

                int variableNodesMapCount = storage.ReadInteger(FieldCode.VariableNodesMapCount);
                this.variableNodesMap.Clear();
                for (int i = 0; i < variableNodesMapCount; i++)
                {
                    string key = storage.ReadString(FieldCode.VariableNodesMapKey);
                    List<uint> value = new List<uint>();
                    int valueCount = storage.ReadInteger(FieldCode.VariableNodesMapValueCount);
                    for (int j = 0; j < valueCount; j++)
                        value.Add(storage.ReadUnsignedInteger(FieldCode.VariableNodesMapValue));
                    this.variableNodesMap.Add(key, value);
                }

                // After deserialization is done, we'll move all the previously defined variables
                // into the "undefinedVarsTracker". Note that we copy ALL of them into the tracker,
                // but some of them may still be defined after the "variableNodesMap" got updated.
                // This is because eventually these variables which are still in the system will
                // be removed in the final pass in "EndDefinitionMonitor" call.
                //
                if (null != oldDefinitions && (oldDefinitions.Count > 0))
                {
                    foreach (KeyValuePair<string, uint> oldDefinition in oldDefinitions)
                    {
                        string name = oldDefinition.Key;
                        uint nodeId = oldDefinition.Value;
                        if (!undefinedVarsTracker.ContainsKey(nodeId))
                            undefinedVarsTracker[nodeId] = new List<string>();

                        List<string> variables = undefinedVarsTracker[nodeId];
                        if (!variables.Contains(name))
                            variables.Add(name);
                    }
                }

                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n RuntimeStates deserialization failed.");
                return false;
            }
        }
Пример #3
0
 internal RuntimeStates()
 {
     this.version    = RuntimeStates.Version.Current;
     this.IsModified = false;
 }
Пример #4
0
 internal RuntimeStates()
 {
     this.version = RuntimeStates.Version.Current;
     this.IsModified = false;
 }