Пример #1
0
        private static FieldParseInfo GetParser <T>(XmlElement f,
                                                    MessageFactory <T> mfact) where T : IsoMessage
        {
            var itype  = Enumm.Parse <IsoType>(f.GetAttribute("type"));
            var length = 0;

            if (f.GetAttribute("length").Length > 0)
            {
                length = int.Parse(f.GetAttribute("length"));
            }
            Debug.Assert(itype != null,
                         "itype != null");
            var fpi = FieldParseInfo.GetInstance(itype.Value,
                                                 length,
                                                 mfact.Encoding);
            var subs = f.GetElementsByTagName("field");

            if (subs != null && subs.Count > 0)
            {
                var combo = new CompositeField();
                for (var i = 0; i < subs.Count; i++)
                {
                    var sf = (XmlElement)subs.Item(i);
                    Debug.Assert(sf != null,
                                 "sf != null");
                    if (sf.ParentNode == f)
                    {
                        combo.AddParser(GetParser(sf,
                                                  mfact));
                    }
                }
                fpi.Decoder = combo;
            }
            return(fpi);
        }
Пример #2
0
 public Worker(string name, Enumm workerLevel, double baseSalary, Department department)
 {
     // Sempre que tiver uma associação apra muitos, não inclui essa propiedade no construtor
     Name            = name;
     WorkerLevel     = workerLevel;
     this.BaseSalary = baseSalary;
     Department      = department;
 }
Пример #3
0
        public bool Parse(string name, string value)
        {
            switch (name)
            {
            case "channel-state":
                State = ChannelStateParser.Parse(value);
                break;

            case "channel-state-number":
                int.TryParse(value, out _stateNumber);
                break;

            case "channel-name":
                Parse(value);
                break;

            case "channel-read-codec-name":
                ReadCodecName = value;
                break;

            case "channel-read-codec-rate":
                int.TryParse(value, out _readCodecRate);
                break;

            case "channel-write-codec-name":
                WriteCodecName = value;
                break;

            case "channel-write-codec-rate":
                int.TryParse(value, out _writeCodecRate);
                break;

            case "channel-presence-id":
                PresenceId = value;
                break;

            case "channel-call-uuid":
                CallId = new UniqueId(value);
                break;

            case "channel-call-state":
                CallState = Enumm.Parse <CallState>(value);
                break;

            case "channel-read-codec-bit-rate":
                ReadCodecBitRate = value.Split(',').Select(int.Parse).ToArray();
                break;

            case "channel-write-codec-bit-rate":
                WriteCodecBitRate = value.Split(',').Select(int.Parse).ToArray();
                break;

            default:
                return(false);
            }
            return(true);
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.Write("Enter department's name :");
            string deptName = Console.ReadLine();

            Console.WriteLine("Enter worker data:");
            Console.Write("Name:");
            string name = Console.ReadLine();

            Console.Write("Level :");
            Enumm level = Enum.Parse <Enumm>(Console.ReadLine());

            Console.Write("Base Salary : ");
            double salary = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

            // Instanciaros objetos relacionados

            Department dept = new Department(deptName);

            Worker worker = new Worker(name, level, salary, dept); // Usa o objeto instanciado anteriormente

            Console.Write(" How many Contracts to this worker?");
            int num_contracts = int.Parse(Console.ReadLine());

            for (int i = 1; i <= num_contracts; i++)
            {
                Console.WriteLine($"Enter #{i} contract data: "); // $ para funcionar a interpolação {i}
                Console.Write("Date (DD/MM/YYY)");
                DateTime date = DateTime.Parse(Console.ReadLine());
                Console.Write("Value per hour:");
                double value_per_hour = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
                Console.Write("Duration(hours):");
                int hours = int.Parse(Console.ReadLine());

                // Instanciamos o contrato
                Contract contract = new Contract(date, value_per_hour, hours);

                // Adicionar aos contratos do trabalhador
                worker.AddContract(contract);
            }

            Console.Write("Enter month and year to calculat income (MM/YYY) :");
            string my = Console.ReadLine();

            // Manipular string para recortar a data

            int m = int.Parse(my.Substring(0, 2));
            int y = int.Parse(my.Substring(3));

            Console.WriteLine("Name: " + worker.Name);
            Console.WriteLine("Department : " + worker.Department.Name); // Navegação entre os objetos
            Console.WriteLine("Income for " + m + " : " + worker.Income(y, m));
        }
Пример #5
0
        /// <summary>
        /// Parse a parameter from FreeSWITCH
        /// </summary>
        /// <param name="name">Parameter name as defined by FS</param>
        /// <param name="value">Parameter value</param>
        /// <returns>
        /// true if parsed sucessfully; otherwise false.
        /// </returns>
        public override bool ParseParameter(string name, string value)
        {
            switch (name)
            {
            case "unique-id":
                Id = new UniqueId(value);
                break;

            case "answer-state":
                AnswerState = value;
                break;

            case "call-direction":
                CallDirection = Enumm.Parse <ChannelDirection>(value);
                break;

            case "channel-call-state":
                CallState = Enumm.Parse <CallState>(value);
                break;

            case "presence-call-direction":
                PresenceCallDirection = Enumm.Parse <ChannelDirection>(value);
                break;

            case "channel-hit-dialplan":
                HasHitDialplan = value == "true";
                break;

            case "proto":
                Protocol = value;
                break;

            default:
                if (name.StartsWith("variable_"))
                {
                    Variables.Add(name.Remove(0, 10), value);
                    return(true);
                }
                if (name.Length > 8 && name.Substring(0, 8) == "channel-")
                {
                    if (ChannelInfo == null)
                    {
                        ChannelInfo = new ChannelInfo();
                    }
                    return(ChannelInfo.Parse(name, value));
                }

                return(base.ParseParameter(name, value));
            }

            return(true);
        }
Пример #6
0
        /// <summary>
        /// Parse a parameter from FreeSWITCH
        /// </summary>
        /// <param name="name">Parameter name as defined by FS</param>
        /// <param name="value">Parameter value</param>
        /// <returns>
        /// true if parsed sucessfully; otherwise false.
        /// </returns>
        public override bool ParseParameter(string name, string value)
        {
            switch (name)
            {
            case "original-channel-call-state":
                OriginalChannelCallState = Enumm.Parse <CallState>(value);
                break;

            default:
                return(base.ParseParameter(name, value));
            }

            return(true);
        }
Пример #7
0
        public override bool ParseParameter(string name, string value)
        {
            if (name == "hangupcause" || name == "hangup-cause")
            {
                var cause = value.UnderscoreToCamelCase();
                _hangupCause = Enumm.Parse <HangupCause>(cause);
            }
            else
            {
                return(base.ParseParameter(name, value));
            }

            return(true);
        }
Пример #8
0
 public void OnEventReceived(EslMessage eslMessage)
 {
     try
     {
         var eslEvent  = new EslEvent(eslMessage);
         var eventType = Enumm.Parse <EslEventType>(eslEvent.EventName);
         _eventReceived.OnNext(new EslEventStream(eslEvent,
                                                  eventType));
     }
     catch (Exception exception)
     {
         _logger.Warn($"Encountered an issue on the channel: {exception}.");
         _eventReceived.OnError(exception);
     }
 }
Пример #9
0
        private DirectionBase Rotate(Enumm direction)
        {
            if (direction == Enumm.East)
            {
                return(East());
            }
            else if (direction == Enumm.South)
            {
                return(South());
            }
            else if (direction == Enumm.West)
            {
                return(West());
            }
            else if (direction == Enumm.North)
            {
                return(North());
            }

            throw new Exception(direction.ToString());
        }
Пример #10
0
 public static ChannelState Parse(string value)
 {
     // skip "CS_" prefix.
     return(Enumm.Parse <ChannelState>(value.Substring(3).Replace("_", "")));
 }
Пример #11
0
        /// <summary>
        ///     Creates an IsoValue from the XML definition in a message template.
        ///     If it's for a toplevel field and the message factory has a codec for this field,
        ///     that codec is assigned to that field. For nested fields, a CompositeField is
        ///     created and populated.
        /// </summary>
        /// <returns>The template field.</returns>
        /// <param name="f">xml element</param>
        /// <param name="mfact">message factory</param>
        /// <param name="toplevel">If set to <c>true</c> toplevel.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        private static IsoValue GetTemplateField <T>(XmlElement f,
                                                     MessageFactory <T> mfact,
                                                     bool toplevel) where T : IsoMessage
        {
            var num     = int.Parse(f.GetAttribute("num"));
            var typedef = f.GetAttribute("type");

            if ("exclude".Equals(typedef))
            {
                return(null);
            }

            var length = 0;

            if (f.GetAttribute("length").Length > 0)
            {
                length = int.Parse(f.GetAttribute("length"));
            }

            var itype = Enumm.Parse <IsoType>(typedef);
            var subs  = f.GetElementsByTagName("field");

            if (subs.Count > 0)
            {
                var cf = new CompositeField();
                for (var j = 0; j < subs.Count; j++)
                {
                    var sub = (XmlElement)subs.Item(j);
                    if (sub != null && sub.ParentNode != f)
                    {
                        continue;
                    }
                    var sv = GetTemplateField(
                        sub,
                        mfact,
                        false);
                    if (sv == null)
                    {
                        continue;
                    }
                    sv.Encoding = mfact.Encoding;
                    cf.AddValue(sv);
                }

                Debug.Assert(itype != null, nameof(itype) + " != null");
                return(itype.Value.NeedsLength()
                    ? new IsoValue(
                           itype.Value,
                           cf,
                           length,
                           cf)
                    : new IsoValue(
                           itype.Value,
                           cf,
                           cf));
            }

            var v           = f.ChildNodes.Count == 0 ? string.Empty : f.ChildNodes.Item(0)?.Value;
            var customField = toplevel ? mfact.GetCustomField(num) : null;

            if (customField != null)
            {
                Debug.Assert(
                    itype != null,
                    "itype != null");

                return(itype.Value.NeedsLength()
                    ? new IsoValue(
                           itype.Value,
                           customField.DecodeField(v),
                           length,
                           customField)
                    : new IsoValue(
                           itype.Value,
                           customField.DecodeField(v),
                           customField));
            }

            Debug.Assert(
                itype != null,
                "itype != null");

            return(itype.Value.NeedsLength()
                ? new IsoValue(
                       itype.Value,
                       v,
                       length)
                : new IsoValue(
                       itype.Value,
                       v));
        }
Пример #12
0
 private DirectionBase(Enumm enumm, Enumm left, Enumm right)
 {
     Enumm  = enumm;
     _left  = left;
     _right = right;
 }
Пример #13
0
        public void OnEventReceived(EslMessage eslMessage)
        {
            var eslEvent  = new EslEvent(eslMessage);
            var eventName = eslEvent.EventName;
            var eventType = Enumm.Parse <EslEventType>(eventName);

            switch (eventType)
            {
            case EslEventType.BACKGROUND_JOB:
                var backgroundJob = new BackgroundJob(eslMessage);
                eslEvent = backgroundJob;
                break;

            case EslEventType.CALL_UPDATE:
                var callUpdate = new CallUpdate(eslMessage);
                eslEvent = callUpdate;
                break;

            case EslEventType.CHANNEL_BRIDGE:
                var channelBridge = new ChannelBridge(eslMessage);
                eslEvent = channelBridge;
                break;

            case EslEventType.CHANNEL_HANGUP:
            case EslEventType.CHANNEL_HANGUP_COMPLETE:
                var channelHangup = new ChannelHangup(eslMessage);
                eslEvent = channelHangup;
                break;

            case EslEventType.CHANNEL_PROGRESS:
                var channelProgress = new ChannelProgress(eslMessage);
                eslEvent = channelProgress;
                break;

            case EslEventType.CHANNEL_PROGRESS_MEDIA:
                var channelProgressMedia = new ChannelProgressMedia(eslMessage);
                eslEvent = channelProgressMedia;
                break;

            case EslEventType.CHANNEL_EXECUTE:
                var channelExecute = new ChannelExecute(eslMessage);
                eslEvent = channelExecute;
                break;

            case EslEventType.CHANNEL_EXECUTE_COMPLETE:
                var channelExecuteComplete = new ChannelExecuteComplete(eslMessage);
                eslEvent = channelExecuteComplete;
                break;

            case EslEventType.CHANNEL_UNBRIDGE:
                var channelUnbridge = new ChannelUnbridge(eslMessage);
                eslEvent = channelUnbridge;
                break;

            case EslEventType.SESSION_HEARTBEAT:
                var sessionHeartbeat = new SessionHeartbeat(eslMessage);
                eslEvent = sessionHeartbeat;
                break;

            case EslEventType.DTMF:
                var dtmf = new Dtmf(eslMessage);
                eslEvent = dtmf;
                break;

            case EslEventType.RECORD_STOP:
                var recordStop = new RecordStop(eslMessage);
                eslEvent = recordStop;
                break;

            case EslEventType.CUSTOM:
                var custom = new Custom(eslMessage);
                eslEvent = custom;
                break;

            case EslEventType.CHANNEL_STATE:
                var channelState = new ChannelStateEvent(eslMessage);
                eslEvent = channelState;
                break;

            case EslEventType.CHANNEL_ANSWER:
                eslEvent = new EslEvent(eslMessage);
                break;

            case EslEventType.CHANNEL_ORIGINATE:
                eslEvent = new EslEvent(eslMessage);
                break;

            case EslEventType.CHANNEL_PARK:
                var channelPark = new ChannelPark(eslMessage);
                eslEvent = channelPark;
                break;

            case EslEventType.CHANNEL_UNPARK:
                eslEvent = new EslEvent(eslMessage);
                break;

            default:
                OnUnhandledEvents(new EslEvent(eslMessage));
                break;
            }
            HandleEvents(eslEvent,
                         eventType);
        }
Пример #14
0
        public bool Parse(string name, string value)
        {
            switch (name)
            {
            case "username":
                UserName = value;
                break;

            case "dialplan":
                DialplanType = value;
                break;

            case "caller-id-name":
                _callerIdName = value;
                CreateCallerId();
                break;

            case "caller-id-number":
                _callerIdNumber = value;
                CreateCallerId();
                break;

            case "callee-id-name":
                _calleeIdName = value;
                CreateCalleeId();
                break;

            case "callee-id-number":
                _calleeIdNumber = value;
                CreateCalleeId();
                break;

            case "network-addr":
                IpAddress = value;
                break;

            case "ani":
                ANI = value;
                break;

            case "destination-number":
                DestinationNumber = value;
                break;

            case "unique-id":
                Id = new UniqueId(value);
                break;

            case "context":
                Context = value;
                break;

            case "channel-name":
                ChannelInfo = new ChannelName();
                ChannelInfo.Parse(value);
                break;

            case "profile-created-time":
                ProfileCreatedAt = value.FromUnixTime();
                break;

            case "channel-created-time":
                CreatedAt = value.FromUnixTime();
                break;

            case "channel-answered-time":
                AnsweredAt = value.FromUnixTime();
                break;

            case "channel-hangup-time":
                HangupAt = value.FromUnixTime();
                break;

            case "channel-transfer-time":
                TransferredAt = value.FromUnixTime();
                break;

            case "screen-bit":
                ScreenBit = value == "yes";
                break;

            case "privacy-hide-name":
                PrivacyHideName = value == "yes";
                break;

            case "privacy-hide-number":
                PrivacyHideNumber = value == "yes";
                break;

            case "direction":
                Direction = Enumm.Parse <ChannelDirection>(value);
                break;

            case "source":
                EndpointSource = value;
                break;

            case "profile-index":
                ProfileIndex = int.Parse(value);
                break;

            case "channel-progress-time":
                ChannelProgressTime = long.Parse(value);
                break;

            case "channel-progress-media-time":
                ChannelProgressMediaTime = long.Parse(value);
                break;

            default:
                return(false);
            }
            return(true);
        }
Пример #15
0
        public async Task OnEventReceived(EslMessage eslMessage)
        {
            var eslEvent     = new EslEvent(eslMessage);
            var eventType    = Enumm.Parse <EslEventType>(eslEvent.EventName);
            var eslEventArgs = new EslEventArgs(new EslEvent(eslMessage));
            AsyncEventHandler <EslEventArgs> handler;

            switch (eventType)
            {
            case EslEventType.BACKGROUND_JOB:
                handler = OnBackgroundJob;
                break;

            case EslEventType.CALL_UPDATE:
                handler = OnCallUpdate;
                break;

            case EslEventType.CHANNEL_BRIDGE:
                handler = OnChannelBridge;
                break;

            case EslEventType.CHANNEL_HANGUP:
                handler = OnChannelHangup;
                break;

            case EslEventType.CHANNEL_HANGUP_COMPLETE:
                handler = OnChannelHangupComplete;
                break;

            case EslEventType.CHANNEL_PROGRESS:
                handler = OnChannelProgress;
                break;

            case EslEventType.CHANNEL_PROGRESS_MEDIA:
                handler = OnChannelProgressMedia;
                break;

            case EslEventType.CHANNEL_EXECUTE:
                handler = OnChannelExecute;
                break;

            case EslEventType.CHANNEL_EXECUTE_COMPLETE:
                handler = OnChannelExecuteComplete;
                break;

            case EslEventType.CHANNEL_UNBRIDGE:
                handler = OnChannelUnbridge;
                break;

            case EslEventType.SESSION_HEARTBEAT:
                handler = OnSessionHeartbeat;
                break;

            case EslEventType.DTMF:
                handler = OnDtmf;
                break;

            case EslEventType.RECORD_STOP:
                handler = OnRecordStop;
                break;

            case EslEventType.CUSTOM:
                handler = OnCustom;
                break;

            case EslEventType.CHANNEL_STATE:
                handler = OnChannelState;
                break;

            case EslEventType.CHANNEL_ANSWER:
                handler = OnChannelAnswer;
                break;

            case EslEventType.CHANNEL_ORIGINATE:
                handler = OnChannelOriginate;
                break;

            case EslEventType.CHANNEL_PARK:
                handler = OnChannelPark;
                break;

            case EslEventType.CHANNEL_UNPARK:
                handler = OnChannelUnPark;
                break;

            default:
                _logger.Debug("received unhandled freeSwitch event:");
                _logger.Debug(eslEvent);
                handler = OnReceivedUnHandledEvent;
                break;
            }
            if (handler != null)
            {
                await handler(this, eslEventArgs);
            }
        }