示例#1
0
        private async void dataGridView_ItemList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            // Get the item ID of clicked row.
            string id = dataGridView_ItemList.Rows[e.RowIndex].Tag.ToString();

            client = await GetOutlookServiceClient();

            var results = await client.Me.Messages[id].ExecuteAsync();

            // Create columns
            dataGridView_ItemProps.Rows.Clear();

            try
            {
                foreach (var prop in results.GetType().GetProperties())
                {
                    DataGridViewRow propRow = new DataGridViewRow();

                    string propName  = prop.Name;
                    string propValue = "";
                    string propType  = "";

                    if (prop.GetIndexParameters().Length == 0)
                    {
                        try
                        {
                            var tempValue = prop.GetValue(results);
                            propType = tempValue.GetType().ToString();

                            if (tempValue is DateTimeOffset)
                            {
                                DateTimeOffset dateTimeOffsetValue = (DateTimeOffset)tempValue;
                                propValue = dateTimeOffsetValue.DateTime.ToString("yyyy/MM/dd HH:mm:ss");
                            }
                            else if (tempValue is ItemBody)
                            {
                                ItemBody itemBodyValue = (ItemBody)tempValue;
                                propValue = itemBodyValue.Content;
                            }
                            else if (tempValue is Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <Recipient> )
                            {
                                Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <Recipient> recipientValue = (Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <Recipient>)tempValue;

                                foreach (Recipient recipient in recipientValue)
                                {
                                    propValue += recipient.EmailAddress.Name + "<" + recipient.EmailAddress.Address + ">; ";
                                }

                                propValue = propValue.TrimEnd(new char[] { ';', ' ' });
                            }
                            else if (tempValue is Microsoft.OData.ProxyExtensions.EntityCollectionImpl <Attachment> )
                            {
                                // To get the list of attachments, we have to send a request again.
                                // We don't do that and prepare an attachment view.

                                continue;
                            }
                            else if (tempValue is Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <string> )
                            {
                                Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <string> stringValue = (Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <string>)tempValue;

                                foreach (string value in stringValue)
                                {
                                    propValue += value + "; ";
                                }

                                propValue = propValue.TrimEnd(new char[] { ';', ' ' });
                            }
                            else
                            {
                                propValue = tempValue.ToString();
                            }
                        }
                        catch
                        {
                            propValue = "";
                        }
                    }
                    else
                    {
                        propValue = "indexed";
                    }

                    propRow.CreateCells(dataGridView_ItemProps, new object[] { propName, propValue, propType });

                    if (dataGridView_ItemProps.InvokeRequired)
                    {
                        dataGridView_ItemProps.Invoke(new MethodInvoker(delegate
                        {
                            dataGridView_ItemProps.Rows.Add(propRow);
                        }));
                    }
                    else
                    {
                        dataGridView_ItemProps.Rows.Add(propRow);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
        private void CreatePropTable(object itemResult)
        {
            try
            {
                foreach (var prop in itemResult.GetType().GetProperties())
                {
                    DataGridViewRow propRow = new DataGridViewRow();

                    string propName  = prop.Name;
                    string propValue = "";
                    string propType  = "";

                    if (prop.GetIndexParameters().Length == 0)
                    {
                        try
                        {
                            var tempValue = prop.GetValue(itemResult);
                            propType = tempValue.GetType().ToString();

                            if (tempValue is DateTimeOffset)
                            {
                                DateTimeOffset dateTimeOffsetValue = (DateTimeOffset)tempValue;
                                propValue = dateTimeOffsetValue.DateTime.ToString("yyyy/MM/dd HH:mm:ss");
                            }
                            else if (tempValue is ItemBody)
                            {
                                ItemBody itemBodyValue = (ItemBody)tempValue;
                                propValue = itemBodyValue.Content;
                            }
                            else if (tempValue is Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <Recipient> )
                            {
                                Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <Recipient> recipientValue = (Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <Recipient>)tempValue;

                                foreach (Recipient recipient in recipientValue)
                                {
                                    propValue += recipient.EmailAddress.Name + "<" + recipient.EmailAddress.Address + ">; ";
                                }

                                propValue = propValue.TrimEnd(new char[] { ';', ' ' });
                            }
                            else if (tempValue is Microsoft.OData.ProxyExtensions.EntityCollectionImpl <Attachment> )
                            {
                                // To get the list of attachments, we have to send a request again.
                                // We don't do that and prepare an attachment view.

                                continue;
                            }
                            else if (tempValue is Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <string> )
                            {
                                Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <string> stringValue = (Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <string>)tempValue;

                                foreach (string value in stringValue)
                                {
                                    propValue += value + "; ";
                                }

                                propValue = propValue.TrimEnd(new char[] { ';', ' ' });
                            }
                            else if (tempValue is Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <EmailAddress> )
                            {
                                Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <EmailAddress> emailAddressValue = (Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <EmailAddress>)tempValue;

                                foreach (EmailAddress emailAddress in emailAddressValue)
                                {
                                    propValue += emailAddress.Name + "<" + emailAddress.Address + ">; ";
                                }

                                propValue = propValue.TrimEnd(new char[] { ';', ' ' });
                            }
                            else if (tempValue is PhysicalAddress)
                            {
                                PhysicalAddress physicalAddressValue = (PhysicalAddress)tempValue;
                                propValue = physicalAddressValue.PostalCode + " " + physicalAddressValue.Street + " " + physicalAddressValue.City + " " + physicalAddressValue.State + " " + physicalAddressValue.CountryOrRegion;
                            }
                            else if (tempValue is ResponseStatus)
                            {
                                ResponseStatus responseStatusValue = (ResponseStatus)tempValue;

                                if (responseStatusValue.Time.HasValue)
                                {
                                    propValue = responseStatusValue.Time.Value.DateTime.ToString("yyyy/MM/dd HH:mm:ss") + " ";
                                }

                                propValue += responseStatusValue.Response.ToString();
                            }
                            else if (tempValue is DateTimeTimeZone)
                            {
                                DateTimeTimeZone dateTimeTimeZoneValue = (DateTimeTimeZone)tempValue;
                                propValue = dateTimeTimeZoneValue.TimeZone + " " + dateTimeTimeZoneValue.DateTime;
                            }
                            else if (tempValue is Location)
                            {
                                Location locationValue = (Location)tempValue;
                                propValue = locationValue.DisplayName;
                            }
                            else if (tempValue is Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <Attendee> )
                            {
                                Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <Attendee> attendeeValue = (Microsoft.OData.ProxyExtensions.NonEntityTypeCollectionImpl <Attendee>)tempValue;

                                foreach (Recipient attendee in attendeeValue)
                                {
                                    propValue += attendee.EmailAddress.Name + "<" + attendee.EmailAddress.Address + ">; ";
                                }

                                propValue = propValue.TrimEnd(new char[] { ';', ' ' });
                            }
                            else if (tempValue is Recipient)
                            {
                                Recipient recipientValue = (Recipient)tempValue;
                                propValue = recipientValue.EmailAddress.Name + "<" + recipientValue.EmailAddress.Address + ">";
                            }
                            else if (tempValue is Microsoft.OData.ProxyExtensions.EntityCollectionImpl <Event> )
                            {
                                // I'm not sure what this prop is.
                                // This prop has a Nested structure.
                                continue;
                            }
                            else
                            {
                                propValue = tempValue.ToString();
                            }
                        }
                        catch
                        {
                            propValue = "";
                        }
                    }
                    else
                    {
                        propValue = "indexed";
                    }

                    propRow.CreateCells(dataGridView_ItemProps, new object[] { propName, propValue, propType });

                    if (dataGridView_ItemProps.InvokeRequired)
                    {
                        dataGridView_ItemProps.Invoke(new MethodInvoker(delegate
                        {
                            dataGridView_ItemProps.Rows.Add(propRow);
                        }));
                    }
                    else
                    {
                        dataGridView_ItemProps.Rows.Add(propRow);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Office365APIEditor");
            }
        }