Exemple #1
0
 public Client(IPEndPoint _remoteEndPoint, DateTime _connectedAt, ClientStates _clientState)
 {
     this.remoteEndPoint = _remoteEndPoint;
     this.connectedAt    = _connectedAt;
     this.clientState    = _clientState;
     this.PageHistory    = new Stack <Page>();
     this.KeyBuffer      = new Queue <Byte>();
     this.CurrentCommand = "";
     this.CommandState   = CommandStates.RegularRouting;
     this.IACState       = IACStates.OutsideIAC;
     this._random        = new Random();
     this._latencyBytes  = new byte[100];
     this._random.NextBytes(this._latencyBytes);
     this._latencyPacketCount = 0;
     this._queuedPage         = null;
     this._queuedPageTimer    = null;
     this._carouselPages      = new List <Tuple <int, int> >();
     this._carouselPages.Add(new Tuple <int, int>(91, 0));
     this._carouselPages.Add(new Tuple <int, int>(91, 1));
     this._carouselPages.Add(new Tuple <int, int>(150, 0));
     this._carouselPages.Add(new Tuple <int, int>(666, 0));
     this._carouselPages.Add(new Tuple <int, int>(999, 3));
     this._carousel        = new Carousel(this);
     this.ShowingNotices   = false;
     this.LastNoticeReadID = -1;
 }
Exemple #2
0
        public void UpdateCommand(MenuCommand cmd, CommandAction action)
        {
            CommandStates states = GetStatus(action);

            cmd.Visible = (CommandStates.Visible & states) == CommandStates.Visible;
            cmd.Enabled = (CommandStates.Enabled & states) == CommandStates.Enabled;
        }
Exemple #3
0
        public void Cancel()
        {
            if (State != CommandStates.Trying)
            {
                if (State != CommandStates.Rollback)
                {
                    CommanderReader.DispatchNack(NodeCode, trackingId, TrackingExtraData, ResponseDispatcher);
                }

                STrace.Debug(typeof(DeviceCommand).FullName, String.Format("CMD: {0} {1} {2} Node[{3:D6}] Cancel No se inicia por estado invalido.", State, trackingId, SecondsTimeout, NodeCode));
                return;
            }

            State = CommandStates.TryingCancel;
            var st = CommanderReader.DataProvider.Get(NodeCode) as ICanQueueOutgoingMessages;

            if (st != null)
            {
                st.CancelMessage(trackingId);
            }
            CommanderReader.DispatchNack(NodeCode, trackingId, TrackingExtraData, ResponseDispatcher);

            if (Timer == null)
            {
                return;
            }
            Timer.Change(10000, Timeout.Infinite);
        }
Exemple #4
0
 public void Begin()
 {
     if (State != CommandStates.JustWaitingForBegin)
     {
         STrace.Debug(typeof(DeviceCommand).FullName, Node.Id, String.Format("CMD: State={0} MessageId={1} SecondsTimeout={2} No se inicia por estado invalido.", State, MessageId, SecondsTimeout));
         return;
     }
     State = CommandStates.Trying;
     Timer.Change(SecondsTimeout * 1000, Timeout.Infinite);
 }
Exemple #5
0
 public void Begin()
 {
     if (State != CommandStates.JustWaitingForBegin)
     {
         STrace.Debug(typeof(DeviceCommand).FullName, String.Format("CMD: {0} {1} {2} Node[{3:D6}] No se inicia por estado invalido.", State, trackingId, SecondsTimeout, NodeCode));
         return;
     }
     State = CommandStates.Trying;
     Timer.Change(SecondsTimeout * 1000, Timeout.Infinite);
 }
Exemple #6
0
 public void Rollback()
 {
     State = CommandStates.Rollback;
     if (Timer == null)
     {
         return;
     }
     Timer.Dispose();
     Timer = null;
 }
Exemple #7
0
        public DeviceCommand(ulong messageId, int gatewayMessageId, INode device, IDataTransportLayer responseDispatcher, int SecondsTimeout, String TrackingExtraData)
        {
            State = CommandStates.JustWaitingForBegin;
            this.TrackingExtraData = TrackingExtraData;
            Node                    = device;
            this.MessageId          = messageId;
            this.GatewayMessageId   = gatewayMessageId;
            this.SecondsTimeout     = SecondsTimeout;
            this.ResponseDispatcher = responseDispatcher;

            Timer = new Timer(OnTimeout, this, Timeout.Infinite, Timeout.Infinite);
        }
Exemple #8
0
 public virtual ICommandProxy NoteCommandCompleted(ICommandResult commandResult)
 {
     lock (threadLock)
     {
         if (!IsCompleted)
         {
             Result = commandResult;
             State  = CommandStates.Completed;
         }
     }
     return(this);
 }
Exemple #9
0
        public DeviceCommand(int trackingId, int gatewayMessageId, int NodeCode, IDispatcherLayer ResponseDispatcher, int SecondsTimeout, String TrackingExtraData, CommanderReader CommanderReader)
        {
            State = CommandStates.JustWaitingForBegin;
            this.TrackingExtraData  = TrackingExtraData;
            this.NodeCode           = NodeCode;
            this.CommanderReader    = CommanderReader;
            this.trackingId         = trackingId;
            this.gatewayMessageId   = gatewayMessageId;
            this.SecondsTimeout     = SecondsTimeout;
            this.ResponseDispatcher = ResponseDispatcher;

            Timer = new Timer(OnTimeout, this, Timeout.Infinite, Timeout.Infinite);
        }
Exemple #10
0
        private CommandStates GetStatus(CommandAction action)
        {
            CommandStates result = CommandStates.Visible;

            bool isBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(_application.Version);

            if (!isBridgeVsConfigured)
            {
                return(result); //just show it as visible
            }
            bool isSolutionEnabled = BridgeCommand.IsSolutionEnabled(SolutionName, _application.Version);

            if (isSolutionEnabled && action == CommandAction.Disable || !isSolutionEnabled && action == CommandAction.Enable)
            {
                result |= CommandStates.Enabled;
            }

            return(result);
        }
Exemple #11
0
        public void Cancel()
        {
            if (State != CommandStates.Trying)
            {
                if (State != CommandStates.Rollback)
                {
                    CommanderReader.DispatchNack(Node, MessageId, TrackingExtraData, ResponseDispatcher);
                }

                STrace.Debug(typeof(DeviceCommand).FullName, Node.Id, String.Format("CMD: State={0} MessageId={1} SecondsTimeout={2} Cancel No se inicia por estado invalido.", State, MessageId, SecondsTimeout));
                return;
            }

            State = CommandStates.TryingCancel;
            CommanderReader.DispatchNack(Node, MessageId, TrackingExtraData, ResponseDispatcher);

            if (Timer == null)
            {
                return;
            }
            Timer.Change(10000, Timeout.Infinite);
        }
Exemple #12
0
        public void Invoke()
        {
            lock (threadLock)
            {
                switch ((CommandStates)_state)
                {
                case CommandStates.Defined:
                case CommandStates.Queued:
                    if (_cancelRequested)
                    {
                        NoteCommandCompleted(CommandResults.Cancelled);
                        return;
                    }
                    State = CommandStates.Running;
                    break;

                case CommandStates.Running:
                    // Do nothing, already invoked.
                    return;

                case CommandStates.Completed:
                    // Do nothing, already invoked.
                    return;
                }
            }

            if (null == _commandDelegate)
            {
                NoteCommandCompleted(CommandResults.Failed("Null command delegate"));
                return;
            }

            var commandResult = _commandDelegate(this);

            if (commandResult != CommandResults.InProgress)
            {
                NoteCommandCompleted(commandResult);
            }
        }
Exemple #13
0
        private CommandStates GetStatus(CommandAction action)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            CommandStates result = CommandStates.Visible;

            bool isBridgeVsConfigured = PackageConfigurator.IsBridgeVsConfigured(_application.Version);

            if (!isBridgeVsConfigured)
            {
                return(result); //just show it as visible
            }
            string solutionDir       = Path.GetDirectoryName(_application.Solution.FileName);
            string directoryTarget   = Path.Combine(solutionDir, "Directory.Build.targets");
            bool   isSolutionEnabled = File.Exists(directoryTarget);

            if (isSolutionEnabled && action == CommandAction.Disable || !isSolutionEnabled && action == CommandAction.Enable)
            {
                result |= CommandStates.Enabled;
            }

            return(result);
        }
Exemple #14
0
 public void SwitchStats(CommandStates newState)
 {
     cmdStates = newState;
 }
Exemple #15
0
 public bool HasCommandState(CommandStates state)
 {
     return(_CommandState == state);
 }
Exemple #16
0
 public void SetCommandState(CommandStates st)
 {
     _CommandState = st;
 }
Exemple #17
0
 private void Tmp()
 {
     cmdStates = CommandStates.interactable;
 }
Exemple #18
0
 public void NoteCommandQueued()
 {
     State = CommandStates.Queued;
 }
Exemple #19
0
        public bool ProcessInput(byte[] Chars, int Received, out Page NextPage, out byte[] SendIAC)
        {
            var sendIAC = new List <byte>();

            //Page first = null;
            //foreach (var item in PageHistory)
            //    first = item;
            //Debug.Assert(first.Routing.Count == 1);

            for (int i = 0; i < Received; i++)
            {
                KeyBuffer.Enqueue(Chars[i]);
            }

            NextPage = null;
            int count = KeyBuffer.Count;

            for (int i = 0; i < count; i++)
            {
                var b = KeyBuffer.Peek();

                if (b == IACCommands.IAC && IACState == IACStates.OutsideIAC)
                {
                    if (Options.IACEnabled)
                    {
                        IACState = IACStates.InsideIAC;
                    }
                    KeyBuffer.Dequeue();
                    continue;
                }

                if (b == IACCommands.IAC && IACState == IACStates.InsideIAC)
                {
                    Debugger.Break(); // This is an escaped 255
                    KeyBuffer.Dequeue();
                    continue;
                }

                if (b == IACCommands.DO && IACState == IACStates.InsideIAC)
                {
                    IACState = IACStates.Doing;
                    KeyBuffer.Dequeue();
                    continue;
                }

                if (IACState == IACStates.Doing)
                {
                    if (b == IACOptions.CUSTOM_LATENCY)
                    {
                        sendIAC.AddRange(_latencyBytes);
                        KeyBuffer.Dequeue();
                        IACState = IACStates.OutsideIAC;
                        if (_latencyPacketCount == 0)
                        {
                            _latencyStart = DateTime.Now;
                            _latencyPacketCount++;
                            Console.WriteLine("Starting LAT test. One LAT is 10 bytes->server + 100 bytes->client (To: "
                                              + string.Format("{0}", LogAddress) + ")");
                        }
                        else
                        {
                            double tot = (DateTime.Now - _latencyStart).TotalMilliseconds;
                            double avg = Math.Round(tot / _latencyPacketCount, 0);
                            Console.WriteLine(_latencyPacketCount + " LATs in " + tot.ToString()
                                              + "ms = avg " + avg.ToString() + "ms (To: " + string.Format("{0}", LogAddress) + ")");
                            _latencyPacketCount++;
                        }
                        continue;
                    }
                    if (b == IACOptions.SUPPRESS_GOAHEAD)
                    {
                        sendIAC.Add(IACCommands.IAC);
                        sendIAC.Add(IACCommands.WILL);
                        sendIAC.Add(IACOptions.SUPPRESS_GOAHEAD);
                        KeyBuffer.Dequeue();
                        IACState = IACStates.OutsideIAC;
                    }
                    else if (b == IACOptions.NEW_ENVIRON)
                    {
                        sendIAC.Add(IACCommands.IAC);
                        sendIAC.Add(IACCommands.WILL);
                        sendIAC.Add(IACOptions.NEW_ENVIRON);
                        KeyBuffer.Dequeue();
                        IACState = IACStates.OutsideIAC;
                    }
                    else
                    {
                        // If it's not an option we support, we send IAC WONT <OPTION>
                        sendIAC.Add(IACCommands.IAC);
                        sendIAC.Add(IACCommands.WONT);
                        sendIAC.Add(IACOptions.NEW_ENVIRON);
                        KeyBuffer.Dequeue();
                        IACState = IACStates.OutsideIAC;
                    }
                    continue;
                }

                if (CommandState == CommandStates.InsideStarPageCommand)
                {
                    if (b == '*')
                    {
                        CommandState = CommandStates.InsideFastTextCommand;
                        KeyBuffer.Dequeue();
                        continue;
                    }

                    if (b >= '0' && b <= '9')
                    {
                        KeyBuffer.Dequeue();
                        CurrentCommand += Convert.ToChar(b).ToString();
                        //Console.WriteLine(string.Format("Inside Star Page Command, Adding {0}; CurrentCommand: '{1}' (",
                        //    b.ToString("X2"), CurrentCommand) + string.Format("{0}", LogAddress) + ")");
                        continue;
                    }
                    if (b == ENTER)
                    {
                        //Console.WriteLine(string.Format("Exiting Star Page Command; CurrentCommand: '{0}' (", CurrentCommand)
                        //    + string.Format("{0}", LogAddress) + ")");
                        KeyBuffer.Dequeue();
                        if (CurrentCommand == "00") // Previous page
                        {
                            CommandState   = CommandStates.RegularRouting;
                            CurrentCommand = "";
                            if (PageHistory.Count > 1)
                            {
                                PageHistory.Pop();
                            }
                            NextPage = PageHistory.Peek();
                            Debug.Assert(PageHistory.Count > 0);
                            SendIAC = sendIAC.ToArray();
                            return(true);
                        }
                        else
                        {
                            int pageNo;
                            int.TryParse(CurrentCommand, out pageNo);
                            NextPage = Page.Load(pageNo, 0, _carousel, LastSeen);
                            if (NextPage.PageNo != pageNo)
                            {
                                NextPage = Page.Load(1, 0, _carousel, LastSeen);
                            }
                            PageHistory.Push(NextPage);
                            CommandState   = CommandStates.RegularRouting;
                            CurrentCommand = "";
                            SendIAC        = sendIAC.ToArray();
                            return(true);
                        }
                    }
                    KeyBuffer.Dequeue();
                    CommandState   = CommandStates.RegularRouting;
                    CurrentCommand = "";
                    //Console.WriteLine(string.Format("Exiting Star Page Command, Invalid {0}; CurrentCommand: '{1}' (",
                    //    b.ToString("X2"), CurrentCommand) + string.Format("{0}", LogAddress) + ")");
                    continue;
                }

                if (CommandState == CommandStates.RegularRouting)
                {
                    if (b == '*')
                    {
                        //Console.WriteLine(string.Format("Entering Star Page Command; CurrentCommand: '{0}' (", CurrentCommand)
                        //    + string.Format("{0}", LogAddress) + ")");
                        CommandState = CommandStates.InsideStarPageCommand;
                        KeyBuffer.Dequeue();
                        continue;
                    }
                    if (ShowingNotices && b == ENTER)
                    {
                        var np = Notice.GetNextNotice(PageHistory.Peek(), ClientHash, ref ShowingNotices, ref LastNoticeReadID);
                        if (np != null)
                        {
                            NextPage = np;
                            PageHistory.Push(NextPage);
                            KeyBuffer.Dequeue();
                            SendIAC = sendIAC.ToArray();
                            return(true);
                        }
                    }
                    //Console.WriteLine(string.Format("Outside Commands, Processing {0} (", b.ToString("X2"))
                    //    + string.Format("{0}", LogAddress) + ")");
                    var route = CurrentPage.Routing.FirstOrDefault(r => r.KeyCode == b);
                    if (route != null)
                    {
                        if (CurrentPage.PageType == PageTypes.TeleSoftware && route.NextPageNo != null && route.NextFrameNo != null)
                        {
                            NextPage = Page.Load((int)route.NextPageNo, (int)route.NextFrameNo, _carousel, LastSeen);
                            PageHistory.Push(NextPage);
                            KeyBuffer.Dequeue();
                            SendIAC = sendIAC.ToArray();
                            return(true);
                        }
                        else if (route.GoesToPageNo >= 0 && route.GoesToFrameNo >= 0 && route.GoesToFrameNo <= 25)
                        {
                            NextPage = Page.Load(route.GoesToPageNo, route.GoesToFrameNo, _carousel, LastSeen);
                            PageHistory.Push(NextPage);
                            KeyBuffer.Dequeue();
                            SendIAC = sendIAC.ToArray();
                            return(true);
                        }
                        KeyBuffer.Dequeue();
                        SendIAC = sendIAC.ToArray();
                        return(false);
                    }
                    KeyBuffer.Dequeue();
                }
                if (CommandState == CommandStates.InsideFastTextCommand)
                {
                    b = KeyBuffer.Peek();

                    if (b >= '0' && b <= '9')
                    {
                        KeyBuffer.Dequeue();
                        CurrentCommand += Convert.ToChar(b).ToString();
                        continue;
                    }

                    if (b == ENTER)
                    {
                        KeyBuffer.Dequeue();
                        int col;
                        if (!int.TryParse(CurrentCommand, out col))
                        {
                            col = -1;
                        }
                        if (col < 0 || col > 7 || PageHistory.Count == 0 || PageHistory.Peek().Routing == null)
                        {
                            CommandState   = CommandStates.RegularRouting;
                            CurrentCommand = "";
                            continue;
                        }
                        byte colour = Convert.ToByte(col | 0x80);
                        foreach (var route in PageHistory.Peek().Routing)
                        {
                            if (route.KeyCode == colour)
                            {
                                if (route.GoesToPageNo >= 0 && route.GoesToFrameNo >= 0 && route.GoesToFrameNo <= 25)
                                {
                                    NextPage = Page.Load(route.GoesToPageNo, route.GoesToFrameNo, _carousel, LastSeen);
                                    PageHistory.Push(NextPage);
                                    CommandState   = CommandStates.RegularRouting;
                                    CurrentCommand = "";
                                    SendIAC        = sendIAC.ToArray();
                                    return(true);
                                }
                            }
                        }
                        CommandState   = CommandStates.RegularRouting;
                        CurrentCommand = "";
                        continue;
                    }

                    KeyBuffer.Dequeue();
                    CommandState   = CommandStates.RegularRouting;
                    CurrentCommand = "";
                    //Console.WriteLine(string.Format("Exiting Star Page Command, Invalid {0}; CurrentCommand: '{1}' (",
                    //    b.ToString("X2"), CurrentCommand) + string.Format("{0}", LogAddress) + ")");
                    continue;
                }
            }

            SendIAC = sendIAC.ToArray();
            return(false);
        }