Пример #1
0
        private string GetCommand(string command, string logtext, bool needPassword = true)
        {
            // null Error message
            ErrorMessage = "";

            _logger.LogDebug("Start {0} func", logtext);
            int localPort = 0;

            if (needPassword)
            {
                localPort = Send(ACKPacketFactory.REQUEST(command, SendId, Password));
            }
            else
            {
                localPort = Send(ACKPacketFactory.SEND(command, SendId));
            }


            if (localPort == 0)
            {
                ErrorMessage = string.Format("{0} sending error!", logtext);
                return("");
            }

            // get request
            string ret = Get(localPort);

            if (ret.StartsWith(string.Format("ERROR {0}", SendId)))
            {
                ErrorMessage = ret.Substring(string.Format("ERROR {0} ", SendId).Length);
                _logger.LogWarning("{0} receive error. SendID: {1} Error message: {2}", logtext, SendId, ErrorMessage);
                OnSmsSendError(this, new GoIpSmsSendErrorEventArgs(ErrorMessage, SendId));
                return("");
            }

            if (!ret.StartsWith(string.Format("{0} {1}", command, SendId)))
            {
                ErrorMessage = string.Format("{0} sending error!", logtext);
                _logger.LogWarning("{0} receive error. SendID: {1} Return value: {2}", logtext, SendId, ret);
                OnSmsSendError(this, new GoIpSmsSendErrorEventArgs(ErrorMessage, SendId));
                return("");
            }


            _logger.LogDebug("End {0} func", logtext);
            return(ret.Substring(string.Format("{0} {1} ", command, SendId).Length));
        }
Пример #2
0
        /// <summary>
        /// Set GSM call forward
        /// </summary>
        /// <param name="ftime">timeout (second) of noreply forward type. Other types set to 0.</param>
        /// <param name="mode">enable or disable forward。3:enable,4:disable</param>
        /// <param name="num">forward to this number</param>
        /// <param name="reason">type of call forward. 0: unconditional,1: busy,2: noreply,3: noreachable, 4: all,5:busy,noreply,noreachable</param>
        /// <returns></returns>
        public bool SetGsmCallForward(string reason, string mode, string num, int ftime)
        {
            string s = SetCommand("CF", string.Format("{0} {1} {2} {3} {4}", Password, reason, mode, num, ftime.ToString()), "Set GSM call forward");

            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }

            // null Error message
            ErrorMessage = "";

            _logger.LogDebug("Start {0} func", "Set GSM call forward");

            int localPort = Send(ACKPacketFactory.REQUEST("CF", SendId, Password, reason, mode, num, ftime.ToString()));

            if (localPort == 0)
            {
                ErrorMessage = string.Format("{0} sending error!", "Set GSM call forward");
                return(false);
            }

            // get request
            string ret = Get(localPort);

            if (ret.StartsWith(string.Format("CFERROR {0}", SendId)))
            {
                ErrorMessage = ret.Substring(string.Format("ERROR {0} ", SendId).Length);
                _logger.LogWarning("{0} receive error. SendID: {1} Error message: {2}", "Set GSM call forward", SendId, ErrorMessage);
                OnSmsSendError(this, new GoIpSmsSendErrorEventArgs(ErrorMessage, SendId));
                return(false);
            }

            if (!ret.StartsWith(string.Format("{0} {1}", "CFOK", SendId)))
            {
                ErrorMessage = string.Format("{0} sending error!", "Set GSM call forward");
                _logger.LogWarning("{0} receive error. SendID: {1} Return value: {2}", "Set GSM call forward", SendId, ret);
                OnSmsSendError(this, new GoIpSmsSendErrorEventArgs(ErrorMessage, SendId));
                return(false);
            }

            Send(ACKPacketFactory.SEND("DONE", SendId));

            _logger.LogDebug("End {0} func", "Set GSM call forward");
            return(true);
        }