Example #1
0
        public async System.Threading.Tasks.Task TestFetchAsync()
        {
            SayingsAbstractModel m = new MockedRemoteModel();

            //Now how the following "captures m"
            Func <Task> atest = async() =>
            {
                (bool success, string ErrorString) = await m.NextSaying();

                Assert.IsTrue(success, "NextSaying failed");
                Assert.IsTrue(ErrorString.Equals("OK"));
                Assert.IsTrue(m.CurrentSaying.Equals(Sayings[0]));
                (success, ErrorString) = await m.NextSaying();

                Assert.IsTrue(success, "NextSaying failed");
                Assert.IsTrue(ErrorString.Equals("OK"));
                Assert.IsTrue(m.CurrentSaying.Equals(Sayings[1]));
            };

            await atest();

            //Change m
            m = new RemoteModel();

            //Rerun tests
            await atest();
        }
        public Task <LoadModelResult> Load(RemoteModel model, Entity parent)
        {
            var machine = AppServices.RemoteRendering?.PrimaryMachine;

            if (machine == null)
            {
                var msg = $"Unable to load model: this is no remote rendering session. (url = {model.Url})";
                Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, "{0}", msg);
                AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error);
                return(null);
            }

            if (machine.Session.Connection.ConnectionStatus != ConnectionStatus.Connected)
            {
                var msg = $"Unable to load model: manager is not connected. (url = {model.Url})";
                Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, "{0}", msg);
                AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error);
                return(null);
            }

            ModelProgressStatus progressTask = new ModelProgressStatus();
            var loadModelTask = ScaleLoad(model, parent, progressTask);

            return(loadModelTask);
        }
Example #3
0
        public AddRemoteWindow(RemoteModel config)
        {
            InitializeComponent();
            DataContext = Model = new AddRemoteViewModel(this, config);

            Title         = MainViewModel.GetLocalized("AddRemote_EditTitle");
            text_add.Text = MainViewModel.GetLocalized("AddRemote_EditSave");
        }
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            IModel        model      = new RemoteModel("http://localhost:59876/");
            MainViewModel viewModel  = new MainViewModel(model);
            MainWindow    mainWindow = new MainWindow(viewModel);

            mainWindow.Show();
        }
Example #5
0
        private async void ScaleLoad(RemoteModel model, Entity parent, ModelProgressStatus progressTask)
        {
            var machine = AppServices.RemoteRendering?.PrimaryMachine;

            // Remember the current connection, so we can cancel the load on a new connection
            uint connectionId = _connectionId;

            LoadModelAsync loadOperation = null;

            _progress.Add(progressTask);

            while (true)
            {
                if (machine == null)
                {
                    var msg = $"Unable to load model: there is no remote rendering session. (url = {model.Url})";
                    Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, "{0}", msg);
                    AppServices.AppNotificationService.RaiseNotification(msg, AppNotificationType.Error);
                    break;
                }

                lock (_loadingTasks)
                {
                    if (_loadingTasks.Count == 0 ||
                        _loadingTasks.Count < _remoteObjectFactoryServiceProfile.ConcurrentModelLoads)
                    {
                        loadOperation = machine.Actions.LoadModelAsyncAsOperation(model, parent);
                        break;
                    }
                }

                await Task.WhenAll(_loadingTasks);

                lock (_loadingTasks)
                {
                    _loadingTasks.Clear();
                }
            }

            if (loadOperation != null)
            {
                if (_connectionId != connectionId)
                {
                    progressTask.Start(null);
                }
                else
                {
                    progressTask.Start(loadOperation);
                    _loadingTasks.Add(IgnoreFailure(progressTask.Result));
                }
            }
        }
        /// <summary>
        /// 从本地主动获取NTF消息包
        /// </summary>
        private static void ReadNTFMessageFromLocal()
        {
            MessageManager msgManager  = MessageManager.Instance;
            RemoteModel    remoteModel = RemoteModel.Instance;
            // ulong time = 1560234066;
            List <NetworkMessage> NTFMessageBody = msgManager.deserializeFromLocalByTimeStamp <NetworkMessage>(MessageManager.DEST_PATH_CSharp, remoteModel.CurrentTime);

            if (NTFMessageBody.Count > 0)
            {
                List <object> messagesBody = new List <object>();
                try
                {
                    messagesBody.Add(NTFMessageBody[0].MessagesBodyBuffer[0]);
                    messagesBody.Add(PBSerializer.NDeserialize(NTFMessageBody[0].MessagesBodyBuffer[1], NTFMessageBody[0].MessageType));
                }
                catch (Exception e)
                {
                    Debug.LogWarning(e.Message);
                }
                __Proxy.__QueueAddMessage(NTFMessageBody[0].CmdID, 0, messagesBody);
            }
        }
Example #7
0
        protected List <object> ReadBody(ClientHead head, MemoryStream stream)
        {
            ///此处对读取 BODYSTEAM做了一些优化,如果有问题请注意排查 2015 08 21
            //byte[] bodyBuffer = new byte[head.BodyLength];
            //int bodyBufferOffset = 0;
            //stream.Read(bodyBuffer, 0, (int)head.BodyLength);

            byte[] bodyBuffer = stream.GetBuffer();

            int bodyBufferOffset = (int)stream.Position;

            int bodyLen = (int)head.BodyLength;

            if (bodyLen < 0)
            {
                bodyLen = 0;
            }

            stream.Position = bodyBufferOffset + bodyLen;

            ///bodylen大于零才去读MESSAGE

            //if (bodyLen > 0) //去掉吧,有些协议的长度就是为零
            {
                List <object> msgs = new List <object>();
                if (head.Format == ClientHeadFormatType.Protobuf)
                {
                    bool isLua    = false;
                    bool isCSharp = false;
                    if (__Proxy.__LuaPBProcessor.ContainsKey(head.CmdId) && _router.getPBType(head.Serial) == PBTYPE.LuaPB || _router.getPBType(head.Serial) == PBTYPE.Both)
                    {
                        byte[] buff = new byte[bodyLen];
                        //stream.Write(buff, bodyBufferOffset, bodyLen);
                        stream.Position = bodyBufferOffset;
                        stream.Read(buff, 0, bodyLen);
                        stream.Position = bodyBufferOffset + bodyLen;
                        msgs.Add(buff);
                        //return buff;
                        isLua = true;
                    }


                    if (_typeProvider.ContainsKey(head.CmdId) && _router.getPBType(head.Serial) == PBTYPE.CSharpPB || _router.getPBType(head.Serial) == PBTYPE.Both)
                    {
                        ReceiveMessageStream.Write(bodyBuffer, bodyBufferOffset, bodyLen);
                        ReceiveMessageStream.Position = 0;

                        Type messageType;
                        TypeProvider.TryGetValue(head.CmdId, out messageType);

                        if (DefineExt.Net_Log_Level > 0)
                        {
                            Debuger.Log(string.Format("Received Package 0x{0}({4}), Body Length = {1}, Message Id = {2}, Serial Id = {3}.", _recentHead.CmdId.ToString("X2"), _recentHead.BodyLength.ToString(), _recentHead.MessageId, _recentHead.Serial, _recentHead.CmdId));
                            ///解析详细的字段
                            ///todo..
                        }

                        if (messageType == null)
                        {
                            ReceiveMessageStream.SetLength(0);
                            if (_router.getPBType(head.Serial) == PBTYPE.CSharpPB)
                            {
                                Debuger.LogWarning(@"返回cmdID消息类型未注册。请在NetworkManager.registerTypes()方法中添加cmdID到返回消息类型的映射。
        CmdId = 0x" + _recentHead.CmdId.ToString("X2") + "(" + _recentHead.CmdId + ")");
                                //return null;
                            }
                        }
                        else
                        {
                            object message = null;
                            message = Serializer.NonGeneric.Deserialize(messageType, ReceiveMessageStream);
                            ReceiveMessageStream.SetLength(0);

                            if ((DefineExt.Net_Log_Level & DefineExt.LOG_FULL_RECV_PROTO_INFO) > 0)
                            {
                                Debuger.Log(String.Format("Receive ----> cmd={0}, serial={1}, proto={2}", head.CmdId, head.Serial, KHUtil.GetProtoStr(message, messageType.FullName)));
                            }

                            msgs.Add(message);

                            isCSharp = true;
                        }
                    }


                    // Update by Chicheng
                    if (msgManager.IsActivate && msgManager.IsSerializeToLocal)
                    {
                        Type messageType;
                        TypeProvider.TryGetValue(head.CmdId, out messageType);

                        // Debug.LogWarning("把读到的消息包序列化到本地");
                        RemoteModel remoteModel = RemoteModel.Instance;
                        ulong       timeStamp   = remoteModel.CurrentTime;
                        if (isCSharp && isLua)
                        {
                            serializeToLocalWithType(msgs, messageType, head.CmdId, timeStamp, head.Serial, MessageSource.CSharpAndLua);
                        }
                        else if (isLua)
                        {
                            serializeToLocalWithType(msgs, null, head.CmdId, timeStamp, head.Serial, MessageSource.Lua);
                        }
                        else if (isCSharp)
                        {
                            if (messageType != null)
                            {
                                serializeToLocalWithType(msgs, messageType, head.CmdId, 0, head.Serial, MessageSource.CSharp);
                            }
                            else
                            {
                                Debug.LogWarning("丢弃" + head.Serial);
                            }
                        }
                    }
                }
                return(msgs);
            }
        }