Esempio n. 1
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        protected override void OnInvoke(ScheduledTask task)
        {
            Debug.WriteLine("[ScheduledAgentImpl] ScheduledAgentImpl has been invoked with argument of type {0}.", task.GetType());

            // Indicate that an agent has started running
            AgentHost.OnAgentStarted();

            VoipHttpIncomingCallTask incomingCallTask = task as VoipHttpIncomingCallTask;
            if (incomingCallTask != null)
            {
                this.isIncomingCallAgent = true;

                // Parse the the incoming push notification payload
                Notification pushNotification;
                using (MemoryStream ms = new MemoryStream(incomingCallTask.MessageBody))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(Notification));
                    pushNotification = (Notification)xs.Deserialize(ms);
                }

                Debug.WriteLine("[{0}] Incoming call from caller {1}, number {2}", ScheduledAgentImpl.incomingCallAgentId, pushNotification.Name, pushNotification.Number);

                // Initiate incoming call processing
                // If you want to pass in additional information such as pushNotification.Number, you can
                bool incomingCallProcessingStarted = BackEnd.Globals.Instance.CallController.OnIncomingCallReceived(pushNotification.Name, pushNotification.Number, this.OnIncomingCallDialogDismissed);

                if (!incomingCallProcessingStarted)
                {
                    // For some reasons, the incoming call processing was not started.
                    // There is nothing more to do.
                    this.Complete();
                    return;
                }
            }
            else
            {
                VoipKeepAliveTask keepAliveTask = task as VoipKeepAliveTask;
                if (keepAliveTask != null)
                {
                    this.isIncomingCallAgent = false;

                    // Refresh tokens, get new certs from server, etc.
                    BackEnd.Globals.Instance.DoPeriodicKeepAlive();
                    this.Complete();
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType()));
                }
            }
        }
        protected override void OnInvoke(ScheduledTask task)
        {
            Debug.WriteLine("[LinphoneScheduledAgent] ScheduledAgentImpl has been invoked with argument of type {0}.", task.GetType());
            AgentHost.OnAgentStarted();
            VoipHttpIncomingCallTask incomingCallTask = task as VoipHttpIncomingCallTask;
            if (incomingCallTask != null)
            {
                this.isIncomingCallAgent = true;
                Debug.WriteLine("[IncomingCallAgent] Received VoIP Incoming Call task");

                BackgroundManager.Instance.OopServer.CallController.IncomingCallViewDismissed = OnIncomingCallDialogDismissed;
                BackgroundManager.Instance.InitLinphoneCore();
            }
            else
            {
                VoipKeepAliveTask keepAliveTask = task as VoipKeepAliveTask;
                if (keepAliveTask != null)
                {
                    this.isIncomingCallAgent = false;
                    Debug.WriteLine("[KeepAliveAgent] Keep Alive task");

                    if (DeviceNetworkInformation.IsNetworkAvailable)
                    {
                        var server = BackgroundManager.Instance.OopServer;
                        InitManager.CreateLinphoneCore(server, this, OutputTraceLevel.Message);
                        server.LinphoneCore.NetworkReachable = true;
                        server.LinphoneCore.IterateEnabled = true;
                        Debug.WriteLine("[KeepAliveAgent] Linphone Core created");
                    }
                    else
                    {
                        Debug.WriteLine("[KeepAliveAgent] Not connected, can't refresh register");
                        base.NotifyComplete();
                    }
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType()));
                }
            }
        }
Esempio n. 3
0
        public async Task UnscheduleAsync(ScheduledTask task, bool force = false)
        {
            switch (task)
            {
            case GuildTask _:
                if (this.tasks.TryRemove(task.Id, out ScheduledTaskExecutor? taskExec))
                {
                    taskExec.Dispose();
                }
                else
                {
                    Log.Warning("Failed to remove guild task from task collection: {GuildTaskId}", task.Id);
                }
                using (TheGodfatherDbContext db = this.dbb.CreateContext()) {
                    db.GuildTasks.Remove(new GuildTask {
                        Id = task.Id
                    });
                    await db.SaveChangesAsync();
                }
                break;

            case Reminder rem:
                if (!force && rem.IsRepeating && rem.RepeatInterval < this.ReloadSpan)
                {
                    break;
                }

                if (this.reminders.TryRemove(task.Id, out ScheduledTaskExecutor? remindExec))
                {
                    remindExec.Dispose();
                }
                else
                {
                    Log.Warning("Failed to remove reminder from task collection: {ReminderId}", task.Id);
                }

                using (TheGodfatherDbContext db = this.dbb.CreateContext()) {
                    db.Reminders.Remove(new Reminder {
                        Id = task.Id
                    });
                    await db.SaveChangesAsync();
                }
                break;

            default:
                Log.Warning("Unknown scheduled task type: {ScheduledTaskType}", task.GetType());
                break;
            }
        }
 protected override void OnInvoke(ScheduledTask task)
 {
     Debug.WriteLine("[Mediastreamer2ScheduledAgent] ScheduledAgentImpl has been invoked with argument of type {0}.", task.GetType());
     VoipHttpIncomingCallTask incomingCallTask = task as VoipHttpIncomingCallTask;
     if (incomingCallTask != null)
     {
         this.isIncomingCallAgent = true;
         Debug.WriteLine("[IncomingCallAgent] Received VoIP Incoming Call task");
     }
     else
     {
         VoipKeepAliveTask keepAliveTask = task as VoipKeepAliveTask;
         if (keepAliveTask != null)
         {
             this.isIncomingCallAgent = false;
             Debug.WriteLine("[KeepAliveAgent] Keep Alive task");
             base.NotifyComplete();
         }
         else
         {
             throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType()));
         }
     }
 }
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        protected override void OnInvoke(ScheduledTask task)
        {
            var incomingCallTask = task as VoipHttpIncomingCallTask;
            if (incomingCallTask != null)
            {
                // Parse the the incoming push notification payload
                IncomingCallInfo pushNotification;
                using (var ms = new MemoryStream(incomingCallTask.MessageBody))
                {
                    var xs = new XmlSerializer(typeof(IncomingCallInfo));
                    pushNotification = (IncomingCallInfo)xs.Deserialize(ms);
                }

                String defaultContactImageUri = Package.Current.InstalledLocation.Path + @"\Assets\DefaultContactImage.jpg";
                String logoUrl = Package.Current.InstalledLocation.Path + @"\Assets\ApplicationIcon.png";

                VoipPhoneCall callObj;
                var callCoordinator = VoipCallCoordinator.GetDefault();
                callCoordinator.RequestNewIncomingCall("/Views/SplashScreenPage.xaml?incomingCall=" + pushNotification.Number,
                                                       pushNotification.Name, pushNotification.Number, new Uri(defaultContactImageUri),
                                                       "VoipTranslator.Client.WinPhone", new Uri(defaultContactImageUri), "VoIP Translator", new Uri(logoUrl), VoipCallMedia.Audio,
                                                       TimeSpan.FromMinutes(5), out callObj);
                callObj.AnswerRequested += callObj_AnswerRequested;
                callObj.RejectRequested += callObj_RejectRequested;
            }
            else
            {
                var keepAliveTask = task as VoipKeepAliveTask;
                if (keepAliveTask != null)
                {
                    this.Complete();
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType()));
                }
            }
        }
        protected override void OnInvoke(ScheduledTask task)
        {
            Debug.WriteLine("[LinphoneScheduledAgent] ScheduledAgentImpl has been invoked with argument of type {0}.", task.GetType());
            AgentHost.OnAgentStarted();
            VoipHttpIncomingCallTask incomingCallTask = task as VoipHttpIncomingCallTask;

            if (incomingCallTask != null)
            {
                this.isIncomingCallAgent = true;
                Debug.WriteLine("[IncomingCallAgent] Received VoIP Incoming Call task");

                BackgroundManager.Instance.OopServer.CallController.IncomingCallViewDismissed = OnIncomingCallDialogDismissed;
                BackgroundManager.Instance.InitLinphoneCore();
            }
            else
            {
                VoipKeepAliveTask keepAliveTask = task as VoipKeepAliveTask;
                if (keepAliveTask != null)
                {
                    this.isIncomingCallAgent = false;
                    Debug.WriteLine("[KeepAliveAgent] Keep Alive task");

                    if (DeviceNetworkInformation.IsNetworkAvailable)
                    {
                        var server = BackgroundManager.Instance.OopServer;
                        InitManager.CreateLinphoneCore(server, this, OutputTraceLevel.Message);
                        server.LinphoneCore.NetworkReachable = true;
                        server.LinphoneCore.IterateEnabled   = true;
                        Debug.WriteLine("[KeepAliveAgent] Linphone Core created");
                    }
                    else
                    {
                        Debug.WriteLine("[KeepAliveAgent] Not connected, can't refresh register");
                        base.NotifyComplete();
                    }
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType()));
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        protected override void OnInvoke(ScheduledTask task)
        {
            var incomingCallTask = task as VoipHttpIncomingCallTask;

            if (incomingCallTask != null)
            {
                // Parse the the incoming push notification payload
                IncomingCallInfo pushNotification;
                using (var ms = new MemoryStream(incomingCallTask.MessageBody))
                {
                    var xs = new XmlSerializer(typeof(IncomingCallInfo));
                    pushNotification = (IncomingCallInfo)xs.Deserialize(ms);
                }

                String defaultContactImageUri = Package.Current.InstalledLocation.Path + @"\Assets\DefaultContactImage.jpg";
                String logoUrl = Package.Current.InstalledLocation.Path + @"\Assets\ApplicationIcon.png";

                VoipPhoneCall callObj;
                var           callCoordinator = VoipCallCoordinator.GetDefault();
                callCoordinator.RequestNewIncomingCall("/Views/SplashScreenPage.xaml?incomingCall=" + pushNotification.Number,
                                                       pushNotification.Name, pushNotification.Number, new Uri(defaultContactImageUri),
                                                       "VoipTranslator.Client.WinPhone", new Uri(defaultContactImageUri), "VoIP Translator", new Uri(logoUrl), VoipCallMedia.Audio,
                                                       TimeSpan.FromMinutes(5), out callObj);
                callObj.AnswerRequested += callObj_AnswerRequested;
                callObj.RejectRequested += callObj_RejectRequested;
            }
            else
            {
                var keepAliveTask = task as VoipKeepAliveTask;
                if (keepAliveTask != null)
                {
                    this.Complete();
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType()));
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        protected override void OnInvoke(ScheduledTask task)
        {
            Debug.WriteLine("[ScheduledAgentImpl] ScheduledAgentImpl has been invoked with argument of type {0}.", task.GetType());

            // Indicate that an agent has started running
            AgentHost.OnAgentStarted();

            VoipHttpIncomingCallTask incomingCallTask = task as VoipHttpIncomingCallTask;

            if (incomingCallTask != null)
            {
                this.isIncomingCallAgent = true;

                // Parse the the incoming push notification payload
                Notification pushNotification;
                using (MemoryStream ms = new MemoryStream(incomingCallTask.MessageBody))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(Notification));
                    pushNotification = (Notification)xs.Deserialize(ms);
                }

                Debug.WriteLine("[{0}] Incoming call from caller {1}, number {2}", ScheduledAgentImpl.incomingCallAgentId, pushNotification.Name, pushNotification.Number);

                // Initiate incoming call processing
                // If you want to pass in additional information such as pushNotification.Number, you can
#if FIXME_TO_BE_IMPLEMENTED
                bool incomingCallProcessingStarted = BackEnd.Globals.Instance.CallController.OnIncomingCallReceived(pushNotification.Name, pushNotification.Number, this.OnIncomingCallDialogDismissed);

                if (!incomingCallProcessingStarted)
                {
                    // For some reasons, the incoming call processing was not started.
                    // There is nothing more to do.
                    this.Complete();
                    return;
                }
#endif
            }
            else
            {
                VoipKeepAliveTask keepAliveTask = task as VoipKeepAliveTask;
                if (keepAliveTask != null)
                {
                    this.isIncomingCallAgent = false;

                    // Refresh tokens, get new certs from server, etc.
                    BackEnd.Globals.Instance.DoPeriodicKeepAlive();
                    this.Complete();
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType()));
                }
            }
        }
        protected override void OnInvoke(ScheduledTask task)
        {
            Debug.WriteLine("[ScheduledAgentImpl {0}] ScheduledAgentImpl has been invoked with argument of type {1}.", GetHashCode(), task.GetType());

            // Indicate that an agent has started running
            AgentHost.OnAgentStarted();

            Log(string.Format("start with argument of type {0}", task.GetType()));
            if (!_appOpenMutex.WaitOne(0))
            {
                Log("cancel");
                Complete();
                return;
            }
            _appOpenMutex.ReleaseMutex();

            var incomingCallTask = task as VoipHttpIncomingCallTask;

            if (incomingCallTask != null)
            {
                isIncomingCallAgent = true;

                var          messageBody      = HttpUtility.HtmlDecode(Encoding.UTF8.GetString(incomingCallTask.MessageBody, 0, incomingCallTask.MessageBody.Length));
                Notification pushNotification = null;
                try
                {
                    using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(messageBody ?? string.Empty)))
                    {
                        var xs = new XmlSerializer(typeof(Notification));
                        pushNotification = (Notification)xs.Deserialize(ms);
                    }
                }
                catch (Exception ex)
                {
                    Log(string.Format("cannot deserialize message_body={0}", messageBody));
#if DEBUG
                    var toastNotifier = ToastNotificationManager.CreateToastNotifier();

                    var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
                    SetText(toastXml, "Notification Exception", string.Empty);

                    try
                    {
                        var toast = new ToastNotification(toastXml);
                        //RemoveToastGroup(group);
                        toastNotifier.Show(toast);
                    }
                    catch (Exception ex2)
                    {
                        Telegram.Logs.Log.Write(ex.ToString());
                    }
#endif
                }

                if (pushNotification != null)
                {
                    var rootObject = PushUtils2.GetRootObject <RootObject>(pushNotification.Data);
                    if (rootObject != null &&
                        rootObject.data != null)
                    {
                        if (rootObject.data.custom != null &&
                            rootObject.data.custom.from_id != null &&
                            rootObject.data.custom.call_id != null &&
                            rootObject.data.custom.call_ah != null)
                        {
                            var contactImage = PushUtils2.GetImageSource(rootObject.data.custom.mtpeer) ?? string.Empty;
                            var contactName  = rootObject.data.loc_args != null && rootObject.data.loc_args.Length > 0
                                ? rootObject.data.loc_args[0]
                                : string.Empty;
                            Debug.WriteLine("[{0}] Incoming call from caller {1}, id {2}", incomingCallAgentId,
                                            contactName, rootObject.data.custom.from_id);

                            long contactId      = 0;
                            long callId         = 0;
                            long callAccessHash = 0;
                            if (long.TryParse(rootObject.data.custom.from_id, out contactId) &&
                                long.TryParse(rootObject.data.custom.call_id, out callId) &&
                                long.TryParse(rootObject.data.custom.call_ah, out callAccessHash))
                            {
                                if (string.Equals(rootObject.data.loc_key, "PHONE_CALL_REQUEST",
                                                  StringComparison.OrdinalIgnoreCase))
                                {
                                    if (BackEnd.Globals.Instance.CallController.CallStatus == CallStatus.InProgress)
                                    {
                                        OnIncomingCallDialogDismissed(callId, callAccessHash, true);
                                        return;
                                    }

                                    // Initiate incoming call processing
                                    // If you want to pass in additional information such as pushNotification.Number, you can
                                    var incomingCallProcessingStarted =
                                        BackEnd.Globals.Instance.CallController.OnIncomingCallReceived(contactName,
                                                                                                       contactId, contactImage, callId, callAccessHash,
                                                                                                       OnIncomingCallDialogDismissed);
                                    if (incomingCallProcessingStarted)
                                    {
                                        // will Complete() at OnIncomingCallDialogDismissed
                                        return;
                                    }

                                    //PushUtils2.AddToast(rootObject, "Caption", "Message", "", "", "tag", "group");
                                }
                                else if (string.Equals(rootObject.data.loc_key, "PHONE_CALL_DECLINE",
                                                       StringComparison.OrdinalIgnoreCase))
                                {
                                    var currentCallId = BackEnd.Globals.Instance.CallController.CallId;
                                    if (currentCallId == callId)
                                    {
                                        Log(string.Format("PHONE_CALL_DECLINE CallController.EndCall call_id={0}", callId));
                                        var result = BackEnd.Globals.Instance.CallController.EndCall();
                                        Log(string.Format("PHONE_CALL_DECLINE CallController.EndCall call_id={0} result={1}", callId, result));
                                    }
                                }
                            }
                        }
                        else if (string.Equals(rootObject.data.loc_key, "GEO_LIVE_PENDING"))
                        {
                            ProcessLiveLocations();
                        }
                        else
                        {
                            //PushUtils2.UpdateToastAndTiles(rootObject);
                        }
                    }
                }

                Complete();
                return;
            }
            else
            {
                VoipKeepAliveTask keepAliveTask = task as VoipKeepAliveTask;
                if (keepAliveTask != null)
                {
                    this.isIncomingCallAgent = false;

                    // Refresh tokens, get new certs from server, etc.
                    BackEnd.Globals.Instance.DoPeriodicKeepAlive();
                    this.Complete();
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType()));
                }
            }
        }
        protected override void OnInvoke(ScheduledTask task)
        {
            Debug.WriteLine("[Mediastreamer2ScheduledAgent] ScheduledAgentImpl has been invoked with argument of type {0}.", task.GetType());
            VoipHttpIncomingCallTask incomingCallTask = task as VoipHttpIncomingCallTask;

            if (incomingCallTask != null)
            {
                this.isIncomingCallAgent = true;
                Debug.WriteLine("[IncomingCallAgent] Received VoIP Incoming Call task");
            }
            else
            {
                VoipKeepAliveTask keepAliveTask = task as VoipKeepAliveTask;
                if (keepAliveTask != null)
                {
                    this.isIncomingCallAgent = false;
                    Debug.WriteLine("[KeepAliveAgent] Keep Alive task");
                    base.NotifyComplete();
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unknown scheduled task type {0}", task.GetType()));
                }
            }
        }