Ejemplo n.º 1
0
        private void LoadForm()
        {
            PropertySet oPropertySet = GetPropSet();

            _ExchangeService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID.
            Folder oFolder = Folder.Bind(_ExchangeService, _FolderId, oPropertySet);
            string sFrom   = EwsExtendedPropertyHelper.GetExtendedProp_Byte_AsString(oFolder, Prop_PR_ARCHIVE_TAG);

            if (sFrom != "")
            {
                byte[] oFromBytes          = System.Convert.FromBase64String(sFrom);
                Guid   guidTemp            = new Guid(oFromBytes);
                string sPR_ARCHIVE_TAG     = guidTemp.ToString();
                string sPR_RETENTION_FLAGS = EwsExtendedPropertyHelper.GetExtendedProp_Int_AsString(oFolder, Prop_PR_RETENTION_FLAGS);
                string sPR_ARCHIVE_PERIOD  = EwsExtendedPropertyHelper.GetExtendedProp_Int_AsString(oFolder, Prop_PR_ARCHIVE_PERIOD);

                txtPR_ARCHIVE_TAG.Text     = sPR_ARCHIVE_TAG;
                txtPR_RETENTION_FLAGS.Text = sPR_RETENTION_FLAGS;
                txtPR_ARCHIVE_PERIOD.Text  = sPR_ARCHIVE_PERIOD;
            }
            else
            {
                txtPR_ARCHIVE_TAG.Text     = "";
                txtPR_RETENTION_FLAGS.Text = "";
                txtPR_ARCHIVE_PERIOD.Text  = "";
            }
        }
        static void FindFoldersWithPolicyTag(ExchangeService oExchangeService,
                                             WellKnownFolderName oParentFolder,
                                             string sPolicyTag,
                                             ref ListView oListView,
                                             FolderTraversal oFolderTraversal)
        {
            int pageSize = 5;
            int offset   = 0;

            FolderView oFolderView = new FolderView(pageSize + 1, offset);
            //ItemView view = new ItemView(pageSize + 1, offset);

            PropertySet oPropertySet = new PropertySet(BasePropertySet.IdOnly);

            oPropertySet.Add(FolderSchema.DisplayName);
            oPropertySet.Add(FolderSchema.FolderClass);

            oPropertySet.Add(Prop_PR_POLICY_TAG);
            oPropertySet.Add(Prop_PR_RETENTION_FLAGS);
            oPropertySet.Add(Prop_PR_RETENTION_PERIOD);

            //oPropertySet.Add(Prop_PR_RETENTION_DATE);
            //oPropertySet.Add(Prop_PR_ARCHIVE_TAG);
            //oPropertySet.Add(Prop_PR_ARCHIVE_PERIOD);
            oPropertySet.Add(FolderSchema.TotalCount);
            oPropertySet.Add(Prop_PR_FOLDER_PATH);
            oPropertySet.Add(Prop_PR_IS_HIDDEN);

            oListView.Columns.Add("Id", 200, HorizontalAlignment.Left);
            oListView.Columns.Add("FolderName", 250, HorizontalAlignment.Left);
            oListView.Columns.Add("Folder Path", 400, HorizontalAlignment.Left);

            oListView.Columns.Add("PR_POLICY_TAG", 100, HorizontalAlignment.Left);
            oListView.Columns.Add("PR_RETENTION_FLAGS", 100, HorizontalAlignment.Left);
            oListView.Columns.Add("PR_RETENTION_Period", 100, HorizontalAlignment.Left);

            oListView.Columns.Add("PR_IS_HIDDEN", 100, HorizontalAlignment.Left);
            oListView.Columns.Add("TotalCount", 100, HorizontalAlignment.Left);

            oFolderView.PropertySet = oPropertySet;


            oFolderView.Traversal = oFolderTraversal;
            string             sPath = string.Empty;;
            FindFoldersResults oFindFoldersResults = null;
            ListViewItem       oListViewItem       = null;
            bool moreItems = true;

            //FolderId anchorId = null;
            while (moreItems)
            {
                try
                {
                    oExchangeService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID.
                    oFindFoldersResults = oExchangeService.FindFolders(oParentFolder, oFolderView);
                    moreItems           = oFindFoldersResults.MoreAvailable;

                    if (moreItems)
                    {
                        oFolderView.Offset += pageSize;
                    }


                    int displayCount = oFindFoldersResults.Folders.Count > pageSize ? pageSize : oFindFoldersResults.Folders.Count;

                    string sPR_POLICY_TAG       = string.Empty;
                    string iPR_RETENTION_FLAGS  = string.Empty;
                    string iPR_RETENTION_PERIOD = string.Empty;

                    //private static ExtendedPropertyDefinition Prop_PR_POLICY_TAG = new ExtendedPropertyDefinition(0x3019, MapiPropertyType.Binary);  // PR_POLICY_TAG 0x3019   Data type: PtypBinary, 0x0102
                    //private static ExtendedPropertyDefinition Prop_PR_RETENTION_FLAGS = new ExtendedPropertyDefinition(0x301D, MapiPropertyType.Integer);   // PR_RETENTION_FLAGS 0x301D
                    //private static ExtendedPropertyDefinition Prop_PR_RETENTION_PERIOD = new ExtendedPropertyDefinition(0x301A, MapiPropertyType.Integer);  // PR_RETENTION_PERIOD 0x301A


                    for (int i = 0; i < displayCount; i++)
                    {
                        Folder oFolder = oFindFoldersResults.Folders[i];
                        //string sResult = EwsExtendedPropertyHelper.GetExtendedProp_Byte_AsString(oFolder, Prop_PR_POLICY_TAG);
                        //sResult = EwsExtendedPropertyHelper.GetExtendedProp_Int_AsString(oFolder, Prop_PR_RETENTION_FLAGS);
                        //sResult = EwsExtendedPropertyHelper.GetExtendedProp_Int_AsString(oFolder, Prop_PR_RETENTION_PERIOD);

                        string sFrom = EwsExtendedPropertyHelper.GetExtendedProp_Byte_AsString(oFolder, Prop_PR_POLICY_TAG);
                        if (sFrom == "")
                        {
                            sPR_POLICY_TAG = "";
                        }
                        else
                        {
                            byte[] oFromBytes = System.Convert.FromBase64String(sFrom);
                            Guid   guidTemp   = new Guid(oFromBytes);
                            sPR_POLICY_TAG = guidTemp.ToString();
                        }
                        string sPR_RETENTION_FLAGS  = EwsExtendedPropertyHelper.GetExtendedProp_Int_AsString(oFolder, Prop_PR_RETENTION_FLAGS);
                        string sPR_RETENTION_PERIOD = EwsExtendedPropertyHelper.GetExtendedProp_Int_AsString(oFolder, Prop_PR_RETENTION_PERIOD);

                        if (sPR_POLICY_TAG != "")
                        {
                            Console.WriteLine("Folder: " + oFolder.DisplayName + "      Policy: " + sPR_POLICY_TAG);
                        }

                        if (sPR_POLICY_TAG == sPolicyTag)
                        {
                            oListViewItem = oListView.Items.Add(oFolder.Id.ToString());
                            oListViewItem.SubItems.Add(oFolder.DisplayName);
                            EwsFolderHelper.GetFolderPath(oFolder, ref sPath);
                            oListViewItem.SubItems.Add(sPath);
                            oListViewItem.SubItems.Add(sPR_POLICY_TAG);   // Policy

                            oListViewItem.SubItems.Add(sPR_RETENTION_FLAGS);
                            oListViewItem.SubItems.Add(sPR_RETENTION_PERIOD);
                            //oListViewItem.SubItems.Add(EwsExtendedPropertyHelper.GetExtendedProp_Byte_AsString(oFolder, Prop_PR_RETENTION_PERIOD).ToString());

                            oListViewItem.SubItems.Add(EwsExtendedPropertyHelper.GetExtendedProp_Bool_AsString(oFolder, Prop_PR_IS_HIDDEN).ToString());

                            oListViewItem.SubItems.Add(FolderSchema.TotalCount.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error while paging results");
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        public static string GetExtendedPropertiesForItemAsCsvContent(
            ExchangeService oExchangeService,
            ItemId oItemId,
            List <ExtendedPropertyDefinition> oExtendedPropertyDefinitions,
            CsvExportOptions oCsvExportOptions
            )
        {
            //AddExtendedPropertPropertyDefinitionsToPropertySet(oExtendedPropertyDefinitions)

            PropertySet oExtendedPropSet = GetExtendedPropertPropertySet(oExtendedPropertyDefinitions);

            string        sExtendedValue = string.Empty;
            StringBuilder oStringBuilder = new StringBuilder();
            int           ix             = 0;

            //// Debug
            //foreach ( ExtendedPropertyDefinition  x in oExtendedPropSet )
            //{
            //    ix++;
            //    if (x.Id == null)
            //        Console.WriteLine("MapiType: " + x.MapiType.ToString() + "  Type: " + x.Type.ToString() + "  PropertySetId" + x.PropertySetId.ToString() + " Count: " + ix.ToString());
            //    else
            //        Console.WriteLine("MapiType: " + x.MapiType.ToString() + "  Type: " + x.Type.ToString() + "  PropertySetId" + x.PropertySetId.ToString() + "  Id:" + x.Id.ToString() + " Count: " + ix.ToString());
            //    if (x.Id == null)
            //        Console.Write("");
            //    else
            //        if (x.Id == 0)
            //             Console.Write("");
            //}

            oExchangeService.ClientRequestId = Guid.NewGuid().ToString();  // Set a new GUID.
            Item oItem = Item.Bind(oExchangeService, oItemId, oExtendedPropSet);

            string sItemLine = string.Empty;

            char[] TrimChars = { ',', ' ' };
            byte[] oFromBytes;

            foreach (ExtendedPropertyDefinition oEPD in oExtendedPropertyDefinitions)
            {
                switch (oEPD.MapiType)
                {
                case MapiPropertyType.Integer:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_Int_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.String:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_String_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.Binary:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_Byte_AsString(oItem, oEPD);
                    if (oCsvExportOptions.HexEncodeBinaryData == true)
                    {
                        //if (oEPD.Id == 0x0005 ||
                        //    oEPD.Id == 0x8223 ||
                        //    oEPD.Id == 0x000C ||
                        //    oEPD.Id == 0x000D ||
                        //    oEPD.Id == 0x000F ||
                        //    oEPD.Id == 0x0019
                        //    )
                        //{
                        //    int a = 0;
                        //    a = 1;
                        //}
                        //byte[] oFromBytes;
                        oFromBytes     = System.Convert.FromBase64String(sExtendedValue); // Base64 to byte array.
                        sExtendedValue = StringHelper.HexStringFromByteArray(oFromBytes, false);
                    }
                    break;

                case MapiPropertyType.Long:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_Long_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.Boolean:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_Bool_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.SystemTime:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_DateTime_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.Short:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_Short_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.Float:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_Float_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.IntegerArray:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_IntArr_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.StringArray:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_StringArr_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.BinaryArray:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_ByteArr_AsString(oItem, oEPD);

                    break;

                case MapiPropertyType.LongArray:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_LongArr_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.SystemTimeArray:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_DateTimeArr_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.ShortArray:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_ShortArr_AsString(oItem, oEPD);
                    break;

                case MapiPropertyType.FloatArray:
                    sExtendedValue = EwsExtendedPropertyHelper.GetExtendedProp_FloatArr_AsString(oItem, oEPD);
                    break;

                default:
                    sExtendedValue = "";
                    break;
                }  // end switch

                if (sExtendedValue == null)
                {
                    sExtendedValue = "";
                }


                // String  Handling
                if (oCsvExportOptions._CsvStringHandling != CsvStringHandling.None)
                {
                    sExtendedValue = DoStringHandling(sExtendedValue, oCsvExportOptions._CsvStringHandling);
                }

                //// Hex encode binary (base64 encoded) data.
                //if (oCsvExportOptions.HexEncodeBinaryData == true)
                //{
                //    //bColumnIsByteArray = StringHelper.IsBase64Encoded(s);
                //    if (StringHelper.IsBase64Encoded(sExtendedValue) == true)
                //    {
                //        oFromBytes = System.Convert.FromBase64String(sExtendedValue); // Base64 to byte array.
                //        sExtendedValue = StringHelper.HexStringFromByteArray(oFromBytes, false);
                //    }
                //}



                oStringBuilder.Append(sExtendedValue);
                oStringBuilder.Append(",");


                if (sExtendedValue.Trim().Length != 0)
                {
                    System.Diagnostics.Debug.WriteLine("Warning - Should not have reached this line");
                }
            }  // end foreach

            sItemLine = oStringBuilder.ToString();
            sItemLine = sItemLine.TrimEnd(TrimChars);
            return(sItemLine);
        }