コード例 #1
0
ファイル: Sharepoint.cs プロジェクト: dmdaher/TrakUpdated
        public Sharepoint(Program prog)
        {
            this.mIsNewList = true;
            this.mInitialMilestoneRowCount = 0;
            milestonesWithAddCommands      = new List <int>();
            mIsNewList = false;
            //this.mErrorCode = 0;
            this.mProg       = prog;
            this.mEmailError = new EmailErrors(mProg);
            string       siteUrl  = "https://3mdtech.sharepoint.com/DDTest";
            SecureString password = new SecureString();

            foreach (char c in "Welcome2018".ToCharArray())
            {
                password.AppendChar(c);
            }

            // Starting with ClientContext, the constructor requires a URL to the
            // server running SharePoint.
            ClientContext clientContext = new ClientContext(siteUrl);

            mClientContext = clientContext;

            mSPCreds = new SharePointOnlineCredentials("*****@*****.**", password);
            mClientContext.Credentials = mSPCreds;
            //clientContext.Credentials = new SharePointOnlineCredentials("*****@*****.**", password);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: dmdaher/Trak
        Program()
        {
            Service service = new Service();

            this.mService = service.getMService();
            //this.mMilestoneNum = new string[20];
            //this.mMilestoneCommand = new string[20];
            //this.mMilestoneComment = new string[20];
            this.mCurrMilestone       = new Milestone(0, "", "");
            this.mMilestoneObjMap     = new Dictionary <int, Milestone>();
            this.mMilestoneNumMap     = new Dictionary <int, string>();
            this.mMilestoneCommandMap = new Dictionary <int, string>();
            this.mMilestoneCommentMap = new Dictionary <int, string>();
            mMilestoneSize            = 0;
            this.mEmailError          = new EmailErrors(this);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: dmdaher/Trak
        //PARSE THE STRING
        //LOOK FOR KEYWORDS LIKE Milestone, Estimated Start Time, Resources,
        //get the value after keyword and put that in variable to add to SP list
        public void parseEmail(Program prog, ExchangeService service)
        {
            //Program prog = new Program();
            string       aLine          = null;
            StringReader strReader      = new StringReader(this.getMBody());
            int          actualCount    = 0;
            int          milestoneCount = 0;

            Console.WriteLine("the private variable is: " + this.mProjectTitle);
            aLine = strReader.ReadLine();
            while (aLine != null)
            {
                //aLine.ToLower();
                //aLine = aLine.Replace(" ", String.Empty);

                aLine.Trim();
                if (aLine != null && aLine != "")
                {
                    //aParagraph = aParagraph + aLine + " ";
                    //Console.WriteLine("the line is: " + aLine);
                    string parsedValue = valueParser(aLine);
                    parsedValue = parsedValue.Trim();
                    if (aLine.Contains("Milestone"))
                    {
                        this.mCurrMilestone = new Milestone(0, "", "");
                        //setting milestone converts the string milestone to a milestone number
                        prog.setMMilestoneNum(parsedValue);
                        int pos = Convert.ToInt32(parsedValue);
                        this.mCurrMilestone.setNumber(pos);
                        Console.WriteLine("milestone is SET! " + prog.getMMilestoneNum(pos));
                        milestoneCount++;
                        //mMilestoneCurrentNum = pos;
                    }
                    //gets milestone command
                    //if command is remove, sets comment to ""
                    else if (aLine.Contains("Command"))
                    {
                        prog.setMMilestoneCommand(parsedValue);
                        this.mCurrMilestone.setCommand(parsedValue);
                        if (parsedValue == "Remove")
                        {
                            prog.setMMilestoneComment("");
                            this.mCurrMilestone.setComment("");
                            this.setMilestone();
                        }
                        Console.WriteLine("milestoneCommand is READY! " + prog.getMMilestoneCommand(mMilestoneCurrentNum));
                    }
                    //gets milestone comment and adds it to correlated position with command and num
                    //if there is no comment like when a remove command is given, comment is set to "" in command if statement
                    else if (aLine.Contains("Comment"))
                    {
                        prog.setMMilestoneComment(parsedValue);
                        Console.WriteLine("milestone is PERFECT! " + prog.getMMilestoneComment(mMilestoneCurrentNum));
                        this.mCurrMilestone.setComment(parsedValue);
                        this.setMilestone();
                    }
                    //calls helper function to retrieve estimated date and times
                    else if (aLine.Contains("Estimated"))
                    {
                        helperEstimatedParser(aLine, prog);
                    }
                    //gets actual date and time
                    else if (actualCount == 0)
                    {
                        helperActualParser(prog);
                        actualCount++;
                    }
                    //gets milestone comment
                    else if (aLine.Contains("Resources"))
                    {
                        prog.setMResources(parsedValue);
                        Console.WriteLine("Found the resources needed to be... " + prog.getMResources());
                    }
                    else if (aLine.Contains("Time Spent"))
                    {
                        prog.setMTimeSpent(parsedValue);
                        Console.WriteLine("Found the time spent as...  " + prog.getMTimeSpent());
                    }
                    else if (aLine.Contains("Current Status"))
                    {
                        prog.setMCurrentStatus(parsedValue);
                        Console.WriteLine("Found the current status as...  " + prog.getMCurrentStatus());
                    }
                    else if (aLine.Contains("Status Reason"))
                    {
                        prog.setMStatusReason(parsedValue);
                        Console.WriteLine("Found the status reason as...  " + prog.getMStatusReason());
                    }
                }
                aLine = strReader.ReadLine();
            }
            Sharepoint sp = new Sharepoint(prog);

            try
            {
                bool        isNewList  = false;
                EmailErrors emailError = sp.getMEmailErrors();
                isNewList = sp.TryGetList(prog.getMProjectTitle());
                sp.addAllData(prog.getMProjectTitle());
                //Dictionary<int, Milestone> newMilestoneObjMap = new Dictionary<int, Milestone>();
                this.setMilestoneObjMap(new Dictionary <int, Milestone>());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: dmdaher/Trak
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                //connect to exchange
                //autodiscoverurl
                //Service service = new Service();
                Program         prog    = new Program();
                ExchangeService service = prog.getMService();

                // Bind the Inbox folder to the service object.
                Microsoft.Exchange.WebServices.Data.Folder inbox = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, WellKnownFolderName.Inbox);
                // The search filter to get unread email.
                Console.WriteLine("BEFORE");

                //TIP to create search filter
                //first create search collection list
                //add any search filter like a filter that looks for a certain email or checks if email is unread or read
                //then if you want more searches, create a new search filter that ANDS the previous list collection
                //then if you want to let's say check for a domain name in the email, create new list
                //with that new list, add new search filter & add previous filter
                //then create a new search filter and AND or OR it with previous collection
                //idea is this starts chaining filters together
                //Another tip: Make sure you properly use AND and OR...e.g. can't filter two email domains
                //  and say you want the substring to contain denali AND tmobile
                //  so you choose OR operator to say i want to filter for either domain

                //SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
                List <SearchFilter> searchANDFilter = new List <SearchFilter>();
                //searchANDFilter.Add(sf);
                ExtendedPropertyDefinition PidTagSenderSmtpAddress = new ExtendedPropertyDefinition(0x5D01, MapiPropertyType.String);
                //searchANDFilter.Add(new SearchFilter.ContainsSubstring(PidTagSenderSmtpAddress, "@denaliai.com"));
                searchANDFilter.Add(new SearchFilter.ContainsSubstring(PidTagSenderSmtpAddress, "@denaliai.com"));
                searchANDFilter.Add(new SearchFilter.ContainsSubstring(PidTagSenderSmtpAddress, "@usc.edu"));
                //Console.WriteLine("the address is: " + PidTagSenderSmtpAddress.PropertySet.Value.ToString());
                SearchFilter        domainSF          = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchANDFilter);
                List <SearchFilter> searchFinalFilter = new List <SearchFilter>();
                searchFinalFilter.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false)));
                searchFinalFilter.Add(domainSF);
                SearchFilter finalSF = new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchFinalFilter);
                //new SearchFilter.ContainsSubstring(EmailMessageSchema.Sender, "@denaliai.com", ContainmentMode.Substring, ComparisonMode.IgnoreCase)
                //SearchFilter.ContainsSubstring subjectFilter = new SearchFilter.ContainsSubstring(EmailMessageSchema.Sender,"@denaliai.com", ContainmentMode.Substring, ComparisonMode.IgnoreCase);

                Console.WriteLine("AFTER");

                ItemView view = new ItemView(4);
                // Fire the query for the unread items.
                // This method call results in a FindItem call to EWS.
                view.PropertySet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Sender);
                view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
                //Queue<FindItemsResults<Item>> allEmails = new Queue<FindItemsResults<Item>>();
                //Queue<EmailMessage> allEmails = new Queue<EmailMessage>();
                FindItemsResults <Item> findResults = service.FindItems(WellKnownFolderName.Inbox, finalSF, view);

                try
                {
                    //allEmails.Enqueue(message);
                    MailItem     mail      = new MailItem();
                    Stack <Item> allEmails = new Stack <Item>();
                    foreach (Item item in findResults.Items)
                    {
                        allEmails.Push(item);
                    }
                    foreach (Item item in allEmails)
                    {
                        mail.loadMail(findResults, item, service, prog);
                        prog.setMailItem(mail);
                        prog.setMProjectTitle(mail.mSubject);
                        Console.WriteLine("&&&&&&&&&&&&&&&&&&&&&&&&the project title is: " + prog.getMProjectTitle());
                        if (mail.mIsAuthority == true)
                        { //idea is to send project report if authority is true
                          //EmailErrors ee = new EmailErrors(prog);
                          //ee.sendMilestoneErrorEmail();
                            try
                            {
                                Sharepoint sp         = new Sharepoint(prog);
                                string     fullReport = sp.createProjectReport(prog.getMProjectTitle());
                                //Create Response Email
                                mail.sendEmail(fullReport, prog.getMProjectTitle(), service);
                            }
                            catch (ServerException se)
                            {
                                if (se.Message.Contains("does not exist at site with URL"))
                                {
                                    EmailErrors ee = new EmailErrors(prog);
                                    ee.sendProjectDoesNotExistEmail(mail.mMailboxAddress);
                                }
                            }
                        }
                        else
                        {
                            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                            //doc.LoadHtml(body);
                            doc.LoadHtml(mail.mBody);
                            String fullBodyText = "";
                            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//text()"))
                            {
                                if (node.InnerText != "")
                                {
                                    Console.WriteLine(node.InnerText);
                                    fullBodyText += "\n" + node.InnerText;
                                }
                            }
                            //fullBodyText = adjustString(fullBodyText);
                            prog.setMBody(fullBodyText);
                            //prog.setMProjectTitle(subject);
                            prog.setMProjectTitle(mail.mSubject);
                            Console.WriteLine("body is: " + prog.getMBody());
                            prog.parseEmail(prog, service);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }