Beispiel #1
0
        //Get Resource from Resource GUID
        private string GetWindowsAccountByResGUID(string ls_guid, Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, string url)
        {
            try
            {
                Guid   trackingGuid = Guid.NewGuid();
                string lcid         = "1033";

                ResourceDerived.SetImpersonationContext(true, contextInfo.UserName, contextInfo.UserGuid, trackingGuid, contextInfo.SiteGuid, lcid);
                ResourceDerived Resource = new ResourceDerived();
                Resource.Url = url + "/_vti_bin/psi/resource.asmx";

                //WebSvcResource.Resource Resource = new WebSvcResource.Resource();
                WebSvcResource.ResourceDataSet lo_resDS = new WebSvcResource.ResourceDataSet();
                //Resource.Credentials = System.Net.CredentialCache.DefaultCredentials;

                string nameColumn = lo_resDS.Resources.RES_UIDColumn.ColumnName;

                string resAccount = lo_resDS.Resources.WRES_ACCOUNTColumn.ColumnName;

                PSLibrary.Filter.FieldOperationType equal = PSLibrary.Filter.FieldOperationType.Equal;
                PSLibrary.Filter lo_filter = new PSLibrary.Filter();

                lo_filter.FilterTableName = lo_resDS.Resources.TableName;
                lo_filter.Fields.Add(new PSLibrary.Filter.Field(resAccount));
                lo_filter.Criteria = new PSLibrary.Filter.FieldOperator(equal, nameColumn, ls_guid);
                lo_resDS           = Resource.ReadResources(lo_filter.GetXml(), false);
                return((string)lo_resDS.Tables[lo_resDS.Resources.TableName].Rows[0][1]);
            }
            catch (Exception ex)
            {
                string logEntry = "Error: " + ex.Message + ex.StackTrace;
                ErrorTrap(3010, logEntry);
                return("");
            }
        }
        public Guid GetResourceUidFromNtAccount(String ntAccount)
        {
            //ntAccount = "i:0#.w|" + ntAccount;  //this is an inconsequential change
            ntAccount = ntAccount.Trim('\"');

            string ntAccountCopy = ntAccount;

            SvcResource.ResourceDataSet rds = new SvcResource.ResourceDataSet();

            Microsoft.Office.Project.Server.Library.Filter filter = new Microsoft.Office.Project.Server.Library.Filter();
            filter.FilterTableName = rds.Resources.TableName;

            Microsoft.Office.Project.Server.Library.Filter.Field ntAccountField1 = new Microsoft.Office.Project.Server.Library.Filter.Field(rds.Resources.TableName, rds.Resources.WRES_ACCOUNTColumn.ColumnName);
            filter.Fields.Add(ntAccountField1);

            Microsoft.Office.Project.Server.Library.Filter.Field ntAccountField2 = new Microsoft.Office.Project.Server.Library.Filter.Field(rds.Resources.TableName, rds.Resources.RES_IS_WINDOWS_USERColumn.ColumnName);
            filter.Fields.Add(ntAccountField2);

            Microsoft.Office.Project.Server.Library.Filter.FieldOperator op = new Microsoft.Office.Project.Server.Library.Filter.FieldOperator(Microsoft.Office.Project.Server.Library.Filter.FieldOperationType.Equal,
                rds.Resources.WRES_ACCOUNTColumn.ColumnName, ntAccountCopy);
            filter.Criteria = op;

            rds = resourceClient.ReadResources(filter.GetXml(), false);

            var obj = (Guid)rds.Resources.Rows[0]["RES_UID"];
            return obj;
        }
Beispiel #3
0
        private int getResourceIdByEmail(string email)
        {
            try
            {
                PSLibrary.Filter cfFilter = new PSLibrary.Filter();
                cfFilter.FilterTableName = "Resources";
                cfFilter.Fields.Add(new PSLibrary.Filter.Field("WRES_ACCOUNT"));
                cfFilter.Fields.Add(new PSLibrary.Filter.Field("RES_IS_WINDOWS_USER"));
                cfFilter.Fields.Add(new PSLibrary.Filter.Field("RES_UID"));
                cfFilter.Criteria = new PSLibrary.Filter.FieldOperator(PSLibrary.Filter.FieldOperationType.Equal, "WRES_EMAIL", email);

                WebSvcResource.ResourceDataSet rDs = new WebSvcResource.ResourceDataSet();

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    rDs = psiResource.ReadResources(cfFilter.GetXml(), false);
                });

                if (rDs.Resources.Count > 0)
                {
                    if (rDs.Resources[0].RES_IS_WINDOWS_USER)
                    {
                        return(getResourceWssId(rDs.Resources[0].RES_UID));
                    }
                }
            }
            catch (Exception ex)
            {
                myLog.WriteEntry("Error in getResourceIdByEmail(): " + ex.Message + ex.StackTrace, EventLogEntryType.Error, 330);
            }
            return(0);
        }
        public static Guid GetResourceGuidByWindowsAccount(string ls_name)
        {
            string errLoc = "";

            try
            {
                WebSvcResource.Resource        res      = new WebSvcResource.Resource();
                WebSvcResource.ResourceDataSet lo_resDS = new WebSvcResource.ResourceDataSet();
                res.Credentials = System.Net.CredentialCache.DefaultCredentials;

                string nameColumn = lo_resDS.Resources.WRES_ACCOUNTColumn.ColumnName;

                string resUID = lo_resDS.Resources.RES_UIDColumn.ColumnName;

                PSLibrary.Filter.FieldOperationType equal = PSLibrary.Filter.FieldOperationType.Equal;
                PSLibrary.Filter lo_filter = new PSLibrary.Filter();

                lo_filter.FilterTableName = lo_resDS.Resources.TableName;
                lo_filter.Fields.Add(new PSLibrary.Filter.Field(resUID));
                lo_filter.Criteria = new PSLibrary.Filter.FieldOperator(equal, nameColumn, ls_name);
                errLoc             = "ReadResources()";
                lo_resDS           = res.ReadResources(lo_filter.GetXml(), false);
                errLoc             = "Returning Guid";
                return((Guid)lo_resDS.Tables[lo_resDS.Resources.TableName].Rows[0][0]);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());

                using (var myLog = new EventLog("EPM Live", ".", "EPM Live Helper"))
                {
                    myLog.WriteEntry($"Error at GetResourceGuidByWindowsAccount: {ex.Message}{ex.StackTrace}", EventLogEntryType.Error, 401);
                    return(new Guid());
                }
            }
        }
Beispiel #5
0
        public static Guid GetResourceUidFromNtAccount(String ntAccount, out bool isWindowsUser)
        {
            SvcResource.ResourceDataSet rds = new SvcResource.ResourceDataSet();

            Microsoft.Office.Project.Server.Library.Filter filter = new Microsoft.Office.Project.Server.Library.Filter();
            filter.FilterTableName = rds.Resources.TableName;

            Microsoft.Office.Project.Server.Library.Filter.Field ntAccountField1 = new Microsoft.Office.Project.Server.Library.Filter.Field(rds.Resources.TableName, rds.Resources.WRES_ACCOUNTColumn.ColumnName);
            filter.Fields.Add(ntAccountField1);

            Microsoft.Office.Project.Server.Library.Filter.Field ntAccountField2 = new Microsoft.Office.Project.Server.Library.Filter.Field(rds.Resources.TableName, rds.Resources.RES_IS_WINDOWS_USERColumn.ColumnName);
            filter.Fields.Add(ntAccountField2);

            Microsoft.Office.Project.Server.Library.Filter.FieldOperator op = new Microsoft.Office.Project.Server.Library.Filter.FieldOperator(Microsoft.Office.Project.Server.Library.Filter.FieldOperationType.Equal,
                rds.Resources.WRES_ACCOUNTColumn.ColumnName, ntAccount);
            filter.Criteria = op;

            rds = resourceClient.ReadResources(filter.GetXml(), false);

            isWindowsUser = rds.Resources[0].RES_IS_WINDOWS_USER;

            var obj = (Guid)rds.Resources.Rows[0]["RES_UID"];
            return obj;
        }
Beispiel #6
0
        // Get the GUID for a Project Server account name.
        public static Guid GetResourceUid(String accountName)
        {
            Guid resourceUid = Guid.Empty;
            ResourceDataSet resourceDs = new ResourceDataSet();

            // Filter for the account name, which can be a
            // Windows account or Project Server account.
            PSLib.Filter filter = new PSLib.Filter();
            filter.FilterTableName = resourceDs.Resources.TableName;

            PSLib.Filter.Field accountField = new PSLib.Filter.Field(
                    resourceDs.Resources.TableName,
                    resourceDs.Resources.WRES_ACCOUNTColumn.ColumnName);
            filter.Fields.Add(accountField);

            PSLib.Filter.FieldOperator op = new PSLib.Filter.FieldOperator(
                    PSLib.Filter.FieldOperationType.Equal,
                    resourceDs.Resources.WRES_ACCOUNTColumn.ColumnName, accountName);
            filter.Criteria = op;

            string filterXml = filter.GetXml();

            resourceDs = resourceClient.ReadResources(filterXml, false);

            // Return the account GUID.
            if (resourceDs.Resources.Rows.Count > 0)
                resourceUid = (Guid)resourceDs.Resources.Rows[0]["RES_UID"];

            return resourceUid;
        }