protected override void ProcessRecord() { if (!(this.CalendarFolder is CalendarFolder)) this.WriteWarning("Provided folder is not Calendar folder. Category list can be only stored in Calendar folder."); else { try { CalendarFolder calendarFolder = (CalendarFolder)this.CalendarFolder; UserConfiguration ewsMasterCategoryConfiguration = UserConfiguration.Bind(this.EwsSession, "CategoryList", calendarFolder.Id, UserConfigurationProperties.All); string categoryListDefinition = EwsHelper.GetStringFromByte(ewsMasterCategoryConfiguration.XmlData); if (string.IsNullOrEmpty(categoryListDefinition)) { StringBuilder xmlBuilder = new StringBuilder(); xmlBuilder.AppendLine("<?xml version=\"1.0\"?>"); xmlBuilder.AppendLine("<categories default=\"\" lastSavedSession=\"\" lastSavedTime=\"\" xmlns=\"CategoryList.xsd\">"); xmlBuilder.AppendLine("</categories>"); categoryListDefinition = xmlBuilder.ToString(); } EwsCategoryList ewsCategoryList = new EwsCategoryList(categoryListDefinition); List<EwsCategory> currentCategories = ewsCategoryList.ReadCategory(); foreach (EwsCategory category in currentCategories) { if (this.Categories.Contains(category)) this.Categories.Remove(category); } string newCategories = ewsCategoryList.InsertElement(this.Categories); byte[] xmlData = Encoding.UTF8.GetBytes(newCategories); EwsCategory.UpdateCategoryList(this.EwsSession, this.CalendarFolder.Id, xmlData); } catch (Exception e) { throw new InvalidOperationException(e.Message); } } }
protected override void ProcessRecord() { if (this.CalendarFolder is CalendarFolder) { try { CalendarFolder calendarFolder = (CalendarFolder)this.CalendarFolder; UserConfiguration ewsMasterCategoryConfiguration = UserConfiguration.Bind(this.EwsSession, "CategoryList", calendarFolder.Id, UserConfigurationProperties.All); if (this.RawData.IsPresent) this.WriteObject(ewsMasterCategoryConfiguration); else { string categoryListDefinition = EwsHelper.GetStringFromByte(ewsMasterCategoryConfiguration.XmlData); if (string.IsNullOrEmpty(categoryListDefinition)) this.WriteObject(ewsMasterCategoryConfiguration); else { EwsCategoryList ewsCategoryList = new EwsCategoryList(categoryListDefinition); this.WriteObject(ewsCategoryList.ReadCategory(), true); } } } catch (ServiceResponseException responseException) { if (responseException.ErrorCode == ServiceError.ErrorItemNotFound) this.WriteWarning("CategoryList item not found in specified calendar folder."); else this.WriteWarning(responseException.Message); } catch (Exception exception) { throw new InvalidOperationException(exception.Message); } } else this.WriteWarning("Provided folder is not calendar folder. Please specify calendar folder since Category list is stored in Calendar."); }