Esempio n. 1
0
        public async Task CreateNewMeeting()
        {
            try
            {
                Microsoft.Graph.Event evt = new Microsoft.Graph.Event();

                Location location = new Location();
                location.DisplayName = tbLocation.Text;

                ItemBody body = new ItemBody();
                body.Content     = tbBody.Text;
                body.ContentType = BodyType.Html;

                List <Attendee> attendees = new List <Attendee>();
                Attendee        attendee  = new Attendee();
                EmailAddress    email     = new EmailAddress();
                email.Address         = tbToRecipients.Text;
                attendee.EmailAddress = email;
                attendee.Type         = AttendeeType.Required;
                attendees.Add(attendee);

                evt.Subject   = tbSubject.Text;
                evt.Body      = body;
                evt.Location  = location;
                evt.Attendees = attendees;

                DateTimeTimeZone dtStart = new DateTimeTimeZone();
                dtStart.TimeZone = TimeZoneInfo.Local.Id;
                DateTime dts = dtpStartDate.Value.Date + dtpStartTime.Value.TimeOfDay;
                dtStart.DateTime = dts.ToString();

                DateTimeTimeZone dtEnd = new DateTimeTimeZone();
                dtEnd.TimeZone = TimeZoneInfo.Local.Id;
                DateTime dte = dtpEndDate.Value.Date + dtpEndTime.Value.TimeOfDay;
                dtEnd.DateTime = dte.ToString();

                evt.Start = dtStart;
                evt.End   = dtEnd;

                // log the request info
                sdklogger.Log(graphClient.Me.Events.Request().GetHttpRequestMessage().Headers.ToString());
                sdklogger.Log(graphClient.Me.Events.Request().GetHttpRequestMessage().RequestUri.ToString());

                // send the new message
                var createdEvent = await graphClient.Me.Events.Request().AddAsync(evt);

                // log the send and associated id
                sdklogger.Log("Meeting Sent : Id = " + createdEvent.Id);
            }
            catch (Exception ex)
            {
                sdklogger.Log("NewMeetingSend Failed: " + ex.Message);
                sdklogger.Log(ex.Message);
            }
            finally
            {
                // close the form
                Close();
            }
        }
Esempio n. 2
0
        public async Task CreateNewContact()
        {
            try
            {
                // create contact and get names
                Microsoft.Graph.Contact contact = new Microsoft.Graph.Contact();
                contact.GivenName  = tbFName.Text;
                contact.Surname    = tbLName.Text;
                contact.MiddleName = tbMName.Text;

                // check for email addresses
                if (tbEmailAddress1.Text != "")
                {
                    AddEmailAddressToCollection(tbEmailAddress1.Text);
                }

                if (tbEmailAddress1.Text != "")
                {
                    AddEmailAddressToCollection(tbEmailAddress2.Text);
                }

                if (tbEmailAddress1.Text != "")
                {
                    AddEmailAddressToCollection(tbEmailAddress3.Text);
                }

                // set the addresses for the contact
                contact.EmailAddresses = emailAddresses;

                // get phone numbers
                contact.MobilePhone = tbMobilePhone.Text;
                businessPhones.Add(tbBusinessPhone.Text);
                homePhones.Add(tbHomePhone.Text);
                contact.BusinessPhones = businessPhones;
                contact.HomePhones     = homePhones;

                // get company info
                contact.JobTitle    = tbTitle.Text;
                contact.CompanyName = tbCompany.Text;
                contact.FileAs      = tbFileAs.Text;

                // log the request info
                sdklogger.Log(graphClient.Me.Contacts.Request().GetHttpRequestMessage().Headers.ToString());
                sdklogger.Log(graphClient.Me.Contacts.Request().GetHttpRequestMessage().RequestUri.ToString());

                // sent the new contact request
                await graphClient.Me.Contacts.Request().AddAsync(contact);
            }
            catch (Exception ex)
            {
                sdklogger.Log("NewContactSend Failed: " + ex.Message);
                sdklogger.Log(ex.Message);
            }
            finally
            {
                // close the form
                Close();
            }
        }
Esempio n. 3
0
 public void GetAppTokenWithSecret()
 {
     try
     {
         _lastOAuthResult = Task.Run(async() => await OAuthHelper.GetApplicationToken(ApplicationId, TenantId, ClientSecret)).Result;
         _logger?.Log($"Token obtained, expires {_lastOAuthResult.ExpiresOn}");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Unable to acquire token", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Deserialize the object from XML storage
        /// </summary>
        /// <param name="xmlData"></param>
        public override void FromXml(System.Xml.XmlNode xmlData)
        {
            DateTime Start = Debug.ExecStart;

            base.FromXml(xmlData);
            this._Path = xmlData.SelectSingleNode(XmlPropPath).InnerText;
            ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), "");
        }
Esempio n. 5
0
        public void LogCredentials(ClassLogger Logger)
        {
            StringBuilder sCredentialInfo = new StringBuilder();

            switch (_authType)
            {
            case AuthType.Default:
                sCredentialInfo.AppendLine("Using default credentials");
                sCredentialInfo.Append("Username: "******"Domain: ");
                sCredentialInfo.AppendLine(Environment.UserDomainName);
                break;

            case AuthType.Basic:
                sCredentialInfo.AppendLine("Using specific credentials");
                sCredentialInfo.Append("Username: "******"Domain: ");
                sCredentialInfo.AppendLine(Domain);
                break;

            case AuthType.Certificate:
                sCredentialInfo.AppendLine("Using certificate");
                if (_certificate != null)
                {
                    sCredentialInfo.Append("Subject: ");
                    sCredentialInfo.AppendLine(_certificate.Subject);
                }
                else
                {
                    sCredentialInfo.AppendLine("NO CERTIFICATE SPECIFIED");
                }
                break;

            case AuthType.OAuth:
                sCredentialInfo.AppendLine("Using OAuth");
                if (_lastOAuthResult != null)
                {
                    sCredentialInfo.AppendLine($"Current access token expiry: {_lastOAuthResult.ExpiresOn}");
                }
                break;
            }

            Logger.Log(sCredentialInfo.ToString(), "Request Credentials");
        }
        /// <summary>
        /// Deserialize the instance from XML
        /// </summary>
        /// <param name="xmlData"></param>
        public override void FromXml(XmlNode xmlData)
        {
            DateTime Start = Debug.ExecStart;

            try { base.FromXml(xmlData); }
            catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load base instance data."), null); }
            try { this._Server = xmlData.SelectSingleNode(XmlPropServ).InnerText; }
            catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load FTP server."), null); }
            try { this._Path = xmlData.SelectSingleNode(XmlPropPath).InnerText; }
            catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load FTP path."), null); }
            try { this._Username = xmlData.SelectSingleNode(XmlPropUser).InnerText; }
            catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load FTP username."), null); }
            try { this._Password = xmlData.SelectSingleNode(XmlPropPass).InnerText; }
            catch { ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, "Cannot load FTP password."), null); }

            ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), "");
        }
Esempio n. 7
0
        public void Logout()
        {
            try
            {
                if (rdoGraphAPI.Checked)
                {
                    // clear the token cache
                    authContext.TokenCache.Clear();

                    // check for cache type
                    if (Properties.Settings.Default.TokenCache == "File")
                    {
                        fc.Clear();
                    }
                    else
                    {
                        // clear cookies from browser control
                        ClearCookies();
                    }

                    // clear the user info
                    user.Clear();
                }
                else
                {
                    // reset basic auth controls
                    passwordEntered     = null;
                    userNameEntered     = null;
                    tbUsername.Enabled  = true;
                    mskPassword.Enabled = true;
                    ToggleButtons();
                    ToggleRdoButtons();
                }
            }
            catch (Exception ex)
            {
                applogger.Log(ex.Message);
            }
            finally
            {
                // reset UI text
                ToggleRdoButtons();
                ToggleButtons();
                lblUsername.Text    = "No User Logged In";
                btnLoginLogout.Text = "Login";
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Serialize the object to XML
        /// </summary>
        /// <returns></returns>
        public override System.Xml.XmlDocument ToXml()
        {
            DateTime Start = Debug.ExecStart;

            System.Xml.XmlDocument xmlDoc = base.ToXml();

            System.Xml.XmlElement xmlTypeEl = xmlDoc.CreateElement(XmlPropType);
            System.Xml.XmlNode    xmlType   = xmlDoc.CreateNode(System.Xml.XmlNodeType.Text, XmlPropType, String.Empty);
            xmlType.Value = this.GetType().ToString();
            xmlTypeEl.AppendChild(xmlType);

            System.Xml.XmlElement xmlPathEl = xmlDoc.CreateElement(XmlPropPath);
            System.Xml.XmlNode    xmlPath   = xmlDoc.CreateNode(System.Xml.XmlNodeType.Text, XmlPropPath, String.Empty);
            xmlPath.Value = Path;
            xmlPathEl.AppendChild(xmlPath);

            xmlDoc.ChildNodes[0].AppendChild(xmlTypeEl);
            xmlDoc.ChildNodes[0].AppendChild(xmlPathEl);

            ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), "");
            return(xmlDoc);
        }
        /// <summary>
        /// Seralize the instance to XML
        /// </summary>
        /// <returns></returns>
        public override System.Xml.XmlDocument ToXml()
        {
            DateTime Start = Debug.ExecStart;

            try
            {
                XmlDocument xmlDoc = base.ToXml();

                xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropType, this.GetType().ToString()));
                xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropServ, Server));
                xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropPath, Path));
                xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropUser, Username));
                xmlDoc.ChildNodes[0].AppendChild(XMLOps.createXmlNode(xmlDoc, XmlPropPass, Password));

                ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), "");
                return(xmlDoc);
            }
            catch (Exception Ex)
            {
                ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null);
                return(null);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Retrieve the instance's log files
        /// </summary>
        public override void Retrieve()
        {
            DateTime Start = Debug.ExecStart;

            // Don't retrieve data if we only retrieved successfully less than a minute ago
            if ((LastRetrievalTime + new TimeSpan(0, 1, 0)) > DateTime.Now)
            {
                return;
            }

            if (MakeInstanceDir())
            {
                // Retrieve FAHLog.txt (or equivalent)
                System.IO.FileInfo fiLog      = new System.IO.FileInfo(_Path + "\\" + RemoteFAHLogFilename);
                String             FAHLog_txt = base.BaseDirectory + LocalFAHLog;
                try { fiLog.CopyTo(FAHLog_txt, true); }
                catch (Exception Ex)
                {
                    ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null);
                    return;
                }

                // Retrieve UnitInfo.txt (or equivalent)
                System.IO.FileInfo fiUI         = new System.IO.FileInfo(_Path + "\\" + RemoteUnitInfoFilename);
                String             UnitInfo_txt = base.BaseDirectory + LocalUnitInfo;
                try { fiUI.CopyTo(UnitInfo_txt, true); }
                catch (Exception Ex)
                {
                    ClassLogger.LogException(LogLevel.Error, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null);
                    return;
                }

                base.Retrieve();
            }

            ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), "");
        }
Esempio n. 11
0
        public void TestClassLoggerLevel()
        {
            TheLog.FilterThreshold = LogLevel.Trace;
            TheLog.AddProvider(InMemoryDatabaseProvider.TheOne, LogLevel.Trace);
            var database = InMemoryDatabaseProvider.TheOne;

            var classLogger = new ClassLogger(typeof(LoggingTests));

            classLogger.Trace("Test");
            Assert.AreEqual(LogLevel.Trace, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Debug("Test");
            Assert.AreEqual(LogLevel.Debug, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Info("Test");
            Assert.AreEqual(LogLevel.Info, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Warn("Test");
            Assert.AreEqual(LogLevel.Warn, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Error("Test");
            Assert.AreEqual(LogLevel.Error, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
            classLogger.Fatal("Test");
            Assert.AreEqual(LogLevel.Fatal, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);

            classLogger.Log(LogLevel.Debug, "Message");
            Assert.AreEqual(LogLevel.Debug, database.Messages[database.Messages.Count - 1].LogMessage.LogLevel);
        }
        public AttachmentsForm(string id, List <FileAttachment> fAttachments, List <ItemAttachment> iAttachments, List <ReferenceAttachment> rAttachments, ref ClassLogger appLogger)
        {
            InitializeComponent();
            applogger = appLogger;

            // init dictionaries
            dAdditionalFileData = new Dictionary <string, object>();
            dAdditionalItemData = new Dictionary <string, object>();
            dAdditionalRefData  = new Dictionary <string, object>();
            dContentBytes       = new Dictionary <string, byte[]>();

            try
            {
                Cursor = Cursors.WaitCursor;

                if (fAttachments != null)
                {
                    foreach (var fItem in fAttachments)
                    {
                        // populate the grid view for file attachments
                        int n = dgFileAttachments.Rows.Add();
                        if (fItem.ContentBytes != null)
                        {
                            dgFileAttachments.Rows[n].Cells[0].Value = "View Data";
                            dContentBytes.Add(fItem.Id, fItem.ContentBytes);
                        }
                        dgFileAttachments.Rows[n].Cells[1].Value = fItem.ContentId;
                        dgFileAttachments.Rows[n].Cells[2].Value = fItem.ContentLocation;
                        dgFileAttachments.Rows[n].Cells[3].Value = fItem.ContentType;
                        dgFileAttachments.Rows[n].Cells[4].Value = fItem.LastModifiedDateTime;
                        dgFileAttachments.Rows[n].Cells[5].Value = fItem.Id;
                        dgFileAttachments.Rows[n].Cells[6].Value = fItem.IsInline.ToString();
                        dgFileAttachments.Rows[n].Cells[7].Value = fItem.Name;
                        dgFileAttachments.Rows[n].Cells[8].Value = AttachmentHelper.SizeSuffix(fItem.Size.Value);

                        if (fItem.AdditionalData != null)
                        {
                            dgFileAttachments.Rows[n].Cells[9].Value = "View Data";
                            foreach (var data in fItem.AdditionalData)
                            {
                                dAdditionalFileData.Add(data.Key, data.Value);
                            }
                        }
                    }
                }

                if (iAttachments != null)
                {
                    // populate the grid for item attachments
                    foreach (var iItem in iAttachments)
                    {
                        int m = dgItemAttachments.Rows.Add();
                        dgItemAttachments.Rows[m].Cells[0].Value = iItem.ContentType;
                        dgItemAttachments.Rows[m].Cells[1].Value = iItem.LastModifiedDateTime;
                        dgItemAttachments.Rows[m].Cells[2].Value = iItem.Id;
                        dgItemAttachments.Rows[m].Cells[3].Value = iItem.Item;
                        dgItemAttachments.Rows[m].Cells[4].Value = iItem.IsInline.ToString();
                        dgItemAttachments.Rows[m].Cells[5].Value = iItem.Name;
                        dgItemAttachments.Rows[m].Cells[6].Value = AttachmentHelper.SizeSuffix(iItem.Size.Value);

                        if (iItem.AdditionalData != null)
                        {
                            dgItemAttachments.Rows[m].Cells[7].Value = "View Data";
                            foreach (var data in iItem.AdditionalData)
                            {
                                dAdditionalItemData.Add(data.Key, data.Value);
                            }
                        }
                    }
                }

                if (rAttachments != null)
                {
                    // populate the grid for reference attachments
                    foreach (var iItem in rAttachments)
                    {
                        int m = dgRefAttachments.Rows.Add();
                        dgRefAttachments.Rows[m].Cells[0].Value = iItem.ContentType;
                        dgRefAttachments.Rows[m].Cells[1].Value = iItem.LastModifiedDateTime;
                        dgRefAttachments.Rows[m].Cells[2].Value = iItem.Id;
                        dgRefAttachments.Rows[m].Cells[3].Value = iItem.IsInline.ToString();
                        dgRefAttachments.Rows[m].Cells[4].Value = iItem.Name;
                        dgRefAttachments.Rows[m].Cells[5].Value = AttachmentHelper.SizeSuffix(iItem.Size.Value);

                        if (iItem.AdditionalData != null)
                        {
                            dgRefAttachments.Rows[m].Cells[6].Value = "View Data";
                            foreach (var data in iItem.AdditionalData)
                            {
                                dAdditionalRefData.Add(data.Key, data.Value);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                applogger.Log("ctor exception:");
                applogger.Log(ex.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
 private void copyToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         int x = dgFileAttachments.CurrentCell.RowIndex;
         int y = dgFileAttachments.CurrentCell.ColumnIndex;
         Clipboard.SetText(dgFileAttachments.Rows[x].Cells[y].Value.ToString());
     }
     catch (NullReferenceException nre)
     {
         applogger.Log("Copy Error: ");
         applogger.Log(nre.Message);
     }
     catch (Exception ex)
     {
         applogger.Log("Copy Error: " + ex.Message);
         applogger.Log(ex.Message);
     }
 }
Esempio n. 14
0
        private async Task GetFoldersAsync()
        {
            try
            {
                // adjust UI so user knows work is happening
                Cursor = Cursors.WaitCursor;

                // log the request
                sdklogger.Log("REQUEST");
                sdklogger.Log(graphClient.Me.MailFolders.Request().GetHttpRequestMessage().ToString());
                sdklogger.Log(graphClient.Me.MailFolders.Request().GetHttpRequestMessage().RequestUri.ToString());

                // get the folders
                var mailFolders = await graphClient.Me.MailFolders.Request()
                                  .Expand("childfolders")
                                  .Top(100)
                                  .GetAsync();

                // clear any previous tree view
                tvwFolders.Nodes.Clear();

                // loop parent folders
                foreach (var mailFolder in mailFolders.CurrentPage)
                {
                    // populate folder ids in the local dictionary
                    // any requests for a specific folder need to use Id, not display name
                    dFolderIds.Add(mailFolder.DisplayName, mailFolder.Id);

                    // need to check each folder for child folders
                    AddFoldersToTree(mailFolder);
                }
            }
            catch (ServiceException se)
            {
                sdklogger.Log("Mail:GetFoldersAsync ServiceException:");
                sdklogger.Log(se.Message);
                sdklogger.Log(se.StackTrace);
            }
            catch (Exception ex)
            {
                sdklogger.Log("Mail:GetFoldersAsync Exception:");
                sdklogger.Log(ex.Message);
                sdklogger.Log(ex.StackTrace);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Esempio n. 15
0
        private void dgMessages_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                // get the selected item Id
                string mId = dgMessages.Rows[e.RowIndex].Cells[(int)columns.Id].Value.ToString();

                // open the associated form based on the selected column
                if (e.ColumnIndex == (int)columns.To)
                {
                    // create a temp recip collection
                    List <Recipient> tRecips = null;

                    // loop through the cached dictionary values
                    foreach (KeyValuePair <string, List <Recipient> > pair in dRecips)
                    {
                        // if the value matches the selected item id
                        // add it to the temp dictionary
                        if (pair.Key == mId)
                        {
                            tRecips = pair.Value;
                        }
                    }

                    // pass the temp dictionary to the form
                    RecipientCollection mRecipients = new RecipientCollection(mId, tRecips);
                    mRecipients.Owner = this;
                    mRecipients.ShowDialog(this);
                }

                if (e.ColumnIndex == (int)columns.Attachments)
                {
                    if (dFileAttachments.Count > 0 || dItemAttachments.Count > 0)
                    {
                        List <FileAttachment>      tFileAttachments = null;
                        List <ItemAttachment>      tItemAttachments = null;
                        List <ReferenceAttachment> tRefAttachments  = null;

                        foreach (KeyValuePair <string, List <FileAttachment> > pair in dFileAttachments)
                        {
                            if (pair.Key == mId)
                            {
                                tFileAttachments = pair.Value;
                            }
                        }

                        foreach (KeyValuePair <string, List <ItemAttachment> > pair in dItemAttachments)
                        {
                            if (pair.Key == mId)
                            {
                                tItemAttachments = pair.Value;
                            }
                        }

                        foreach (KeyValuePair <string, List <ReferenceAttachment> > pair in dReferenceAttachments)
                        {
                            if (pair.Key == mId)
                            {
                                tRefAttachments = pair.Value;
                            }
                        }

                        AttachmentsForm mAttachment = new AttachmentsForm(mId, tFileAttachments, tItemAttachments, tRefAttachments, ref applogger);
                        mAttachment.Owner = this;
                        mAttachment.ShowDialog(this);
                    }
                }

                if (e.ColumnIndex == (int)columns.Bcc)
                {
                    List <Recipient> tRecips = null;

                    foreach (KeyValuePair <string, List <Recipient> > pair in dBcc)
                    {
                        if (pair.Key == mId)
                        {
                            tRecips = pair.Value;
                        }
                    }

                    RecipientCollection mRecipients = new RecipientCollection(mId, tRecips);
                    mRecipients.Owner = this;
                    mRecipients.ShowDialog(this);
                }

                if (e.ColumnIndex == (int)columns.Cc)
                {
                    List <Recipient> tRecips = null;

                    foreach (KeyValuePair <string, List <Recipient> > pair in dCc)
                    {
                        if (pair.Key == mId)
                        {
                            tRecips = pair.Value;
                        }
                    }

                    RecipientCollection mRecipients = new RecipientCollection(mId, tRecips);
                    mRecipients.Owner = this;
                    mRecipients.ShowDialog(this);
                }

                if (e.ColumnIndex == (int)columns.ReplyTo)
                {
                    List <Recipient> tRecips = null;

                    foreach (KeyValuePair <string, List <Recipient> > pair in dReplyTo)
                    {
                        if (pair.Key == mId)
                        {
                            tRecips = pair.Value;
                        }
                    }

                    RecipientCollection mRecipients = new RecipientCollection(mId, tRecips);
                    mRecipients.Owner = this;
                    mRecipients.ShowDialog(this);
                }

                if (e.ColumnIndex == (int)columns.Body)
                {
                    List <ItemBody> lBody = null;
                    foreach (KeyValuePair <string, List <ItemBody> > pair in dItemBody)
                    {
                        if (pair.Key == mId)
                        {
                            lBody = pair.Value;
                        }
                    }

                    ItemBodyForm mItemBodyCollection = new ItemBodyForm(mId, lBody);
                    mItemBodyCollection.Owner = this;
                    mItemBodyCollection.ShowDialog(this);
                }

                if (e.ColumnIndex == (int)columns.Categories)
                {
                    List <string> lCategories = null;
                    foreach (KeyValuePair <string, List <string> > pair in dCategories)
                    {
                        if (pair.Key == mId)
                        {
                            lCategories = pair.Value;
                        }
                    }

                    CategoriesForm mCategories = new CategoriesForm(lCategories);
                    mCategories.Owner = this;
                    mCategories.ShowDialog(this);
                }
            }
            catch (Exception ex)
            {
                applogger.Log("Double-click Error:");
                applogger.Log(ex.Message);
            }
        }
        private async Task GetFoldersAsync()
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                sdklogger.Log("REQUEST");
                sdklogger.Log(graphClient.Me.ContactFolders.Request().GetHttpRequestMessage().ToString());
                sdklogger.Log(graphClient.Me.ContactFolders.Request().GetHttpRequestMessage().RequestUri.ToString());

                var contactFolders = await graphClient.Me.ContactFolders.Request()
                                     .GetAsync();

                foreach (var contactFolder in contactFolders.CurrentPage)
                {
                    cmbFolders.Items.Add(contactFolder.DisplayName);
                    cmbFolders.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                sdklogger.Log("Contacts:GetFolderAsync Exception:");
                sdklogger.Log(ex.ToString());
                sdklogger.Log(ex.Message);
                sdklogger.Log(ex.StackTrace);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        private void dgContactsList_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                // get the selected items Id
                string mId = dgContactsList.Rows[e.RowIndex].Cells[(int)columns.Id].Value.ToString();

                // open the associated form based on the selected column
                if (e.ColumnIndex == (int)columns.HomeAddress)
                {
                    PhysicalAddress tHomeAddress = null;

                    foreach (KeyValuePair <string, PhysicalAddress> pair in dHomeAddress)
                    {
                        if (pair.Key == mId)
                        {
                            tHomeAddress = (PhysicalAddress)pair.Value;
                        }
                    }

                    PhysicalAddressForm mPhysicalAddress = new PhysicalAddressForm(tHomeAddress);
                    mPhysicalAddress.Owner = this;
                    mPhysicalAddress.ShowDialog(this);
                }
                if (e.ColumnIndex == (int)columns.BusinessAddress)
                {
                    PhysicalAddress tBusinessAddress = null;

                    foreach (KeyValuePair <string, PhysicalAddress> pair in dBusinessAddress)
                    {
                        if (pair.Key == mId)
                        {
                            tBusinessAddress = (PhysicalAddress)pair.Value;
                        }
                    }

                    PhysicalAddressForm mPhysicalAddress = new PhysicalAddressForm(tBusinessAddress);
                    mPhysicalAddress.Owner = this;
                    mPhysicalAddress.ShowDialog(this);
                }
                if (e.ColumnIndex == (int)columns.OtherAddress)
                {
                    PhysicalAddress tOtherAddress = null;

                    foreach (KeyValuePair <string, PhysicalAddress> pair in dOtherAddress)
                    {
                        if (pair.Key == mId)
                        {
                            tOtherAddress = (PhysicalAddress)pair.Value;
                        }
                    }

                    PhysicalAddressForm mPhysicalAddress = new PhysicalAddressForm(tOtherAddress);
                    mPhysicalAddress.Owner = this;
                    mPhysicalAddress.ShowDialog(this);
                }
                if (e.ColumnIndex == (int)columns.BusinessPhone)
                {
                    List <string> lBusinessPhones = null;
                    foreach (KeyValuePair <string, List <string> > pair in dBusinessPhones)
                    {
                        if (pair.Key == mId)
                        {
                            lBusinessPhones = pair.Value;
                        }
                    }

                    CategoriesForm mCategories = new CategoriesForm(lBusinessPhones);
                    mCategories.Owner = this;
                    mCategories.ShowDialog(this);
                }
                if (e.ColumnIndex == (int)columns.Categories)
                {
                    List <string> lCategories = null;
                    foreach (KeyValuePair <string, List <string> > pair in dCategories)
                    {
                        if (pair.Key == mId)
                        {
                            lCategories = pair.Value;
                        }
                    }

                    CategoriesForm mCategories = new CategoriesForm(lCategories);
                    mCategories.Owner = this;
                    mCategories.ShowDialog(this);
                }
                if (e.ColumnIndex == (int)columns.HomePhone)
                {
                    List <string> lHomePhones = null;
                    foreach (KeyValuePair <string, List <string> > pair in dHomePhones)
                    {
                        if (pair.Key == mId)
                        {
                            lHomePhones = pair.Value;
                        }
                    }

                    CategoriesForm mCategories = new CategoriesForm(lHomePhones);
                    mCategories.Owner = this;
                    mCategories.ShowDialog(this);
                }
                if (e.ColumnIndex == (int)columns.ImAddresses)
                {
                    List <string> lImAddress = null;
                    foreach (KeyValuePair <string, List <string> > pair in dImAddresses)
                    {
                        if (pair.Key == mId)
                        {
                            lImAddress = pair.Value;
                        }
                    }

                    CategoriesForm mCategories = new CategoriesForm(lImAddress);
                    mCategories.Owner = this;
                    mCategories.ShowDialog(this);
                }
                if (e.ColumnIndex == (int)columns.EmailAddress)
                {
                    List <string> lEmailAddresses = null;
                    foreach (KeyValuePair <string, List <string> > pair in dEmailAddresses)
                    {
                        if (pair.Key == mId)
                        {
                            lEmailAddresses = pair.Value;
                        }
                    }

                    CategoriesForm mCategories = new CategoriesForm(lEmailAddresses);
                    mCategories.Owner = this;
                    mCategories.ShowDialog(this);
                }
            }
            catch (NullReferenceException nre)
            {
                // likely a cell collection that is empty, just return
                applogger.Log(nre.Message);
            }
            catch (Exception ex)
            {
                applogger.Log(ex.Message);
            }
        }
Esempio n. 18
0
        private void dgEvents_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                // get the selected items Id
                string mId = dgEvents.Rows[e.RowIndex].Cells[0].Value.ToString();

                // open the associated form based on the selected column
                if (e.ColumnIndex == (int)columns.Body)
                {
                    List <ItemBody> tItemBody = null;

                    foreach (KeyValuePair <string, List <ItemBody> > pair in dItemBody)
                    {
                        if (pair.Key == mId)
                        {
                            tItemBody = pair.Value;
                        }
                    }

                    ItemBodyForm mItemBody = new ItemBodyForm(mId, tItemBody);
                    mItemBody.Owner = this;
                    mItemBody.ShowDialog(this);
                }
                // open the associated form based on the selected column
                if (e.ColumnIndex == (int)columns.Attendees)
                {
                    List <Attendee> tAttendees = null;

                    foreach (KeyValuePair <string, List <Attendee> > pair in dAttendees)
                    {
                        if (pair.Key == mId)
                        {
                            tAttendees = pair.Value;
                        }
                    }

                    AttendeeForm mAttendees = new AttendeeForm(mId, tAttendees);
                    mAttendees.Owner = this;
                    mAttendees.ShowDialog(this);
                }
                if (e.ColumnIndex == (int)columns.Categories)
                {
                    List <string> lCategories = null;
                    foreach (KeyValuePair <string, List <string> > pair in dCategories)
                    {
                        if (pair.Key == mId)
                        {
                            lCategories = pair.Value;
                        }
                    }

                    CategoriesForm mCategories = new CategoriesForm(lCategories);
                    mCategories.Owner = this;
                    mCategories.ShowDialog(this);
                }
                if (e.ColumnIndex == (int)columns.Recurrence)
                {
                    RecurrencePattern tPattern = null;
                    RecurrenceRange   tRange   = null;
                    foreach (KeyValuePair <string, RecurrencePattern> pair in dRecurrencePattern)
                    {
                        if (pair.Key == mId)
                        {
                            tPattern = pair.Value;
                        }
                    }

                    foreach (KeyValuePair <string, RecurrenceRange> pair in dRecurrenceRange)
                    {
                        if (pair.Key == mId)
                        {
                            tRange = pair.Value;
                        }
                    }

                    RecurrenceForm mRecurrence = new RecurrenceForm(tPattern, tRange);
                    mRecurrence.Owner = this;
                    mRecurrence.ShowDialog(this);
                }

                if (e.ColumnIndex == (int)columns.Attachments)
                {
                    if (dFileAttachments.Count > 0 || dItemAttachments.Count > 0)
                    {
                        List <FileAttachment>      tFileAttachments = null;
                        List <ItemAttachment>      tItemAttachments = null;
                        List <ReferenceAttachment> tRefAttachments  = null;

                        foreach (KeyValuePair <string, List <FileAttachment> > pair in dFileAttachments)
                        {
                            if (pair.Key == mId)
                            {
                                tFileAttachments = pair.Value;
                            }
                        }

                        foreach (KeyValuePair <string, List <ItemAttachment> > pair in dItemAttachments)
                        {
                            if (pair.Key == mId)
                            {
                                tItemAttachments = pair.Value;
                            }
                        }

                        foreach (KeyValuePair <string, List <ReferenceAttachment> > pair in dReferenceAttachments)
                        {
                            if (pair.Key == mId)
                            {
                                tRefAttachments = pair.Value;
                            }
                        }

                        AttachmentsForm mAttachment = new AttachmentsForm(mId, tFileAttachments, tItemAttachments, tRefAttachments, ref applogger);
                        mAttachment.Owner = this;
                        mAttachment.ShowDialog(this);
                    }
                }
            }
            catch (NullReferenceException nre)
            {
                applogger.Log("Double-click Error:");
                applogger.Log(nre.Message);
            }
            catch (Exception ex)
            {
                applogger.Log("Double-click Error:");
                applogger.Log(ex.Message);
            }
        }
        /// <summary>
        /// Retrieve the log and unit info files from the configured FTP location
        /// </summary>
        public override void Retrieve()
        {
            DateTime Start = Debug.ExecStart;

            // If last retrieval was less than a minute ago, don't do it again
            if ((LastRetrievalTime + new TimeSpan(0, 1, 0)) > DateTime.Now)
            {
                return;
            }

            if (MakeInstanceDir())
            {
                Preferences.PreferenceSet Prefs = Preferences.PreferenceSet.Instance;

                // Download FAHlog.txt
                FtpWebRequest ftpc1 = (FtpWebRequest)FtpWebRequest.Create("ftp://" + this._Server + this._Path + this.RemoteFAHLogFilename);
                ftpc1.Method = WebRequestMethods.Ftp.DownloadFile;
                if ((_Username != "") && (_Username != null))
                {
                    if (_Username.Contains("\\"))
                    {
                        String[] UserParts = _Username.Split('\\');
                        ftpc1.Credentials = new NetworkCredential(UserParts[1], _Password, UserParts[0]);
                    }
                    else
                    {
                        ftpc1.Credentials = new NetworkCredential(_Username, _Password);
                    }
                }
                ftpc1.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                if (Prefs.UseProxy)
                {
                    ftpc1.Proxy = new WebProxy(Prefs.ProxyServer, Prefs.ProxyPort);
                    if (Prefs.UseProxyAuth)
                    {
                        ftpc1.Proxy.Credentials = new NetworkCredential(Prefs.ProxyUser, Prefs.ProxyPass);
                    }
                }
                else
                {
                    ftpc1.Proxy = null;
                }

                FtpWebResponse ftpr1;
                try
                {
                    ftpr1 = (FtpWebResponse)ftpc1.GetResponse();
                }
                catch (Exception Ex)
                {
                    ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null);
                    return;
                }
                String       FAHLog_txt = base.BaseDirectory + LocalFAHLog;
                StreamWriter sw1        = new StreamWriter(FAHLog_txt, false);
                StreamReader sr1        = new StreamReader(ftpr1.GetResponseStream(), Encoding.ASCII);

                sw1.Write(sr1.ReadToEnd());
                sw1.Flush();
                sw1.Close();
                sr1.Close();

                // Download unitinfo.txt
                FtpWebRequest ftpc2 = (FtpWebRequest)FtpWebRequest.Create("ftp://" + this._Server + this._Path + this.RemoteUnitInfoFilename);
                if ((_Username != "") && (_Username != null))
                {
                    if (_Username.Contains("\\"))
                    {
                        String[] UserParts = _Username.Split('\\');
                        ftpc2.Credentials = new NetworkCredential(UserParts[1], _Password, UserParts[0]);
                    }
                    else
                    {
                        ftpc2.Credentials = new NetworkCredential(_Username, _Password);
                    }
                }
                ftpc2.Method      = System.Net.WebRequestMethods.Ftp.DownloadFile;
                ftpc2.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                if (Prefs.UseProxy)
                {
                    ftpc2.Proxy = new WebProxy(Prefs.ProxyServer, Prefs.ProxyPort);
                    if (Prefs.UseProxyAuth)
                    {
                        ftpc2.Proxy.Credentials = new NetworkCredential(Prefs.ProxyUser, Prefs.ProxyPass);
                    }
                }
                else
                {
                    ftpc2.Proxy = null;
                }

                System.Net.FtpWebResponse ftpr2;
                try
                {
                    ftpr2 = (System.Net.FtpWebResponse)ftpc2.GetResponse();
                }
                catch (Exception Ex)
                {
                    ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null);
                    return;
                }
                String       UnitInfo_txt = base.BaseDirectory + LocalUnitInfo;
                StreamWriter sw2          = new StreamWriter(UnitInfo_txt, false);
                StreamReader sr2          = new StreamReader(ftpr2.GetResponseStream(), Encoding.ASCII);

                sw2.Write(sr2.ReadToEnd());
                sw2.Flush();
                sw2.Close();
                sr2.Close();

                base.Retrieve();
            }

            ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), "");
        }
Esempio n. 20
0
        /// <summary>
        /// Logs info/Error to Log file
        /// </summary>
        /// <param name="record"></param>
        private void Log(TraceRecord record)
        {
            var          message   = new StringBuilder();
            LogEventInfo eventInfo = new LogEventInfo();

            eventInfo.LoggerName = Constants.LoggerName;
            eventInfo.Properties[Constants.CorrelationId] = getCorrelationId(record);
            // Set Log Property Is Service Side true.
            eventInfo.Properties[Constants.IsServiceSideLog] = 1;

            if (!string.IsNullOrWhiteSpace(record.Message))
            {
                message.Append(record.Message + Environment.NewLine);
            }

            // Get request Information and append to the message
            if (record.Request != null)
            {
                if (record.Request.Method != null)
                {
                    message.Append("Method: ").Append(record.Request.Method).Append(Environment.NewLine);
                }

                if (record.Request.RequestUri != null)
                {
                    message.Append("URL: ").Append(record.Request.RequestUri).Append(Environment.NewLine);
                }

                if (record.Request.Headers != null && record.Request.Headers.Contains("Token") && record.Request.Headers.GetValues("Token") != null && record.Request.Headers.GetValues("Token").FirstOrDefault() != null)
                {
                    message.Append("Token: ").Append(record.Request.Headers.GetValues("Token").FirstOrDefault()).Append(Environment.NewLine);
                }
            }

            if (!string.IsNullOrWhiteSpace(record.Category))
            {
                message.Append(record.Category);
            }

            if (!string.IsNullOrWhiteSpace(record.Operator))
            {
                message.Append(record.Operator).Append(" ").Append(record.Operation);
            }

            // Get exception information; append to the message details and Event exception object
            if (record.Exception != null && !string.IsNullOrWhiteSpace(record.Exception.GetBaseException().Message))
            {
                eventInfo.Exception = record.Exception;

                var apiException = record.Exception as BaseApiException;
                if (apiException != null)
                {
                    message.Append("Error: ").Append(apiException.ErrorDescription).Append(Environment.NewLine);
                    message.Append("Error Code: ").Append(apiException.ErrorCode).Append(Environment.NewLine);
                }
                else
                {
                    message.Append("Error: ").Append(record.Exception.GetBaseException().Message).Append(Environment.NewLine);
                }
            }

            // Not every request will have user details. Unauthenticated users will not return anything
            var currentUserName = TryToFindUserName(record);

            eventInfo.Properties[Constants.UserName] = currentUserName;

            eventInfo.Message = Convert.ToString(message);
            eventInfo.Level   = LogLevel.FromString(record.Level.ToString());

            // Log to the database
            ClassLogger.Log(eventInfo);
        }
Esempio n. 21
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            // setup variables for response time
            DateTime responseReceived = new DateTime();
            DateTime requestStarted   = new DateTime();

            try
            {
                Cursor = Cursors.WaitCursor;
                ClearResponseTree();

                // get the request url and request method
                string     graphRequest = tbRequestUrl.Text;
                HttpMethod HttpRequestMethod;

                switch (cmbHttpMethod.Text)
                {
                case "GET":
                    HttpRequestMethod = HttpMethod.Get;
                    break;

                case "POST":
                    HttpRequestMethod = HttpMethod.Post;
                    break;

                case "PUT":
                    HttpRequestMethod = HttpMethod.Put;
                    break;

                case "HEAD":
                    HttpRequestMethod = HttpMethod.Head;
                    break;

                case "OPTIONS":
                    HttpRequestMethod = HttpMethod.Options;
                    break;

                default:
                    HttpRequestMethod = HttpMethod.Delete;
                    break;
                }

                // create the http request and add the access token in the header
                HttpRequestMessage request = new HttpRequestMessage(HttpRequestMethod, graphRequest);
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);

                // check for diagnostics flag
                if (Properties.Settings.Default.OutlookDiagnostics == "On")
                {
                    AddRequestHeader("Prefer", "outlook.diagnostics");
                }

                // add headers to the request
                foreach (DataGridViewRow row in dgRequestHeaders.Rows)
                {
                    request.Headers.Add(row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString());
                }

                // check for a request body
                if (tbRequestBody.Text != "")
                {
                    request.Content = new StringContent(tbRequestBody.Text, System.Text.Encoding.UTF8, "application/json");
                }

                logger.Log("REQUEST HEADER:");
                logger.Log(request.Headers.ToString());
                logger.Log("REQUEST:");
                logger.Log(request.ToString());

                // get the current time for response time calculation
                requestStarted = DateTime.Now;

                // start processing the response
                HttpResponseMessage response = httpClient.SendAsync(request).Result;

                // get the current time again to figure out the response time
                responseReceived = DateTime.Now;

                // calculate the number of milliseconds that the request took to complete
                TimeSpan milliseconds = responseReceived.Subtract(requestStarted);
                logger.Log("RESPONSE TIME = " + milliseconds);

                // handle non-successful requests
                if (!response.IsSuccessStatusCode)
                {
                    string errorJsonContent = response.Content.ReadAsStringAsync().Result;

                    JObject jResult = JObject.Parse(errorJsonContent);

                    // check for odata error
                    if (jResult["odata.error"] != null)
                    {
                        throw new Exception((string)jResult["odata.error"]["message"]["value"]);
                    }

                    // check for null result
                    if (jResult[""] != null)
                    {
                        logger.Log("## null response ##");
                    }

                    // log non-odata errors
                    logger.Log("RESPONSE JSON CONTENT:");
                    logger.Log(jResult.ToString());

                    // display error details in the UI
                    TreeNode errorParent = TreeViewHelper.Json2Tree(jResult);
                    errorParent.Text = "Request failed.";
                    treeViewResult   = errorParent.ToString();
                    tvw.Nodes.Add(errorParent);

                    // finally throw the exception to prevent further processing of the request
                    throw new WebException(response.StatusCode.ToString() + ": " + response.ReasonPhrase);
                }

                // process successful request
                string content = response.Content.ReadAsStringAsync().Result;

                logger.Log("RESPONSE HEADER:");
                logger.Log(response.Headers.ToString());
                logger.Log("RESPONSE:");

                if (response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.Created)
                {
                    // POST responses that are successful return 202 Accepted or 201 Created,
                    // there is no response body so let the user know it was successful
                    tvw.Nodes.Add(new TreeNode("Message created/sent succesfully."));
                    logger.Log("StatusCode = " + response.StatusCode.ToString());
                }
                else if (response.StatusCode == HttpStatusCode.OK)
                {
                    // GET responses should have a return type of xml or json
                    if (content[0] == '<')
                    {
                        // check for an xml response and populate the tree
                        // this is mainly for the metadata query
                        XmlDocument dom = new XmlDocument();
                        dom.LoadXml(content);

                        tvw.Nodes.Clear();
                        tvw.Nodes.Add(new TreeNode(dom.DocumentElement.Name));
                        TreeNode tNode = new TreeNode();
                        tNode = tvw.Nodes[0];

                        TreeViewHelper.AddNode(dom.DocumentElement, tNode);
                        treeViewResult = dom.ToString();
                        logger.Log(dom.ToString());
                    }
                    else
                    {
                        // if it isn't xml it should be json, populate the tree
                        JObject jResult = JObject.Parse(content);

                        if (jResult["odata.error"] != null)
                        {
                            throw new Exception((string)jResult["odata.error"]["message"]["value"]);
                        }

                        if (jResult[""] != null)
                        {
                            logger.Log("");
                        }

                        tvw.Nodes.Clear();
                        TreeNode parent = TreeViewHelper.Json2Tree(jResult);
                        parent.Text = "Root Object";
                        tvw.Nodes.Add(parent);
                        logger.Log(jResult.ToString());
                        treeViewResult = jResult.ToString();
                    }
                }
                else
                {
                    // log anything that is not an OK or Accepted response, but also not an error
                    logger.Log(response.StatusCode.ToString());
                }
            }
            catch (Exception ex)
            {
                logger.Log("Exception: " + ex.Message);
            }
            finally
            {
                // clear the headers
                dgRequestHeaders.Rows.Clear();
                Cursor = Cursors.Default;
            }
        }
Esempio n. 22
0
 private void WriteLog()
 {
     // Write the log data to the EWS log
     _logger.Log(_logData, "Autodiscover Process");
     _logData = "";
 }
        private void btnAddAttachment_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                string   file = openFileDialog1.FileName;
                FileInfo f    = new FileInfo(file);

                try
                {
                    int    n    = dgAttachments.Rows.Add();
                    string size = Utils.AttachmentHelper.SizeSuffix(f.Length);
                    dgAttachments.Rows[n].Cells[0].Value = file;
                    dgAttachments.Rows[n].Cells[1].Value = Path.GetFileName(file);
                    dgAttachments.Rows[n].Cells[2].Value = "Octet";
                    dgAttachments.Rows[n].Cells[3].Value = size;
                    dgAttachments.Rows[n].Cells[4].Value = "";
                    dgAttachments.Rows[n].Cells[5].Value = "False";
                    dgAttachments.Rows[n].Cells[6].Value = "#Microsoft.OutlookServices.FileAttachment";
                }
                catch (IOException ioe)
                {
                    sdklogger.Log("Error: " + ioe.Message);
                    sdklogger.Log("StackTrace: " + ioe.StackTrace);
                }
                catch (Exception ex)
                {
                    sdklogger.Log("Error: " + ex.Message);
                    sdklogger.Log("StackTrace: " + ex.StackTrace);
                }
            }
        }
Esempio n. 24
0
        private async Task GetFoldersAsync()
        {
            try
            {
                // adjust UI so user knows work is happening
                Cursor = Cursors.WaitCursor;

                // log the request
                sdklogger.Log("REQUEST");
                sdklogger.Log(graphClient.Me.Calendars.Request().GetHttpRequestMessage().ToString());
                sdklogger.Log(graphClient.Me.Calendars.Request().GetHttpRequestMessage().RequestUri.ToString());

                // get the folders
                var calFolders = await graphClient.Me.Calendars.Request().GetAsync();

                // loop parent folders
                foreach (var cal in calFolders.CurrentPage)
                {
                    // populate folder ids in the local dictionary
                    // any requests for a specific folder need to use Id, not display name
                    dCalendarIds.Add(cal.Name, cal.Id);
                    cmbCalendars.Items.Add(cal.Name);
                    cmbCalendars.SelectedIndex = 0;
                }
            }
            catch (ServiceException se)
            {
                sdklogger.Log("Calendar:GetFoldersAsync ServiceException:");
                sdklogger.Log(se.Message);
                sdklogger.Log(se.StackTrace);
            }
            catch (Exception ex)
            {
                sdklogger.Log("Calendar:GetFoldersAsync Exception:");
                sdklogger.Log(ex.Message);
                sdklogger.Log(ex.StackTrace);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }