Example #1
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());
                }
            }
        }