ProjToolV2.CsomHelper.LoadMe C# (CSharp) Method

LoadMe() public static method

public static LoadMe ( ) : EnterpriseResource
return EnterpriseResource
        public static EnterpriseResource LoadMe()
        {
            string currentUserName = UserPrincipal.Current.DisplayName;
            Log.WriteVerbose(new SourceInfo(), "Loading current user:[{0}] info.", currentUserName);
            User user = ProjContext.Web.CurrentUser;
            IEnumerable<EnterpriseResource> resources =
                ProjContext.LoadQuery(ProjContext.EnterpriseResources.Where(r => r.Name == user.Title).IncludeWithDefaultProperties(r => r.User));
            ProjContext.ExecuteQuery();
            return resources.FirstOrDefault();
        }

Usage Example

コード例 #1
0
        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;
        }