private void LoginProjectServer()
{
Log.WriteVerbose(new SourceInfo(), "Logging into project server on url:{0}", TB_Url.Text);
ProjContext = new ProjectContext(TB_Url.Text);
Log.WriteVerbose(new SourceInfo(), "Authenticating against {0} pwa instance", CB_Online.Checked ? "Online" : "OnPerm");
if (CB_Online.Checked && RB_Forms.Checked)
{
//case online with user credential
SecureString secpassword = new SecureString();
foreach (char c in TB_Password.Text)
{
secpassword.AppendChar(c);
}
ProjContext.Credentials = new SharePointOnlineCredentials(TB_UserName.Text, secpassword);
}
else if (!CB_Online.Checked && RB_Forms.Checked)
{
//case onprem with user credential
ProjContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo(TB_UserName.Text, TB_Password.Text);
ProjContext.FormsAuthenticationLoginInfo = formsAuthInfo;
}
else
{
//Default case - Windows Auth
ProjContext.Credentials = CredentialCache.DefaultCredentials;
}
CsomHelper.ProjContext = ProjContext;
CsomBase.CurrentResource = CsomHelper.LoadMe();
CsomBase.CurrentUser = CsomBase.CurrentResource.User;
if (_bge.TaskCancelled || _bge.ActionTask.IsFaulted)
{
return;
}
Log.WriteVerbose(new SourceInfo(), "Login on url:{0} for user:{1}", TB_Url.Text, CsomBase.CurrentUser.Title);
DialogResult = DialogResult.OK;
}