コード例 #1
0
        public void CreateDefect(V1Connector CurrentV1Connection, List <Message> CurrentEmails)
        {
            V1XMLHelper  V1XML        = new V1XMLHelper();
            V1Logging    Logs         = new V1Logging();
            string       ProjectScope = "Something for Testing";
            string       EmailBody;
            MessagePart  MessageParts;
            SMTPResponse V1Response = new SMTPResponse();
            MailChecker  MailCheck  = new MailChecker();

            IServices services = new Services(CurrentV1Connection);


            try
            {
                foreach (Message MailItem in CurrentEmails)
                {
                    for (int ToCtr = 0; ToCtr < MailItem.Headers.To.Count; ToCtr++)
                    {
                        ProjectScope = V1XML.GetProjectScope(MailItem.Headers.To[ToCtr].Address);
                        if (ProjectScope != null)
                        {
                            Oid                  projectId     = services.GetOid(ProjectScope);
                            IAssetType           defectType    = services.Meta.GetAssetType("Defect");
                            Asset                NewDefect     = services.New(defectType, projectId);
                            IAttributeDefinition nameAttribute = defectType.GetAttributeDefinition("Name");
                            NewDefect.SetAttributeValue(nameAttribute, MailItem.Headers.Subject.ToString());

                            MessageParts = MailItem.FindFirstHtmlVersion();
                            if (MessageParts == null)
                            {
                                MessageParts = MailItem.FindFirstPlainTextVersion();
                            }
                            EmailBody = MessageParts.GetBodyAsText();

                            Logs.LogEvent("Operation - Creating Defect for " + MailItem.Headers.To[ToCtr].Address);

                            IAttributeDefinition descriptionAttribute = defectType.GetAttributeDefinition("Description");
                            NewDefect.SetAttributeValue(descriptionAttribute, EmailBody);
                            IAttributeDefinition FoundByAttribute = defectType.GetAttributeDefinition("FoundBy");
                            NewDefect.SetAttributeValue(FoundByAttribute, MailItem.Headers.From.ToString());
                            services.Save(NewDefect);

                            IAttributeDefinition DefectIDAttribute = defectType.GetAttributeDefinition("Number");
                            Query IDQuery = new Query(NewDefect.Oid);
                            IDQuery.Selection.Add(DefectIDAttribute);
                            QueryResult ResultID = services.Retrieve(IDQuery);
                            Asset       defect   = ResultID.Assets[0];

                            //NewDefect.GetAttribute(DefectIDAttribute).Value
                            Logs.LogEvent("Operation - Sending Response to Defect Sender.");
                            //Commented out the Response back to the Sender per John Waedekin
                            //V1Response.SendResponse(MailItem, defect.GetAttribute(DefectIDAttribute).Value + " " + NewDefect.GetAttribute(nameAttribute).Value, ProjectScope);
                            MailCheck.DeleteMessagesOnServer(MailItem, ProjectScope);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logs.LogEvent("ERROR - Creating Defect - " + ex.InnerException.Message);
            }
        }