void callHandler_CurrentProfileChanged(object sender, CurrentProfileChangedEventArgs e)
        {
            var currentProfileChanged = new CurrentProfileChanged();

            try
            {
                var _sender = sender as MyPhonePlugins.IMyPhoneCallHandler;

                fillCallHandler_1(_sender, currentProfileChanged.CallHandler);
                currentProfileChanged.NewProfileId = e.NewProfileId;
                currentProfileChanged.OldProfileId = e.OldProfileId;

                foreach (var call in _sender.ActiveCalls)
                {
                    var newCall = new CallStatus();
                    fillCallStatus(call, newCall);
                    currentProfileChanged.CallHandler.ActiveCalls.Add(newCall);
                }

                foreach (var profile in _sender.Profiles)
                {
                    var newProfile = new UserProfileStatus();
                    fillProfiles(profile, newProfile);
                    currentProfileChanged.CallHandler.Profiles.Add(newProfile);
                }
            }
            catch
            {
                currentProfileChanged = null;
            }

            Callback(channel => channel.CurrentProfileChanged(currentProfileChanged));
        }
        void callHandler_ProfileExtendedStatusChanged(object sender, ProfileExtendedStatusChangedEventArgs e)
        {
            var profileExtendedStatusChanged = new ProfileExtendedStatusChanged();

            try
            {
                var _sender = sender as MyPhonePlugins.IMyPhoneCallHandler;

                fillCallHandler_1(_sender, profileExtendedStatusChanged.CallHandler);
                profileExtendedStatusChanged.ProfileId = e.ProfileId;
                profileExtendedStatusChanged.Status    = e.Status;

                foreach (var call in _sender.ActiveCalls)
                {
                    var newCall = new CallStatus();
                    fillCallStatus(call, newCall);
                    profileExtendedStatusChanged.CallHandler.ActiveCalls.Add(newCall);
                }

                foreach (var profile in _sender.Profiles)
                {
                    var newProfile = new UserProfileStatus();
                    fillProfiles(profile, newProfile);
                    profileExtendedStatusChanged.CallHandler.Profiles.Add(newProfile);
                }
            }
            catch
            {
                profileExtendedStatusChanged = null;
            }

            Callback(channel => channel.ProfileExtendedStatusChanged(profileExtendedStatusChanged));
        }
        public CallHandler ProfilesEx()
        {
            try
            {
                var _сallHandler = new CallHandler();

                foreach (var call in callHandler.ActiveCalls)
                {
                    var newCall = new CallStatus();
                    fillCallStatus(call, newCall);
                    _сallHandler.ActiveCalls.Add(newCall);
                }

                foreach (var profile in callHandler.Profiles)
                {
                    var newProfile = new UserProfileStatus();
                    fillProfiles(profile, newProfile);
                    _сallHandler.Profiles.Add(newProfile);
                }

                fillCallHandler_1(callHandler, _сallHandler);

                return(_сallHandler);
            }
            catch
            {
                return(null);
            }
        }
 void fillProfiles(MyPhonePlugins.UserProfileStatus source, UserProfileStatus target)
 {
     target.IsActive       = source.IsActive;
     target.ProfileId      = source.ProfileId;
     target.Name           = source.Name;
     target.CustomName     = source.CustomName;
     target.ExtendedStatus = source.ExtendedStatus;
 }
        private void callHandler_OnMyPhoneStatusChanged(object sender, MyPhonePlugins.MyPhoneStatus status)
        {
            if (status == MyPhonePlugins.MyPhoneStatus.LoggedIn)
            {
                this.extensionInfo = sender as MyPhonePlugins.IExtensionInfo;
            }

            var onMyPhoneStatusChanged = new OnMyPhoneStatusChanged();

            try
            {
                var _sender = sender as MyPhonePlugins.IMyPhoneCallHandler;

                fillCallHandler_1(_sender, onMyPhoneStatusChanged.CallHandler);

                onMyPhoneStatusChanged.Status = status.ToString();

                foreach (var call in _sender.ActiveCalls)
                {
                    var newCall = new CallStatus();
                    fillCallStatus(call, newCall);
                    onMyPhoneStatusChanged.CallHandler.ActiveCalls.Add(newCall);
                }

                foreach (var profile in _sender.Profiles)
                {
                    var newProfile = new UserProfileStatus();
                    fillProfiles(profile, newProfile);
                    onMyPhoneStatusChanged.CallHandler.Profiles.Add(newProfile);
                }
            }
            catch
            {
                onMyPhoneStatusChanged = null;
            }

            LogHelper.Log(Environment.SpecialFolder.ApplicationData, "CallTriggerCmd.log",
                          String.Format("MyPhoneStatusChanged - Status='{0}' - Extension='{1}'", status, extensionInfo == null ? String.Empty : extensionInfo.Number));
            Callback(channel => channel.MyPhoneStatusChanged(onMyPhoneStatusChanged));
        }
        private void callHandler_OnCallStatusChanged(object sender, MyPhonePlugins.CallStatus callInfo)
        {
            LogHelper.Log(Environment.SpecialFolder.ApplicationData, "CallTriggerCmd.log",
                          String.Format("CallStatusChanged - CallID='{0}' - Incoming='{1}' - OtherPartyNumber='{2}' - State='{3}'", callInfo.CallID, callInfo.Incoming, callInfo.OtherPartyNumber, callInfo.State));

            var onCallStatusChanged = new OnCallStatusChanged();

            try
            {
                var _sender = sender as MyPhonePlugins.IMyPhoneCallHandler;

                fillCallHandler_1(_sender, onCallStatusChanged.CallHandler);

                fillCallStatus(callInfo, onCallStatusChanged.CallStatus);

                foreach (var call in _sender.ActiveCalls)
                {
                    var newCall = new CallStatus();
                    fillCallStatus(call, newCall);
                    onCallStatusChanged.CallHandler.ActiveCalls.Add(newCall);
                }

                foreach (var profile in _sender.Profiles)
                {
                    var newProfile = new UserProfileStatus();
                    fillProfiles(profile, newProfile);
                    onCallStatusChanged.CallHandler.Profiles.Add(newProfile);
                }
            }
            catch
            {
                onCallStatusChanged = null;
            }

            Callback(channel => channel.CallStatusChanged(onCallStatusChanged));
        }