Beispiel #1
0
 public LiveContactViewModel(Contact contact, string token, LiveOperatingEnvironment liveOperatingEnvironment)
 {
     this.contact = contact;
     this.liveAuthenticationToken  = token;
     this.liveOperatingEnvironment = liveOperatingEnvironment;
     GetProfile(this.contact);
     DownloadProfileImage();
 }
 private LiveContactsCollection GetAllContacts(LiveOperatingEnvironment liveOperatingEnvironment)
 {
     if (liveOperatingEnvironment != null)
     {
         if (!liveOperatingEnvironment.Contacts.IsLoaded)
         {
             liveOperatingEnvironment.Contacts.Load();
         }
         LiveContactsCollection contacts = new LiveContactsCollection(liveOperatingEnvironment.Contacts.Entries);
         return(contacts);
     }
     return(new LiveContactsCollection());
 }
Beispiel #3
0
 private void LoginCommand_Complete(LiveStatus liveStatus)
 {
     if (liveStatus.HasLoginErrors)
     {
         MessageBox.Show(liveStatus.LoginErrorMessage, "Live Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
     }
     else
     {
         this.liveAuthenticationToken  = liveStatus.Token;
         this.liveOperatingEnvironment = liveStatus.LiveOperatingEnvironment;
         this.loginName = this.liveOperatingEnvironment.Mesh.ProvisionedUser.Name;
         OnPropertyChanged("LiveOperatingEnvironment");
         OnPropertyChanged("LoginName");
         this.NeedsAuthentication = false;
         OnPropertyChanged("NeedsAuthentication");
     }
 }
 void mainWindowViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "LiveOperatingEnvironment")
     {
         this.liveOperatingEnvironment = mainWindowViewModel.LiveOperatingEnvironment;
         this.liveContacts             = GetAllContacts(this.liveOperatingEnvironment);
         OnPropertyChanged("LiveContacts");
         OnPropertyChanged("ChatDisclaimerVisibility");
     }
     if (e.PropertyName == "LibraryItems")
     {
         this.libraryItems = mainWindowViewModel.LibraryItems;
         GetImageLibraryItems();
         GetXpsLibraryItems();
         OnPropertyChanged("ImageLibraryItems");
         OnPropertyChanged("XpsLibraryItems");
     }
 }
 public LiveLoginView()
 {
     InitializeComponent();
     liveOperatingEnvironment = new LiveOperatingEnvironment();
     CheckForStoredInfo();
 }
		public void FetchTask()
		{
			

			if (syncEngine.SyncCanceled)
			{
				this.FetchSem.Release();
				return;
			}

			mans.Clear();
			contactsByFullName.Clear();

			string appId = "000000004000FCD9";

			if (Credentials == null)
			{
				this.FetchSem.Release();
				return;
			}
			else
			{
				if (Credentials.UserName != null && !Credentials.UserName.Contains("@") && Credentials.UserName.Trim() != "")
				{
					Credentials.UserName += "@live.com";
				}
			}

			// Synrc Contacts
			// https://lx.azure.microsoft.com/Cloud/Provisioning/Manage.aspx?AppID=000000004000FCD9

			//IdentityManager manager = null;

			//try
			//{
			//    manager = IdentityManager.CreateInstance(appId, "Synrc Contacts");
			//}
			//catch (Exception e)
			//{
			//    Credentials = null;
			//    syncEngine.CancelSync(e.Message);
			//    this.FetchSem.Release();
			//    return;
			//}
			//Identity identity = null;

			//if (String.IsNullOrEmpty(defaultUserName) && manager != null)
			//{
			//    identity = manager.CreateIdentity();
			//}
			//else if (manager != null)
			//{
			//    identity = manager.CreateIdentity(defaultUserName);
			//}

			//if (identity != null && identity.SavedCredentials == CredentialType.UserNameAndPassword)
			//{
			//    identity.Authenticate(AuthenticationType.Silent);
			//}
			//else if (identity != null)
			//{
			//    identity.Authenticate();
			//    defaultUserName = identity.UserName;
			//}
			
			env = new LiveOperatingEnvironment();

			string serverUrl = "https://user-ctp.windows.net";
			Uri uri = new Uri(serverUrl);
			LiveItemAccessOptions liao = new LiveItemAccessOptions(true);

			string token = null;
			env.ConnectCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(env_ConnectCompleted);

			if (Credentials.UserName == null || Credentials.UserName.Trim() == "")
			{
				Credentials = null;
				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, "Cannot logon with blank username.", null);
				//syncEngine.CancelSync("Cannot logon with blank username.");
				this.FetchSem.Release();
				return;
			}

			try
			{
				token = Credentials.GetWindowsLiveAuthenticationToken(appId, true);
				//token = identity.GetTicket("user-ctp.windows.net", "MBI_SSL", true);
				env.Connect(token, AuthenticationTokenType.UserToken, uri, liao);
			}
			catch (WebException e)
			{
				Credentials = null;
				if (e.Message.Contains("404"))
					Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, "Maybe account not redeemed.", "https://lx.azure.microsoft.com/Cloud/Launch/Redeem.aspx?Token=FFFFF-FFFFF-FFFFF-FFFFF-FFFFF");
					//syncEngine.CancelSync("Maybe account not redeemed.", "", "https://lx.azure.microsoft.com/Cloud/Launch/Redeem.aspx?Token=FFFFF-FFFFF-FFFFF-FFFFF-FFFFF");
				else
					Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, e.Message, null);
					//syncEngine.CancelSync(e.Message);
				this.FetchSem.Release();
				return;
			}
			catch (Exception e)
			{
				Credentials = null;
				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, e.Message, null);
				this.FetchSem.Release();
				return;
			}

			env.Contacts.LoadAsync(new object());
			liveContacts = env.Contacts;

			//var MeshProjects = (from mo in env.Contacts.Entries
			//                    group mo by mo.LiveOperatingEnvironment.BaseUri into result
			//                    select new LinqRes { Count = result.Count() });
			//syncEngine.CurrentTotal += MeshProjects.First<LinqRes>().Count;// .3;

			foreach (Microsoft.LiveFX.Client.Contact live in liveContacts.Entries)
			{
				//live.LoadAsync(new object());
				syncEngine.CurrentTotal++;
			}

			foreach (Microsoft.LiveFX.Client.Contact live in liveContacts.Entries)
			{
				if (owner != null)
				{
					syncEngine.CurrentItemNum++;
					Dispatcher.Invoke(new SyncProgressEventHandler(owner.Progress), this,
						"Loading " + "(" + syncEngine.CurrentItemNum + "/" + syncEngine.CurrentTotal + ")",
						syncEngine.CurrentItemNum, syncEngine.CurrentTotal);
				}

				Microsoft.Communications.Contacts.Contact contact = GetCanonicalContact(live);

				if (contact != null && contact.FullName != null && contact.FullName.Trim() != "")
				{
					if (!contactsByFullName.ContainsKey(contact.FullName))
					{
						contactsByFullName[contact.FullName] = contact;
						liveContactByFullname[contact.FullName] = live;
						mans.Add(new Man { FullName = contact.FullName, EMail = contact.EMail, Phone = contact.Phone });
					}
				}

			}

			this.FetchSem.Release();
		}