Esempio n. 1
0
        public void Send(string state)
        {
            if (this.session != null)
            {
                if (this.session.Reachable)
                {
                    this.SendMessage(state);
                }
            }
            else
            {
                if (WCSession.DefaultSession.ActivationState == WCSessionActivationState.Activated)
                {
                    // if here is an old delegate - dispose it
                    if (WCSession.DefaultSession.Delegate != null)
                    {
                        WCSession.DefaultSession.Delegate.Dispose();
                        WCSession.DefaultSession.Delegate = null;
                    }

                    WCSession.DefaultSession.Delegate = this;
                    this.session = WCSession.DefaultSession;
                    this.Send(state);
                }
                else
                {
                    WCSession.DefaultSession.Delegate = this;
                    WCSession.DefaultSession.ActivateSession();
                    this.statesToSend.Add(state);
                }
            }
        }
 void SharedManager_ApplicationContextUpdated(WCSession session, Dictionary <string, object> applicationContext)
 {
     if (applicationContext.ContainsKey("startDate") && applicationContext.ContainsKey("endDate"))
     {
         _feedings.Add(new Feeding
         {
             Start = applicationContext["startDate"] as string,
             End   = applicationContext["endDate"] as string,
         });
         InvokeOnMainThread(() =>
         {
             this.Table.ReloadData();
         });
     }
     if (applicationContext.ContainsKey("HeartRate"))
     {
         _feedings.Add(new Message
         {
             Text = $"Check up Baby it got Heart Rate: {applicationContext["HeartRate"] as string}"
         });
         InvokeOnMainThread(() =>
         {
             this.Table.ReloadData();
         });
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Called when a userInfo is received.
        /// </summary>
        public override void DidReceiveUserInfo(WCSession session, NSDictionary <NSString, NSObject> userInfo)
        {
            var commandStatus = new CommandStatus(Command.TransferUserInfo, Phrase.Received)
            {
                TimedColor = new TimedColor(userInfo)
            };

            if (userInfo.TryGetValue(PayloadKey.IsCurrentComplicationInfo, out NSObject isComplicationInfoObject) &&
                isComplicationInfoObject is NSNumber isComplicationInfo && isComplicationInfo.BoolValue)
            {
                commandStatus.Command = Command.TransferCurrentComplicationUserInfo;

#if __WATCHOS__
                var server        = CLKComplicationServer.SharedInstance;
                var complications = server.ActiveComplications;
                if (complications != null && complications.Any())
                {
                    foreach (var complication in complications)
                    {
                        // Call this method sparingly. If your existing complication data is still valid,
                        // consider calling the extendTimeline(for:) method instead.
                        server.ReloadTimeline(complication);
                    }
                }
#endif
            }

            this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
        }
Esempio n. 4
0
    protected void cConnectWallet_Click(object sender, EventArgs e)
    {
        var t = Task.Run(async() =>
        {
            try
            {
                var myMeta           = new { name = ".NET Dapp", accounts = new List <string>() };
                var wcSessionRequest = await WCSession.CreateSession("https://bridge.walletconect.org", myMeta);
                var wcUrl            = wcSessionRequest.wcUri;

                //var result = await wcSessionRequest.wcSessionRequest.Value;
                var x = 1;
                return(wcUrl);
            } catch (Exception ex)
            {
                var r = ex.Message;
                return(null);
            }
        });

        t.ConfigureAwait(false);
        t.Wait();
        var xx = t.Result;

        cWcUrl.Text = xx;
    }
Esempio n. 5
0
        public void DidReceiveUserInfo(WCSession session, NSDictionary <NSString, NSObject> userInfo)
        {
            var writer = new BarcodeWriter <UIImage>
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = new EncodingOptions
                {
                    Height = 200,
                    Width  = 200,
                    Margin = 0
                },
                Renderer = new BarcodeRenderer()
            };

            var qrCodeUrl = new NSObject();

            userInfo.TryGetValue(new NSString("qrCode"), out qrCodeUrl);

            var img = writer.Write(qrCodeUrl.ToString());

            myImage.SetImage(img);
            myImage.SetRelativeWidth(0.98f, 0);
            myImage.SetRelativeHeight(0.98f, 0);

            var asdf = WKExtension.SharedExtension.Delegate as ExtensionDelegate;

            HealthStore.EndWorkoutSession(asdf.WorkoutSession);
        }
Esempio n. 6
0
        /// <summary>
        /// Called when a file transfer is done.
        /// </summary>
        public override void DidFinishFileTransfer(WCSession session, WatchConnectivity.WCSessionFileTransfer fileTransfer, NSError error)
        {
            var commandStatus = new CommandStatus(Command.TransferFile, Phrase.Finished);

            if (error != null)
            {
                commandStatus.ErrorMessage = error.LocalizedDescription;
                this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
            }
            else
            {
                commandStatus.FileTransfer = fileTransfer;
                commandStatus.TimedColor   = new TimedColor(fileTransfer.File.Metadata);

#if __WATCHOS__
                if (!string.IsNullOrEmpty(WatchSettings.SharedContainerId))
                {
                    var defaults = new NSUserDefaults(WatchSettings.SharedContainerId, NSUserDefaultsType.SuiteName);
                    if (defaults.BoolForKey(WatchSettings.ClearLogsAfterTransferred))
                    {
                        Logger.Shared.ClearLogs();
                    }
                }
#endif
                this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
            }
        }
Esempio n. 7
0
        /*
         * public override void DidReceiveApplicationContext(WCSession session, NSDictionary<NSString, NSObject> applicationContext)
         * {
         *      System.Diagnostics.Debug.WriteLine($"Receiving App Context on {Device}");
         *      if (ApplicationContextUpdated != null)
         *      {
         *              var keys = applicationContext.Keys.Select(k => k.ToString()).ToArray();
         *              var values = applicationContext.Values.Select(v => JsonConvert.DeserializeObject(v.ToString())).ToArray();
         *              var dictionary = keys.Zip(values, (k, v) => new { Key = k, Value = v })
         *                                                       .ToDictionary(x => x.Key, x => x.Value);
         *              ApplicationContextUpdated?.Invoke(session, null);
         *      }
         * }
         */

        public override void DidReceiveMessage(WCSession session, NSDictionary <NSString, NSObject> message)
        {
            System.Diagnostics.Debug.WriteLine($"Receiving Message on {Device}");
            if (MessageReceived != null)
            {
                var dictionary = new Dictionary <WatchMessage, object>();
                foreach (var nativeKey in message.Keys)
                {
                    var key = _nativeStringToWatchMessage[nativeKey];

                    if (key == WatchMessage.Awake || key == WatchMessage.Speed || key == WatchMessage.BatteryPercent)
                    {
                        dictionary[key] = (message[nativeKey] as NSNumber)?.Int32Value ?? 0;
                    }
                    else if (key == WatchMessage.Voltage)
                    {
                        dictionary[key] = (message[nativeKey] as NSNumber)?.FloatValue ?? 0f;
                    }
                    else if (key == WatchMessage.Distance || key == WatchMessage.SpeedUnitsLabel)
                    {
                        dictionary[key] = (message[nativeKey] as NSString)?.ToString() ?? String.Empty;
                    }
                }
                MessageReceived?.Invoke(session, dictionary);
            }
        }
Esempio n. 8
0
 public override void ActivationDidComplete(WCSession session, WCSessionActivationState activationState, NSError error)
 {
     if (activationState == WCSessionActivationState.Activated)
     {
         this.session = session;
         this.SendPending();
     }
 }
        public void DidReceiveApplicationContext(WCSession session, Dictionary<string, object> applicationContext)
		{
			var message = (string)applicationContext["MessagePhone"];
			if (message != null)
			{
				Console.WriteLine($"Application context update received : {message}");
				label.SetText($"\ud83d\udcf1 : {message}");
			}
		}
Esempio n. 10
0
        /// <summary>
        /// Called when an app context is received.
        /// </summary>
        public override void DidReceiveApplicationContext(WCSession session, NSDictionary <NSString, NSObject> applicationContext)
        {
            var commandStatus = new CommandStatus(Command.UpdateAppContext, Phrase.Received)
            {
                TimedColor = new TimedColor(applicationContext)
            };

            this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
        }
Esempio n. 11
0
        /// <summary>
        /// Called when a piece of message data is received and the peer doesn't need a respons
        /// </summary>
        public override void DidReceiveMessageData(WCSession session, NSData messageData)
        {
            var commandStatus = new CommandStatus(Command.SendMessageData, Phrase.Received)
            {
                TimedColor = TimedColor.Create(messageData)
            };

            this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
        }
Esempio n. 12
0
        /// <summary>
        /// Called when a message is received and the peer doesn't need a response.
        /// </summary>
        public override void DidReceiveMessage(WCSession session, NSDictionary <NSString, NSObject> message)
        {
            var commandStatus = new CommandStatus(Command.SendMessage, Phrase.Received)
            {
                TimedColor = new TimedColor(message)
            };

            this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
        }
Esempio n. 13
0
        public void DidReceiveApplicationContext(WCSession session, Dictionary <string, object> applicationContext)
        {
            var message = (string)applicationContext["MessagePhone"];

            if (message != null)
            {
                Console.WriteLine($"Application context update received : {message}");
                label.SetText($"\ud83d\udcf1 : {message}");
            }
        }
        // Called when the phone has new values to update on the watch display.
        // Messages are mostly sent from Watch.cs on phone side
        public void DidReceiveMessage(WCSession session, Dictionary <WatchMessage, object> messages)
        {
            try
            {
                // Since we got a response from the phone, cancel the timer
                // task that would have prompted the user to connect to the board on the phone
                source.Cancel();

                // Make sure we hide the "Connect to board" message and show the
                // ride details.
                HideConnectToBoardViaPhoneMessage();

                // Now process the message itself
                foreach (var message in messages)
                {
                    /*
                     * if (message.Key == WatchMessage.MessagePhone)
                     * {
                     *  var messageString = message.Value as string;
                     *  if (messageString != null)
                     *  {
                     *      System.Diagnostics.Debug.WriteLine($"Application context update received : {messageString}");
                     *      this.myLabel.SetText(messageString);
                     *  }
                     * }
                     * else */
                    if (message.Key == WatchMessage.BatteryPercent)
                    {
                        this.batteryPercentageLabel.SetText($"{message.Value}%");
                    }
                    else if (message.Key == WatchMessage.Speed)
                    {
                        this.speedLabel.SetText(String.Format("{0:F0}", message.Value));
                    }
                    else if (message.Key == WatchMessage.Voltage)
                    {
                        this.voltageLabel.SetText(String.Format("{0:F2}V", message.Value));
                    }
                    else if (message.Key == WatchMessage.Distance)
                    {
                        this.tripDistanceLabel.SetText(message.Value as string);
                    }
                    else if (message.Key == WatchMessage.SpeedUnitsLabel)
                    {
                        // Update the speed units to mph or km/h
                        this.speedUnitsLabel.SetText(message.Value as string);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Exception Processing Message: {ex.Message}");
                this.errorMessages.SetText($"Exception: {ex.Message}");
            }
        }
Esempio n. 15
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            this.statesToSend.Clear();

            if (this.session != null)
            {
                this.session.Dispose();
                this.session = null;
            }
        }
		public override void SessionReachabilityDidChange(WCSession session)
		{
			Console.WriteLine($"Watch connectivity Reachable:{(session.Reachable ? '✓' : '✗')} from {Device}");
			// handle session reachability change
			if (session.Reachable)
			{
				// great! continue on with Interactive Messaging
			}
			else {
				// 😥 prompt the user to unlock their iOS device
			}
		}
Esempio n. 17
0
 public void ActivationDidComplete(WCSession session, WCSessionActivationState activationState, NSError error)
 {
     if (activationState == WCSessionActivationState.Activated)
     {
         var activationCompletion = this.sessionActivationCompletion;
         if (activationCompletion != null)
         {
             activationCompletion(session);
             this.sessionActivationCompletion = null;
         }
     }
 }
Esempio n. 18
0
 public void DidReceiveMessage(WCSession session, Foundation.NSDictionary<Foundation.NSString, Foundation.NSObject> message)
 {
     NSObject state;
     if (message.TryGetValue(new NSString("State"), out state))
     {
         DispatchQueue.MainQueue.DispatchAsync(() =>
         {
             var @string = state as NSString;
             this.UpdateSessionState(@string);
         });
     }
 }
Esempio n. 19
0
        public void DidReceiveApplicationContext(WCSession session, Dictionary <string, object> applicationContext)
        {
            var message = (string)applicationContext["MessageWatch"];

            if (message != null)
            {
                Console.WriteLine($"Application context update received : {message}");
                InvokeOnMainThread(() =>
                {
                    label.Text = $"⌚️ : {message}";
                });
            }
        }
Esempio n. 20
0
        public override void DidReceiveApplicationContext(WCSession session, NSDictionary <NSString, NSObject> applicationContext)
        {
            Console.WriteLine($"Receiving Message on {Device}");
            if (ApplicationContextUpdated != null)
            {
                var keys       = applicationContext.Keys.Select(k => k.ToString()).ToArray();
                var values     = applicationContext.Values.Select(v => JsonConvert.DeserializeObject(v.ToString())).ToArray();
                var dictionary = keys.Zip(values, (k, v) => new { Key = k, Value = v })
                                 .ToDictionary(x => x.Key, x => x.Value);

                ApplicationContextUpdated(session, dictionary);
            }
        }
Esempio n. 21
0
 public override void SessionReachabilityDidChange(WCSession session)
 {
     Console.WriteLine($"Watch connectivity Reachable:{(session.Reachable ? '✓' : '✗')} from {Device}");
     // handle session reachability change
     if (session.Reachable)
     {
         // great! continue on with Interactive Messaging
     }
     else
     {
         // 😥 prompt the user to unlock their iOS device
     }
 }
Esempio n. 22
0
        /// <summary>
        /// Called when a file is received.
        /// </summary>
        public override void DidReceiveFile(WCSession session, WCSessionFile file)
        {
            var commandStatus = new CommandStatus(Command.TransferFile, Phrase.Received)
            {
                File       = file,
                TimedColor = new TimedColor(file.Metadata)
            };

            // Note that WCSessionFile.fileURL will be removed once this method returns,
            // so instead of calling postNotificationOnMainQueue(name: .dataDidFlow, userInfo: userInfo),
            // we dispatch to main queue SYNCHRONOUSLY.

            DispatchQueue.MainQueue.DispatchSync(() =>
            {
                NSNotificationCenter.DefaultCenter.PostNotificationName(NotificationName.DataDidFlow, commandStatus);
            });
        }
Esempio n. 23
0
        public void DidReceiveApplicationContext(WCSession session, Dictionary <string, object> applicationContext)
        {
            var message = (string)applicationContext["MessagePhone"];

            if (message != null)
            {
                Console.WriteLine($"Application context update received : {message}");
                if (rows.Contains(message))
                {
                    LoadTableRows();
                }
                else
                {
                    rows.Add(message);
                    LoadTableRows();
                }
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Called when sending a userInfo is done.
        /// </summary>
        public override void DidFinishUserInfoTransfer(WCSession session, WCSessionUserInfoTransfer userInfoTransfer, NSError error)
        {
            var commandStatus = new CommandStatus(Command.TransferUserInfo, Phrase.Finished)
            {
                TimedColor = new TimedColor(userInfoTransfer.UserInfo)
            };

#if __IOS__
            if (userInfoTransfer.CurrentComplicationInfo)
            {
                commandStatus.Command = Command.TransferCurrentComplicationUserInfo;
            }
#endif

            if (error != null)
            {
                commandStatus.ErrorMessage = error.LocalizedDescription;
            }

            this.PostNotificationOnMainQueueAsync(NotificationName.DataDidFlow, commandStatus);
        }
Esempio n. 25
0
    protected void cConnectDApp_Click(object sender, EventArgs e)
    {
        var t = Task.Run(async() =>
        {
            try
            {
                var myMeta           = new { name = ".NET Dapp", description = "some description", accounts = new List <string>() };
                var wcSessionRequest = await WCSession.ConnectSession(cWcUrl.Text, myMeta);
                var wcSession        = wcSessionRequest.Key;
                var request          = wcSessionRequest.Value;
                await wcSession.SendSessionRequestResponse(request, myMeta, new List <string>(), true, "https://kovan.infura.io", 42, true);
                return(wcSessionRequest);
            }
            catch (Exception ex)
            {
                var r = ex.Message;
                throw;
            }
        });

        t.ConfigureAwait(false);
        t.Wait();
        var xx = t.Result;
    }
Esempio n. 26
0
 /// <summary>
 /// Called when a message is received and the peer needs a response.
 /// </summary>
 public override void DidReceiveMessage(WCSession session, NSDictionary <NSString, NSObject> message, WCSessionReplyHandler replyHandler)
 {
     this.DidReceiveMessage(session, message);
     replyHandler(message); // Echo back the time stamp.
 }
Esempio n. 27
0
 public void DidReceiveMessage(WCSession session, Dictionary <WatchMessage, object> message)
 {
     WatchSyncEventHandler.HandleWatchMessage(message, _board);
 }
Esempio n. 28
0
 public override void SessionWatchStateDidChange(WCSession session)
 {
     Console.WriteLine($"SessionWatchStateDidChange: activationState = {session.ActivationState}");
 }
Esempio n. 29
0
 /// <summary>
 /// Called when WCSession activation state is changed.
 /// </summary>
 public override void ActivationDidComplete(WCSession session, WCSessionActivationState activationState, NSError error)
 {
     this.PostNotificationOnMainQueueAsync(NotificationName.ActivationDidComplete);
 }
Esempio n. 30
0
 /// <summary>
 /// Called when WCSession reachability is changed.
 /// </summary>
 public override void SessionReachabilityDidChange(WCSession session)
 {
     this.PostNotificationOnMainQueueAsync(NotificationName.ReachabilityDidChange);
 }
Esempio n. 31
0
 /// <summary>
 /// Called when a piece of message data is received and the peer needs a response.
 /// </summary>
 public override void DidReceiveMessageData(WCSession session, NSData messageData, WCSessionReplyDataHandler replyHandler)
 {
     this.DidReceiveMessageData(session, messageData);
     replyHandler(messageData); // Echo back the time stamp.
 }
		public override void DidReceiveApplicationContext(WCSession session, NSDictionary<NSString, NSObject> applicationContext)
		{
			Console.WriteLine($"Recieving Message on {Device}");
			if (ApplicationContextUpdated != null)
			{
				var keys = applicationContext.Keys.Select(k => k.ToString()).ToArray();
				var values = applicationContext.Values.Select(v => JsonConvert.DeserializeObject(v.ToString())).ToArray();
				var dictionary = keys.Zip(values, (k, v) => new { Key = k, Value = v })
									 .ToDictionary(x => x.Key, x => x.Value);

				ApplicationContextUpdated(session, dictionary);
			}
		}
Esempio n. 33
0
 public override void DidDeactivate(WCSession session)
 {
     // Activate the new session after having switched to a new watch.
     session.ActivateSession();
 }