Beispiel #1
0
        private void LogIn()
        {
            try
            {
                string baseUrl = Settings.Default.ENVIRONMENT_BASE_URL;
                string result = Rest.Get(baseUrl + "Users?email=" + txtEmail.Text);
                User u = JsonConvert.DeserializeObject<User>(result);
                if (u != null)
                    this._user = u;
                else
                    CreateUser(baseUrl);

                this._device = new Device();
                this._device.Name = txtDevicename.Text;

                if (chkClient.IsChecked == true)
                    FindClient();
                else
                    StartActivityManager();
                SaveSettings();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        /// <summary>
        /// Initializes the Activity Service
        /// </summary>
        /// <param name="owner">User that owns this activity manager</param>
        private void InitializeActivityService(User owner)
        {
            if (!_useCloud) return;
            var serviceAddress = _useLocalCloud ? "http://localhost:56002" : "http://activitycloud-1.apphb.com";

            _activityCloudConnector = new ActivityCloudConnector();
            _activityCloudConnector.ConnectionSetup += ActivityCloudConnectorConnectionSetup;
            _activityCloudConnector.ActivityAdded += ActivityCloudConnectorActivityAdded;
            _activityCloudConnector.ActivityDeleted += ActivityCloudConnectorActivityDeleted;
            _activityCloudConnector.ActivityUpdated += ActivityCloudConnectorActivityUpdated;

            _activityCloudConnector.FileDeleteRequest += ActivityCloudConnectorFileDeleteRequest;
            _activityCloudConnector.FileDownloadRequest += ActivityCloudConnectorFileDownloadRequest;
            _activityCloudConnector.FileUploadRequest += ActivityCloudConnectorFileUploadRequest;

            _activityCloudConnector.FriendDeleted += ActivityCloudConnectorFriendDeleted;
            _activityCloudConnector.FriendAdded += ActivityCloudConnectorFriendAdded;
            _activityCloudConnector.FriendRequestReceived += ActivityCloudConnectorFriendRequestReceived;
            _activityCloudConnector.ParticipantAdded += ActivityCloudConnectorParticipantAdded;
            _activityCloudConnector.ParticipantRemoved += ActivityCloudConnectorParticipantRemoved;

            _activityCloudConnector.ConnectToCloud(serviceAddress + "/Api/",owner);

            _connectionActive = true;
            Log.Out("ActivityManager", string.Format("Cloud connector connected to {0}", serviceAddress), LogCode.Net);
        }
        public User Owner { get; set; } //User account that is loaded from cloud

        #endregion

        #region Constructor

        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="localPath"></param>
        /// <param name="useLocalCloud"></param>
        /// <param name="useCloud"></param>
        public ActivityManager(User owner, string localPath, bool useLocalCloud = false, bool useCloud = true)
        {
            Owner = owner;
            _useLocalCloud = useLocalCloud;
            _useCloud = useCloud;

            IntializeEventSystem();
            InitializeFileService(localPath);
            InitializeActivityService(Owner);
        }
Beispiel #4
0
 private void LogIn()
 {
     var baseUrl = Resources.GetString(Resource.String.ApiPath);
     var result = Rest.Get(baseUrl + "Users?email=" + FindViewById<TextView>(Resource.Id.Email).Text);
     var u = JsonConvert.DeserializeObject<User>(result);
     if (u != null) _user = u;
     else CreateUser(baseUrl);
     SetStatus("Succesfully logged in.");
     
     StartMainActivity();
 }
 private void CreateUser(string baseUrl)
 {
     User user = new User();
     user.Email = txtEmail.Text;
     user.Name = txtUsername.Text;
     string added = Rest.Post(baseUrl + "Users", user);
     if (JsonConvert.DeserializeObject<bool>(added))
     {
         var result = Rest.Get(baseUrl + "Users?email=" + txtEmail.Text);
         var u = JsonConvert.DeserializeObject<User>(result);
         this.User = u;
     }
 }
Beispiel #6
0
 private void CreateUser(string baseUrl)
 {
     var email = FindViewById<TextView>(Resource.Id.Email).Text;
     var username = FindViewById<TextView>(Resource.Id.Username).Text;
     var user = new User
     {
         Email = email,
         Name = username
     };
     var added = Rest.Post(baseUrl + "Users", user);
     if (!JsonConvert.DeserializeObject<bool>(added)) return;
     var result = Rest.Get(baseUrl + "Users?email=" + email);
     var u = JsonConvert.DeserializeObject<User>(result);
     this._user = u;
 }
 /// <summary>
 /// Adds a participant to an activity
 /// </summary>
 /// <param name="a">Activity</param>
 /// <param name="u">Participant</param>
 /// <param name="deviceId"> </param>
 public void AddParticipant(Activity a, User u, string deviceId)
 {
     if (_useCloud && _connectionActive)
         _activityCloudConnector.AddParticipant(a.Id, u.Id);
     ParticipantStore.Participants.Add(u.Id, u);
     Console.WriteLine("ActivityManager: Added participant {0} to activity {1}", u.Name, a.Name);
 }
 public bool Upsert(Guid id, User obj)
 {
     return base.Upsert(Collection, obj, id);
 }
 public bool Add(User obj)
 {
     return base.Add(Collection, obj);
 }
Beispiel #10
0
 private void SetUser(string json)
 {
     _user = JsonConvert.DeserializeObject<User>(json);
 }
 private void Connect(User user)
 {
     _connection.Received += SignalRecieved;
     _connection.Start().Wait();
     Register(user.Id);
     if (ConnectionSetup != null)
         ConnectionSetup(this, new EventArgs());
     //_connection.Start().ContinueWith(task =>
     //{
     //    if (task.IsFaulted)
     //    {
     //        if (task.Exception != null)
     //            Console.WriteLine("Failed to start: {0}", task.Exception.InnerException.ToString());
     //    }
     //    else
     //    {
     //        Register(user.Id);
     //        if (ConnectionSetup != null)
     //            ConnectionSetup(this, new EventArgs());
     //    }
     //});
 }
        /// <summary>
        /// Initializes the device, user and system
        /// </summary>
        private void IntializeSystem()
        {
            _device = _login.Device;
            _device.Location = "pIT lab";

            _owner = _login.User;
            _startMode = _login.Mode;
            InitializeNetwork();
        }
 public virtual void ParticipantNetRemoved(User u, Guid activityId)
 {
     if (ParticipantRemoved != null)
         ParticipantRemoved(this, new ParticipantEventArgs(u, activityId));
 }
 public virtual void FriendNetRequest(User u)
 {
     if (FriendRequestReceived != null)
         FriendRequestReceived(this, new FriendEventArgs(u));
 }
 public virtual void FriendNetAdded(User u)
 {
     if (FriendAdded != null)
         FriendAdded(this, new FriendEventArgs(u));
 }
 public void ConnectToCloud(string baseUrl,User user)
 {
     BaseUrl = baseUrl;
     _connection = new Connection(baseUrl+ "Connect");
    Connect(user);
 }
 public ParticipantEventArgs(User participant,Guid activityId)
 {
     Participant = participant;
     ActivityId = activityId;
 }
 public FriendEventArgs(User u)
 {
     User = u;
 }