Exemplo n.º 1
0
 public bool DeleteErrorLog(ErrorLogObject errorLog)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_ErrorLog WHERE ErrorLogId = @ErrorLogId", errorLog);
     }
     catch { return(false); }
     return(true);
 }
Exemplo n.º 2
0
 public bool DeleteOpenNet(OpenNetObject openNet)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_OpenNet WHERE OpenNetId = @OpenNetId", openNet);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("OpenNetObject::DeleteOpenNet", ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 3
0
 public bool DeleteFunding(FundingObject funding)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_Funding WHERE FundingId = @FundingId", funding);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("FundingObject::DeleteFunding", ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 4
0
 public bool DeleteAuthor(AuthorObject author)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_Author WHERE AuthorId = @AuthorId", author);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("AuthorObject::DeleteAuthor", ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 5
0
 public bool DeleteEmailTemplate(EmailTemplateObject emailTemplate)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_EmailTemplate WHERE EmailTemplateId = @EmailTemplateId", emailTemplate);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("EmailTemplateObject::DeleteEmailTemplate", ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 6
0
 public bool DeleteReview(ReviewObject review)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_Review WHERE ReviewId = @ReviewId", review);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("ReviewObject::DeleteReview", ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 7
0
 public bool DeleteContact(ContactObject contact)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_Contact WHERE ContactId = @ContactId", contact);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("ContactObject::IsValid", ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 8
0
 public bool DeleteSortMetaData(SortMetaDataObject sortMetaData)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_SortMetaData WHERE MetaDataId = @MetaDataId", sortMetaData);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("SortMetaDataObject::DeleteSortMetaData", ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 9
0
 public bool DeleteProtectedData(ProtectedDataObject protectedData)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_ProtectedData WHERE ProtectedDataId = @ProtectedDataId", protectedData);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("ProtectedDataObject::DeleteProtectedData", ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 10
0
 public static void LogError(string name, Exception ex)
 {
     try
     {
         var error = new ErrorLogObject();
         error.Name       = name;
         error.ErrorDate  = DateTime.Now;
         error.Message    = ex.Message;
         error.StackTrack = ex.StackTrace;
         error.Save();
     }
     catch { }
 }
Exemplo n.º 11
0
 public static void LogError(string name, string message, string stackTrace)
 {
     try
     {
         var error = new ErrorLogObject();
         error.Name       = name;
         error.ErrorDate  = DateTime.Now;
         error.Message    = message;
         error.StackTrack = stackTrace;
         error.Save();
     }
     catch { }
 }
Exemplo n.º 12
0
 public bool Delete(SortAttachmentObject sortAttachment)
 {
     try
     {
         Config.Conn.Execute("DELETE FROM dat_SortAttachmentFile WHERE SortAttachmentId = @SortAttachmentId", sortAttachment);
         Config.Conn.Execute("DELETE FROM dat_SortAttachment WHERE SortAttachmentId = @SortAttachmentId", sortAttachment);
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("SortAttachmentObject::Delete", ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 13
0
        public static WebResponse GetResponseWithoutException(this WebRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            try
            {
                return(request.GetResponse());
            }
            catch (WebException ex)
            {
                ErrorLogObject.LogError("InlDigitalLibrary::GetResponseWithoutException", ex);
                return(ex.Response);
            }
        }
Exemplo n.º 14
0
 public static void AddLogRecord(int sortMainId, string xml, string response, string status)
 {
     try
     {
         OstiUploadObject o = new OstiUploadObject();
         o.SortMainId = sortMainId;
         o.RequestXml = xml;
         o.Response   = response;
         o.Status     = status;
         o.RecordDate = DateTime.Now;
         o.Save();
     }
     catch (Exception ex)
     {
         ErrorLogObject.LogError("OstiUploadObject::AddLogRecord", ex);
     }
 }
Exemplo n.º 15
0
        public void Delete()
        {
            IsDeleted = true;
            try
            {
                DeletedByEmployeeId = UserObject.CurrentUser.EmployeeId;
            }
            catch (Exception ex)
            {
                ErrorLogObject.LogError("SortAttachmentObject::Delete", ex);
            }
            DeletedDate = DateTime.Now;
            Save();

            // If we mark the Final Document as deleted, we need to perminately delete the OSTI Attachment.
            // This way a new one will be generated.
            if (AttachmentTypeEnum == AttachmentTypeEnum.FinalDoc)
            {
                GetOstiAttachment(SortMainId)?.PerminateDelete();
            }
        }
Exemplo n.º 16
0
        private static bool SendReleaseOfficerEmail(SortMainObject sort, string subject, string body, EmailTypeEnum emailType, ref string errorMsg)
        {
            bool   allMailSent = false;
            string ownerEmail  = ConfigurationManager.AppSettings["OwnerEmail"].ToString();

            try
            {
                Email  email   = new Email();
                string addInfo = string.Empty;
                email.SendTo  = new List <string>();
                email.Subject = subject;

                foreach (var user in UserObject.GetUsers().Where(n => n.IsInAnyRole("ReleaseOfficial")))
                {
                    if (!string.IsNullOrWhiteSpace(user.Email))
                    {
                        email.SendTo.Add(user.Email);
                    }
                }

                if (email.SendTo.Count == 0)
                {
                    email.SendTo.Add(ownerEmail);
                    addInfo = "<em><p><strong>This message has been sent to you in lieu of the intended target.  Their email was not found in Employee Data. Please review the email and determine appropriate course of action.</strong></p></em><hr />";
                }

                email.Body  = addInfo + body;
                email.Body += "<hr /><p> You are being contacted because you are a Release Official in the SORT system.</p>";
                email.Body += "<p> If you believe this has been in error, please contact the admin: " + ownerEmail + "</p>";
                email.Send(emailType);

                allMailSent = true;
            }
            catch (Exception ex)
            {
                ErrorLogObject.LogError("Email::SendReleaseOfficerEmail", ex);
                errorMsg = $"Exeption Caught on sending Email: {ex.Message}";
            }
            return(allMailSent);
        }
Exemplo n.º 17
0
        private static bool UploadFilesFtpS(int sortMainId, string ostiId, ref string error)
        {
            bool uploaded = false;

            //// https://github.com/hgupta9/FluentFTP
            try
            {
                var file = SortAttachmentObject.GetOstiAttachment(sortMainId);
                if (file != null)
                {
                    using (FtpClient client = new FtpClient(Config.OstiFtpSite, Config.OstiFtpPort, Config.OstiFtpUsername, Config.OstiFtpPassword))
                    {
                        client.EncryptionMode       = FtpEncryptionMode.Explicit;
                        client.SslProtocols         = SslProtocols.Tls12;
                        client.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
                        client.Connect();

                        if (client.IsConnected)
                        {
                            string fileName = $"{ostiId}{Path.GetExtension(file.FileName)}";
                            Stream stream   = file.Contents;
                            stream.Seek(0, SeekOrigin.Begin);

                            uploaded = client.Upload(stream, $"{Config.OstiFtpDirectory}{fileName}");

                            client.Disconnect();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogObject.LogError("OstiUploadObject::UploadFilesFtpS", ex);
                error = ex.Message;
            }

            return(uploaded);
        }
Exemplo n.º 18
0
        public static bool SendEmail(SortMainObject sort, EmailTypeEnum emailType, bool includeAuthors, ref string errorMsg)
        {
            try
            {
                var template = EmailTemplateObject.GetEmailTemplate(emailType.ToString());
                if (template != null)
                {
                    string subject = template.Header.Replace("{STI_Number}", sort.TitleStr).Replace("{PublishTitle}", sort.PublishTitle);
                    string body    = template.Body
                                     .Replace("{STI_Number}", sort.TitleStr)
                                     .Replace("{PublishTitle}", sort.PublishTitle)
                                     .Replace("{Authors}", string.Join(", ", sort.Authors.Select(n => $"{n.FirstName} {n.LastName}")))
                                     .Replace("{DueDate}", $"{sort.DueDate:d}")
                                     .Replace("{ReviewStatus}", sort.ReviewStatus)
                                     .Replace("{ReviewProgress}", $"{sort.ReviewProgress:P}")
                                     .Replace("{ViewUrl}", $"<a href=\"{Config.SortUrl(false).TrailingForwardSlash()}Artifact/{sort.SortMainId}\">STI Artifact</a>")
                                     .Replace("{EditUrl}", $"<a href=\"{Config.SortUrl(false).TrailingForwardSlash()}Artifact/Edit/{sort.SortMainId}\">STI Artifact</a>");

                    if (emailType == EmailTypeEnum.FirstYearReminder || emailType == EmailTypeEnum.DelayedReminder)
                    {
                        return(SendReleaseOfficerEmail(sort, subject, body, emailType, ref errorMsg));
                    }

                    return(SendOwnerEmail(sort, subject, body, includeAuthors, emailType, ref errorMsg));
                }

                errorMsg = $"Unable to find the Template for Email Type: {emailType}";
            }
            catch (Exception ex)
            {
                ErrorLogObject.LogError("Email::SendEmail", ex);
                errorMsg = $"Exception Caught while attempting to send an email: {ex.Message}";
            }

            return(false);
        }
Exemplo n.º 19
0
 public ErrorLogObject SaveErrorLog(ErrorLogObject errorLog)
 {
     if (errorLog.ErrorLogId > 0) // Update
     {
         string sql = @"
             UPDATE  dat_ErrorLog
             SET     ErrorDate = @ErrorDate,
                     SortmainId = @SortmainId,
                     Name = @Name,
                     Message = @Message,
                     StackTrack = @StackTrack
             WHERE   ErrorLogId = @ErrorLogId";
         Config.Conn.Execute(sql, errorLog);
     }
     else
     {
         string sql = @"
             INSERT INTO dat_ErrorLog (
                 ErrorDate,
                 SortmainId,
                 Name,
                 Message,
                 StackTrack
             )
             VALUES (
                 @ErrorDate,
                 @SortmainId,
                 @Name,
                 @Message,
                 @StackTrack
             )
             SELECT CAST(SCOPE_IDENTITY() AS INT)";
         errorLog.ErrorLogId = Config.Conn.Query <int>(sql, errorLog).Single();
     }
     return(errorLog);
 }
Exemplo n.º 20
0
        public static bool UploadToOsti(SortMainObject sort)
        {
            string xml = string.Empty;

            try
            {
                // upload to OSTI
                HttpWebRequest  webreq = null;
                HttpWebResponse webres = null;
                string          res    = string.Empty;
                xml = sort.GetXml();

                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;

                webreq                 = WebRequest.Create(Config.OstiUrl) as HttpWebRequest;
                webreq.Credentials     = new NetworkCredential(Config.OstiUserName, Config.OstiPassword);
                webreq.PreAuthenticate = true;

                webreq.ContentType = "application/xml";
                webreq.Method      = "POST";
                webreq.Timeout     = 10000000;

                Stream postData = null;
                byte[] buffer   = Encoding.UTF8.GetBytes(xml);
                try
                {
                    postData = webreq.GetRequestStream();
                }
                catch (Exception ex)
                {
                    ErrorLogObject.LogError("OstiUploadObject::UploadToOsti1", ex);
                    sort.OstiStatusMsg = $"Exception Caught while connecting to OSTI API: {ex.Message}";
                    AddLogRecord(sort.SortMainId.Value, xml, sort.OstiStatusMsg, "FAILED - Exception Caught while connecting to OSTI API");
                    return(false);
                }

                if (postData != null && buffer != null)
                {
                    postData.Write(buffer, 0, buffer.Length);
                    postData.Close();
                }

                WebResponse xres = null;
                try
                {
                    xres = webreq.GetResponse();
                }
                catch (WebException ex)
                {
                    ErrorLogObject.LogError("OstiUploadObject::UploadToOsti", ex);
                    if (ex.Response != null)
                    {
                        using (var stream = ex.Response.GetResponseStream())
                            using (var reader = new StreamReader(stream))
                            {
                                res = reader.ReadToEnd();
                            }
                    }
                    else
                    {
                        sort.OstiStatusMsg = $"Error returned:{ex.Message} => Could be that the password for OSTI site has expired.";
                        AddLogRecord(sort.SortMainId.Value, xml, sort.OstiStatusMsg, "FAILED - webreq.GetResponse");
                        return(false);
                    }
                }

                if (xres is HttpWebResponse)
                {
                    if (((HttpWebResponse)xres).StatusCode != HttpStatusCode.OK)
                    {
                        sort.OstiStatusMsg = "Status Code returned was: " + ((HttpWebResponse)xres).StatusDescription;
                        AddLogRecord(sort.SortMainId.Value, xml, sort.OstiStatusMsg, "FAILED - StatusCode");
                        return(false);
                    }

                    using (webres = xres as HttpWebResponse)
                    {
                        StreamReader reader = new StreamReader(webres.GetResponseStream());
                        res = reader.ReadToEnd();
                    }
                    xres.Close();
                }

                if (!string.IsNullOrWhiteSpace(res))
                {
                    try
                    {
                        OstiRecords record = null;
                        if (!string.IsNullOrWhiteSpace(res))
                        {
                            using (TextReader reader = new StringReader(res))
                            {
                                XmlSerializer serializer = new XmlSerializer(typeof(OstiRecords));
                                record = (OstiRecords)serializer.Deserialize(reader);
                            }
                        }

                        if (record != null && record.Record != null && record.Record.Length > 0)
                        {
                            OstiRecord rec = record.Record[0];
                            sort.OstiId        = rec.Id.HasValue ? (rec.Id.Value > 0 ? rec.Id.Value.ToString() : sort.OstiId) : sort.OstiId;
                            sort.OstiStatus    = record.Record[0].Status;
                            sort.OstiStatusMsg = record.Record[0].StatusMessage;
                            sort.OstiDate      = DateTime.Now;
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLogObject.LogError("OstiUploadObject::UploadToOsti2", ex);
                        using (XmlReader rdr = XmlReader.Create(new StringReader(res)))
                        {
                            rdr.ReadToFollowing(Extensions.GetPropertyShortName(() => sort.OstiId));
                            sort.OstiId = rdr.ReadElementContentAsString();

                            rdr.ReadToFollowing(Extensions.GetPropertyShortName(() => sort.OstiStatus));
                            sort.OstiStatus = rdr.ReadElementContentAsString();

                            rdr.ReadToFollowing(Extensions.GetPropertyShortName(() => sort.OstiStatusMsg));
                            if (rdr.NodeType == XmlNodeType.Element)
                            {
                                sort.OstiStatusMsg = rdr.ReadElementContentAsString();
                            }

                            sort.OstiDate = DateTime.Now;
                        }
                    }

                    AddLogRecord(sort.SortMainId.Value, xml, res, sort.OstiStatus);

                    if (!string.IsNullOrWhiteSpace(sort.OstiId) && sort.OstiStatus.Equals("success", StringComparison.OrdinalIgnoreCase))
                    {
                        if (!sort.PublicRelease)
                        {
                            string error = string.Empty;
                            if (!UploadFilesFtpS(sort.SortMainId.Value, sort.OstiId, ref error))
                            {
                                sort.OstiStatusMsg = $"FAILED - MetaData Uploaded, but FTPS Failed to upload the document to OSTI: {error}";
                                sort.OstiStatus    = "FAILED";
                                AddLogRecord(sort.SortMainId.Value, xml, sort.OstiStatusMsg, "FAILED - FTPS Exception Caught");
                                return(false);
                            }
                        }
                        else
                        {
                            // Update Digital Library for file that was uploaded to them.
                            string jsonStr = Config.DigitalLibraryManager.GetDigitalLibraryJson(sort);
                            Config.DigitalLibraryManager.ReportData(sort.StiSpId.Value, jsonStr);
                        }

                        //Report all LDRD Funding to LOI-ESS
                        if (sort.SharePointId.HasValue) // SharePoint ID is also the LRS ID
                        {
                            try
                            {
                                StimsData.SendToLoiess(sort);
                            }
                            catch (Exception ex)
                            {
                                ErrorLogObject.LogError("OstiUploadObject::UploadToOsti3", ex);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    sort.OstiStatusMsg = "No data returned from OSTI, Unable to complete the transfer.";
                    AddLogRecord(sort.SortMainId.Value, xml, sort.OstiStatusMsg, "FAILED - Return Data");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ErrorLogObject.LogError("OstiUploadObject::UploadToOsti4", ex);
                sort.OstiStatusMsg = ex.Message;
                AddLogRecord(sort.SortMainId.Value, xml, sort.OstiStatusMsg, "FAILED - Exception Caught");
                return(false);
            }

            return(true);
        }
Exemplo n.º 21
0
        public int?Import()
        {
            int?sortId = null;

            var sort = new SortMainObject();

            sort.StatusEnum   = StatusEnum.Imported;
            sort.SharePointId = LrsId;
            sort.Title        = $"{StiNumber}-Revision-{Revision}";
            sort.StiNumber    = StiNumber;
            sort.Revision     = Revision;

            sort.PublishTitle        = Title;
            sort.Abstract            = Abstract;
            sort.JournalName         = JournalName;
            sort.ConferenceName      = ConferenceName;
            sort.ConferenceSponsor   = ConferenceSponsor;
            sort.ConferenceLocation  = ConferenceLocation;
            sort.ConferenceBeginDate = ConferenceBeginDate;
            sort.ConferenceEndDate   = ConferenceEndDate;

            sort.OwnerName       = OwnerName ?? EmployeeCache.GetName(OwnerEmployeeId);
            sort.OwnerEmployeeId = OwnerEmployeeId;
            sort.CreateDate      = CreateDate;
            sort.ModifiedDate    = ModifiedDate;
            sort.ApprovedDate    = ApprovedDate;
            sort.RelatedSti      = RelatedSti;
            if (sort.ApprovedDate.HasValue && sort.ApprovedDate.Value > new DateTime(2000, 1, 1))
            {
                sort.DueDate = sort.ApprovedDate.Value.AddMonths(1);
            }

            sort.ReviewStatus         = ReviewStatus;
            sort.ReviewProgress       = ReviewProgress;
            sort.AccessLimitationEnum = AccessLimitationEnum.Unlimited; //Default to Unlimited
            sort.Country   = "US";
            sort.Language  = "English";
            sort.IsFromLrs = true;
            if (!string.IsNullOrWhiteSpace(sort.OwnerEmployeeId) || !string.IsNullOrWhiteSpace(sort.OwnerName))
            {
                sort.Save();
                sortId = sort.SortMainId;
                ProcessLogObject.Add(sort.SortMainId, "Added Entry");
                if (Contacts != null)
                {
                    foreach (var contact in Contacts)
                    {
                        var cont = new ContactObject();
                        cont.SortMainId      = sort.SortMainId.Value;
                        cont.FirstName       = contact.FirstName ?? EmployeeCache.GetEmployee(contact.EmployeeId)?.FirstName;
                        cont.MiddleName      = contact.MiddleName ?? EmployeeCache.GetEmployee(contact.EmployeeId)?.MiddleName;
                        cont.LastName        = contact.LastName ?? EmployeeCache.GetEmployee(contact.EmployeeId)?.LastName;
                        cont.ContactTypeEnum = ContactTypeEnum.POC;
                        cont.Phone           = contact.Phone ?? EmployeeCache.GetEmployee(contact.EmployeeId)?.PhoneNumber;
                        cont.EmployeeId      = contact.EmployeeId;
                        cont.WorkOrg         = contact.WorkOrg;
                        //cont.OrcidId = contact.OrcidId;
                        cont.Save();
                        ProcessLogObject.Add(sort.SortMainId, "Added Contact");
                    }
                }

                if (Authors != null)
                {
                    foreach (var author in Authors)
                    {
                        var auth = new AuthorObject();
                        auth.SharePointId = author.AuthorId;
                        auth.SortMainId   = sort.SortMainId.Value;
                        auth.FirstName    = author.FirstName;
                        auth.MiddleName   = author.MiddleName;
                        auth.LastName     = author.LastName;
                        auth.Affiliation  = author.Affiliation;
                        switch (author.AffiliationType)
                        {
                        case "INL":
                            auth.AffiliationEnum = AffiliationEnum.INL;
                            auth.Affiliation     = "Idaho National Laboratory";
                            break;

                        case "University":
                            auth.AffiliationEnum = AffiliationEnum.University;
                            break;

                        default:
                            auth.AffiliationEnum = AffiliationEnum.Other;
                            break;
                        }

                        auth.Email      = author.Email;
                        auth.OrcidId    = author.OrcidId;
                        auth.IsPrimary  = author.IsPrimary;
                        auth.EmployeeId = author.EmployeeId;
                        auth.WorkOrg    = author.WorkOrg;
                        auth.CountryId  = MemoryCache.GetCountryByCode(author.CountryCode)?.CountryId;
                        auth.StateId    = MemoryCache.GetStateByShortName(author.StateCode)?.StateId;
                        auth.Save();
                        ProcessLogObject.Add(sort.SortMainId, "Added Author");
                    }
                }

                if (Fundings != null)
                {
                    foreach (var funding in Fundings)
                    {
                        var fund = new FundingObject();
                        fund.SortMainId              = sort.SortMainId.Value;
                        fund.Year                    = funding.Year;
                        fund.FundingTypeId           = funding.FundingTypeId;
                        fund.Org                     = funding.Org;
                        fund.ContractNumber          = funding.ContractNumber;
                        fund.Percent                 = funding.Percent;
                        fund.DoeFundingCategoryId    = funding.DoeFundingCategoryId;
                        fund.GrantNumber             = funding.GrantNumber;
                        fund.TrackingNumber          = funding.TrackingNumber;
                        fund.SppCategoryId           = funding.SppCategoryId;
                        fund.SppApproved             = funding.SppApproved;
                        fund.FederalAgencyId         = funding.FederalAgencyId;
                        fund.ApproveNoReason         = funding.ApproveNoReason;
                        fund.OtherDescription        = funding.OtherDescription;
                        fund.CountryId               = funding.CountryId;
                        fund.AdditionalInfo          = funding.AdditionalInfo;
                        fund.ProjectArea             = funding.ProjectArea;
                        fund.ProjectNumber           = funding.ProjectNumber;
                        fund.PrincipalInvEmployeeId  = funding.PrincipalInvEmployeeId;
                        fund.MilestoneTrackingNumber = funding.MilestoneTrackingNumber;

                        try
                        {
                            fund.Save();
                            ProcessLogObject.Add(sort.SortMainId, "Added Funding Type");
                        }
                        catch (Exception ex)
                        {
                            ErrorLogObject.LogError("Console:ImportFromSharepoint:FundingSave", ex);
                        }
                    }
                }

                if (Subjects != null)
                {
                    foreach (var subject in Subjects)
                    {
                        SortMetaDataObject.AddNew(MetaDataTypeEnum.SubjectCategories, sort.SortMainId.Value, subject);
                        ProcessLogObject.Add(sort.SortMainId, "Added subject Metadata");
                    }
                }

                if (Keywords != null)
                {
                    foreach (var keyword in Keywords)
                    {
                        SortMetaDataObject.AddNew(MetaDataTypeEnum.Keywords, sort.SortMainId.Value, keyword);
                        ProcessLogObject.Add(sort.SortMainId, "Added Keyword Metadata");
                    }
                }

                if (CoreCapabilities != null)
                {
                    foreach (var core in CoreCapabilities)
                    {
                        SortMetaDataObject.AddNew(MetaDataTypeEnum.CoreCapabilities, sort.SortMainId.Value, core);
                        ProcessLogObject.Add(sort.SortMainId, "Added Core Capability Metadata");
                    }
                }

                if (Reviewers != null)
                {
                    foreach (var reviewer in Reviewers)
                    {
                        try
                        {
                            ReviewObject review = new ReviewObject();
                            review.SortMainId = sort.SortMainId.Value;
                            switch (reviewer.ReviewerType)
                            {
                            case "Manager":
                                review.ReviewerTypeEnum = ReviewerTypeEnum.Manager;
                                break;

                            case "Classification":
                                review.ReviewerTypeEnum = ReviewerTypeEnum.Classification;
                                break;

                            case "ExportControl":
                                review.ReviewerTypeEnum = ReviewerTypeEnum.ExportControl;
                                break;

                            case "TechDeployment":
                                review.ReviewerTypeEnum = ReviewerTypeEnum.TechDeployment;
                                break;

                            case "PeerTechnical":
                                review.ReviewerTypeEnum = ReviewerTypeEnum.PeerTechnical;
                                break;
                            }

                            review.Reviewer             = reviewer.ReviewerName ?? EmployeeCache.GetName(reviewer.ReviewerEmployeeId) ?? "Unknown";
                            reviewer.ReviewerEmployeeId = reviewer.ReviewerEmployeeId;
                            review.ReviewDate           = reviewer.ReviewDate;
                            review.Approval             = reviewer.Status;
                            review.Save();
                        }
                        catch (Exception ex)
                        {
                            ErrorLogObject.LogError("Console:ProcessReviewers", ex);
                        }
                    }
                }

                Email.SendEmail(sort, EmailTypeEnum.Initial, true);
                ProcessLogObject.Add(sort.SortMainId, "Email Sent");
                ProcessLogObject.Add(sort.SortMainId, "Success");
            }

            return(sortId);
        }
Exemplo n.º 22
0
        private static bool SendOwnerEmail(SortMainObject sort, string subject, string body, bool includeAuthors, EmailTypeEnum emailType, ref string errorMsg)
        {
            bool   allMailSent = false;
            string ownerEmail  = ConfigurationManager.AppSettings["OwnerEmail"].ToString();

            try
            {
                Email  email   = new Email();
                string addInfo = string.Empty;
                email.SendTo  = new List <string>();
                email.Subject = subject;


                foreach (var contact in sort.Contacts)
                {
                    if (!string.IsNullOrWhiteSpace(contact.EmployeeId))
                    {
                        var user = UserObject.GetUser(contact.EmployeeId);
                        if (user != null && !string.IsNullOrWhiteSpace(user.Email))
                        {
                            if (!email.SendTo.Exists(n => n.Equals(user.Email, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                email.SendTo.Add(user.Email);
                            }
                        }
                    }
                }

                if (email.SendTo.Count == 0)
                {
                    if (!string.IsNullOrWhiteSpace(sort.OwnerEmail))
                    {
                        if (!email.SendTo.Exists(n => n.Equals(sort.OwnerEmail, StringComparison.InvariantCultureIgnoreCase)))
                        {
                            email.SendTo.Add(sort.OwnerEmail);
                        }
                    }
                }

                if (includeAuthors)
                {
                    foreach (var author in sort.Authors.Where(n => n.AffiliationEnum == AffiliationEnum.INL))
                    {
                        if (!string.IsNullOrWhiteSpace(author.EmployeeId))
                        {
                            var user = UserObject.GetUser(author.EmployeeId);
                            if (user != null && !string.IsNullOrWhiteSpace(user.Email))
                            {
                                email.SendTo.Add(user.Email);
                            }
                        }
                    }
                }

                if (email.SendTo.Count == 0)
                {
                    email.SendTo.Add(ownerEmail);
                    addInfo = "<em><p><strong>This message has been sent to you in lieu of the intended target.  Their email was not found in Employee Data. Please review the email and determine appropriate course of action.</strong></p></em><hr />";
                }

                email.Body  = addInfo + body;
                email.Body += "<hr /><p> You are being contacted because you are either the Owner or a Contact for the Artifact.</p>";
                email.Body += "<p> If you believe this has been in error, please contact the admin: " + ownerEmail + "</p>";
                email.Send(emailType);

                allMailSent = true;
            }
            catch (Exception ex)
            {
                ErrorLogObject.LogError("Email::SendOwnerEmail", ex);
                errorMsg = $"Exeption Caught on sending Email: {ex.Message}";
            }
            return(allMailSent);
        }
Exemplo n.º 23
0
        private void Send(EmailTypeEnum emailType)
        {
            MailMessage message = new MailMessage();

            message.From       = new MailAddress(Config.FromAddress);
            message.Subject    = Subject;
            message.Body       = Body;
            message.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["EmailServer"]);

            if (Config.ApplicationMode == ApplicationMode.Production)// || (Config.ApplicationMode == ApplicationMode.Acceptance && emailType == EmailTypeEnum.Initial))
            {
                // We are in prodution, send the email to the person(s) we should.
                foreach (string to in SendTo)
                {
                    message.To.Clear();
                    message.CC.Clear();
                    message.Bcc.Clear();
                    message.To.Add(new MailAddress(to));
                    if (!String.IsNullOrEmpty(CC))
                    {
                        message.CC.Add(new MailAddress(CC));
                    }
                    smtp.Send(message);
                }
            }
            else if (Config.ApplicationMode != ApplicationMode.CyberScan)
            {
                // As long as we are not in production or CyberScan, send email to user
                // or if user does not have email, send to developer or acceptance person.
                message.Subject = "**TESTING** " + message.Subject;
                message.Body    = "<em>Original Email Recipient(s): " + string.Join(", ", SendTo) + "</em><hr />" + Body;
                message.To.Clear();
                message.CC.Clear();
                message.Bcc.Clear();
                try
                {
                    if (!string.IsNullOrWhiteSpace(UserObject.RealCurrentUser.Email))
                    {
                        message.To.Add(UserObject.RealCurrentUser.Email);
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogObject.LogError("Email::Send", ex);
                }

                if (message.To.Count == 0)
                {
                    if (Config.ApplicationMode == ApplicationMode.Acceptance)
                    {
                        message.To.Add(Config.OwnerEmail);
                    }
                    else
                    {
                        message.To.Add(Config.DeveloperEmail);
                    }
                }
                smtp.Send(message);
            }
        }