Example #1
0
        private void AdjustParseSpan(ref SnapshotSpan span)
        {
            int start       = span.Start.Position;
            int endPosition = span.End.Position;

            ITextSnapshotLine firstDirtyLine = null;

            if (_firstDirtyLine.HasValue)
            {
                firstDirtyLine = span.Snapshot.GetLineFromLineNumber(_firstDirtyLine.Value);
                start          = Math.Min(start, firstDirtyLine.Start.Position);
            }

            int startLine = span.Snapshot.GetLineNumberFromPosition(start);

            while (startLine > 0)
            {
                LineStateInfo lineState = _lineStates[startLine - 1];
                if (!lineState.MultilineToken)
                {
                    break;
                }

                startLine--;
            }

            start = span.Snapshot.GetLineFromLineNumber(startLine).Start;
            int length = endPosition - start;

            span = new SnapshotSpan(span.Snapshot, start, length);
        }
        protected virtual void SetLineState(int line, LineStateInfo state)
        {
            _lineStates[line] = state;
            if (!state.IsDirty && _firstDirtyLine.HasValue && _firstDirtyLine == line)
            {
                _firstDirtyLine++;
            }

            if (!state.IsDirty && _lastDirtyLine.HasValue && _lastDirtyLine == line)
            {
                _firstDirtyLine = null;
                _lastDirtyLine  = null;
            }
        }
Example #3
0
        protected virtual TState AdjustParseSpan(ClassifierState classifierState, ref SnapshotSpan span)
        {
            int start       = span.Start.Position;
            int endPosition = span.End.Position;

            ITextSnapshotLine firstDirtyLine = null;

            if (classifierState._firstDirtyLine.HasValue)
            {
                firstDirtyLine = span.Snapshot.GetLineFromLineNumber(classifierState._firstDirtyLine.Value);
                start          = Math.Min(start, firstDirtyLine.Start.Position);
            }

            bool   haveState = false;
            TState state     = default(TState);

            int startLine = span.Snapshot.GetLineNumberFromPosition(start);

            while (startLine > 0)
            {
                LineStateInfo lineState = classifierState._lineStates[startLine - 1];
                if (!lineState.MultilineToken)
                {
                    haveState = true;
                    state     = lineState.EndLineState;
                    break;
                }

                startLine--;
            }

            if (startLine == 0)
            {
                haveState = true;
                state     = GetStartState();
            }

            start = span.Snapshot.GetLineFromLineNumber(startLine).Start;
            int length = endPosition - start;

            span = new SnapshotSpan(span.Snapshot, start, length);
            Debug.Assert(haveState);
            return(state);
        }
        protected virtual void SetLineState(TaggerState taggerState, int line, LineStateInfo state)
        {
            Contract.Requires(state.IsDirty || !taggerState._firstDirtyLine.HasValue || line <= taggerState._firstDirtyLine);

            using (_lock.WriteLock())
            {
                taggerState._lineStates[line] = state;
                if (!state.IsDirty && taggerState._firstDirtyLine == line)
                {
                    taggerState._firstDirtyLine++;
                }

                if (!state.IsDirty && taggerState._lastDirtyLine == line)
                {
                    taggerState._firstDirtyLine = null;
                    taggerState._lastDirtyLine  = null;
                }
            }
        }
        protected virtual void HandleTextBufferChangedHighPriority(object sender, TextContentChangedEventArgs e)
        {
            foreach (ITextChange change in e.Changes)
            {
                int lineNumberFromPosition = e.After.GetLineNumberFromPosition(change.NewPosition);
                int num2 = e.After.GetLineNumberFromPosition(change.NewEnd);
                if (change.LineCountDelta < 0)
                {
                    _lineStates.RemoveRange(lineNumberFromPosition, Math.Abs(change.LineCountDelta));
                }
                else if (change.LineCountDelta > 0)
                {
                    TState        endLineState = _lineStates[lineNumberFromPosition].EndLineState;
                    LineStateInfo element      = new LineStateInfo(endLineState);
                    _lineStates.InsertRange(lineNumberFromPosition, Enumerable.Repeat(element, change.LineCountDelta));
                }

                if (_lastDirtyLine.HasValue && _lastDirtyLine.Value > lineNumberFromPosition)
                {
                    _lastDirtyLine += change.LineCountDelta;
                }

                if (_lastChangedLine.HasValue && _lastChangedLine.Value > lineNumberFromPosition)
                {
                    _lastChangedLine += change.LineCountDelta;
                }

                for (int i = lineNumberFromPosition; i <= num2; i++)
                {
                    TState        num5  = _lineStates[i].EndLineState;
                    LineStateInfo info2 = new LineStateInfo(num5, true);
                    _lineStates[i] = info2;
                }

                _firstChangedLine = _firstChangedLine.HasValue ? Math.Min(_firstChangedLine.Value, lineNumberFromPosition) : lineNumberFromPosition;
                _lastChangedLine  = _lastChangedLine.HasValue ? Math.Max(_lastChangedLine.Value, num2) : num2;
            }
        }
Example #6
0
        protected virtual void HandleTextBufferChangedHighPriority(object sender, TextContentChangedEventArgs e)
        {
            try
            {
                using (_lock.WriteLock(TimeSpan.FromSeconds(1)))
                {
                    ClassifierState beforeState = _lineStatesCache.GetValue(e.Before, CreateClassifierState);

                    ClassifierState afterState = _lineStatesCache.GetValue(e.After, CreateClassifierState);
                    afterState._firstChangedLine = beforeState._firstChangedLine;
                    afterState._lastChangedLine  = beforeState._lastChangedLine;
                    afterState._firstDirtyLine   = beforeState._firstDirtyLine;
                    afterState._lastDirtyLine    = beforeState._lastDirtyLine;

                    List <LineStateInfo> lineStates = new List <LineStateInfo>(beforeState._lineStates);

                    foreach (ITextChange change in e.Changes)
                    {
                        int lineNumberFromPosition = e.After.GetLineNumberFromPosition(change.NewPosition);
                        int num2 = e.After.GetLineNumberFromPosition(change.NewEnd);
                        if (change.LineCountDelta < 0)
                        {
                            lineStates.RemoveRange(lineNumberFromPosition, Math.Abs(change.LineCountDelta));
                        }
                        else if (change.LineCountDelta > 0)
                        {
                            TState        endLineState = lineStates[lineNumberFromPosition].EndLineState;
                            LineStateInfo element      = new LineStateInfo(endLineState);
                            lineStates.InsertRange(lineNumberFromPosition, Enumerable.Repeat(element, change.LineCountDelta));
                        }

                        if (afterState._lastDirtyLine > lineNumberFromPosition)
                        {
                            afterState._lastDirtyLine += change.LineCountDelta;
                        }

                        if (afterState._lastChangedLine > lineNumberFromPosition)
                        {
                            afterState._lastChangedLine += change.LineCountDelta;
                        }

                        for (int i = lineNumberFromPosition; i <= num2; i++)
                        {
                            TState        num5  = lineStates[i].EndLineState;
                            LineStateInfo info2 = new LineStateInfo(num5, true);
                            lineStates[i] = info2;
                        }

                        afterState._firstChangedLine = Math.Min(afterState._firstChangedLine ?? lineNumberFromPosition, lineNumberFromPosition);
                        afterState._lastChangedLine  = Math.Max(afterState._lastChangedLine ?? num2, num2);
                    }

                    Debug.Assert(lineStates.Count == afterState._lineStates.Length);
                    lineStates.CopyTo(afterState._lineStates);
                }
            }
            catch (TimeoutException)
            {
                _failedTimeout = true;
                UnsubscribeEvents();
            }
        }
Example #7
0
        protected virtual void SetLineState(ClassifierState classifierState, int line, LineStateInfo state)
        {
            Debug.Assert(state.IsDirty || !classifierState._firstDirtyLine.HasValue || line <= classifierState._firstDirtyLine);

            using (_lock.WriteLock())
            {
                classifierState._lineStates[line] = state;
                if (!state.IsDirty && classifierState._firstDirtyLine == line)
                {
                    classifierState._firstDirtyLine++;
                }

                if (!state.IsDirty && classifierState._lastDirtyLine == line)
                {
                    classifierState._firstDirtyLine = null;
                    classifierState._lastDirtyLine  = null;
                }
            }
        }
Example #8
0
        /// <summary>
        /// Processes all events.
        /// </summary>
        /// <param name="altiEvent">Block of data to process.</param>
        /// <returns>An object whith the event.</returns>
        protected override void ProcessEvent(AltiLinkPlus.ALPEvent altiEvent)
        {
            // Getting information only if event is for our SP control line.
            TraceOut.Put("AltiGenSP::ProcessEvent LocId=" + altiEvent.LocationId + " EventId=" + ((ALPEvID)altiEvent.CommandId).ToString());
            if (altiEvent.LocationId == ControlLocationID)
            {
                switch ((ALPEvID)(altiEvent.CommandId))
                {
                // Event Ev.Ring.
                case ALPEvID.APC_CALLPRESENT:
                {
                    CallInfo rInfo = new CallInfo(((AltiLinkPlus.ALPParameter)(altiEvent[0])));
                    ALPLine  _line = this[rInfo.lineID];
                    if (!_line.IsUnderAPCControl)
                    {
                        AltiLinkPlus.ALPCommand ac = new AltiLinkPlus.ALPCommand(ControlLocationID, (int)(ALPCmdID.APC_GET_DATA));
                        ac[0] = new AltiLinkPlus.ALPParameter(rInfo.lineID);
                        ac[1] = new AltiLinkPlus.ALPParameter((int)Diacom.AltiGen.ALPInfoType.APC_DATATYPE_USER);
                        ac[2] = new AltiLinkPlus.ALPParameter(0);
                        StoredRingInfo.Add(ac.SequenceId, rInfo);
                        base.SendALPCommand(ac);
                        _line.InfoState = ALPLine.CallInfoState.CALL_INFO_REQ_SENT;
                        _line.Digits.Clear();
                        TraceOut.Put("AltiGenSP::APC_CALLPRESENT from :" + rInfo.callerID + " - requested extra info");
                    }
                    break;
                }

                // Event Ev.RingBack.
                case ALPEvID.APC_RINGBACK:
                {
                    CallInfo rbInfo = new CallInfo(((AltiLinkPlus.ALPParameter)(altiEvent[0])));
                    // Getting current line from hashtable.
                    ALPLine _line = this[rbInfo.lineID];
                    if (_line != null)
                    {
                        // Updating line information.
                        if (_line.SPLineInfo.Type == "T")
                        {
                            _line.SPLineInfo.CalledNumber = _line.SPLineInfo.AccessCode + rbInfo.calleeID;
                            _line.SPLineInfo.CalledName   = rbInfo.calleeName;
                        }
                        else
                        {
                            _line.SPLineInfo.CalledNumber = rbInfo.callerID;
                            _line.SPLineInfo.CalledName   = rbInfo.callerName;
                        }
                        _line.SPLineInfo.DNISNumber = rbInfo.DNISID;
                        _line.SPLineInfo.DNISName   = rbInfo.DNISName;
                        _line.SPLineInfo.CIDNumber  = rbInfo.ANIID;
                        _line.SPLineInfo.CIDName    = rbInfo.ANIName;
                        _line.SPLineInfo.DIDNumber  = rbInfo.calleeID;
                        _line.SPLineInfo.DIDName    = rbInfo.calleeName;
                        TraceOut.Put("AltiGenSP::APC_RINGBACK");

                        if (!_line.IsUnderAPCControl)
                        {
                            this.SendSpEvent(new Ev.RingBack(rbInfo.lineID, (SPLine)_line.SPLineInfo.Clone()));
                        }
                    }
                    break;
                }

                // Event Ev.Connect.
                case ALPEvID.STCHG:
                {
                    // Getting parameters.
                    ALPLineState state  = ((ALPLineState)(altiEvent[0].ReadInt32()));
                    int          lineID = altiEvent[1].ReadInt32();
                    // Getting current line from hashtable.
                    ALPLine _line = this[lineID];
                    TraceOut.Put("AltiGenSP::Line State=" + ((ALPLineState)state).ToString());

                    if ((_line != null) && (state == ALPLineState.APC))
                    {
                        if (_line.IsUnderAPCControl &&
                            (_line.InfoState == ALPLine.CallInfoState.SNATCHED_SLAVE_LINE))
                        {
                            this.SendSpEvent(new Ev.CommandStatus(_line.ConnectedLine.SPLineInfo.ID, Cmd.CommandID.DISCONNECT_LINE, Diacom.Ev.CmdStatus.OK));
                        }
                        else if (!_line.IsUnderAPCControl)
                        {
                            if (_line.InfoState == ALPLine.CallInfoState.CALL_INFO_RECEIVED)
                            {
                                // Have new connected line. Creating and sending event.
                                TraceOut.Put("AltiGenSP:: Line is APC controlled now");
                                _line.IsUnderAPCControl = true;
                                this.SendSpEvent(new Ev.Connect(lineID));
                                foreach (string _digit in _line.Digits)
                                {
                                    this.SendSpEvent(new Ev.Digit(lineID, _digit[0]));
                                }
                            }
                            else
                            {
                                _line.InfoState = ALPLine.CallInfoState.CONNECT_DELAYED;
                            }
                        }
                    }
                    break;
                }

                // Event Ev.Digit.
                case ALPEvID.APC_DIGIT:
                {
                    // Getting parameters.
                    AltiLinkPlus.ALPParameter param = (AltiLinkPlus.ALPParameter)altiEvent[0];
                    int  lineID = param.ReadInt32();
                    char digit  = Convert.ToChar(param.ReadByte());
                    // Creating and sending event.
                    ALPLine _line = this[lineID];
                    if (_line.IsUnderAPCControl)
                    {
                        this.SendSpEvent(new Ev.Digit(lineID, digit));
                    }
                    else
                    {
                        _line.Digits.Add(digit.ToString());
                    }
                    break;
                }

                // Event Ev.Disconnect.
                case ALPEvID.APC_CALLDROP:
                {
                    // Getting parameters.
                    int     lineID = altiEvent[0].ReadInt32();
                    ALPLine _line  = this[lineID];
                    break;
                }

                // Event Ev.CommandStatus.
                case ALPEvID.APC_STATUS:
                {
                    // Creating new StateInfo object.
                    LineStateInfo sInfo         = new LineStateInfo((AltiLinkPlus.ALPParameter)(altiEvent[0]));
                    ALPCmdStatus  lastCmdStatus = (ALPCmdStatus)sInfo.cmdStatus;
                    TraceOut.Put("AltiGenSP::APC Status Line=" + sInfo.lineID + " CmdId=" + ((ALPCmdID)sInfo.commandID).ToString()
                                 + " Status=" + lastCmdStatus.ToString());

                    // Getting current line from hashtable.
                    ALPLine _line = this[sInfo.lineID];
                    if (_line == null)
                    {
                        break;
                    }

                    // Save the last status
                    _line.LastCommand.Status = lastCmdStatus;
                    // What was the command issued?
                    switch ((ALPCmdID)(sInfo.commandID))
                    {
                    // Status of APC_PLAY_DTMF command.
                    case ALPCmdID.APC_PLAY_DTMF:
                        if (lastCmdStatus == ALPCmdStatus.FAILED)
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.PLAY_DTMF, Ev.CmdStatus.ERROR));
                        }
                        else
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.PLAY_DTMF, Ev.CmdStatus.OK));
                        }
                        break;

                    // Status of APC_PLAY_VOICE command.
                    case ALPCmdID.APC_PLAY_VOICE:
                        if (lastCmdStatus == ALPCmdStatus.FINISHED)
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.PLAY_FILE, Ev.CmdStatus.OK));
                        }
                        else if (lastCmdStatus == ALPCmdStatus.FAILED)
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.PLAY_FILE, Ev.CmdStatus.ERROR));
                        }
                        break;

                    // Status of APC_RECORD_VOICE command.
                    case ALPCmdID.APC_RECORD_VOICE:
                        if (lastCmdStatus == ALPCmdStatus.FINISHED)
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.RECORD_FILE, Ev.CmdStatus.OK));
                        }
                        else if (lastCmdStatus == ALPCmdStatus.FAILED)
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.RECORD_FILE, Ev.CmdStatus.ERROR));
                        }
                        break;

                    // Status of APC_CONNECT_CALL command.
                    case ALPCmdID.APC_CONNECT_CALL:
                        if (lastCmdStatus == ALPCmdStatus.SUCCEED)
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.CONNECT_LINES, Ev.CmdStatus.OK));
                        }
                        else
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.CONNECT_LINES, Ev.CmdStatus.ERROR));
                        }
                        break;

                    // Status of APC_TRANSFER_CALL command.
                    case ALPCmdID.APC_TRANSFER_CALL:
                        if (lastCmdStatus != ALPCmdStatus.SUCCEED)
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.TRANSFER, Ev.CmdStatus.ERROR));
                        }
                        break;

                    // Status of APC_DROP_CALL command.
                    case ALPCmdID.APC_DROP_CALL:
                        if (lastCmdStatus == ALPCmdStatus.SUCCEED)
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.DROP_CALL, Ev.CmdStatus.OK));
                        }
                        else
                        {
                            this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.DROP_CALL, Ev.CmdStatus.ERROR));
                        }
                        break;
                    }
                    break;
                }

                default:
                {
                    base.ProcessEvent(altiEvent);
                    break;
                }
                }
            }
            // Getting information for ALL line PADs - just want to know that is going on.
            switch ((ALPEvID)(altiEvent.CommandId))
            {
            case ALPEvID.STCHG:
            {
                if (altiEvent.LocationId == ControlLocationID)
                {
                    break;                              // We already processed this above
                }
                // Saving line state.
                ALPLineState state = (ALPLineState)(altiEvent[0].ReadInt32());
                ALPLine      _line = this[altiEvent.LocationId];
                TraceOut.Put("AltiGenSP::Line State=" + ((SPLineState)state).ToString());

                if (_line != null)
                {
                    // Rasing event the line is disconnected if status is DISCONNECT.
                    if (state == ALPLineState.IDLE)
                    {
                        if (_line.IsUnderAPCControl)
                        {
                            TraceOut.Put("AltiGenSP:: Line is not APC controlled");
                            _line.IsUnderAPCControl = false;
                            _line.InfoState         = ALPLine.CallInfoState.INITIAL;
                            this.SendSpEvent(new Ev.Disconnect(_line.SPLineInfo.ID));
                        }
                    }
                    else if ((state == ALPLineState.CONNECTED) && (_line.LastCommand.ID == ALPCmdID.APC_TRANSFER_CALL))
                    {
                        this.SendSpEvent(new Ev.CommandStatus(_line.SPLineInfo.ID, Cmd.CommandID.TRANSFER, Ev.CmdStatus.OK));
                    }
                    _line.SPLineInfo.State = (SPLineState)state;
                    // Rasing event state of the line changed.
                    this.SendSpEvent(new Ev.LineStateChanged(_line.SPLineInfo.ID, (SPLineState)state));
                }
                break;
            }

            // Event Ev.Tone.
            case ALPEvID.TONE:
            {
                // Getting parameters.
                AltiLinkPlus.ALPParameter param = (AltiLinkPlus.ALPParameter)altiEvent[0];
                int lineID = param.ReadInt32();
                param = (AltiLinkPlus.ALPParameter)altiEvent[1];
                int tone = Convert.ToChar(param.ReadInt32());
                // Creating and sending event.
                this.SendSpEvent(new Ev.Tone(lineID, ((Ev.ToneType)(tone))));
                break;
            }

            // Line information changed.
            case ALPEvID.CONFIG_CHG:
            {
                const int CONFIG_CHANGED_TYPE_LINEINFO = 0x8000;
                AltiLinkPlus.ALPParameter param        = (AltiLinkPlus.ALPParameter)altiEvent[0];
                int type = param.ReadInt32();
                if (type == CONFIG_CHANGED_TYPE_LINEINFO)
                {
                    // Command to Get Lines Information.
                    this.SendALPCommand(new Diacom.AltiGen.AltiLinkPlus.ALPCommand(altiEvent.LocationId, Convert.ToInt32(ALPCmdID.GET_LINEINFO)));
                }
                break;
            }

            // System configuration changed.
            case ALPEvID.SYSCONFIG_CHG:
            {
                AltiLinkPlus.ALPParameter param = (AltiLinkPlus.ALPParameter)altiEvent[0];
                SystemConfigChangeCodes   type  = ((SystemConfigChangeCodes)(param.ReadInt32()));
                switch (type)
                {
                // Line added.
                case SystemConfigChangeCodes.LINEADD:
                {
                    // Issue command to Get Line Information. When we get the response - then the code there will send an event.
                    this.SendALPCommand(new Diacom.AltiGen.AltiLinkPlus.ALPCommand(altiEvent.LocationId, Convert.ToInt32(ALPCmdID.GET_LINEINFO)));
                    break;
                }

                // Line removed.
                case SystemConfigChangeCodes.LINEREMOVE:
                {
                    this.SendSpEvent(new Ev.LineStateChanged(altiEvent.LocationId, SPLineState.LINE_REMOVE));
                    break;
                }
                }
                break;
            }

            default:
            {
                if (altiEvent.LocationId != ControlLocationID)
                {
                    base.ProcessEvent(altiEvent);
                }
                break;
            }
            }
        }
        protected virtual void HandleTextBufferChangedHighPriority(object sender, TextContentChangedEventArgs e)
        {
            foreach (ITextChange change in e.Changes)
            {
                int lineNumberFromPosition = e.After.GetLineNumberFromPosition(change.NewPosition);
                int num2 = e.After.GetLineNumberFromPosition(change.NewEnd);
                if (change.LineCountDelta < 0)
                {
                    _lineStates.RemoveRange(lineNumberFromPosition, Math.Abs(change.LineCountDelta));
                }
                else if (change.LineCountDelta > 0)
                {
                    LineStateInfo element = new LineStateInfo();
                    _lineStates.InsertRange(lineNumberFromPosition, Enumerable.Repeat(element, change.LineCountDelta));
                }

                if (_lastDirtyLine.HasValue && _lastDirtyLine.Value > lineNumberFromPosition)
                {
                    _lastDirtyLine += change.LineCountDelta;
                }

                if (_lastChangedLine.HasValue && _lastChangedLine.Value > lineNumberFromPosition)
                {
                    _lastChangedLine += change.LineCountDelta;
                }

                for (int i = lineNumberFromPosition; i <= num2; i++)
                {
                    LineStateInfo info2 = new LineStateInfo(true);
                    _lineStates[i] = info2;
                }

                _firstChangedLine = _firstChangedLine.HasValue ? Math.Min(_firstChangedLine.Value, lineNumberFromPosition) : lineNumberFromPosition;
                _lastChangedLine = _lastChangedLine.HasValue ? Math.Max(_lastChangedLine.Value, num2) : num2;
            }
        }
        protected virtual void SetLineState(int line, LineStateInfo state)
        {
            _lineStates[line] = state;
            if (!state.IsDirty && _firstDirtyLine.HasValue && _firstDirtyLine == line)
            {
                _firstDirtyLine++;
            }

            if (!state.IsDirty && _lastDirtyLine.HasValue && _lastDirtyLine == line)
            {
                _firstDirtyLine = null;
                _lastDirtyLine = null;
            }
        }