当前位置: 首页>>代码示例>>C#>>正文


C# ExchangeService.DeleteItems方法代码示例

本文整理汇总了C#中ExchangeService.DeleteItems方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.DeleteItems方法的具体用法?C# ExchangeService.DeleteItems怎么用?C# ExchangeService.DeleteItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExchangeService的用法示例。


在下文中一共展示了ExchangeService.DeleteItems方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UndoInsertion

        /**
         * Function Undo Holiday Insertion
         */
        static void UndoInsertion(ExchangeService service, List<string> mailboxes)
        {
            // Log file
            string datetimeString = DateTime.Now.ToString("MMddyyyy");
            string logfile = "../../logs/" + datetimeString + "_undo_holiday_log.txt";

            using (System.IO.StreamWriter log = new System.IO.StreamWriter(@logfile, true))
            {

                // Mailboxes that need to be rerun that errored during this process
                List<string> rrmailboxes = new List<string>();

                foreach (string mailbox in mailboxes)
                {

                    // Find the holidays
                    try
                    {
                        // Run search
                        // Impersonate that User
                        service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, mailbox);

                        // Search String
                        String category = "Holiday";
                        // Search Filter
                        SearchFilter.IsEqualTo filter = new SearchFilter.IsEqualTo(AppointmentSchema.Categories, category);

                        // Result Return Size, number of items
                        ItemView holidayView = new ItemView(500);
                        // Limit data to only necesary components
                        holidayView.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Categories);

                        FindItemsResults<Item> items = service.FindItems(WellKnownFolderName.Calendar, filter, holidayView);

                        if (items.TotalCount > 0)
                        {
                            List<ItemId> ids = new List<ItemId>();
                            foreach (Item item in items)
                            {

                                ids.Add(item.Id);

                            }

                            service.DeleteItems(ids, DeleteMode.MoveToDeletedItems, SendCancellationsMode.SendToNone, AffectedTaskOccurrence.AllOccurrences);
                            Console.WriteLine("Removed " + items.TotalCount + " holidays in the Calendar folder for " + mailbox);
                            DateTime now = DateTime.Now;
                            log.WriteLine(now + " - Removed " + items.TotalCount + " holidays in the Calendar folder for " + mailbox);

                        }
                        else
                        {
                            Console.WriteLine("Could not find any holidays for mailbox: " + mailbox);
                        }
                    }
                    catch
                    {

                            log.WriteLine("Mailbox Errored: " + mailbox);
                            rrmailboxes.Add(mailbox);

                    }

                    // Clear impersonation.
                    service.ImpersonatedUserId = null;
                }

                // Rerun errored accounts.

                if (rrmailboxes.Count > 0)
                {
                    Console.WriteLine("Looping through errored mailboxes.");
                }
                while (rrmailboxes.Count > 0)
                {

                    // Run search

                    // Current mailbox
                    string mb = rrmailboxes.ElementAt(0);
                    Console.WriteLine("On Mailbox: " + mb);
                    // Take the mailbox out of the first element slot
                    Console.WriteLine("Removing mailbox " + mb + " from beginning of rrmailboxes.");
                    rrmailboxes.RemoveAt(0);
                    rrmailboxes.TrimExcess();

                    // Find the holidays
                    try
                    {

                        // Impersonate that User
                        service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, mb);

                        // Search String
                        String category = "Holiday";
                        // Search Filter
                        SearchFilter.IsEqualTo filter = new SearchFilter.IsEqualTo(AppointmentSchema.Categories, category);
//.........这里部分代码省略.........
开发者ID:rachelmoorehead,项目名称:rockeagle2013,代码行数:101,代码来源:Program.cs

示例2: BatchDeleteEmailItems

        public static void BatchDeleteEmailItems(ExchangeService service, Collection<ItemId> itemIds)
        {
            // Delete the batch of email message objects.
            // This method call results in an DeleteItem call to EWS.
            ServiceResponseCollection<ServiceResponse> response = service.DeleteItems(itemIds, DeleteMode.SoftDelete, null, AffectedTaskOccurrence.AllOccurrences);

            // Check for success of the DeleteItems method call.
            // DeleteItems returns success even if it does not find all the item IDs.
            if (response.OverallResult == ServiceResult.Success)
            {
                System.Console.WriteLine("Email messages deleted successfully.\r\n");
            }

            // If the method did not return success, print a message.
            else
            {
                System.Console.WriteLine("Not all email messages deleted successfully.\r\n");
            }
        }
开发者ID:fernandoklst,项目名称:Development,代码行数:19,代码来源:Program.cs

示例3: AddHolidays


//.........这里部分代码省略.........
                if (mbs.Count > 0)
                {
                    Console.WriteLine("Looping through re-run mailboxes.");

                    while (mbs.Count > 0)
                    {
                        // Current mailbox
                        string mb = mbs.ElementAt(0);
                        Console.WriteLine("On Mailbox: " + mb);

                        // Take the mailbox out of the first element slot
                        log.WriteLine("Removing mailbox " + mb + " from beginning of mbs.");
                        mbs.RemoveAt(0);
                        mbs.TrimExcess();

                        try
                        {
                            // Reruns: Removes
                            // Run search
                            // Impersonate that User
                            service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, mb);

                            // Search String
                            String category = "Holiday";
                            // Search Filter
                            SearchFilter.IsEqualTo filter = new SearchFilter.IsEqualTo(AppointmentSchema.Categories, category);

                            // Result Return Size, number of items
                            ItemView holidayView = new ItemView(100);
                            // Limit data to only necesary components
                            holidayView.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Categories);

                            FindItemsResults<Item> items = service.FindItems(WellKnownFolderName.Calendar, filter, holidayView);

                            if (items.TotalCount > 0)
                            {

                                Console.WriteLine("Removing " + items.TotalCount + " holidays from " + mb);
                                log.WriteLine("Found " + items.TotalCount + " holidays in the Calendar folder for " + mb + " to be removed.");

                                List<ItemId> ids = new List<ItemId>();
                                foreach (Item item in items)
                                {

                                    ids.Add(item.Id);

                                }

                                service.DeleteItems(ids, DeleteMode.MoveToDeletedItems, null, null);

                            }
                            else
                            {
                                log.WriteLine("Found no holidays in the Calendar folder for " + mb + " to be removed.");
                            }

                            // Rerun: Adds

                            List<Appointment> holidays = new List<Appointment>();

                            // Loop through all the holidays
                            foreach (string[] holiday in holidays)
                            {

                                //Create a new appointment
                                Appointment appointment = new Appointment(service);

                                // Set details
                                appointment.Subject = holiday[0];
                                appointment.Start = DateTime.Parse(holiday[1]);
                                appointment.End = appointment.Start.AddDays(1);
                                appointment.IsAllDayEvent = true;
                                StringList categories = new Microsoft.Exchange.WebServices.Data.StringList();
                                categories.Add("Holiday");
                                appointment.Categories = categories;
                                appointment.IsReminderSet = false;

                                holidays.Add(appointment);

                            }

                            service.CreateItems(holidays, null, null, SendInvitationsMode.SendToNone);
                            Console.WriteLine("Added Holiday Successfully to" + mb);
                            DateTime now = DateTime.Now;
                            log.WriteLine(now + " - Added holidays succesfully to Mailbox: " + mb);

                        }
                        catch
                        {
                            log.WriteLine("Fatal Mailbox Errored on Re-Run Removes: " + mb + "; Will not retry.");
                            Console.WriteLine("Fatal Mailbox Errored on Re-Run Removes: " + mb + "; Will not retry.");
                        }

                        // Clear impersonation.
                        service.ImpersonatedUserId = null;

                    }
                }
            }
        }
开发者ID:rachelmoorehead,项目名称:rockeagle2013,代码行数:101,代码来源:Program.cs


注:本文中的ExchangeService.DeleteItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。