//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(""); } }
private int getResourceWssId(Guid RES_GUID) { try { WebSvcResource.ResourceDataSet rDs = new WebSvcResource.ResourceDataSet(); SPSecurity.RunWithElevatedPrivileges(delegate() { rDs = psiResource.ReadResource(RES_GUID); }); if (rDs.Resources.Count > 0) { if (rDs.Resources[0].RES_IS_WINDOWS_USER) { string username = rDs.Resources[0].WRES_ACCOUNT; try { return(myWebToPublish.AllUsers[username].ID); } catch { return(0); } } } } catch (Exception ex) { myLog.WriteEntry("Error in getResourceWssId(): " + ex.Message + ex.StackTrace, EventLogEntryType.Error, 330); } return(0); }
private string getResourceUsername(string url, Guid RES_GUID) { try { WebSvcResource.Resource pResource = new WebSvcResource.Resource(); pResource.Url = url + "/_vti_bin/psi/resource.asmx"; pResource.UseDefaultCredentials = true; WebSvcResource.ResourceDataSet rDs = new WebSvcResource.ResourceDataSet(); SPSecurity.RunWithElevatedPrivileges(delegate() { rDs = pResource.ReadResource(RES_GUID); }); if (rDs.Resources.Count > 0) { if (rDs.Resources[0].RES_IS_WINDOWS_USER) { return(rDs.Resources[0].WRES_ACCOUNT); } } } catch (Exception ex) { string logEntry = "Error: " + ex.Message; ErrorTrap(3003, logEntry); } return(""); }
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); }
private void doDeleteResource(SPSite site, SPWeb web, Guid resGuid) { WebSvcResource.ResourceDataSet rds = pResource.ReadResource(resGuid); string resUrl = EPMLiveCore.CoreFunctions.getConfigSetting(web, "EPMLiveResourceURL", true, false); if (resUrl != "") { using (SPSite tempSite = new SPSite(resUrl)) { using (SPWeb resWeb = tempSite.OpenWeb()) { try { SPUser user = resWeb.SiteUsers[rds.Resources[0].WRES_ACCOUNT]; SPList list = resWeb.Lists["Resources"]; SPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name='SharePointAccount'/><Value Type='User'>" + user.Name + "</Value></Eq></Where>"; SPListItemCollection lic = list.GetItems(query); SPListItem li = null; if (lic.Count > 0) { lic[0].Delete(); } } catch { } } } } }
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()); } } }
public void synchAllResources() { SPSecurity.RunWithElevatedPrivileges(delegate() { WebSvcResource.ResourceDataSet ds = pResource.ReadUserList(EPMLiveEnterprise.WebSvcResource.ResourceActiveFilter.All); using (SPSite site = new SPSite(siteGuid)) { using (SPWeb web = site.RootWeb) { string resUrl = EPMLiveCore.CoreFunctions.getConfigSetting(web, "EPMLiveResourceURL", true, false); if (resUrl != "") { using (SPSite tempSite = new SPSite(resUrl)) { using (SPWeb resWeb = tempSite.OpenWeb()) { resWeb.AllowUnsafeUpdates = true; foreach (WebSvcResource.ResourceDataSet.ResourcesRow row in ds.Resources) { processResource(web, row.RES_UID, resWeb); } } } } } } SqlCommand cmd = new SqlCommand("select config_value from econfig where config_name='ConnectedURLs'", cn); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { string sSites = dr.GetString(0); string[] strSites = sSites.Replace("\r\n", "\n").Split('\n'); foreach (string strSite in strSites) { try { using (SPSite site = new SPSite(strSite)) { using (SPWeb web = site.OpenWeb()) { string resUrl = EPMLiveCore.CoreFunctions.getConfigSetting(web, "EPMLiveResourceURL", true, false); if (resUrl != "") { using (SPSite tempSite = new SPSite(resUrl)) { using (SPWeb resWeb = tempSite.OpenWeb()) { resWeb.AllowUnsafeUpdates = true; foreach (WebSvcResource.ResourceDataSet.ResourcesRow row in ds.Resources) { processResource(web, row.RES_UID, resWeb); } } } } } } } catch { } } } dr.Close(); }); }
public void processResource(SPWeb web, Guid resGuid, SPWeb resWeb) { WebSvcResource.ResourceDataSet rds = pResource.ReadResource(resGuid); try { SPUser user = null; SPGroup group = null; if (!rds.Resources[0].IsWRES_ACCOUNTNull()) { try { user = resWeb.SiteUsers[rds.Resources[0].WRES_ACCOUNT]; } catch { } if (user == null) { string email = ""; if (!rds.Resources[0].IsWRES_EMAILNull()) { email = rds.Resources[0].WRES_EMAIL; } resWeb.SiteUsers.Add(rds.Resources[0].WRES_ACCOUNT, email, rds.Resources[0].RES_NAME, ""); user = resWeb.SiteUsers[rds.Resources[0].WRES_ACCOUNT]; } } else { try { group = resWeb.SiteGroups[rds.Resources[0].RES_NAME]; } catch { } } SPList list = resWeb.Lists["Resources"]; if (!list.Fields.ContainsField("ResUid")) { SPFieldText fldResUid = (SPFieldText)list.Fields.CreateNewField(SPFieldType.Text.ToString(), "ResUid"); fldResUid.Hidden = true; fldResUid.Required = false; list.Fields.Add(fldResUid); list.Update(); } DataRow [] drFields = rds.ResourceCustomFields.Select("RES_UID='" + rds.Resources[0].RES_UID + "'"); foreach (DataRow drField in drFields) { try { string fname = "ENT" + drField["MD_PROP_ID"]; if (!list.Fields.ContainsField(fname)) { addField(list, drField["MD_PROP_ID"].ToString(), drField["FIELD_TYPE_ENUM"].ToString()); } } catch { } } SPQuery query = new SPQuery(); if (user != null) { query.Query = "<Where><Eq><FieldRef Name='SharePointAccount'/><Value Type='User'>" + user.Name + "</Value></Eq></Where>"; } else if (group != null) { query.Query = "<Where><Eq><FieldRef Name='SharePointAccount'/><Value Type='User'>" + group.Name + "</Value></Eq></Where>"; } else { query.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + rds.Resources[0].RES_NAME + "</Value></Eq></Where>"; } SPListItemCollection lic = list.GetItems(query); SPListItem li = null; if (lic.Count > 0) { li = lic[0]; } else { li = list.Items.Add(); } if (user != null) { li["SharePointAccount"] = new SPFieldUserValue(resWeb, user.ID, user.Name); } if (group != null) { li["SharePointAccount"] = new SPFieldUserValue(resWeb, group.ID, group.Name); } li["ResUid"] = resGuid.ToString(); if (li != null) { string name = rds.Resources[0].RES_NAME; string firstname = ""; try { firstname = name.Split(' ')[0]; } catch { } string lastname = ""; try { lastname = name.Substring(firstname.Length + 1); } catch { } li["Title"] = rds.Resources[0].RES_NAME; li["FirstName"] = firstname; li["LastName"] = lastname; if (!rds.Resources[0].IsWRES_EMAILNull()) { li["Email"] = rds.Resources[0].WRES_EMAIL; } if (!rds.Resources[0].IsRES_TIMESHEET_MGR_UIDNull()) { if (rds.Resources[0].RES_TIMESHEET_MGR_UID != rds.Resources[0].RES_UID) { WebSvcResource.ResourceDataSet tsRds = pResource.ReadResource(rds.Resources[0].RES_TIMESHEET_MGR_UID); if (tsRds.Resources.Count > 0) { try { SPUser tuser = null; try { tuser = resWeb.SiteUsers[tsRds.Resources[0].WRES_ACCOUNT]; } catch { } if (tuser == null) { resWeb.SiteUsers.Add(tsRds.Resources[0].WRES_ACCOUNT, tsRds.Resources[0].WRES_EMAIL, tsRds.Resources[0].RES_NAME, ""); tuser = resWeb.SiteUsers[tsRds.Resources[0].WRES_ACCOUNT]; } li["TimesheetManager"] = new SPFieldUserValue(resWeb, tuser.ID, tuser.Name); } catch { } } } } foreach (DataRow drField in drFields) { try { string fname = "ENT" + drField["MD_PROP_ID"]; if (list.Fields.ContainsField(fname)) { string fVal = getfieldvalue(drField); li[list.Fields.GetFieldByInternalName("ENT" + drField["MD_PROP_ID"]).Id] = fVal; } } catch { } } li.SystemUpdate(); } } catch { } }