切换到宽版
  • 8219阅读
  • 1回复

[分享]Exchange Server 2007 二次开发 (六) [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-02-19
关键词: 服务器exchange

获得某账户的状态:
1public static void GetUserAvailability(ExchangeServiceBinding esb)
2        {
3            // Identify the time to compare free/busy information.
4            Duration duration = new Duration();
5            duration.StartTime = DateTime.Now;
6            duration.EndTime = DateTime.Now.AddHours(4);
7
8            // Identify the options for comparing free/busy information.
9            FreeBusyViewOptionsType fbViewOptions = new FreeBusyViewOptionsType();
10            fbViewOptions.TimeWindow = duration;
11            fbViewOptions.RequestedView = FreeBusyViewType.MergedOnly;
12            fbViewOptions.RequestedViewSpecified = true;
13            fbViewOptions.MergedFreeBusyIntervalInMinutes = 35;
14            fbViewOptions.MergedFreeBusyIntervalInMinutesSpecified = true;
15
16            MailboxData[] mailboxes = new MailboxData[1];
17            mailboxes[0] = new MailboxData();
18
19            // Identify the user mailbox to review for free/busy data.
20            EmailAddress emailAddress = new EmailAddress();
21
22            emailAddress.Address = "邮件地址";
23            emailAddress.Name = String.Empty;
24
25            mailboxes[0].Email = emailAddress;
26            mailboxes[0].ExcludeConflicts = false;
27
28            // Make the request.
29            GetUserAvailabilityRequestType request = new GetUserAvailabilityRequestType();
30
31[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Set the time zone of the request.
32[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone = new SerializableTimeZone();
33[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.Bias = 480;
34[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.StandardTime = new SerializableTimeZoneTime();
35[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.StandardTime.Bias = 0;
36[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.StandardTime.DayOfWeek = DayOfWeekType.Sunday.ToString();
37[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.StandardTime.DayOrder = 1;
38[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.StandardTime.Month = 11;
39[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.StandardTime.Time = "02:00:00";
40[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.DaylightTime = new SerializableTimeZoneTime();
41[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.DaylightTime.Bias = -60;
42[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.DaylightTime.DayOfWeek = DayOfWeekType.Sunday.ToString();
43[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.DaylightTime.DayOrder = 2;
44[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.DaylightTime.Month = 3;
45[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.TimeZone.DaylightTime.Time = "02:00:00";
46[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
47[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Add the mailboxes to the request.
48[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.MailboxDataArray = mailboxes;
49[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
50[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Add the view options to the request.
51[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            request.FreeBusyViewOptions = fbViewOptions;
52[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
53[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            try
54[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]            {
55[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                // Send the request and get the response.
56[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                GetUserAvailabilityResponseType response = esb.GetUserAvailability(request);
57[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
58[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                // Access free/busy information.
59[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                if (response.FreeBusyResponseArray.Length < 1)
60[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                {
61[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                    throw new Exception("No free/busy response data available.");
62[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]                }

63[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                else
64[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                {
65[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                    foreach (FreeBusyResponseType fbrt in response.FreeBusyResponseArray)
66[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                    {
67[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                        if (fbrt.ResponseMessage.ResponseClass == ResponseClassType.Error)
68[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                        {
69[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            Console.WriteLine(string.Format("Error: {0}", fbrt.ResponseMessage.MessageText));
70[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]                        }

71[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                        else
72[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]                        {
73[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            // Show the free/busy stream.
74[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            FreeBusyView fbv = fbrt.FreeBusyView;
75[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                            Console.WriteLine(string.Format("Merged free/busy data: {0}", fbv.MergedFreeBusy));
76[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]                        }

77[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]                    }

78[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]                }

79[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]            }

80[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            catch (Exception e)
81[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]            {
82[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                // Perform error processing.
83[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                Console.WriteLine(e.Message);
84[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                Console.ReadLine();
85[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]            }

86[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif[/img]        }



分享到
只看该作者 1楼  发表于: 2011-03-09
二次开发是充分利用Exchange的最好办法。
快速回复
限60 字节
 
上一个 下一个