public async Task <bool> MeasurePartAsync(Part part)
        {
            bool success = true;

            try
            {
                part.Status = PartStatus.PS_Measuring;
                part.Flag   = 0;
                _timer      = new Timer(TestBack /*_ => part.Flag = ++part.Flag % 2*/, part, 0, 2000);

                //await Task.Delay(5000);
                success = await MeasurePart(part);

                _timer.Change(Timeout.Infinite, Timeout.Infinite);
                part.Flag   = 0;
                part.Status = success ? PartStatus.PS_Measured : PartStatus.PS_Error;
            }
            catch (Exception ex)
            {
                //通讯失败中终止测量
                success   = false;
                part.Pass = false;
                OfflineEvent?.Invoke(this, null);
                _timer.Change(Timeout.Infinite, Timeout.Infinite);
                part.Flag       = 0;
                part.ResultFile = "";
                part.Status     = PartStatus.PS_Idle;
                throw new InvalidOperationException("远程测量异常");
            }

            return(success);
        }
Exemple #2
0
        public ShadowDevice Apply(OfflineEvent offlineEvent)
        {
            var eventHistory = offlineEvent.ToEventHistory();

            this.IsOnline = false;
            this.AddEventHistory(eventHistory);

            Console.WriteLine($"{offlineEvent.DeviceId} is offline at {offlineEvent.EventTime}");

            return(this);
        }
 // 当选择流程分支时,释放测量
 public bool ReleaseMeasure()
 {
     try
     {
         _pcdmisService.ReleaseMeasure();
         return(true);
     }
     catch (Exception)
     {
         ClientLogs.Inst.AddLog(new ClientLog("Pcdmis释放测量失败"));
         OfflineEvent?.Invoke(this, null);
         return(false);
     }
 }
        /// <summary>
        /// disconnect from the device
        /// </summary>
        /// <returns></returns>
        public async Task Logout()
        {
            if (this.State.IsOnline)
            {
                var offlineEvent = new OfflineEvent()
                {
                    DeviceId = this.State.Device.ID
                };
                this.RaiseEvent(offlineEvent);
                await this.ConfirmEvents();

                this._timer.Dispose();// unregistered the timer;
                this.State.IsOnline = false;
            }
        }
        public async Task <bool> MeasurePartAsync(Part part)
        {
            //判断结果,并启动文件回传
            bool success = true;

            try
            {
                part.Status = PartStatus.PS_Measuring;
                part.Flag   = 0;
                _timer      = new Timer(TestBack /*_ => part.Flag = ++part.Flag % 2*/, part, 0, 2000);

                PCDResponse response = await Task.Run(() => Measure(part));

                _timer.Change(Timeout.Infinite, Timeout.Infinite);
                part.Flag       = 0;
                success         = response.Success;
                part.Pass       = response.Pass;
                part.ResultFile = Path.GetFileName(response.ReportFile);
                part.Status     = success ? PartStatus.PS_Measured : PartStatus.PS_Error;

                if (!success)
                {
                    ClientLogs.Inst.AddLog(new ClientLog(response.Message));
                }
            }
            catch (Exception)
            {
                //通讯失败中终止测量
                success   = false;
                part.Pass = false;
                OfflineEvent?.Invoke(this, null);
                _timer.Change(Timeout.Infinite, Timeout.Infinite);
                part.Flag       = 0;
                part.ResultFile = "";
                part.Status     = PartStatus.PS_Idle;
                ClientLogs.Inst.AddLog(new ClientLog("远程服务器通讯异常"));
                throw new InvalidOperationException("远程服务器通讯异常");
            }

            return(success);
        }
Exemple #6
0
    void ShowMessage(GameEvent e, Channel MessageChannel)
    {
        GameObject   message;
        ImageEvent   imageEvent   = e as ImageEvent;
        OfflineEvent offlineEvent = e as OfflineEvent;

        if (imageEvent != null)
        {
            //Handle image messages
            //Get the image from the image manager, and figure out whether it's landscape or portrait
            ImageMapping im = ImageManager.instance.GetImage(imageEvent.ImageName);
            if (im == null)
            {
                Debug.LogError("Image " + imageEvent.ImageName + " not found in the ImageManager");
                return;
            }
            if (im.orientation == ImageOrientation.LANDSCAPE)
            {
                message = GameObject.Instantiate(LandscapeImagePrefab, MessageChannel.ContentPanel.transform);
            }
            else
            {
                AkSoundEngine.PostEvent("Picture", gameObject);
                message = GameObject.Instantiate(PortraitImagePrefab, MessageChannel.ContentPanel.transform);
            }
            message.GetComponent <ImageMessageUI>().image.sprite = im.sprite;
            CleanCanvases(MessageChannel);
        }
        else if (offlineEvent != null)
        {
            SetCharacterOffline(offlineEvent.CharacterName);
        }
        else if (e.Channel == "Group")
        {
            message = GameObject.Instantiate(MessageChannel.IncomingMessagePrefab, MessageChannel.ContentPanel.transform);
            //If we're in a group chat, the message has a portrait and a name that needs to be set up.

            Talking T = message.GetComponent <Talking>();
            T.NameText.text = (e.CharacterName + " is typing...");

            MessageUI M           = message.GetComponent <MessageUI>();
            Channel   CharChannel = Channels.Find(x => x.ChannelName == e.CharacterName);
            if (CharChannel != null)
            {
                M.CharacterImage.sprite = CharChannel.Portrait;
                M.BackgroundImage.color = CharChannel.ChatBubbleColor;
            }
            M.MessageText.text = e.Content;
            M.MessageChannel   = MessageChannel;
            M.CharacterName    = e.CharacterName;
            SetCharacterOnline(e.CharacterName);

            if (CurrentlyActiveChannel != e.Channel)
            {
                StartCoroutine(PreFinishAnimation(M));
            }
            else
            {
                BeginAnimation(M);
            }
        }
        else
        {
            message = GameObject.Instantiate(MessageChannel.IncomingMessagePrefab, MessageChannel.ContentPanel.transform);
            Talking T = message.GetComponent <Talking>();
            T.NameText.text = (e.CharacterName + " is typing...");

            MessageUI M = message.GetComponent <MessageUI>();
            //Single messages don't have to worry about the name or portrait either, just the text content
            M.MessageText.text = e.Content;
            M.MessageChannel   = MessageChannel;
            M.CharacterName    = e.CharacterName;
            SetCharacterOnline(e.CharacterName);
            M.BackgroundImage.color = MessageChannel.ChatBubbleColor;
            if (CurrentlyActiveChannel != e.Channel)
            {
                StartCoroutine(PreFinishAnimation(M));
            }
            else
            {
                BeginAnimation(M);
            }
        }
    }
Exemple #7
0
    //Here we figure out who is saying this line, when, and how long we should wait before the next one
    void ParseLine(string line, List <string> tags, List <string> globalTags)
    {
        string characterName      = "";
        string timeString         = "";
        string contentString      = "";
        string channel            = "";
        float  delayTimeInSeconds = 0.0f;
        string absoluteTimeStamp  = "";
        bool   shouldWait         = false;

        //The global tags determine the channel we're part of
        if (globalTags != null && globalTags.Count > 0)
        {
            channel = globalTags[0];
        }
        else
        {
            Debug.LogError("This ink file isn't tagged with a global channel identifier!");
        }
        //Separate out the character/time info from the text content
        //TODO: pick another character for this, or parse correctly to avoid the : in time strings
        string[] subStrings = line.Split(';');
        //If there was a section at the beginning that means we have meta display info (this might not exist for character chats, we'll see)
        if (subStrings.Length > 1)
        {
            string metaInfo = subStrings[0];
            //Now we separate out the meta info into character name and display time
            string[] metaArray = metaInfo.Split('@');
            if (metaArray.Length > 1)
            {
                characterName = metaArray[0];
                timeString    = metaArray[1];
            }
            else
            {
                //Maybe here we have the ability to only include a timestamp, for character-specific chats?
                characterName = subStrings[0];
            }
            contentString = subStrings[1];


            //Debug.Log("ParseString found - Name: " + characterName + " Time: " + timeString + " Content: " + contentString+" Channel: "+channel);

            foreach (string Tag in tags)
            {
                string[] tagpieces = Tag.Split('=');
                if (tagpieces.Length == 2)
                {
                    switch (tagpieces[0])
                    {
                    case "delay":
                        if (float.TryParse(tagpieces[1], out delayTimeInSeconds))
                        {
                            //Yay everything worked OK
                            Debug.Log("Got a delay value of " + delayTimeInSeconds + " from a tag.");
                        }
                        else
                        {
                            Debug.LogError("Found a 'delay' value in the tag " + Tag + " but it had an invalid timing value " + tagpieces[1] + "!");
                        }
                        break;

                    case "time":

                        absoluteTimeStamp = tagpieces[1];
                        break;
                    }
                }
                else if (tagpieces.Length == 1)
                {
                    switch (tagpieces[0])
                    {
                    case "wait":
                        shouldWait = true;
                        break;
                    }
                }
            }

            if (contentString.StartsWith("<") && !contentString.Contains("sprite"))
            {
                //This is an image message, not a normal message


                ImageEvent imageEvent = new ImageEvent();
                imageEvent.Content       = contentString;
                imageEvent.DisplayTime   = timeString;
                imageEvent.CharacterName = characterName;


                imageEvent.Channel               = channel;
                imageEvent.ShouldWaitAfter       = shouldWait;
                imageEvent.AbsoluteTimeString    = absoluteTimeStamp;
                imageEvent.GameTimeToBeActivated = ParseAbsoluteTimestamp(absoluteTimeStamp);

                int StartIndex = 0;
                StartIndex = contentString.IndexOf("<", StartIndex);
                string ImageName = contentString.Substring(StartIndex + 1, contentString.Length - 2);

                imageEvent.ImageName = ImageName;

                //Debug.Log("Calculated game time active to be " + imageEvent.GameTimeToBeActivated);
                TimelineManager.instance.AddEventToQueue(imageEvent);
                CurrentTimeClocks[channel] = imageEvent.GameTimeToBeActivated;
            }
            else if (contentString.StartsWith("[") && contentString.Contains("offline"))
            {
                //This is an offline message, not a normal message


                OfflineEvent offlineEvent = new OfflineEvent();
                offlineEvent.Content       = contentString;
                offlineEvent.DisplayTime   = timeString;
                offlineEvent.CharacterName = characterName;


                offlineEvent.Channel               = channel;
                offlineEvent.ShouldWaitAfter       = shouldWait;
                offlineEvent.AbsoluteTimeString    = absoluteTimeStamp;
                offlineEvent.GameTimeToBeActivated = ParseAbsoluteTimestamp(absoluteTimeStamp);
                offlineEvent.offline               = true;

                //Debug.Log("Calculated game time active to be " + imageEvent.GameTimeToBeActivated);
                TimelineManager.instance.AddEventToQueue(offlineEvent);
                CurrentTimeClocks[channel] = offlineEvent.GameTimeToBeActivated;
            }
            else
            {
                GameEvent gameEvent = new GameEvent();
                gameEvent.Content       = contentString;
                gameEvent.DisplayTime   = timeString;
                gameEvent.CharacterName = characterName;


                gameEvent.Channel               = channel;
                gameEvent.ShouldWaitAfter       = shouldWait;
                gameEvent.AbsoluteTimeString    = absoluteTimeStamp;
                gameEvent.GameTimeToBeActivated = ParseAbsoluteTimestamp(absoluteTimeStamp);

                Debug.Log("Calculated game time active to be " + gameEvent.GameTimeToBeActivated + " Current time: " + TimelineManager.instance.GetCurrentTime());
                TimelineManager.instance.AddEventToQueue(gameEvent);
                CurrentTimeClocks[channel] = gameEvent.GameTimeToBeActivated;
            }
        }
        else
        {
            //This line wasn't constructed appropriately, let's log an error
            Debug.LogError("String " + line + " in channel " + channel + " has no meta information (character name and in-game timestamp).");
        }
    }