码迷,mamicode.com
首页 > Web开发 > 详细

Project Web Server PSI 常用接口一些操作

时间:2015-11-14 13:41:09      阅读:782      评论:0      收藏:0      [点我收藏+]

标签:

对Project Web Server进行二次,每天都把自己折腾到12点以后才休息,到处都是坑,研究那些烦人的PSI,国内根本查不到PSI相关的资料,对照API文档一点点谷歌资料,全部英文资料,开发终于完成了,总结了个人一些PSI使用心得

  1. 尽量能不用PSI就别用,涉及到查询数据直接用SQL查询数据库,调用PSI速度太慢,不稳定,还有烦人的权限问题,不同人对PSI接口权限不一样,有时候会出现一些权限错误
  2. 只要涉及到修改数据和添加数据就还是要用PSI的接口,因为Project Web Server2010有四个数据库,调用PSI会自己把数据同步到其它数据库最主要还是报表数据库,最重要是需要注意调用PSI对数据量有一定限制,这是用血换来的经验呀!在测试机机测试了无数次都是没有任何问题,一部署到正式环境就出问题,找原因都几个熬了几个通宵,接口是修改项目下面所有的计划一个属性值,当项目达到了500条以上数据,就出现PSI接口错误。
  3. 这点需要注意每个用户对PSI不同接口具有不同权限,这也是血的教训,测试机就那么几个用户来回测试都没有发现什么问题,一部署到正式服务器,有的用户操作出现错误,有的用户又没有问题,无法定位问题原因,通过增加日志功能才发现这个错误,出现多次上线失败,没办法才增加日志功能,也被客户骂了N次。
  4. 这点需要注意调用PSI会走队列,队列有延时,当调用PSI创建数据后又马上去查询该数据就会查询不到数据出现错误,这点取决于数据量大小和网络稳定。
  5. 实在国内资料太少,所以我把自己知道的资料写到博客中,让有需要的人少走弯路,欢迎大家给我提相关问题,我的QQ307334732。

PSI调用代码如下:

ServiceBase类

  1 using HIGHFARINFO.ZTJC.LookupTableWebSvc;
  2 using System;
  3 using System.Collections.Generic;
  4 using System.Linq;
  5 using System.Text;
  6 using HIGHFARINFO.ZTJC.CustomFieldsWebSvc;
  7 using HIGHFARINFO.ZTJC.TimeSheetWebSvc;
  8 using HIGHFARINFO.ZTJC.AdminWebSvc;
  9 using HIGHFARINFO.ZTJC.ResourceWebSvc;
 10 using HIGHFARINFO.ZTJC.ProjectWebSvc;
 11 using HIGHFARINFO.ZTJC.QueueSystemWebSvc;
 12 using HIGHFARINFO.ZTJC.LoginWindowsWebSvc;
 13 using System.Net;
 14 using HIGHFARINFO.ZTJC.StatusingWebSvc;
 15 using HIGHFARINFO.ZTJC.Common;
 16 
 17 namespace HIGHFARINFO.ZTJC.ServiceHelper
 18 {
 19     public class ServiceBase
 20     {
 21         private LookupTable _LookupTableSvc = null;
 22         private CustomFields _CustomFieldsSvc = null;
 23         private TimeSheet _TimeSheetSvc = null;
 24         private Admin _AdminSvc = null;
 25         private Resource _ResourceSvc = null;
 26         private Project _ProjectSvc = null;
 27         private QueueSystem _QueueSystemSvc = null;
 28         private LoginWindows _LoginWindowsSvc = null;
 29         private Statusing _StatusingClient = null;
 30 
 31         public ServiceBase()
 32         {
 33 
 34         }
 35 
 36         protected LookupTable LookupTableSvc
 37         {
 38             get
 39             {
 40                 if (_LookupTableSvc == null)
 41                 {
 42                     _LookupTableSvc = new LookupTable();
 43                     _LookupTableSvc.Url = ServiceUrl.LookupTableUrl;
 44                     _LookupTableSvc.UseDefaultCredentials = true;
 45                     //_LookupTableSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
 46                     //_LookupTableSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
 47                 }
 48                 return _LookupTableSvc;
 49             }
 50         }
 51 
 52         protected CustomFields CustomFieldsSvc
 53         {
 54             get
 55             {
 56                 if (_CustomFieldsSvc == null)
 57                 {
 58                     _CustomFieldsSvc = new CustomFields();
 59                     _CustomFieldsSvc.Url = ServiceUrl.CustomFieldsUrl;
 60                     _CustomFieldsSvc.UseDefaultCredentials = true;
 61                     //_CustomFieldsSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
 62                     //_CustomFieldsSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
 63                 }
 64                 return _CustomFieldsSvc;
 65             }
 66         }
 67 
 68         protected TimeSheet TimeSheetSvc
 69         {
 70             get
 71             {
 72                 if (_TimeSheetSvc == null)
 73                 {
 74                     _TimeSheetSvc = new TimeSheet();
 75                     _TimeSheetSvc.Url = ServiceUrl.TimeSheetUrl;
 76                     _TimeSheetSvc.UseDefaultCredentials = true;
 77                     //_TimeSheetSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
 78                     //_TimeSheetSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
 79                 }
 80                 return _TimeSheetSvc;
 81             }
 82         }
 83 
 84         protected Admin AdminSvc
 85         {
 86             get
 87             {
 88                 if (_AdminSvc == null)
 89                 {
 90                     _AdminSvc = new Admin();
 91                     _AdminSvc.Url = ServiceUrl.AdminUrl;
 92                     _AdminSvc.UseDefaultCredentials = true;
 93                     //_AdminSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
 94                     //_AdminSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
 95                 }
 96                 return _AdminSvc;
 97             }
 98         }
 99 
100         protected Resource ResourceSvc
101         {
102             get
103             {
104                 if (_ResourceSvc == null)
105                 {
106                     _ResourceSvc = new Resource();
107                     _ResourceSvc.Url = ServiceUrl.ResourceUrl;
108                     _ResourceSvc.UseDefaultCredentials = true;
109                     //_ResourceSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
110                     //_ResourceSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
111                 }
112                 return _ResourceSvc;
113             }
114         }
115 
116         protected Project ProjectSvc
117         {
118             get
119             {
120                 if (_ProjectSvc == null)
121                 {
122 
123                     _ProjectSvc = new Project();
124                     _ProjectSvc.Url = ServiceUrl.ProjectUrl;
125                     _ProjectSvc.UseDefaultCredentials = true;
126                     //_ProjectSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
127                     //_ProjectSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
128                 }
129                 return _ProjectSvc;
130             }
131         }
132 
133         protected QueueSystem QueueSystemSvc
134         {
135             get
136             {
137                 if (_QueueSystemSvc == null)
138                 {
139                     _QueueSystemSvc = new QueueSystem();
140                     _QueueSystemSvc.Url = ServiceUrl.QueueSystemUrl;
141                     _QueueSystemSvc.UseDefaultCredentials = true;
142                     //_QueueSystemSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
143                     //_QueueSystemSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
144                 }
145                 return _QueueSystemSvc;
146             }
147         }
148 
149         protected LoginWindows LoginWindowsSvc
150         {
151             get
152             {
153                 if (_LoginWindowsSvc == null)
154                 {
155                     _LoginWindowsSvc = new LoginWindows();
156                     _LoginWindowsSvc.Url = ServiceUrl.LoginWindowsUrl;
157                     _LoginWindowsSvc.UseDefaultCredentials = true;
158                     //_LoginWindowsSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
159                     //_LoginWindowsSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
160                 }
161                 return _LoginWindowsSvc;
162             }
163         }
164 
165         protected Statusing StatusingClient
166         {
167             get
168             {
169                 if (_StatusingClient == null)
170                 {
171                     _StatusingClient = new Statusing();
172                     _StatusingClient.Url = ServiceUrl.StatusingUrl;
173                     _StatusingClient.UseDefaultCredentials = true;
174                     //_StatusingClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
175                     //_StatusingClient.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
176                 }
177                 return _StatusingClient;
178             }
179         }
180 
181 
182         /// <summary>
183         /// 登陆系统
184         /// </summary>
185         private void LoginWebService()
186         {
187             //CredentialCache credentialCache = new CredentialCache();
188             //credentialCache.Add(
189             //    new Uri(Settings.Default.PSI_DataAccess_BaseUri), "NTLM",
190             //        new NetworkCredential(
191             //            Settings.Default.PSI_DataAccess_Username,
192             //            Settings.Default.PSI_DataAccess_Password,
193             //            Settings.Default.PSI_DataAccess_Domain));
194         }
195     }
196 }

ServiceUrl类

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using Microsoft.SharePoint;
 6 
 7 namespace HIGHFARINFO.ZTJC.ServiceHelper
 8 {
 9     public class ServiceUrl
10     {
11         private const string ADMIN_SERVICE_PATH = "/_vti_bin/psi/Admin.asmx";
12         private const string CUSTOMFIELDS_SERVICE_PATH = "/_vti_bin/psi/CustomFields.asmx";
13         private const string LOGINWINDOWS_SERVICE_PATH = "/_vti_bin/psi/LoginWindows.asmx";
14         private const string LOOKUPTABLE_SERVICE_PATH = "/_vti_bin/psi/LookupTable.asmx";
15         private const string PROJECT_SERVICE_PATH = "/_vti_bin/psi/Project.asmx";
16         private const string QUEUESYSTEM_SERVICE_PATH = "/_vti_bin/psi/QueueSystem.asmx";
17         private const string RESOURCE_SERVICE_PATH = "/_vti_bin/psi/Resource.asmx";
18         private const string STATUSING_SERVICE_PATH = "/_vti_bin/psi/Statusing.asmx";
19         private const string TIMESHEET_SERVICE_PATH = "/_vti_bin/PSI/TimeSheet.asmx";
20         private static string PROJECT_SERVER_URI = "http://localhost:8243/PWA";
21 
22         public static string AdminUrl
23         {
24             get { return PROJECT_SERVER_URI + ADMIN_SERVICE_PATH; }
25         }
26 
27         public static string CustomFieldsUrl
28         {
29             get { return PROJECT_SERVER_URI + CUSTOMFIELDS_SERVICE_PATH; }
30         }
31 
32         public static string LoginWindowsUrl
33         {
34             get { return PROJECT_SERVER_URI + LOGINWINDOWS_SERVICE_PATH; }
35         }
36 
37         public static string LookupTableUrl
38         {
39             get { return PROJECT_SERVER_URI + LOOKUPTABLE_SERVICE_PATH; }
40         }
41 
42         public static string ProjectUrl
43         {
44             get { return PROJECT_SERVER_URI + PROJECT_SERVICE_PATH; }
45         }
46 
47         public static string QueueSystemUrl
48         {
49             get { return PROJECT_SERVER_URI + QUEUESYSTEM_SERVICE_PATH; }
50         }
51 
52         public static string ResourceUrl
53         {
54             get { return PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH; }
55         }
56 
57         public static string StatusingUrl
58         {
59             get { return PROJECT_SERVER_URI + STATUSING_SERVICE_PATH; }
60         }
61 
62         public static string TimeSheetUrl
63         {
64             get { return PROJECT_SERVER_URI + TIMESHEET_SERVICE_PATH; }
65         }
66     }
67 }

时间表操作类

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using HIGHFARINFO.ZTJC.TimeSheetWebSvc;
  6 using HIGHFARINFO.ZTJC.AdminWebSvc;
  7 using System.Data;
  8 using Microsoft.Office.Project.Server.Library;
  9 using HIGHFARINFO.ZTJC.Common;
 10 
 11 namespace HIGHFARINFO.ZTJC.ServiceHelper
 12 {
 13     /// <summary>
 14     /// 时间表TimeSheet服务操作类
 15     /// </summary>
 16     public class TimeSheetUtils : ServiceBase
 17     {
 18         private AdminUtils adminutils = null;
 19         private QueueSystemUtils queuesystemutils = null;
 20         /// <summary>
 21         /// 初始化构造器
 22         /// </summary>
 23         public TimeSheetUtils()
 24         {
 25             adminutils = new AdminUtils();
 26             queuesystemutils = new QueueSystemUtils();
 27         }
 28 
 29         /// <summary>
 30         /// 获取用户当前时间表UID
 31         /// </summary>
 32         /// <param name="date">日期</param>
 33         /// <returns></returns>
 34         public Guid GetTimesheetUidByDate(DateTime datetime)
 35         {
 36             TimesheetDataSet timesheetDs = GetTimesheetByDate(datetime);
 37             if (timesheetDs.Headers.Count < 0)
 38                 throw new Exception();
 39             return timesheetDs.Headers[0].TS_UID;
 40         }
 41 
 42         /// <summary>
 43         /// 获取时间表TimesheetDataSet对象
 44         /// </summary>
 45         /// <param name="tsUid">时间表UID</param>
 46         /// <returns></returns>
 47         public TimesheetDataSet GetTimeSheetByUid(Guid tsUid)
 48         {
 49             return TimeSheetSvc.ReadTimesheet(tsUid);
 50         }
 51 
 52         /// <summary>
 53         /// 获取时间表TimesheetDataSet对象
 54         /// </summary>
 55         /// <param name="datetime">日期</param>
 56         /// <returns></returns>
 57         public TimesheetDataSet GetTimesheetByDate(DateTime datetime)
 58         {
 59             Guid periodUid = adminutils.GetTimePeriodUidByDate(datetime);
 60             return GetTimesheetByPeriodUID(periodUid);
 61         }
 62 
 63         /// <summary>
 64         /// 获取时间表TimesheetDataSet对象
 65         /// </summary>
 66         /// <param name="perioduid">周期UID</param>
 67         /// <returns></returns>
 68         public TimesheetDataSet GetTimesheetByPeriodUID(Guid perioduid)
 69         {
 70             Guid myUid = new ResourceUtils().CurrentUserUID;
 71             return TimeSheetSvc.ReadTimesheetByPeriod(myUid, perioduid, TimeSheetWebSvc.Navigation.Current);
 72         }
 73 
 74         /// <summary>
 75         /// 判断日期是否属于当前周期或历史周期
 76         /// </summary>
 77         /// <param name="date"></param>
 78         public bool IsOldCurrenCycles(DateTime datetime)
 79         {
 80             DateTime currendatetime = DateTime.Now;
 81             if (datetime > currendatetime)
 82             {
 83                 return adminutils.GetTimePeriodUidByDate(datetime) == adminutils.GetTimePeriodUidByDate(currendatetime);
 84             }
 85             return true;
 86         }
 87 
 88         /// <summary>
 89         /// 删除时间表
 90         /// </summary>
 91         /// <param name="tsUid"></param>
 92         /// <returns></returns>
 93         public bool DeleteTimeSheet(Guid tsUid)
 94         {
 95             Guid jobUid = Guid.NewGuid();
 96             TimeSheetSvc.QueueDeleteTimesheet(jobUid, tsUid);
 97             return queuesystemutils.WaitForQueue(jobUid);
 98         }
 99 
100         /// <summary>
101         /// 创建时间表
102         /// </summary>
103         /// <param name="resUid"></param>
104         /// <param name="periodUid"></param>
105         /// <returns></returns>
106         public Guid CreateTimeSheet(Guid resUid, Guid periodUid)
107         {
108             Guid tsUid = Guid.NewGuid();
109             TimeSheetWebSvc.TimesheetDataSet tempTimesheetDs = new TimeSheetWebSvc.TimesheetDataSet();
110             TimeSheetWebSvc.TimesheetDataSet.HeadersRow headersRow = tempTimesheetDs.Headers.NewHeadersRow();
111             headersRow.RES_UID = resUid;
112             headersRow.TS_UID = tsUid;
113             headersRow.WPRD_UID = periodUid;
114             headersRow.TS_CREATOR_RES_UID = resUid;
115             headersRow.TS_NAME = "我的时间表 ";
116             headersRow.TS_ENTRY_MODE_ENUM = (byte)TimesheetEnum.EntryMode.Daily;
117             tempTimesheetDs.Headers.AddHeadersRow(headersRow);
118             TimeSheetSvc.CreateTimesheet(tempTimesheetDs, TimeSheetWebSvc.PreloadType.Default);
119             return tsUid;
120         }
121 
122         /// <summary>
123         /// 同步时间表,将删除前时间表填写的实际实际时间,同步到创建后时间表
124         /// </summary>
125         /// <param name="oldTimeSheetDst">删除之前TimesheetDataSet对象</param>
126         /// <param name="newTimeSheetDst">新创建TimesheetDataSet对象</param>
127         /// <returns></returns>
128         public bool TimeSheetSyntonization(TimesheetDataSet oldTimeSheetDst, TimesheetDataSet newTimeSheetDst)
129         {
130             //更新时间表中的时间实际时间
131             foreach (TimeSheetWebSvc.TimesheetDataSet.LinesRow newLinesRow in newTimeSheetDst.Lines)
132             {
133                 DataRow[] oldLineRows = (oldTimeSheetDst.Lines.AsEnumerable().Where((a) => (a as TimeSheetWebSvc.TimesheetDataSet.LinesRow).ASSN_UID == newLinesRow.ASSN_UID)).ToArray();
134                 if (oldLineRows.Count() > 0)
135                 {
136                     TimeSheetWebSvc.TimesheetDataSet.ActualsRow[] newActualsRows = newLinesRow.GetActualsRows();
137                     TimeSheetWebSvc.TimesheetDataSet.LinesRow oldLineRow = oldLineRows.First() as TimeSheetWebSvc.TimesheetDataSet.LinesRow;
138                     TimesheetDataSet.ActualsRow[] oldActualsRows = oldLineRow.GetActualsRows();
139                     if (newLinesRow["TS_LINE_CLASS_TYPE"].ToString() == "0")//标准任务(项目任务)
140                     {
141                         foreach (var newActualsRow in newActualsRows)
142                         {
143                             TimeSheetWebSvc.TimesheetDataSet.ActualsRow[] oldActualsRow = oldLineRow.GetActualsRows().AsEnumerable().Where(a =>
144                               (a as TimeSheetWebSvc.TimesheetDataSet.ActualsRow).TS_ACT_START_DATE == newActualsRow.TS_ACT_START_DATE
145                               && (a as TimeSheetWebSvc.TimesheetDataSet.ActualsRow).TS_ACT_FINISH_DATE == newActualsRow.TS_ACT_FINISH_DATE
146                               && (a as TimeSheetWebSvc.TimesheetDataSet.ActualsRow).TS_ACT_VALUE != newActualsRow.TS_ACT_VALUE).ToArray();
147                             if (oldActualsRow.Count() > 0)
148                             {
149                                 newActualsRow.TS_ACT_VALUE = oldActualsRow.First().TS_ACT_VALUE;
150                             }
151                         }
152                     }
153                     else//非标准任务(管理任务)
154                     {
155                         foreach (TimesheetDataSet.ActualsRow item in oldActualsRows)
156                         {
157                             if (item.TS_ACT_VALUE != 0 || item.TS_ACT_PLAN_VALUE != 0)
158                             {
159                                 AddActualsRow(newTimeSheetDst, newLinesRow.TS_LINE_UID, item.TS_ACT_START_DATE, item.TS_ACT_FINISH_DATE, item.TS_ACT_PLAN_VALUE, item.TS_ACT_VALUE);
160                             }
161                         }
162                     }
163                 }
164             }
165             //1、个人任务
166             //2、如果项目任务锁定,当创建时间表任务时候是不会创建任务的,必须把之前任务同步过来
167             foreach (TimeSheetWebSvc.TimesheetDataSet.LinesRow oldLinesRow in oldTimeSheetDst.Lines)
168             {
169                 DataRow[] newLineRows = (newTimeSheetDst.Lines.AsEnumerable().Where((a) => (a as TimeSheetWebSvc.TimesheetDataSet.LinesRow).TASK_UID == oldLinesRow.TASK_UID)).ToArray();
170                 //if (newLineRows.Count() < 1 && oldLinesRow.TS_LINE_CACHED_PROJ_NAME == "个人任务")
171                 if (newLineRows.Count() < 1)
172                 {
173                     Guid lineuid = AddTimeSheetLine(newTimeSheetDst.Headers[0].TS_UID, newTimeSheetDst, oldLinesRow);
174                     TimesheetDataSet.ActualsRow[] oldActualsRows = oldLinesRow.GetActualsRows();
175                     foreach (TimesheetDataSet.ActualsRow item in oldActualsRows)
176                     {
177                         if ((int)item.TS_ACT_VALUE != 0)
178                         {
179                             AddActualsRow(newTimeSheetDst, lineuid, item.TS_ACT_START_DATE, item.TS_ACT_FINISH_DATE, item.TS_ACT_PLAN_VALUE, item.TS_ACT_VALUE);
180                         }
181                     }
182                 }
183             }
184 
185             //删除无用管理任务
186             List<Guid> lineuidlist = DeleteOtherTask.GetDeleteLineUIDList(newTimeSheetDst);
187             if (lineuidlist.Count > 0)
188             {
189                 foreach (TimeSheetWebSvc.TimesheetDataSet.LinesRow newLinesRow in newTimeSheetDst.Lines)
190                 {
191                     if (lineuidlist.Contains(newLinesRow.TS_LINE_UID))
192                     {
193                         newLinesRow.Delete();
194                     }
195                 }
196             }
197 
198             Guid tsuids = newTimeSheetDst.Headers[0].TS_UID;
199             Guid jobUid = Guid.NewGuid();
200             TimesheetDataSet changedst = (TimeSheetWebSvc.TimesheetDataSet)newTimeSheetDst.GetChanges();
201             bool result = true;
202             if (changedst != null)
203             {
204                 TimeSheetSvc.QueueUpdateTimesheet(jobUid, tsuids, changedst);
205                 result = queuesystemutils.WaitForQueue(jobUid);
206             }
207             return result;
208         }
209 
210         /// <summary>
211         /// 添加ActualsRow
212         /// </summary>
213         /// <param name="timeSheetDst">需要添加ActualsRow的TimesheetDataSet</param>
214         /// <param name="tsUid">TimeSheet的UID</param>
215         /// <param name="startDate">开始时间</param>
216         /// <param name="finishDate">结束时间</param>
217         /// <param name="planValue">计划工时</param>
218         /// <param name="actValue">实际工时</param>
219         private void AddActualsRow(TimesheetDataSet timeSheetDst, Guid tsUid, DateTime startDate, DateTime finishDate, decimal planValue, decimal actValue)
220         {
221             TimesheetDataSet.ActualsRow actualsrow = timeSheetDst.Actuals.NewActualsRow();
222             actualsrow.TS_ACT_FINISH_DATE = finishDate;
223             actualsrow.TS_ACT_PLAN_VALUE = planValue;
224             actualsrow.TS_ACT_START_DATE = startDate;
225             actualsrow.TS_ACT_VALUE = actValue;
226             actualsrow.TS_LINE_UID = tsUid;
227             timeSheetDst.Actuals.AddActualsRow(actualsrow);
228         }
229 
230         /// <summary>
231         /// 添加时间表个人任务
232         /// </summary>
233         /// <param name="TS_UID">时间表UID</param>
234         /// <param name="timeSheetDst"></param>
235         /// <param name="newlinerow"></param>
236         /// <returns></returns>
237         private Guid AddTimeSheetLine(Guid TS_UID, TimesheetDataSet timeSheetDst, TimeSheetWebSvc.TimesheetDataSet.LinesRow newlinerow)
238         {
239             Guid lineuid = Guid.NewGuid();
240             TimeSheetWebSvc.TimesheetDataSet.LinesRow line = timeSheetDst.Lines.NewLinesRow();
241             line.TS_UID = TS_UID;
242             line.TS_LINE_UID = lineuid;
243             line.TS_LINE_CLASS_UID = newlinerow.TS_LINE_CLASS_UID;
244             line.TS_LINE_COMMENT = newlinerow.TS_LINE_COMMENT;
245             line.TS_LINE_STATUS = newlinerow.TS_LINE_STATUS;
246             line.TS_LINE_VALIDATION_TYPE = (byte)(TimesheetEnum.ValidationType.Unverified); //newlinerow.TS_LINE_VALIDATION_TYPE;
247             line.TS_LINE_CACHED_ASSIGN_NAME = newlinerow.TS_LINE_CACHED_ASSIGN_NAME;
248             line.ASSN_UID = newlinerow.ASSN_UID;
249             line.TASK_UID = newlinerow.TASK_UID;
250             //line.PROJ_UID = newlinerow.PROJ_UID;
251             line.TS_LINE_CACHED_PROJ_NAME = newlinerow.TS_LINE_CACHED_PROJ_NAME;
252             timeSheetDst.Lines.AddLinesRow(line);
253             return lineuid;
254         }
255     }
256 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Data;
 6 using HIGHFARINFO.ZTJC.AdminWebSvc;
 7 
 8 namespace HIGHFARINFO.ZTJC.ServiceHelper
 9 {
10     /// <summary>
11     /// Admin服务操作类
12     /// </summary>
13     public class AdminUtils : ServiceBase
14     {
15         private  TimePeriodDataSet _TimePerDst = null;
16 
17         public TimePeriodDataSet TimePeriodDataSet
18         {
19             get { return _TimePerDst; }
20         }
21 
22         /// <summary>
23         /// 初始化构造器
24         /// </summary>
25         public AdminUtils()
26         {
27             if (_TimePerDst == null)
28             {
29                 _TimePerDst = AdminSvc.ReadPeriods(PeriodState.Open);
30             }
31         }
32 
33         /// <summary>
34         /// 根据时间获取当前周期UID
35         /// </summary>
36         /// <param name="date"></param>
37         /// <returns></returns>
38         public Guid GetTimePeriodUidByDate(DateTime date)
39         {
40             var q = TimePeriodDataSet.TimePeriods.AsEnumerable().
41                          Where(a => (a as AdminWebSvc.TimePeriodDataSet.TimePeriodsRow).WPRD_START_DATE <= date
42                          && (a as AdminWebSvc.TimePeriodDataSet.TimePeriodsRow).WPRD_FINISH_DATE >= date);
43             if (q.Count() > 0)
44             {
45                 TimePeriodDataSet.TimePeriodsRow currenttimeper = (TimePeriodDataSet.TimePeriodsRow)q.First();
46                 return currenttimeper.WPRD_UID;
47             }
48             return Guid.Empty;
49         }
50 
51         /// <summary>
52         /// 根据时间表UID获取时间表的开始时间
53         /// </summary>
54         /// <param name="periodsuid">根据时间表UID</param>
55         /// <returns></returns>
56         public DateTime GetPeriodStartDateByPerioduid(Guid periodsuid)
57         {
58             TimePeriodDataSet dst = AdminSvc.ReadPeriods(PeriodState.All);
59             TimePeriodDataSet.TimePeriodsRow timerow = dst.TimePeriods.FindByWPRD_UID(periodsuid);
60             DateTime start = timerow.WPRD_START_DATE;
61             return start;
62         }
63 
64         /// <summary>
65         /// 根据时间表UID获取时间表
66         /// </summary>
67         /// <param name="periodsuid">根据时间表UID</param>
68         /// <returns></returns>
69         public TimePeriodDataSet.TimePeriodsRow GetPeriodByPerioduid(Guid periodsuid)
70         {
71             TimePeriodDataSet dst = AdminSvc.ReadPeriods(PeriodState.All);
72             TimePeriodDataSet.TimePeriodsRow timerow = dst.TimePeriods.FindByWPRD_UID(periodsuid);
73             return timerow;
74         }
75 
76         /// <summary>
77         /// 根据时间表UID获取时间表的开始时间
78         /// </summary>
79         /// <param name="periodsuid">根据时间表UID</param>
80         /// <param name="start">时间表开始时间</param>
81         /// <param name="end">时间表结束时间</param>
82         public void GetPeriodStartDateByPerioduid(Guid periodsuid, ref DateTime start, ref DateTime end)
83         {
84             TimePeriodDataSet dst = AdminSvc.ReadPeriods(PeriodState.All);
85             TimePeriodDataSet.TimePeriodsRow timerow = dst.TimePeriods.FindByWPRD_UID(periodsuid);
86             start = timerow.WPRD_START_DATE;
87             end = timerow.WPRD_FINISH_DATE;
88         }
89     }
90 }
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using HIGHFARINFO.ZTJC.CustomFieldsWebSvc;
  6 using Microsoft.Office.Project.Server.Library;
  7 
  8 namespace HIGHFARINFO.ZTJC.ServiceHelper
  9 {
 10     /// <summary>
 11     /// 自定义域CustomFields服务操作类
 12     /// </summary>
 13     public class CustomFieldsUtils : ServiceBase
 14     {
 15         /// <summary>
 16         /// 初始化构造器
 17         /// </summary>
 18         public CustomFieldsUtils()
 19         {
 20         }
 21 
 22         /// <summary>
 23         /// 根据自定义域名称获取UID
 24         /// </summary>
 25         /// <param name="fieldName"></param>
 26         /// <param name="entityType"></param>
 27         /// <returns></returns>
 28         public Guid GetCustomFieldUID(String fieldName, CustomFieldsEntityType entityType)
 29         {
 30             return GetCustomField(fieldName, entityType).MD_PROP_UID;
 31         }
 32 
 33         /// <summary>
 34         /// 根据自定义域名称获取CustomFieldsRow对象
 35         /// </summary>
 36         /// <param name="fieldName">自定义域名称</param>
 37         /// <param name="entityType">CustomFieldsEntityType对象类型</param>
 38         /// <returns></returns>
 39         public CustomFieldDataSet.CustomFieldsRow GetCustomField(String fieldName, CustomFieldsEntityType entityType)
 40         {
 41             string typeuid = string.Empty;
 42             switch (entityType)
 43             {
 44                 case CustomFieldsEntityType.PROTYPE:
 45                     typeuid = EntityCollection.Entities.ProjectEntity.UniqueId;
 46                     break;
 47                 case CustomFieldsEntityType.RESTYPE:
 48                     typeuid = EntityCollection.Entities.ResourceEntity.UniqueId;
 49                     break;
 50                 case CustomFieldsEntityType.TASKTYPE:
 51                     typeuid = EntityCollection.Entities.TaskEntity.UniqueId;
 52                     break;
 53             }
 54             Guid entityTypeUid = new Guid(typeuid);
 55             using (CustomFieldDataSet filterDS = new CustomFieldDataSet())
 56             {
 57                 string filterxml = GetFilterXml(fieldName, entityTypeUid);
 58 
 59                 using (CustomFieldDataSet customFieldDS = CustomFieldsSvc.ReadCustomFields(filterxml, false))
 60                 {
 61                     if (customFieldDS.CustomFields == null || customFieldDS.CustomFields.Count == 0)
 62                     {
 63                         throw new Exception();
 64                     }
 65                     if (customFieldDS.CustomFields.Count > 1)
 66                     {
 67                         throw new Exception();
 68                     }
 69                     return customFieldDS.CustomFields[0];
 70                 }
 71             }
 72 
 73         }
 74 
 75         /// <summary>
 76         /// 根据名称和类型生成Filter xml
 77         /// </summary>
 78         /// <param name="fieldName">自定义域名称</param>
 79         /// <param name="entityType">类型UID</param>
 80         /// <returns></returns>
 81         private string GetFilterXml(string fieldName, Guid entityType)
 82         {
 83             using (CustomFieldDataSet filterDS = new CustomFieldDataSet())
 84             {
 85                 String tableName = filterDS.CustomFields.TableName;
 86                 String uidColumn = filterDS.CustomFields.MD_PROP_UIDColumn.ColumnName;
 87                 String secUidColumn = filterDS.CustomFields.MD_PROP_ID_SECONDARYColumn.ColumnName;
 88                 String nameColumn = filterDS.CustomFields.MD_PROP_NAMEColumn.ColumnName;
 89                 String entityUidColumn = filterDS.CustomFields.MD_ENT_TYPE_UIDColumn.ColumnName;
 90                 Filter filter = new Filter();
 91                 filter.FilterTableName = tableName;
 92                 filter.Fields.Add(new Filter.Field(tableName, uidColumn));
 93                 filter.Fields.Add(new Filter.Field(secUidColumn));
 94                 filter.Fields.Add(new Filter.Field(nameColumn));
 95                 filter.Fields.Add(new Filter.Field(entityUidColumn));
 96                 filter.Criteria = new Filter.LogicalOperator(
 97                             Filter.LogicalOperationType.And,
 98                             new Filter.FieldOperator(Filter.FieldOperationType.Equal, entityUidColumn, entityType),
 99                             new Filter.FieldOperator(Filter.FieldOperationType.Equal, nameColumn, fieldName));
100                 return filter.GetXml();
101             }
102         }
103     }
104 
105     /// <summary>
106     /// 自定义域枚举类型
107     /// </summary>
108     public enum CustomFieldsEntityType
109     {
110         /// <summary>
111         /// 项目类型
112         /// </summary>
113         PROTYPE,
114         /// <summary>
115         /// 资源类型
116         /// </summary>
117         RESTYPE,
118         /// <summary>
119         /// 任务类型
120         /// </summary>
121         TASKTYPE
122     }
123 }
  1 using HIGHFARINFO.ZTJC.LookupTableWebSvc;
  2 using Microsoft.Office.Project.Server.Library;
  3 using System;
  4 using System.Collections.Generic;
  5 using System.Linq;
  6 using System.Net;
  7 using System.Text;
  8 using System.Web.Services.Protocols;
  9 using System.Data;
 10 
 11 namespace HIGHFARINFO.ZTJC.ServiceHelper
 12 {
 13     /// <summary>
 14     /// 查阅表格LookupTable服务操作类
 15     /// </summary>
 16     public class LookupTableUtils : ServiceBase
 17     {
 18         /// <summary>
 19         /// 初始化构造器
 20         /// </summary>
 21         public LookupTableUtils()
 22         {
 23 
 24         }
 25 
 26         /// <summary>
 27         /// 根据查阅表格名称获取LookupTableDataSet对象
 28         /// </summary>
 29         /// <param name="lookupTableName">查阅表格名称</param>
 30         /// <returns></returns>
 31         public LookupTableDataSet GetLookupTable(String lookupTableName)
 32         {
 33             string filterxml = GetFilterXml(lookupTableName);
 34             using (LookupTableMultiLangDataSet lookupTableDS = LookupTableSvc.ReadLookupTablesMultiLang(filterxml, false))
 35             {
 36                 if (lookupTableDS.LookupTables == null || lookupTableDS.LookupTables.Count == 0)
 37                 {
 38                     throw new Exception();
 39                 }
 40                 if (lookupTableDS.LookupTables.Count > 1)
 41                 {
 42                     throw new Exception();
 43                 }
 44                 return ReadLookupTablesByUID(new Guid[] { lookupTableDS.LookupTables[0].LT_UID });
 45             }
 46         }
 47 
 48         /// <summary>
 49         /// 根据查阅表格的ValueUid获取ValueText
 50         /// </summary>
 51         /// <param name="valueUid">表格中行UID</param>
 52         /// <param name="lookupdst"></param>
 53         /// <returns></returns>
 54         public string GetValueTextByValueUid(Guid valueUid, LookupTableDataSet lookupdst)
 55         {
 56             LookupTableWebSvc.LookupTableDataSet.LookupTableTreesRow lookrow = (LookupTableWebSvc.LookupTableDataSet.LookupTableTreesRow)lookupdst.LookupTableTrees.AsEnumerable().Single(
 57                         a => (a as LookupTableWebSvc.LookupTableDataSet.LookupTableTreesRow).LT_STRUCT_UID == valueUid);
 58             return lookrow.LT_VALUE_TEXT;
 59         }
 60 
 61         /// <summary>
 62         /// 根据查阅表格的ValueText获取ValueUid
 63         /// </summary>
 64         /// <param name="valuetext">表格中行文本值</param>
 65         /// <param name="lookupdst"></param>
 66         /// <returns></returns>
 67         public Guid GetValueUidByValueText(string valuetext, LookupTableDataSet lookupdst)
 68         {
 69             LookupTableDataSet.LookupTableTreesRow tablevaluesrow = lookupdst.LookupTableTrees.AsEnumerable().Single(
 70                         a => (a as LookupTableDataSet.LookupTableTreesRow).LT_VALUE_TEXT == valuetext)
 71                         as LookupTableDataSet.LookupTableTreesRow;
 72             return tablevaluesrow.LT_STRUCT_UID;
 73         }
 74 
 75         #region
 76         /// <summary>
 77         /// 根据表格名称生成Filter XML
 78         /// </summary>
 79         /// <param name="lookupTableName">表格名称</param>
 80         /// <returns></returns>
 81         private string GetFilterXml(string lookupTableName)
 82         {
 83             using (LookupTableDataSet filterDS = new LookupTableDataSet())
 84             {
 85                 String tableName = filterDS.LookupTables.TableName;
 86                 String uidColumn = filterDS.LookupTables.LT_UIDColumn.ColumnName;
 87                 String nameColumn = filterDS.LookupTables.LT_NAMEColumn.ColumnName;
 88                 Filter filter = new Filter();
 89                 filter.FilterTableName = tableName;
 90                 filter.Fields.Add(new Filter.Field(tableName, uidColumn));
 91                 filter.Fields.Add(new Filter.Field(tableName, nameColumn));
 92                 filter.Criteria = new Filter.FieldOperator(Filter.FieldOperationType.Equal, "LT_NAME", new String[] { lookupTableName });
 93                 return filter.GetXml();
 94             }
 95         }
 96 
 97         /// <summary>
 98         /// 根据表格的UID获取LookupTableDataSet对象
 99         /// </summary>
100         /// <param name="uidList">表格UID</param>
101         /// <returns></returns>
102         private LookupTableDataSet ReadLookupTablesByUID(Guid[] uidList)
103         {
104             try
105             {
106                 return LookupTableSvc.ReadLookupTablesByUids(uidList, false, 0);
107             }
108             catch (SoapException ex)
109             {
110                 throw ex;
111             }
112             catch (WebException ex)
113             {
114                 throw ex;
115             }
116         }
117         #endregion
118     }
119 }
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using HIGHFARINFO.ZTJC.ProjectWebSvc;
  6 using System.Data;
  7 using HIGHFARINFO.ZTJC.Common;
  8 using Microsoft.SharePoint.Utilities;
  9 using Microsoft.SharePoint;
 10 using System.Collections.Specialized;
 11 
 12 namespace HIGHFARINFO.ZTJC.ServiceHelper
 13 {
 14     /// <summary>
 15     /// 项目Project服务操作类
 16     /// </summary>
 17     public class ProjectUtils : ServiceBase
 18     {
 19         /// <summary>
 20         /// 初始化构造器
 21         /// </summary>
 22         public ProjectUtils()
 23         {
 24         }
 25 
 26         /// <summary>
 27         /// 根据项目UID获取ProjectDataSet对象
 28         /// </summary>
 29         /// <param name="projectUid">项目UID</param>
 30         /// <returns></returns>
 31         public ProjectDataSet GetProjectByUid(Guid projectUid)
 32         {
 33             return ProjectSvc.ReadProject(projectUid, DataStoreEnum.WorkingStore);
 34         }
 35 
 36         /// <summary>
 37         /// 根据自定义域的UID获取ProjectCustomFieldsRow对象
 38         /// </summary>
 39         /// <param name="customFieldUid">项目类型的自定义域UID</param>
 40         /// <param name="projectDst">ProjectDataSet对象</param>
 41         /// <returns></returns>
 42         public ProjectDataSet.ProjectCustomFieldsRow ProjectCustomFieldsByUid(Guid customFieldUid, ProjectDataSet projectDst)
 43         {
 44             var q = projectDst.ProjectCustomFields.AsEnumerable().Where(a => (a as ProjectWebSvc.ProjectDataSet.ProjectCustomFieldsRow).MD_PROP_UID == customFieldUid);
 45             if (q.Count() > 0)
 46             {
 47                 return (ProjectDataSet.ProjectCustomFieldsRow)q.First();
 48             }
 49             return null;
 50         }
 51 
 52         /// <summary>
 53         /// 根据自定义域的UID获取TaskCustomFieldsRow对象
 54         /// </summary>
 55         /// <param name="customFieldUid">项目类型的自定义域UID</param>
 56         /// <param name="projectDst">ProjectDataSet对象</param>
 57         /// <returns></returns>
 58         public List<ProjectDataSet.TaskCustomFieldsRow> ProjectTaskCustomFieldsByUid(Guid customFieldUid, ProjectDataSet projectDst)
 59         {
 60             List<ProjectDataSet.TaskCustomFieldsRow> taskcusrowslist = new List<ProjectDataSet.TaskCustomFieldsRow>();
 61             var q = projectDst.TaskCustomFields.AsEnumerable().Where(a => (a as ProjectDataSet.TaskCustomFieldsRow).MD_PROP_UID == customFieldUid);
 62             //foreach (ProjectDataSet.TaskRow taskrow in projectDst.Task.Rows)
 63             //{
 64             foreach (ProjectDataSet.TaskCustomFieldsRow item in q)
 65             {
 66                 //if (item.TASK_UID == taskrow.TASK_UID)
 67                 //{
 68                 taskcusrowslist.Add(item);
 69                 //}
 70             }
 71             //}
 72             return taskcusrowslist;
 73         }
 74 
 75         /// <summary>
 76         /// 更新项目
 77         /// </summary>
 78         /// <param name="changeProjectDst">变动的ProjectDataSet对象</param>
 79         /// <param name="projectUid">项目UID</param>
 80         /// <returns></returns>
 81         public bool UpdateProject(ProjectDataSet changeProjectDst, Guid projectUid, Guid sessionUid)
 82         {
 83             QueueSystemUtils queuesystemutils = new QueueSystemUtils();
 84             Guid jobUid = Guid.NewGuid();
 85             try
 86             {
 87                 jobUid = Guid.NewGuid();
 88                 ProjectSvc.QueueUpdateProject(jobUid, sessionUid, changeProjectDst, false);
 89                 bool res = queuesystemutils.WaitForQueue(jobUid);
 90                 return res;
 91             }
 92             catch (Exception ex)
 93             {
 94                 throw new Exception(ex.ToString());
 95             }
 96         }
 97 
 98         /// <summary>
 99         /// 嵌出项目
100         /// </summary>
101         /// <param name="projectUid"></param>
102         public void CheckOutProject(Guid projectUid, Guid sessionUid)
103         {
104             QueueSystemUtils queuesystemutils = new QueueSystemUtils();
105             string session_desc = "Sample utility";
106             //Guid sessionUid = Guid.NewGuid();
107             Guid jobUid = Guid.NewGuid();
108             try
109             {
110                 ProjectSvc.CheckOutProject(projectUid, sessionUid, session_desc);
111             }
112             catch
113             {
114                 ProjectSvc.QueueCheckInProject(jobUid, projectUid, true, sessionUid, session_desc);
115                 bool temps = queuesystemutils.WaitForQueue(jobUid);
116                 ProjectSvc.CheckOutProject(projectUid, sessionUid, session_desc);
117             }
118         }
119 
120         /// <summary>
121         /// 嵌入并发布项目
122         /// </summary>
123         /// <param name="projectUid"></param>
124         public void ChreckInPublishProject(Guid projectUid, Guid sessionUid)
125         {
126             try
127             {
128                 //QueueSystemUtils queuesystemutils = new QueueSystemUtils();
129                 //string session_desc = "Sample utility";
130                 ////Guid sessionUid = Guid.NewGuid();
131                 //Guid jobUid = Guid.NewGuid();
132                 //ProjectSvc.QueueCheckInProject(jobUid, projectUid, true, sessionUid, session_desc);
133                 //bool result = queuesystemutils.WaitForQueue(jobUid);
134                 //jobUid = Guid.NewGuid();
135                 //ProjectSvc.QueuePublish(jobUid, projectUid, true, string.Empty);
136                 //bool ddd = queuesystemutils.WaitForQueue(jobUid);
137 
138                 QueueSystemUtils queuesystemutils = new QueueSystemUtils();
139                 string session_desc = "Sample utility";
140                 //Guid sessionUid = Guid.NewGuid();
141                 Guid jobUid = Guid.NewGuid();
142                 ProjectSvc.QueueCheckInProject(jobUid, projectUid, true, sessionUid, session_desc);
143                 bool result = queuesystemutils.WaitForQueue(jobUid);
144                 jobUid = Guid.NewGuid();
145                 ProjectSvc.QueuePublish(jobUid, projectUid, false, string.Empty);
146                 bool ddd = queuesystemutils.WaitForQueue(jobUid);
147             }
148             catch (Exception ex)
149             {
150                 new LogHelper().WriteLine(ex.ToString());
151             }
152         }
153 
154         /// <summary>
155         /// 获取项目中所有资源者的邮箱
156         /// </summary>
157         /// <param name="projectdataset">ProjectDataSet对象</param>
158         /// <returns></returns>
159         public string[] GetProjectTaskAllUserGuid(ProjectDataSet projectdataset)
160         {
161             List<string> resemaillist = new List<string>();
162             ResourceUtils resourceutils = new ResourceUtils();
163             ProjectDataSet.ProjectResourceDataTable resourcedt = projectdataset.ProjectResource;
164             foreach (ProjectDataSet.ProjectResourceRow resourcerow in resourcedt)
165             {
166                 try
167                 {
168                     if (!string.IsNullOrEmpty(resourcerow.WRES_EMAIL) && !resemaillist.Contains(resourcerow.WRES_EMAIL))
169                     {
170                         resemaillist.Add(resourcerow.WRES_EMAIL);
171                     }
172                 }
173                 catch { }
174             }
175             return resemaillist.ToArray();
176         }
177 
178         /// <summary>
179         /// 项目打开或关闭想用户发送邮件通知
180         /// </summary>
181         /// <param name="projectdataset"></param>
182         /// <returns></returns>
183         public bool ProjectCloseOrOpenSendEmail(SPWeb web, ProjectDataSet projectdataset, bool CloseOrOpen)
184         {
185             try
186             {
187                 string[] mailtoarray = GetProjectTaskAllUserGuid(projectdataset);
188                 if (mailtoarray.Count() > 0)
189                 {
190                     string projectname = projectdataset.Project[0].PROJ_NAME;
191                     string subject = string.Empty;
192                     string mailbody = string.Empty;
193                     bool send_result = false;
194                     if (CloseOrOpen)
195                     {
196                         subject = string.Format("《{0}》项目已打开", projectname);
197                         mailbody = string.Format("你好,《{0}》项目已打开,请知悉,谢谢!", projectname);
198                     }
199                     else
200                     {
201                         subject = string.Format("《{0}》项目已关闭", projectname);
202                         mailbody = string.Format("你好,请注意《{0}》项目已关闭,请知悉,谢谢!", projectname);
203                     }
204                     foreach (string touser in mailtoarray)
205                     {
206                         bool result = SPUtility.SendEmail(web, false, false, touser, subject, mailbody);
207                         if (result)
208                             send_result = true;
209                     }
210                     if (send_result)
211                         new LogHelper().WriteLine(subject + ",并且邮件发送成功");
212                     else
213                         new LogHelper().WriteLine(subject + ",但是邮件发送失败");
214                     return send_result;
215                 }
216                 return false;
217             }
218             catch
219             {
220                 return false;
221             }
222         }
223     }
224 }
  1 using HIGHFARINFO.ZTJC.QueueSystemWebSvc;
  2 using System;
  3 using System.Collections.Generic;
  4 using System.IO;
  5 using System.Linq;
  6 using System.Text;
  7 using System.Threading;
  8 using System.Xml;
  9 using HIGHFARINFO.ZTJC.Common;
 10 
 11 namespace HIGHFARINFO.ZTJC.ServiceHelper
 12 {
 13     public class QueueSystemUtils : ServiceBase
 14     {
 15         // Wait 2 seconds between each check for job completion.
 16         private const int INCREMENTALSLEEPTIME = 2;
 17 
 18         public QueueSystemUtils()
 19         {
 20         }
 21 
 22         public bool WaitForQueue(Guid jobId)
 23         {
 24             int timeOut = 2;
 25             int wait;                            // Number of seconds to wait
 26             string xmlError;                     // XML error output from the queue
 27             bool firstPass = true;               // First iteration through the while statement.
 28             int timeSlept = 0;                   // Total time slept (seconds).
 29             bool jobIsDone = false;              // The queue job completed successfully, if true.
 30             bool stopWait = false;               // Abort the wait, if true.
 31             QueueSystemWebSvc.JobState jobState; // Status of the queue job. 
 32             while (true)
 33             {
 34                 if (firstPass)
 35                 {
 36                     wait = QueueSystemSvc.GetJobWaitTime(jobId);
 37                     if (timeOut < INCREMENTALSLEEPTIME) wait = timeOut;
 38                     else wait = INCREMENTALSLEEPTIME;
 39                     firstPass = false;
 40                 }
 41                 else
 42                 {
 43                     wait = INCREMENTALSLEEPTIME;
 44                 }
 45                 Thread.Sleep(wait * 1000);
 46                 timeSlept += wait;
 47                 jobState = QueueSystemSvc.GetJobCompletionState(jobId, out xmlError);
 48                 while (jobState == QueueSystemWebSvc.JobState.Processing)
 49                 {
 50                     Thread.Sleep(1000);
 51                     jobState = QueueSystemSvc.GetJobCompletionState(jobId, out xmlError);
 52                     if (jobState == QueueSystemWebSvc.JobState.Success) { break; }
 53                 }
 54                 if (jobState == QueueSystemWebSvc.JobState.Success)
 55                 {
 56                     jobIsDone = true;
 57                 }
 58                 else if (jobState == QueueSystemWebSvc.JobState.Unknown
 59                     || jobState == QueueSystemWebSvc.JobState.Failed
 60                     || jobState == QueueSystemWebSvc.JobState.FailedNotBlocking
 61                     || jobState == QueueSystemWebSvc.JobState.CorrelationBlocked
 62                     || jobState == QueueSystemWebSvc.JobState.Canceled)
 63                 {
 64                     stopWait = true;
 65                 }
 66                 if (!jobIsDone && timeSlept >= timeOut)
 67                 {
 68                     new LogHelper().WriteLine(xmlError);
 69                     QueueSystemSvc.CancelJobSimple(jobId);
 70                     stopWait = true;
 71                 }
 72                 if (jobIsDone || stopWait)
 73                 {
 74                     break;
 75                 }
 76             }
 77             return jobIsDone;
 78         }
 79 
 80         public bool WaitForQueue(int timeOut, Guid jobId, out String statusOut)
 81         {
 82             int wait;                 // Number of seconds to wait
 83             decimal seconds;          // for reporting wait time in decimal format.
 84             string xmlError;          // XML error output from the queue
 85             string queueStatus;       // Outer XML of xmlError string.
 86             string status = "";       // Summary status report for output.
 87             bool firstPass = true;    // First iteration through the while statement.
 88             int timeSlept = 0;        // Total time slept (seconds).
 89             bool jobIsDone = false;   // The queue job completed successfully, if true.
 90             bool stopWait = false;    // Abort the wait, if true.
 91             QueueSystemWebSvc.JobState jobState; // Status of the queue job. 
 92             while (true)
 93             {
 94                 // On the first iteration, wait the incremental sleep time  
 95                 // or the maximum requested timeout. 
 96                 if (firstPass)
 97                 {
 98                     // Get the estimated time to wait for the queue to process the job.
 99                     // The output from GetJobWaitTime is in seconds.
100                     wait = QueueSystemSvc.GetJobWaitTime(jobId);
101 
102                     status = string.Format("Estimated job wait time: {0} seconds", wait);
103 
104                     if (timeOut < INCREMENTALSLEEPTIME) wait = timeOut;
105                     else wait = INCREMENTALSLEEPTIME;
106 
107                     firstPass = false;
108                 }
109                 else
110                 {
111                     // If job is not done, wait the incremental sleep time.  
112                     wait = INCREMENTALSLEEPTIME;
113                 }
114 
115                 Thread.Sleep(wait * 1000); // Milliseconds
116 
117                 timeSlept += wait;
118 
119                 // Check job state.
120                 jobState = QueueSystemSvc.GetJobCompletionState(jobId, out xmlError);
121 
122                 // Add the XML error output to the status.
123                 StringReader sr = new StringReader(xmlError);
124                 using (XmlReader reader = XmlReader.Create(sr))
125                 {
126                     reader.MoveToContent();
127                     queueStatus = reader.ReadOuterXml();
128                 }
129                 // Don‘t add an empty <errinfo> element.
130                 if (queueStatus != "<errinfo />") status += "\n\n" + queueStatus;
131 
132                 if (jobState == QueueSystemWebSvc.JobState.Success)
133                 {
134                     jobIsDone = true;
135                 }
136                 else if (jobState == QueueSystemWebSvc.JobState.Unknown
137                     || jobState == QueueSystemWebSvc.JobState.Failed
138                     || jobState == QueueSystemWebSvc.JobState.FailedNotBlocking
139                     || jobState == QueueSystemWebSvc.JobState.CorrelationBlocked
140                     || jobState == QueueSystemWebSvc.JobState.Canceled)
141                 {
142                     stopWait = true;
143                 }
144 
145                 if (!jobIsDone && timeSlept >= timeOut)
146                 {
147                     // Cancel the job, otherwise the queue keeps processing it until it is complete.
148                     QueueSystemSvc.CancelJobSimple(jobId);
149                     stopWait = true;
150                     status += string.Format("\n\nExceeded timeout of {0} seconds", timeOut);
151                 }
152 
153                 if (jobIsDone || stopWait)
154                 {
155                     // Check jobState again, might be cancelled.
156                     seconds = Convert.ToDecimal(timeSlept);
157                     status += string.Format(
158                         "\n\nJobState: {0:G}\n\nTotal time slept: {1:N} seconds",
159                         jobState, seconds);
160                     break;
161                 }
162             }
163             statusOut = status;
164             return jobIsDone;
165         }
166     }
167 }
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using HIGHFARINFO.ZTJC.ResourceWebSvc;
  6 using System.Data;
  7 using Microsoft.SharePoint;
  8 using HIGHFARINFO.ZTJC.Common;
  9 
 10 namespace HIGHFARINFO.ZTJC.ServiceHelper
 11 {
 12     public class ResourceUtils : ServiceBase
 13     {
 14         private Guid _CurrentUserUID = Guid.Empty;
 15 
 16         public ResourceUtils()
 17         {
 18         }
 19 
 20         public Guid CurrentUserUID
 21         {
 22             get
 23             {
 24                 try
 25                 {
 26                     return ResourceSvc.GetCurrentUserUid();
 27                 }
 28                 catch (Exception ex)//如果没有资源中心权限则直接用sql获取用户信息
 29                 {
 30                     string username = SPContext.Current.Web.CurrentUser.LoginName;
 31                     return new ProjectSQLMethod().GetCurrentUserResUID(username);
 32                 }
 33             }
 34         }
 35 
 36         public string CurrentUserName
 37         {
 38             get
 39             {
 40                 try
 41                 {
 42                     ResourceDataSet resdst = ResourceSvc.ReadResource(CurrentUserUID);
 43                     if (resdst.Resources.Count > 0)
 44                     {
 45                         return resdst.Resources[0].RES_NAME;
 46                     }
 47                     return "";
 48                 }
 49                 catch (Exception ex)
 50                 {
 51                     return SPContext.Current.Web.CurrentUser.LoginName;
 52                 }
 53             }
 54         }
 55 
 56 
 57         public Guid GetAdminUserUID
 58         {
 59             get { return ResourceSvc.GetCurrentUserUid(); }
 60         }
 61 
 62 
 63 
 64         /// <summary>
 65         /// 获取当前用户资源ResourceDataSet对象
 66         /// </summary>
 67         /// <returns></returns>
 68         public ResourceDataSet ReadCurrentUserResource()
 69         {
 70             return ResourceSvc.ReadResource(CurrentUserUID);
 71         }
 72 
 73         /// <summary>
 74         /// 获取指定用户资源ResourceDataSet对象
 75         /// </summary>
 76         /// <param name="userUid">用户UID</param>
 77         /// <returns></returns>
 78         public ResourceDataSet ReadUserResourceByUid(Guid userUid)
 79         {
 80             return ResourceSvc.ReadResource(userUid);
 81         }
 82 
 83         /// <summary>
 84         /// 获取当前用户某个自定义属性对象
 85         /// </summary>
 86         /// <param name="customFieldUid"></param>
 87         /// <returns></returns>
 88         public ResourceDataSet.ResourceCustomFieldsRow GetResourceCustomFieldByUid(Guid customFieldUid)
 89         {
 90             ResourceDataSet resdst = ReadCurrentUserResource();
 91             if (resdst.ResourceCustomFields.Count > 0)
 92             {
 93                 var resourceitem = resdst.ResourceCustomFields.AsEnumerable().Where(
 94                                        a => (a as ResourceWebSvc.ResourceDataSet.ResourceCustomFieldsRow).MD_PROP_UID == customFieldUid).ToList();
 95                 if (resourceitem.Count > 0)
 96                     return resourceitem.First() as ResourceDataSet.ResourceCustomFieldsRow;
 97             }
 98             return null;
 99         }
100 
101         /// <summary>
102         /// 获取指定用户某个自定义属性对象
103         /// </summary>
104         /// <param name="resourceDst">ResourceDataSet对象</param>
105         /// <param name="customFieldUid"></param>
106         /// <returns></returns>
107         public ResourceDataSet.ResourceCustomFieldsRow GetResourceCustomFieldByUid(ResourceDataSet resourceDst, Guid customFieldUid)
108         {
109             if (resourceDst.ResourceCustomFields.Count > 0)
110             {
111                 var resourceitem = resourceDst.ResourceCustomFields.AsEnumerable().Single(
112                         a => (a as ResourceWebSvc.ResourceDataSet.ResourceCustomFieldsRow).MD_PROP_UID == customFieldUid);
113                 return resourceitem as ResourceDataSet.ResourceCustomFieldsRow;
114             }
115             return null;
116         }
117 
118         /// <summary>
119         /// 获取用户邮箱
120         /// </summary>
121         /// <param name="resourceuid">用户UID</param>
122         /// <returns></returns>
123         public string GetResourceEmail(Guid resourceuid)
124         {
125             try
126             {
127                 ResourceDataSet resourceds = ResourceSvc.ReadResource(resourceuid);
128                 if (null != resourceds)
129                 {
130                     ResourceDataSet.ResourcesRow resourceRow = (ResourceDataSet.ResourcesRow)resourceds.Resources.Rows[0];
131                     string resourceName = resourceRow.RES_NAME;
132                     string resourceEmail = resourceRow.WRES_EMAIL;
133                     return resourceEmail;
134                 }
135             }
136             catch { }
137             return "";
138         }
139     }
140 }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HIGHFARINFO.ZTJC.StatusingWebSvc;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
    public class StatusingUtils : ServiceBase
    {

        public StatusingWebSvc.Statusing StatusingClientsvc
        {
            get
            {
                return StatusingClient;
            }
        }

        public StatusingUtils() { }

        public StatusingDataSet GetAssignments(DateTime start, DateTime end)
        {
            StatusingDataSet dst = StatusingClient.ReadStatus(Guid.Empty, start, end);
            return dst;
        }

        public StatusingAssignmentsDataSet GetAssignments(Guid[] assnuidarray)
        {
            StatusingAssignmentsDataSet dst = StatusingClient.ReadAssignments(assnuidarray);
            return dst;
        }

        public StatusingDataSet GetAssignments(Guid resuid, DateTime start, DateTime end)
        {
            StatusingDataSet dst = StatusingClient.ReadStatusForResource(resuid, Guid.Empty, start, end);
            return dst;
        }

        public void insertinto(Guid perguid)
        {
            StatusingClient.ImportTimesheet(perguid);
            StatusingWebSvc.ImportTimesheetDataSet importTimeSheetDs = StatusingClient.ReadImportTimesheetData(perguid);
        }
    }
}

 

Project Web Server PSI 常用接口一些操作

标签:

原文地址:http://www.cnblogs.com/systemnet123/p/4964208.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!