Ejemplo n.º 1
0
        /// <summary>
        /// Class Constructor - Best pratice is not to override or use this.
        /// Keep in mind if you do that this is called with every request and your
        /// context at this state is uncertian without doing pre-checking of multiple values
        /// </summary>
        public AsaMvcApplication()
        {
            String logMethodName = ".ctor() - ";

            BeginRequest              += (o, e) => { OnAfterRequestStart(e); };
            EndRequest                += (o, e) => { OnAfterRequestEnd(e); };
            MapRequestHandler         += (o, e) => { OnAfterApplicationRequestStart(e); };
            PostRequestHandlerExecute += (o, e) => { OnAfterApplicationRequestEnd(e); };

            CurrentAppState = ApplicationState.NotStarted;

            if (!_loggingStarted)
            {
                //We load logging first and foremost so we can start tracking the
                //application load process as early as possible. Further this way
                //if logging load fails we can simply ingore it and move on
                //while a failure in filters or routes will cause the application startup to
                //abort.
                try
                {
                    log4net.Config.XmlConfigurator.Configure();
                    _log.Info(logMethodName + "ASA MVC Web Application Logger Started - APPLICATION LOGGING START");
                }
                catch (Exception ex)
                {
                    //There is nothing we can do here, there is no way to log this failue
                    //and we don't want to abort the application just because logging won't load
                    _log.Info(logMethodName + "Exception caught. Message: " + ex.Message);
                }

                _loggingStarted = true;
            }


            //NOTE: Logging statements from this method will not show up on initial load.
            //post application launch they will behave normally

            _log.Debug(logMethodName + "Begin Method");

            if (_configuration == null)
            {
                try
                {
                    _log.Debug(logMethodName + "Getting ASAIntegration Config");
                    _configuration = (ASAIntegration)ConfigurationManager.GetSection("asaIntegration");
                }
                catch (Exception ex)
                {
                    _log.Error(logMethodName + "Unable to load integration configuration", ex);
                    throw new MVCIntegrationException("Unable to load integration configuration", ex);
                }
            }
            //ASAContextLoader handles lower level lifecycle concerns
            //like preloading integration/content, and providing application
            //level context for integration interactions.
            //This call give the context loader an easy way to hook into the application lifecycle
            //at the earliest possible point.
            ASAContextLoader.RegisterApplication(this);
            _log.Debug(logMethodName + "End Method");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Object initilizes using the data in the provided data object. If the data matches a user held by providers then
        /// restore, update, save etc will work properly.
        /// </summary>
        /// <param name="accountData">Account data object</param>
        /// <param name="profileData">Profile data object</param>
        public SiteMember(IMemberAccountData accountData, IMemberProfileData profileData)
        {
            String logMethodName = ".ctor(IMemberAccountData accountData, IMemberProfileData profileData) - ";

            _log.Debug(logMethodName + "Begin Method");

            Init();

            try
            {
                _log.Debug(logMethodName + "Loading Member Account");
                _memberAccount = new MemberAccount(accountData);
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + "Unable to create member account instance from data object provided", ex);
                throw new WtfException("Unable to create member account instance from data object provided", ex);
            }

            //TODO - JHL: Making Profile Member Id = iKey = profileData.Id, but should it be AD Key (_memberAccount.MemberId)

            try
            {
                _log.Debug(logMethodName + "Loading Member Profile");
                _memberProfile = new MemberProfile(profileData.Id, profileData, false);
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + "Unable to create member profile instance from data object provided", ex);
                throw new WtfException("Unable to create member profile instance from data object provided", ex);
            }

            _log.Debug(logMethodName + "End Method");
        }
Ejemplo n.º 3
0
        public static bool SendEmail(MailMessage message)
        {
            bool emailSent = false;

            String logMethodName = ".SendEmail(AskMeRequestModel requestModel) - ";

            _log.Debug(logMethodName + string.Format("Sending email to {0}, SMTPServer ={1}:{2}, subject={3}", message.To, Config.SMTPServer, Config.SMTPServerPort, message.Subject));

            try
            {
                using (System.Net.Mail.SmtpClient client = new SmtpClient(Config.SMTPServer, Config.SMTPServerPort))
                {
                    _log.Info("About to send Email to " + message.To);
                    client.Send(message);
                    emailSent = true;
                    _log.Info("Email sent to " + message.To);
                }
            }
            catch (Exception ex)
            {
                _log.Error(String.Format("Error sending email: {0}\n\n{1}", ex.InnerException));
            }

            return(emailSent);
        }
Ejemplo n.º 4
0
        private void SetAccountDataFromAD(ref MemberAccountData accountData)
        {
            String logMethodName = ".SetAccountDataFromAD(ref MemberAccountData accountData) - ";

            _log.Debug(logMethodName + "Begin Method");
            if (accountData != null)
            {
                String memberId;

                try
                {
                    _log.Debug("User Name: " + accountData.Username);
                    memberId = SaltADMembershipProvider.ADConnector.GetObjectGUID(accountData.Username);
                    _log.Debug("Member Id: " + memberId.ToString());
                }
                catch (Exception ex)
                {
                    _log.Error(logMethodName + "Unable to get user's unique member id from ActiveDirectory", ex);
                    throw new SecurityAdapterException("Unable to get user's unique member id from ActiveDirectory", ex);
                }

                accountData.MemberId = memberId;
            }

            _log.Debug(logMethodName + "End Method");
        }
Ejemplo n.º 5
0
        //Since all the commidized functions are now in AsaMvcApplication we only need to register
        //the routes and polices we care about. The base implmentation will handle adding the correct
        //routes for error, published content and common handling needs for the framework.
        protected override void RegisterRoutes(RouteCollection routes)
        {
            String logMethodName = ".RegisterSiteRoutes() - ";

            _log.Debug(logMethodName + "Begin Method");


            if (routes != null)
            {
                // Dont bother routing these....
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
                routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

                //Standard controller routes, Required due to catch all PublishedContentController
                routes.MapRoute("Home", "Home/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); // What is this one for? Login modals? Please comment
                routes.MapRoute("Account", "Account/{action}/{id}", new { controller = "Account", action = "Index", id = UrlParameter.Optional });
                routes.MapRoute("Root", "", new { controller = "Home", action = "Index" });                                               //routes all requests to root --> Home/Index
                routes.MapRoute("Config", "Config/{action}", new { controller = "Config", action = "Index" });
            }
            else
            {
                //Is it actually possible for this to happen? Is there a case where we expect an external
                //instnace consumer to call this method rather than it being called from within the Global.asax.cs?
                //Is there a case where MVC may pass us a null object collection here?
                _log.Error(logMethodName + "The RouteCollection is null!");
                throw new SALTException("The RouteCollection is null!");
            }

            //Alwyas run the base method last here. If there needs to be inserts at the head or foot of the collections
            //its best to do this witl a completed collection.
            base.RegisterRoutes(routes);
            _log.Debug(logMethodName + "End Method");
        }
Ejemplo n.º 6
0
        public QASearchResult ValidateAddress(QASearch search)
        {
            _log.Info("InvokeQasService.ValidateAddress() starting ...");
            QAPortTypeClient client = null;
            QASearchResult   result = null;

            try
            {
                client = new QAPortTypeClient();
                _log.Info("InvokeQasService.ValidateAddress() client created ...");
                int retryCount = 0;
                result = client.DoSearch(search);
                if (result == null && retryCount == 0)
                {
                    // retry once
                    result = client.DoSearch(search);
                    retryCount++;
                }
                _log.Info("InvokeQasService.ValidateAddress() result was returned from service ...");
            }
            catch (TimeoutException timeout)
            {
                _log.Error("InvokeQasService.ValidateAddress() Timeout Exception:" + timeout.Message);
                ProxyHelper.HandleServiceException(client);
            }
            catch (CommunicationException comm)
            {
                _log.Error("InvokeQasService.ValidateAddress() Communication Exception:" + comm.Message);
                ProxyHelper.HandleServiceException(client);
            }
            catch (Exception e)
            {
                _log.Error("InvokeQasService.ValidateAddress() Exception:" + e.Message);
            }
            finally
            {
                if (client != null && client.State != CommunicationState.Closed)
                {
                    ProxyHelper.CloseChannel(client);
                }
            }

            _log.Info("InvokeQasService.ValidateAddress() ending ...");
            return(result);
        }
Ejemplo n.º 7
0
        private void Init()
        {
            String logMethodName = ".Init() - ";

            _log.Debug(logMethodName + "Begin Method");

            try
            {
                _adapter = IntegrationLoader.CurrentSecurityAdapter;
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + "Unable to get security adapter", ex);
                throw new WtfException("Unable to get security adapter", ex);
            }

            _log.Debug(logMethodName + "End Method");
        }
Ejemplo n.º 8
0
        private void WriteErrorToLog(ExceptionContext filterContext)
        {
            String logMethodName = ".WriteErrorToLog(ExceptionContext filterContext)- ";

            _log.Debug(logMethodName + " - Begin Method");

            StringBuilder sb = new StringBuilder();

            //COV 10383
            sb.Append(" UserName = "******"Not Authenticated"));
            sb.Append(" Controller = " + GetErrorRouteValue(filterContext, "controller"));
            sb.Append(" Action = " + GetErrorRouteValue(filterContext, "action"));
            sb.Append(" Url = " + GetErrorURL(filterContext));
            sb.Append(" Exception = " + GetException(filterContext).ToString());

            _log.Error(sb.ToString());
            _log.Debug(logMethodName + " - End Method");
        }
Ejemplo n.º 9
0
        static ASAContextLoader()
        {
            String logMethodName = ".ctor() - ";

            _log.Debug(logMethodName + "Begin Method");

            try
            {
                _log.Debug(logMethodName + "Getting ASAIntegration Config");
                _configuration = (ASAIntegration)ConfigurationManager.GetSection("asaIntegration");
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + "Unable to load integration configuration", ex);
                throw new MVCIntegrationException("Unable to load integration configuration", ex);
            }

            _log.Debug(logMethodName + "End Method");
        }
Ejemplo n.º 10
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            _log.InfoFormat("inside register routes");
            if (routes != null)
            {
                _log.InfoFormat("about to attach routes");
                if (Config.StartAlertService)
                {
                    routes.Add(new ServiceRoute("AlertService", new WebServiceHostFactory(), typeof(Alert)));
                }
                if (Config.StartContentService)
                {
                    routes.Add(new ServiceRoute("ContentService", new WebServiceHostFactory(), typeof(Content)));
                }
                if (Config.StartMembershipService)
                {
                    routes.Add(new ServiceRoute("ASAMemberService", new WebServiceHostFactory(), typeof(ASAMember)));
                }
                if (Config.StartReminderService)
                {
                    routes.Add(new ServiceRoute("ReminderService", new WebServiceHostFactory(), typeof(Reminder)));
                }
                if (Config.StartSearchService)
                {
                    routes.Add(new ServiceRoute("SearchService", new WebServiceHostFactory(), typeof(Search)));
                }
                if (Config.StartSelfReportedService)
                {
                    routes.Add(new ServiceRoute("SelfReportedService", new WebServiceHostFactory(), typeof(SelfReported)));
                }
                if (Config.StartSurveyService)
                {
                    routes.Add(new ServiceRoute("SurveyService", new WebServiceHostFactory(), typeof(Survey)));
                }

                routes.Add(new ServiceRoute("LessonsService", new WebServiceHostFactory(), typeof(Lessons)));
            }
            else
            {
                _log.Error("The RoutesCollection is null!");
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Handles lazy loading of profile data. Note that current implmentation loads ALL data for the profile
        /// when this method is called.
        /// </summary>
        private void LoadProfileData()
        {
            String logMethodName = ".LoadProfileData() - ";

            _log.Debug(logMethodName + "Begin Method");

            if (!_profileDataLoaded)
            {
                _log.Debug(logMethodName + "Loading Member Profile Data");

                IMemberProfileData profileData = null;

                try
                {
                    _log.Debug(logMethodName + "Calling IContextDataProvider.GetMemberProfile(Object membershipId, Dictionary<String, Object> providerKeys)");
                    _log.Debug(string.Format("_memberId = {0}", _memberId != null ? _memberId : "NULL"));
                    //COV-10330 check for NULL
                    if (_memberId != null)
                    {
                        profileData = _provider.GetMemberProfile(_memberId);
                    }
                }
                catch (Exception ex)
                {
                    String message = logMethodName + "Error getting profile data";
                    _log.Error(message, ex);

                    throw new WtfException(message, ex);
                }

                //If the profile is null it means one does not exsist for this user yet.
                if (profileData != null)
                {
                    _profileData = new MemberProfileData(profileData);
                    _newProfile  = false;
                    _log.Debug(logMethodName + "Profile Data found and loaded successfully");
                }
                else
                {
                    //Internally mark that we have a new profile here. Thie allows save to
                    //work properly.
                    _profileData = new MemberProfileData();
                    _newProfile  = true;
                    _log.Debug(logMethodName + "No profile data found for user, creating empty profile record");
                }

                //_profileData.MemberId = _memberId; //_profileData.MemberId is the memberId in the SALTDb lets leave it alone
                _profileData.Id     = _memberId;
                _orignalProfileData = _profileData;
                //We still set the profile loaded to true because it is in fact loaded.
                //Also this keeps us from hitting the provider over and over as the properties
                //are accessed.
                _profileDataLoaded = true;
            }
            else
            {
                _log.Debug(logMethodName + "Member profile data has already been loaded, skipping");
            }

            _log.Debug(string.Format("About to set WTFSession.ProfileId = {0}", _profileData.Id != null?_profileData.Id:"NULL"));
            WTFSession.ProfileId = _profileData.Id;

            _log.Debug(logMethodName + "End Method");
        }
Ejemplo n.º 12
0
        private static bool retryAuth(netForumXMLSoapClient xWebClient)
        {
            string strAuthResult;

            bool ret = false;

            for (int i = 0; i < Config.XWebRetryAttemps; i++)
            {
                _log.Error("Retrying authentication attempt#: " + i.ToString());
                try
                {
                    _authToken = xWebClient.Authenticate(Config.XWebLogin, Config.XWebPassword, out strAuthResult);
                }
                catch {}

                if (_authToken != null)
                {
                    return(true);
                }
                Thread.Sleep(Config.XWebRetryWait);
            }

            return(ret);
        }
Ejemplo n.º 13
0
        public SiteMember CreateMember(MemberAuthInfo authInfo, MemberProfileData profile, out MemberCreationStatus status, IList <IContextActionValidationRequest <IContextActionValidator> > validationRequests = null)
        {
            const string logMethodName = ".CreateMember(MemberAuthInfo, MemberProfileData, out MemberCreationStatus, IList<IContextActionValidationRequest<IContextActionValidator>>)";
            const string logEndMessage = logMethodName + " - End Method";

            _log.Info(logMethodName + " - Creating new SiteMember");
            _log.Debug(logMethodName + " - Begin Method");
            SiteMember newMember = null;

            status = MemberCreationStatus.Error;

            IMemberAccountData accountData = null;
            int timesToTry = 2;

            //SWD-7461 - adding retry logic.
            for (int i = 0; i < timesToTry; i++)
            {
                try
                {
                    _log.Debug(logMethodName + " - Calling ISecurityAdapter.CreateMember(MemberAuthInfo authInfo, MemberProfileData data, out MemberCreationStatus status)");
                    status      = MemberCreationStatus.Error;
                    accountData = _adapter.CreateMember(authInfo, profile, out status);
                    break;
                }
                catch (Exception ex)
                {
                    _log.Error(logMethodName + " - Error Creating new member account using the ISecurityAdapter.CreateMember will retry again", ex);
                    System.Threading.Thread.Sleep(1000);
                    accountData = null;
                }
            }

            if (status == MemberCreationStatus.Success)
            {
                _log.Info(logMethodName + " - MemberAccount created successfully by ISecurityAdapter.CreateMember - Creating MemberProfile");

                var memberProfile = new MemberProfileData(profile)
                {
                    MemberId       = accountData.MemberId,
                    LastModified   = DateTime.Now,
                    LastModifiedBy = accountData.MemberId
                };
                if (memberProfile.ProviderKeys == null)
                {
                    memberProfile.ProviderKeys = new Dictionary <string, object>();
                }
                memberProfile.ProviderKeys.Add("ActiveDirectoryKey", accountData.MemberId); // We prob dont need this, code using the ADKey lower in the framework will be ignored

                try
                {
                    IMemberProfileData data;
                    _log.Debug(logMethodName + " - Calling IContextDataProvider.CreateMemberProfile(MemberProfileData data, ProviderKeys keys)");
                    //TODO verify and remove provider key integration at this layer. - May need pin based lookup for pre-registered accounts to call update.
                    data          = _provider.CreateMemberProfile(memberProfile, memberProfile.ProviderKeys);
                    memberProfile = new MemberProfileData(data);
                }
                catch (Exception ex)
                {
                    _log.Error(logMethodName + " - Error Creating new member profile using the IContextDataProvider - Rolling back new account", ex);
                    _log.Info(logMethodName + " - Rolling back - STEP 1. DELETE MEMBER ACCOUNT");
                    _log.Debug(logMethodName + " - Calling ISecurityAdapter.DeleteMember(Object memberId)");

                    _adapter.DeleteMember(accountData.Username);
                    status = MemberCreationStatus.AdapterError;

                    _log.Debug(logEndMessage);
                    accountData = null;
                }

                try
                {
                    newMember = new SiteMember(accountData, memberProfile);
                }
                catch (Exception ex)
                {
                    _log.Error(logMethodName + " - Error Creating new sitemember instance", ex);
                    _log.Debug(logEndMessage);
                    newMember = null;
                }
            }
            else
            {
                // SWD-5616
                _log.Warn(logMethodName + " - Member Creation Unsuccessful.  Status: " + status);
            }

            _log.Debug(logEndMessage);
            return(newMember);
        }
Ejemplo n.º 14
0
        public ResultCodeModel InsertSurvey(SurveyModel survey)
        {
            ResultCodeModel result;

            try
            {
                var memberAdapter = new AsaMemberAdapter();
                //add system data
                //response status will be hardcoded in deployment scripts so it will be the same for all environments
                survey.ResponseDate   = DateTime.Now;
                survey.ResponseStatus = "21B65800-5F9A-421F-9E82-DA13B111F790";
                survey.MemberId       = memberAdapter.GetMemberIdFromContext();

                if (SurveyValidation.ValidateSurvey(survey))
                {
                    _log.Info("ASA.Web.Services.SurveyService.InsertSurvey() starting ...");
                    result = _surveyAdapter.InsertSurvey(survey);
                    _log.Info("ASA.Web.Services.SurveyService.InsertSurvey() ending ...");
                }
                else
                {
                    result = new ResultCodeModel();
                    var error = new ErrorModel("Invalid information input for this survey", "Web Survey Service");
                    _log.Error("ASA.Web.Services.SurveyService.InsertSurvey(): Invalid information input for this survey");
                    result.ErrorList.Add(error);

                    if (Config.Testing)
                    {
                        //get validation errors out of list and retrun them
                        if (survey.ErrorList.Count > 0)
                        {
                            foreach (ErrorModel em in survey.ErrorList)
                            {
                                //if not empty copy message
                                if (!string.IsNullOrEmpty(em.Code))
                                {
                                    result.ErrorList.Add(em);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error("ASA.Web.Services.SurveyService.InsertSurvey(): Exception => " + ex.ToString());
                throw new SurveyOperationException("Web Survey Service - Exception in ASA.Web.Services.SurveyService.InsertSurvey()", ex);
            }

            return(result);
        }
Ejemplo n.º 15
0
        private string RenderWidget(ASA.Web.Services.SearchService.DataContracts.SearchRecordModel record)
        {
            string strReturn = "";

            if (HttpContext.Current.Cache[record.Fields["P_Tile_Xml_Path"][0]] != null &&
                HttpContext.Current.Cache[record.Fields["P_Tile_Xml_Path"][0]].ToString() != "")
            {
                strReturn = HttpContext.Current.Cache[record.Fields["P_Tile_Xml_Path"][0]].ToString();
            }
            else
            {
                string name = "";
                string path = HttpContext.Current.Server.MapPath("/PublishedContent" + record.Fields["P_Tile_Xml_Path"][0]);

                if (File.Exists(path))
                {
                    using (XmlTextReader reader = new XmlTextReader(path))
                    {
                        if (reader != null)
                        {
                            try
                            {
                                _log.Debug("begin reading from the XmlReader");
                                //position cursor at first properly readable XML element
                                reader.MoveToContent();

                                bool bFoundElement = false;
                                while (reader.Read())
                                {
                                    switch (reader.NodeType)
                                    {
                                    case XmlNodeType.Element:
                                        if (reader.Name == "content")
                                        {
                                            //read again to retrieve data for "content"
                                            reader.Read();
                                            name          = reader.Value;
                                            bFoundElement = true;
                                        }
                                        break;

                                    default:
                                        break;
                                    }

                                    if (bFoundElement)
                                    {
                                        break;
                                    }
                                }

                                if (!bFoundElement)
                                {
                                    _log.Error("ASA.Web.Services.SearchService.Search.RenderWidget():  Search key not found.");
                                }
                                else
                                {
                                    //remove chars needed for razor templates
                                    name = name.Replace("|%~", "");
                                    name = name.Replace("%|", "");
                                    HttpContext.Current.Cache[record.Fields["P_Tile_Xml_Path"][0]] = name;
                                    strReturn = name;
                                }
                            }
                            catch (Exception ex)
                            {
                                _log.Error("ASA.Web.Services.SearchService.RenderWidget(): Exception =>" + ex.ToString());
                                //assume reader is null
                                strReturn = "";
                                throw new Exception("Web Search Service - RenderWidget()", ex);
                            }
                            finally
                            {
                                _log.Debug("closing the XmlReader");
                                reader.Close();
                            }
                        }
                    }
                }
            }
            return(strReturn);
        }