public static async void SetupPushNotification(IReadOnlyList <IInstaApi> apiList) { try { var helpers = Helper.InstaApiList;//??? if (apiList.Count > 0) { //var api = apiList[0]; var currentPK = Helper.InstaApi.GetLoggedUser().LoggedInUser.Pk; foreach (var api in apiList) { // shutdown mqtt if (api.PushClient != null) { try { api.PushClient.Shutdown(); await Task.Delay(50); api.PushClient = null; } catch { } } } foreach (var api in apiList) { try { var p = new MinistaHelper.Push.PushClient(apiList.ToList(), api); p.MessageReceived += PushClientMessageReceived; p.LogReceived += P_LogReceived; if (api.GetLoggedUser().LoggedInUser.Pk != currentPK) { p.DontTransferSocket = true; } p.OpenNow(); api.PushClient = p; api.PushClient.Start(); //try //{ // await api.PushClient.Shutdown(); //} //catch { } //try //{ // api.PushClient.MessageReceived -= PushClientMessageReceived; //} //catch { } //api.PushClient.MessageReceived += PushClientMessageReceived; //await api.PushClient.Start(); } catch { } } } } catch { } }
public static /*async*/ void SetupPushNotification(IReadOnlyList <IInstaApi> apiList) { try { var helpers = Helper.InstaApiList;//??? if (apiList.Count > 0) { //var api = apiList[0]; var currentPK = Helper.InstaApi.GetLoggedUser().LoggedInUser.Pk; //foreach (var api in apiList) //{ // // shutdown mqtt // if (api.PushClient != null) // { // try // { // api.PushClient.Shutdown(); // await Task.Delay(50); // api.PushClient = null; // } // catch { } // } //} //var canbeMultiple = apiList.Any(x => x.GetCurrentDevice().DeviceGuid.ToString() != Helper.InstaApi.GetCurrentDevice().DeviceGuid.ToString()); //if (!canbeMultiple) //{ // try // { // var api = Helper.InstaApi ?? apiList[0]; // var p = new MinistaHelper.Push.PushClient(apiList.ToList(), api); // p.ValidateData(); // p.FbnsTokenChanged += P_FbnsTokenChanged; // p.MessageReceived += PushClientMessageReceived; // p.LogReceived += P_LogReceived; // if (api.GetLoggedUser().LoggedInUser.Pk != currentPK) // p.DontTransferSocket = true; // p.OpenNow(); // api.PushClient = p; // api.PushClient.Start(); // } // catch { } //} //else { //foreach (var api in apiList) // open only for one account! var api = Helper.InstaApi ?? apiList[0]; { try { var p = new MinistaHelper.Push.PushClient(apiList.ToList(), api); p.ValidateData(); p.FbnsTokenChanged += P_FbnsTokenChanged; p.MessageReceived += PushClientMessageReceived; p.LogReceived += MainView.OnLogReceived; p.OpenNow(); api.PushClient = p; api.PushClient.Start(); } catch { } } } } } catch { } }