Ejemplo n.º 1
0
 protected void VerifyCode(SyncCode actual, SyncCode expected, SyncReader reader, SyncWriter writer)
 {
     if (actual == SyncCode.Error)
     {
         String msg = reader.ReadString();
         throw new SyncException(String.Format("Peer reported error: {0}", msg));
     }
     else if (actual != expected)
     {
         String msg = String.Format("Unexpected code {0} when looking for {1}", actual, expected);
         writer.Write(SyncCode.Error);
         writer.Write(msg);
         throw new SyncException(msg);
     }
 }
Ejemplo n.º 2
0
        private void SyncCodeProcess(string code)
        {
            if (this.InvokeRequired)//如果是在非创建控件的线程访问,即InvokeRequired=true
            {
                SyncCode syncCode = new SyncCode(SyncCodeProcess);
                this.Invoke(syncCode, new object[] { code });
            }
            else
            {
                rtbContext.Text = code;
                int index = rtbContext.Text.IndexOf("public bool Run(");

                rtbContext.SelectionStart  = index;
                rtbContext.SelectionLength = 15;
            }
        }
Ejemplo n.º 3
0
 public void Write(SyncCode code)
 {
     Write((ushort)code);
 }
Ejemplo n.º 4
0
        public Stream UpdateMain(Stream Sync)
        {
            MemoryStream localToGlobalIdResult = new MemoryStream();

            StateFormatter bf = new StateFormatter();

            int rootId = -1;

            SyncCode code = (SyncCode)bf.Deserialize(Sync);

            while (code != SyncCode.End)
            {
                switch (code)
                {
                case SyncCode.NewLocal:
                {
                    object      obj   = bf.Deserialize(Sync);
                    StateObject state = (StateObject)obj;
                    state.ID = -1;
                    SetContainerLinks(state);
                    state.AfterDeserialization();
                    added.Add(state);
                }
                break;

                case SyncCode.Update:
                {
                    object      obj   = bf.Deserialize(Sync);
                    StateObject state = (StateObject)obj;
                    SetContainerLinks(state);
                    state.AfterDeserialization();
                    if (objects.ContainsKey(state.ID))
                    {
                        objects[state.ID] = state;
                    }
                    else
                    {
                        added.Remove(state.localID);
                        objects.Add(state);
                    }
                }
                break;

                case SyncCode.RootId:
                    rootId = (int)bf.Deserialize(Sync);
                    objects.Clear();
                    added.Clear();
                    syncCopy.Clear();
                    break;

                default:
                    throw new InvalidOperationException();
                }

                code = (SyncCode)bf.Deserialize(Sync);
            }

            if (rootId != -1)
            {
                root = objects[rootId] as WorldState;
            }

            UpdateDebugInfo();

            ApplyIDs(localToGlobalIdResult);
            localToGlobalIdResult.Seek(0, SeekOrigin.Begin);
            return(localToGlobalIdResult);
        }
Ejemplo n.º 5
0
        public void Update(Stream sync)
        {
            StateFormatter bf = new StateFormatter();

            List <object> list = new List <object>();

            int rootId = -1;

            Burntime.Platform.Log.Debug("begin sync");

            int countNew    = 0;
            int countUpdate = 0;
            int countDelete = 0;

            SyncCode code = (SyncCode)bf.Deserialize(sync);

            while (code != SyncCode.End)
            {
                switch (code)
                {
                case SyncCode.New:
                {
                    object obj = bf.Deserialize(sync);
                    list.Add(obj);
                    StateObject state = (StateObject)obj;
                    if (state.ID == -1)
                    {
                        throw new Exception("unvalid ID");
                    }

                    SetContainerLinks(state);
                    state.AfterDeserialization();

                    if (objects.ContainsKey(state.ID))
                    {
                        objects[state.ID] = state;
                    }
                    else
                    {
                        objects.Add(state);
                    }

                    countNew++;
                    // Burntime.Platform.Log.Debug("update new: " + state);
                }
                break;

                case SyncCode.Update:
                {
                    object obj = bf.Deserialize(sync);
                    list.Add(obj);
                    StateObject state = (StateObject)obj;
                    if (state.ID == -1)
                    {
                        throw new Exception("unvalid ID");
                    }

                    SetContainerLinks(state);
                    state.AfterDeserialization();
                    if (objects.ContainsKey(state.ID))
                    {
                        objects[state.ID] = state;
                    }
                    else
                    {
                        added.Remove(state.localID);
                        objects.Add(state);
                    }

                    countUpdate++;
                    // Burntime.Platform.Log.Debug("update update: " + state);
                }
                break;

                case SyncCode.Delete:
                {
                    int key = (int)bf.Deserialize(sync);
                    if (objects.ContainsKey(key))
                    {
                        //     Burntime.Platform.Log.Debug("update delete: " + objects[key]);
                        objects.Remove(key);
                    }

                    countDelete++;
                }
                break;

                case SyncCode.RootId:
                    rootId = (int)bf.Deserialize(sync);
                    objects.Clear();
                    added.Clear();
                    syncCopy.Clear();
                    break;
                }

                code = (SyncCode)bf.Deserialize(sync);
            }

            if (rootId != -1)
            {
                root = objects[rootId] as WorldState;
            }

            // CheckConsistency(); // DEBUG
            UpdateDebugInfo();
        }
Ejemplo n.º 6
0
 public SyncObject(int key, SyncCode code)
 {
     Key  = key;
     Code = code;
 }