public void Connect(string permissions)
        {
            Session currentSession = Session.ActiveSession;

            if (currentSession == null || currentSession.IsClosed)
            {
                Session session = new Session.Builder(_mainActivity).Build();
                Session.ActiveSession = session;
                currentSession        = session;
            }

            if (currentSession.IsOpened)
            {
            }
            else if (!currentSession.IsOpened)
            {
                Session.OpenRequest op = new Session.OpenRequest(_mainActivity);

                op.SetLoginBehavior(SessionLoginBehavior.SuppressSso);
                op.SetCallback(null);

                List <string> perms = permissions.Split(',').ToList();
                op.SetPermissions(perms);

                Session s = new Session.Builder(_mainActivity).Build();
                Session.ActiveSession = s;
                s.OpenForRead(op);
            }
        }
Ejemplo n.º 2
0
        public override bool TryStartSession()
        {
            lock (_sessionLocker)
            {
                if (!CheckPermissions() ||
                    string.IsNullOrWhiteSpace(ApiKey) ||
                    string.IsNullOrWhiteSpace(SessionId) ||
                    string.IsNullOrWhiteSpace(UserToken))
                {
                    return(false);
                }

                EndSession();
                IsSessionStarted = true;

                using (var builder = new Session.Builder(CrossCurrentActivity.Current.AppContext, ApiKey, SessionId)
                                     .SessionOptions(new SessionOptions()))
                {
                    Session = builder.Build();
                    Session.ConnectionDestroyed += OnConnectionDestroyed;
                    Session.Connected           += OnConnected;
                    Session.StreamReceived      += OnStreamReceived;
                    Session.StreamDropped       += OnStreamDropped;
                    Session.Error  += OnError;
                    Session.Signal += OnSignal;
                    Session.Connect(UserToken);
                }
                return(true);
            }
        }
        public override bool TryStartSession(bool sendBackToRoot)
        {
            if (!CheckPermissions() ||
                string.IsNullOrWhiteSpace(ApiKey) ||
                string.IsNullOrWhiteSpace(SessionId) ||
                string.IsNullOrWhiteSpace(UserToken))
            {
                return(false);
            }

            IsSessionStarted = true;
            EndSession(sendBackToRoot, false);
            IsVideoPublishingEnabled   = true;
            IsAudioPublishingEnabled   = true;
            IsVideoSubscriptionEnabled = true;
            IsAudioSubscriptionEnabled = true;
            IsSubscriberVideoEnabled   = true;

            Session = new Session.Builder(CrossCurrentActivity.Current.AppContext, ApiKey, SessionId).Build();
            Session.ConnectionDestroyed += OnConnectionDestroyed;
            Session.Connected           += OnDidConnect;
            Session.StreamReceived      += OnStreamCreated;
            Session.StreamDropped       += OnStreamDestroyed;
            Session.Error  += OnError;
            Session.Signal += OnSignal;
            Session.Connect(UserToken);

            return(true);
        }
        public override bool TryStartSession()
        {
            if (!CheckPermissions() ||
                string.IsNullOrWhiteSpace(ApiKey) ||
                string.IsNullOrWhiteSpace(SessionId) ||
                string.IsNullOrWhiteSpace(UserToken))
            {
                return(false);
            }

            IsSessionStarted = true;
            EndSession();

            var builder = new Session.Builder(CrossCurrentActivity.Current.AppContext, ApiKey, SessionId);

            Session = builder.Build();
            Session.ConnectionDestroyed += OnConnectionDestroyed;
            Session.Connected           += OnConnected;
            Session.StreamReceived      += OnStreamReceived;
            Session.StreamDropped       += OnStreamDropped;
            Session.Error  += OnError;
            Session.Signal += OnSignal;
            Session.Connect(UserToken);

            builder.Dispose();

            Log.Debug(Tag, "Session Started");
            return(true);
        }
        public void AuthorizeCallback(int requestCode, int resultCode, Android.Content.Intent data)
        {
            if (Session.ActiveSession != null)
            {
                Session.ActiveSession.OnActivityResult(_mainActivity, requestCode, resultCode, data);
            }

            Session currentSession = Session.ActiveSession;

            if (currentSession == null || currentSession.IsClosed)
            {
                Session session = new Session.Builder(_mainActivity).Build();
                Session.ActiveSession = session;
                currentSession        = session;
            }

            if (currentSession.IsOpened)
            {
                Session.OpenActiveSession(_mainActivity, true, new StatusCallback((session, state, exception) => {
                    ConnectionStatusChanged(this, new FacebookStatus(state == SessionState.Opened));
                }));
            }
        }
        public override bool TryStartSession()
        {
            if (!CheckPermissions() ||
                string.IsNullOrWhiteSpace(ApiKey) ||
                string.IsNullOrWhiteSpace(SessionId) ||
                string.IsNullOrWhiteSpace(UserToken))
            {
                return(false);
            }

            IsSessionStarted = true;
            EndSession();

            Session = new Session.Builder(CrossCurrentActivity.Current.AppContext, ApiKey, SessionId).Build();
            Session.ConnectionDestroyed += OnConnectionDestroyed;
            Session.Connected           += OnDidConnect;
            Session.StreamReceived      += OnStreamCreated;
            Session.StreamDropped       += OnStreamDestroyed;
            Session.Error += OnError;
            Session.Connect(UserToken);

            return(true);
        }
Ejemplo n.º 7
0
        SessionInsertRequest InsertFitnessSession()
        {
            Log.Info(TAG, "Creating a new session for an afternoon run");

            var  epoch         = new DateTime(1970, 1, 1);
            var  now           = DateTime.UtcNow;
            long endTime       = (long)(now - epoch).TotalMilliseconds;
            long endWalkTime   = (long)(now.Subtract(TimeSpan.FromDays(10)) - epoch).TotalMilliseconds;
            long startWalkTime = (long)(now.Subtract(TimeSpan.FromDays(20)) - epoch).TotalMilliseconds;
            long startTime     = (long)(now.Subtract(TimeSpan.FromMinutes(30)) - epoch).TotalMilliseconds;

            var speedDataSource = new DataSource.Builder()
                                  .SetAppPackageName(PackageName)
                                  .SetDataType(DataType.TypeSpeed)
                                  .SetName(SAMPLE_SESSION_NAME + "- speed")
                                  .SetType(DataSource.TypeRaw)
                                  .Build();

            const float runSpeedMps  = 10;
            const float walkSpeedMps = 3;
            // Create a data set of the run speeds to include in the session.
            DataSet speedDataSet = DataSet.Create(speedDataSource);

            DataPoint firstRunSpeed = speedDataSet.CreateDataPoint()
                                      .SetTimeInterval(startTime, startWalkTime, TimeUnit.Milliseconds);

            firstRunSpeed.GetValue(Field.FieldSpeed).SetFloat(runSpeedMps);
            speedDataSet.Add(firstRunSpeed);

            DataPoint walkSpeed = speedDataSet.CreateDataPoint()
                                  .SetTimeInterval(startWalkTime, endWalkTime, TimeUnit.Milliseconds);

            walkSpeed.GetValue(Field.FieldSpeed).SetFloat(walkSpeedMps);
            speedDataSet.Add(walkSpeed);

            DataPoint secondRunSpeed = speedDataSet.CreateDataPoint()
                                       .SetTimeInterval(endWalkTime, endTime, TimeUnit.Milliseconds);

            secondRunSpeed.GetValue(Field.FieldSpeed).SetFloat(runSpeedMps);
            speedDataSet.Add(secondRunSpeed);

            // [START build_insert_session_request_with_activity_segments]
            // Create a second DataSet of ActivitySegments to indicate the runner took a 10-minute walk
            // in the middle of the run.
            var activitySegmentDataSource = new DataSource.Builder()
                                            .SetAppPackageName(PackageName)
                                            .SetDataType(DataType.TypeActivitySegment)
                                            .SetName(SAMPLE_SESSION_NAME + "-activity segments")
                                            .SetType(DataSource.TypeRaw)
                                            .Build();
            DataSet activitySegments = DataSet.Create(activitySegmentDataSource);

            DataPoint firstRunningDp = activitySegments.CreateDataPoint()
                                       .SetTimeInterval(startTime, startWalkTime, TimeUnit.Milliseconds);

            firstRunningDp.GetValue(Field.FieldActivity).SetActivity(FitnessActivities.Running);
            activitySegments.Add(firstRunningDp);

            DataPoint walkingDp = activitySegments.CreateDataPoint()
                                  .SetTimeInterval(startWalkTime, endWalkTime, TimeUnit.Milliseconds);

            walkingDp.GetValue(Field.FieldActivity).SetActivity(FitnessActivities.Walking);
            activitySegments.Add(walkingDp);

            DataPoint secondRunningDp = activitySegments.CreateDataPoint()
                                        .SetTimeInterval(endWalkTime, endTime, TimeUnit.Milliseconds);

            secondRunningDp.GetValue(Field.FieldActivity).SetActivity(FitnessActivities.Running);
            activitySegments.Add(secondRunningDp);

            var session = new Session.Builder()
                          .SetName(SAMPLE_SESSION_NAME)
                          .SetDescription("Long run around Shoreline Park")
                          .SetIdentifier("UniqueIdentifierHere")
                          .SetActivity(FitnessActivities.Running)
                          .SetStartTime(startTime, TimeUnit.Milliseconds)
                          .SetEndTime(endTime, TimeUnit.Milliseconds)
                          .Build();

            var insertRequest = new SessionInsertRequest.Builder()
                                .SetSession(session)
                                .AddDataSet(speedDataSet)
                                .AddDataSet(activitySegments)
                                .Build();

            return(insertRequest);
        }
Ejemplo n.º 8
0
		SessionInsertRequest InsertFitnessSession()
		{
			Log.Info(TAG, "Creating a new session for an afternoon run");

			var epoch = new DateTime (1970, 1, 1);
			var now = DateTime.UtcNow;
			long endTime = (long)(now - epoch).TotalMilliseconds;
			long endWalkTime = (long)(now.Subtract (TimeSpan.FromMinutes (10)) - epoch).TotalMilliseconds;
			long startWalkTime = (long)(now.Subtract (TimeSpan.FromMinutes (20)) - epoch).TotalMilliseconds;
			long startTime = (long)(now.Subtract (TimeSpan.FromMinutes (30)) - epoch).TotalMilliseconds;

			var speedDataSource = new DataSource.Builder()
				.SetAppPackageName (PackageName)
				.SetDataType (DataType.TypeSpeed)
				.SetName (SAMPLE_SESSION_NAME + "- speed")
				.SetType (DataSource.TypeRaw)
				.Build ();

			const float runSpeedMps = 10;
			const float walkSpeedMps = 3;
			// Create a data set of the run speeds to include in the session.
			DataSet speedDataSet = DataSet.Create (speedDataSource);

			DataPoint firstRunSpeed = speedDataSet.CreateDataPoint ()
				.SetTimeInterval (startTime, startWalkTime, TimeUnit.Milliseconds);
			firstRunSpeed.GetValue (Field.FieldSpeed).SetFloat (runSpeedMps);
			speedDataSet.Add (firstRunSpeed);

			DataPoint walkSpeed = speedDataSet.CreateDataPoint ()
				.SetTimeInterval (startWalkTime, endWalkTime, TimeUnit.Milliseconds);
			walkSpeed.GetValue (Field.FieldSpeed).SetFloat (walkSpeedMps);
			speedDataSet.Add (walkSpeed);

			DataPoint secondRunSpeed = speedDataSet.CreateDataPoint ()
				.SetTimeInterval (endWalkTime, endTime, TimeUnit.Milliseconds);
			secondRunSpeed.GetValue (Field.FieldSpeed).SetFloat(runSpeedMps);
			speedDataSet.Add (secondRunSpeed);

			// [START build_insert_session_request_with_activity_segments]
			// Create a second DataSet of ActivitySegments to indicate the runner took a 10-minute walk
			// in the middle of the run.
			var activitySegmentDataSource = new DataSource.Builder()
				.SetAppPackageName (PackageName)
				.SetDataType (DataType.TypeActivitySegment)
				.SetName (SAMPLE_SESSION_NAME + "-activity segments")
				.SetType (DataSource.TypeRaw)
				.Build ();
			DataSet activitySegments = DataSet.Create (activitySegmentDataSource);

			DataPoint firstRunningDp = activitySegments.CreateDataPoint ()
				.SetTimeInterval (startTime, startWalkTime, TimeUnit.Milliseconds);
			firstRunningDp.GetValue (Field.FieldActivity).SetActivity (FitnessActivities.Running);
			activitySegments.Add (firstRunningDp);

			DataPoint walkingDp = activitySegments.CreateDataPoint ()
				.SetTimeInterval (startWalkTime, endWalkTime, TimeUnit.Milliseconds);
			walkingDp.GetValue (Field.FieldActivity).SetActivity (FitnessActivities.Walking);
			activitySegments.Add (walkingDp);

			DataPoint secondRunningDp = activitySegments.CreateDataPoint ()
				.SetTimeInterval (endWalkTime, endTime, TimeUnit.Milliseconds);
			secondRunningDp.GetValue (Field.FieldActivity).SetActivity (FitnessActivities.Running);
			activitySegments.Add (secondRunningDp);

			var session = new Session.Builder ()
				.SetName (SAMPLE_SESSION_NAME)
				.SetDescription ("Long run around Shoreline Park")
				.SetIdentifier ("UniqueIdentifierHere")
				.SetActivity (FitnessActivities.Running)
				.SetStartTime (startTime, TimeUnit.Milliseconds)
				.SetEndTime (endTime, TimeUnit.Milliseconds)
				.Build ();

			var insertRequest = new SessionInsertRequest.Builder()
				.SetSession (session)
				.AddDataSet (speedDataSet)
				.AddDataSet (activitySegments)
				.Build ();

			return insertRequest;
		}