public bool ProcessTimesheet(Guid siteGuid, Guid tsGuid, string lcid, string userName, bool submitStatus, string sspName)
{
#region Local Variables
string exceptionMsg = null;
string tsInfo = string.Empty;
Stopwatch timeToProcessAll = new Stopwatch();
Stopwatch timeToProcessStatus = new Stopwatch();
timeToProcessAll.Start();
//SPSite spSite = new SPSite("http://win-9dubqmslff7/pwa/");
bool result = false;
#endregion try
{
if (appLog == null) appLog = new AppLog(LoggingPrefix, LoggingFolder, LogFileEveryHour); #region STEP 1 - Initialize Web Service urls statusing.Url = "http://win-9dubqmslff7/PWA/_vti_bin/psi/statusing.asmx";//WSUrl( HostName, sspName, "statusing", true);
resource.Url = WSUrl(HostName, sspName, "resource", false);
timesheet.Url = WSUrl(HostName, sspName, "timesheet", false); if (logEvents)
appLog.WriteLine(string.Format("STEP 1 - Initialize Web Service urls")); #endregion #region STEP 2 - Retrieve Timesheet DataSet TimesheetWS.TimesheetDataSet timesheetDS = timesheet.ReadTimesheet(tsGuid);
TimesheetPSI tsHeader = new TimesheetPSI(timesheetDS);
Guid tspUID = tsHeader.PeriodUID;
Guid tresUID = tsHeader.ResUID; if (logEvents)
{
appLog.WriteLine(string.Format("STEP 2 - Start event override for timesheet UID: {0}", tsGuid.ToString()));
tsInfo = string.Format("Timesheet: {0}; Resource: {1}; Creator: {2}, Period: {3}",
tsHeader.Name, tsHeader.ResName, tsHeader.CreatorResName, tspUID.ToString());
}
#endregion ResourceWS.ResourceDataSet resourceDS = resource.ReadResource(tresUID);
ResourcePSI resourcePSI = new ResourcePSI(resourceDS); bool isWindowsUser = userName.StartsWith("AspNetSqlMembershipProvider") ? false : true;
statusing.SetImpersonationContext(isWindowsUser, userName, tresUID, Guid.Empty, siteGuid, lcid);
timesheet.SetImpersonationContext(isWindowsUser, userName, tresUID, Guid.Empty, siteGuid, lcid); if (logEvents) appLog.WriteLine(string.Format("STEP 3 - Statusing Impersonation for RES_UID: {0}", tresUID.ToString())); #endregion TimesheetWS.TimesheetDataSet timeSheetDs = new TimesheetWS.TimesheetDataSet();
TimesheetWS.TimesheetDataSet.HeadersRow headersRow = timeSheetDs.Headers.NewHeadersRow();
headersRow.RES_UID = new Guid("97B3EBBF-871B-4ED6-B366-5EFE59B68F4A");
headersRow.TS_UID = Guid.NewGuid();
headersRow.WPRD_UID = new Guid("EE8C2B3E-556B-4FAC-9CE1-537A51B4CCF6");
headersRow.TS_CREATOR_RES_UID = new Guid("97B3EBBF-871B-4ED6-B366-5EFE59B68F4A");
headersRow.TS_NAME = "我的时间表";
headersRow.TS_COMMENTS = "Create By PSI";
headersRow.TS_ENTRY_MODE_ENUM = (byte)PSLibrary.TimesheetEnum.EntryMode.Weekly;
timeSheetDs.Headers.AddHeadersRow(headersRow); timesheet.CreateTimesheet(timeSheetDs, TimesheetWS.PreloadType.Default); } using System;
using System.Collections.Generic;
using System.Net;
using System.Text; // Project Server 2007 References
using Microsoft.Office.Project.Server.Library; namespace Microsoft.EPM.TSAutoStatus
{
/// <summary>
/// Timesheet Helper Methods
/// </summary>
class TimesheetPSI
{
#region Properties private string name;
private string resName;
private string creatorResName;
private Guid creatorResUID;
private Guid resUID;
private Guid periodUID;
private decimal totalActValue;
/// <summary>
/// Timesheet Name
/// </summary>
public string Name
{
get { return name; }
}
/// <summary>
/// Resource Name
/// </summary>
public string ResName
{
get { return resName; }
}
/// <summary>
/// Timesheet creator resource name
/// </summary>
public string CreatorResName
{
get { return creatorResName; }
}
/// <summary>
/// Timesheet creator resource UID
/// </summary>
public Guid CreatorResUID
{
get { return creatorResUID; }
}
/// <summary>
/// Resource UID
/// </summary>
public Guid ResUID
{
get { return resUID; }
}
/// <summary>
/// Period UID
/// </summary>
public Guid PeriodUID
{
get { return periodUID; }
}
/// <summary>
/// Total actual value in hours
/// </summary>
public decimal TotalActValue
{
get { return totalActValue; }
}
#endregion #region Constructor /// <summary>
/// Timesheet header information
/// </summary>
/// <param name="timesheetDS">Timesheet DataSet</param>
public TimesheetPSI(TimesheetWS.TimesheetDataSet timesheetDS)
{
name = timesheetDS.Headers[0].TS_NAME;
resName = timesheetDS.Headers[0].TS_CACHED_RES_NAME;
creatorResName = timesheetDS.Headers[0].TS_CACHED_CREATOR_RES_NAME;
creatorResUID = timesheetDS.Headers[0].TS_CREATOR_RES_UID != Guid.Empty ? timesheetDS.Headers[0].TS_CREATOR_RES_UID : Guid.NewGuid();
resUID = timesheetDS.Headers[0].RES_UID != Guid.Empty ? timesheetDS.Headers[0].RES_UID : Guid.NewGuid();
periodUID = timesheetDS.Headers[0].WPRD_UID != Guid.Empty ? timesheetDS.Headers[0].WPRD_UID : Guid.NewGuid();
totalActValue = timesheetDS.Headers[0].TS_TOTAL_ACT_VALUE/60000;
} #endregion
} /// <summary>
/// Perform WS impersonation
/// </summary>
class TimesheetDerived : TimesheetWS.TimeSheet
{
private String contextString = String.Empty; protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest webRequest = base.GetWebRequest(uri);
if (contextString != String.Empty)
{
webRequest.UseDefaultCredentials = true;
webRequest.Credentials = CredentialCache.DefaultCredentials;
webRequest.Headers.Add("PjAuth", contextString);
webRequest.Headers.Add("ForwardFrom", "/_vti_bin/psi/timesheet.asmx");
webRequest.PreAuthenticate = true;
}
return webRequest;
} public void SetImpersonationContext(bool isWindowsUser, String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
{
contextString = GetImpersonationContext(isWindowsUser, userNTAccount, userGuid, trackingGuid, siteId, lcid);
} private String GetImpersonationContext(bool isWindowsUser, String userNTAccount, Guid userGuid, Guid trackingGuid, Guid siteId, String lcid)
{
PSContextInfo contextInfo = new PSContextInfo(isWindowsUser, userNTAccount, userGuid, trackingGuid, siteId, lcid);
return PSContextInfo.SerializeToString(contextInfo);
}
}
}

  调用的时候:

UpdateStatus update = new UpdateStatus("http://win-9dubqmslff7/pwa");
Guid siteGuid = new Guid("4E925E19-93AC-4275-9FD6-336D7E874377");
Guid tsGuid = new Guid("C06F9A45-F19F-404A-A1D6-DF3ACDBA05BE");
string lcid = "1033";
string userName = @"HN\xxxx";
bool submitStatus = true;
string sspName = "pwa";
update.ProcessTimesheet( siteGuid, tsGuid, lcid, userName, submitStatus, sspName);

  这里详细介绍下参数:

siteGuid就是我们网站集的GUID,一般指PWA的网站集

tsGuid就是我们的时间表的GUID,这里我们创建时间表的时候无需用到,如果是读取时间表的数据,在[ProjectServer_Published].[dbo].[MSP_TIMESHEETS]下的TS_UID字段

lcid指中英文版本,中文1033

userName指被模拟的账户,如果我想模拟X账户,只需填写X的用户名即可

headersRow.RES_UID = new Guid("97B3EBBF-871B-4ED6-B366-5EFE59B68F4A");指的是被模拟账户的RESOURCE GUID

headersRow.TS_CREATOR_RES_UID = new Guid("97B3EBBF-871B-4ED6-B366-5EFE59B68F4A");指的是创建时间表用户的RESOURCE GUID,一般指本人

headersRow.WPRD_UID = new Guid("EE8C2B3E-556B-4FAC-9CE1-537A51B4CCF6");指的是时间表的日期GUID,从[ProjectServer_Reporting].[dbo].[MSP_TimesheetPeriod]表里面查找,找到指定日期的GUID即可。

同理,根据模拟账户还可以做很多事情,比如有些用户保存了时间表的工时,但是忘记提交,系统可以自动模拟用户将未提交的工时提交上去。

ProjectServer如何让系统管理员模拟普通用户创建自己的时间表的更多相关文章

  1. 使用 Web API 模拟其他用户

    模拟的要求 模拟可代表另一个 Microsoft Dynamics CRM 用户,用于执行业务逻辑(代码)以便提供所需功能或服务,它使用模拟用户的相应角色和基于对象的安全性.这项技术很有必要,因为 M ...

  2. linux 用户创建、管理、权限分配

    (1)su与sudo su:通过su可以在用户之间切换,如果超级权限用户root向普通或虚拟用户切换不需要密码,什么是权力?这就是!而普通用户切换到其它任何用户都需要密码验证: sudo: sudo扮 ...

  3. oracle用户创建及权限设置及表空间

    建立表空间: create tablespace portx_data datafile 'D:\oracle_data\portx.dbf' size 50m autoextend on next ...

  4. oracle用户创建及权限设置

    权限: create session create table unlimited tablespace connect resource dba 例: #sqlplus /nolog SQL> ...

  5. [转载]Oracle用户创建及权限设置

    出处:https://www.cnblogs.com/buxingzhelyd/p/7865194.html 权限: create session  允许用户登录数据库权限 create table  ...

  6. 写了一个Windows服务,通过C#模拟网站用户登录并爬取BUG列表查询有没有新的BUG,并提醒我

    写了一个Windows服务,通过C#模拟网站用户登录并爬取BUG列表查询有没有新的BUG,并提醒我 1.HttpUtil工具类,用于模拟用户登录以及爬取网页: using System; using ...

  7. 转载:oracle用户创建及权限设置

    权限: create session create table unlimited tablespace connect resource dba 例: #sqlplus /nolog SQL> ...

  8. oracle用户创建及权限设置(转)

    权限: create session create table unlimited tablespace connect resource dba 例: #sqlplus /nolog SQL> ...

  9. MYSQL添加新用户 MYSQL为用户创建数据库 MYSQL为新用户分配权限

    1.新建用户 //登录MYSQL @>mysql -u root -p @>密码 //创建用户 mysql> insert into mysql.user(Host,User,Pas ...

随机推荐

  1. 从XCodeGhost事件看软件来源鉴别的重要性

    事件 事件引爆于9月18日乌云网公布的一则分析报告:"XCode编译器里有鬼 – XCodeGhost样本分析",这份纯粹的技术分析报告引发中国iOS生态链的众多开发者的关注. 引 ...

  2. SpringBoot | 第三十三章:Spring web Servcies集成和使用

    前言 最近有个单位内网系统需要对接统一门户,进行单点登录和待办事项对接功能.一般上政府系统都会要求做统一登录功能,这个没啥问题,反正业务系统都是做单点登录的,改下shiro相关类就好了.看了接入方案, ...

  3. [转] 微信小程序 页面跳转 传递参数

    本文转自:http://blog.csdn.net/qq_31383345/article/details/52795212 微信小程序的页面跳转,页面之间传递参数笔记. CSDN微信小程序开发专栏, ...

  4. 上下文(Context)和作用域(Scope)

    函数的每次调用都有与之紧密相关的作用域和上下文.从根本上来说,作用域是基于函数的,而上下文是基于对象的. 换句话说,作用域涉及到所被调用函数中的变量访问,并且不同的调用场景是不一样的.上下文始终是th ...

  5. sql 行列转换

    create table #test1(id int,name varchar(20), Q1 int, Q2 int, Q3 int, Q4 int) insert into #test1 valu ...

  6. 基于RBAC模式的权限管理系统设计概要

    很多人都知道以角色为基础的权限管理设计(RBAC),但是大部分人似懂非懂,不知道完整的权限管理系统都包括哪些内容.  在此以权限管理的使用场景来说明一下完整的权限管理内容.     一是鉴权管理,即权 ...

  7. Csharp: Detect Mobile Browsers

    /// <summary> /// 檢測手機客戶端 HttpCapabilitiesBase.IsMobileDevice /// .NET 4.5 /// 塗聚文注 /// </s ...

  8. Flask插件---flask_script与flask_migrate

    import app from flask_script import Manager from flask_migrate import Migrate,MigrateCommand my_app ...

  9. Linux漏洞分析入门笔记-CVE-2015-0235

    Ubuntu 12.04 32位 ida 7.0 0x00:漏洞描述 1.glibc的__nss_hostname_digits_dots存在缓冲区溢出漏洞,导致使用gethostbyname系列函数 ...

  10. ANR android

    1.android ANR产生原因和解决办法 2.Android ANR异常及解决方法 3.Android ANR 分析解决方法 4.[原创]Android 系统稳定性 - ANR(一) 5.[原创] ...