示例#1
0
 public static void GetHpFramesAndScripts(string countryCode, string languageCode, out HpFramesDto frames, out HpScriptsDto scripts)
 {
     frames = GetHpFramesFromCache(countryCode, languageCode, false);
     scripts = utility.fillHpScripts(countryCode, languageCode);
 }
示例#2
0
        internal static HpFramesDto GetHpFramesFromService(string countryCode, string languageCode)
        {
            string header = null;
            string footer = null;
            string headererror = null;
            string footererror = null;

            try
            {
                string maskedCc = page_utilities.MaskCc(countryCode, false);
                string WebServiceUrl = utility.getParameter("framepartsWebserviceUrl").Replace("{ccMasked}", maskedCc).Replace("{ll}",languageCode);
                //QC6165 - send expiration notifications times out - Starts
                Boolean bFramePartEnableWebProxy = utility.getParameter("framepartEnableWebProxy").ToString() == "true";
                string sFramePartWebProxy = utility.getParameter("framepartWebProxy").ToString();
                //QC6165 - send expiration notifications times out - Ends
                string root = utility.getParameter("rootForRelativePaths");
                if (!string.IsNullOrEmpty(root))
                    _absoluteRoot = new Uri(root);

                string frames;
                WebRequest wr = WebRequest.Create(WebServiceUrl);
                //QC6165 - send expiration notifications times out - Starts

                if(bFramePartEnableWebProxy)
                {
                    WebProxy Proxy = new WebProxy(sFramePartWebProxy);
                    wr.Proxy = Proxy;
                }
                //QC6165 - send expiration notifications times out - Ends
                WebResponse r = wr.GetResponse();
                using (StreamReader sr = new StreamReader(r.GetResponseStream()))
                {
                    frames = sr.ReadToEnd();
                }

                Match m = rgx.Match(frames);
                if (m.Success)
                {
                    header = m.Groups["header"].Value;
                    footer = m.Groups["footer"].Value;

                    header = rgx_unesc.Replace(header, Unescape);
                    footer = rgx_unesc.Replace(footer, Unescape);

                    header = rgx_relurl.Replace(header, MakeAbsolute);
                    footer = rgx_relurl.Replace(footer, MakeAbsolute);
                }
                else
                {
                    headererror = footererror = "Header and footer data could not be matched by Regex in Webservice Response!";
                }
            }
            catch (Exception e)
            {
                headererror = footererror = e.Message;
                header = footer = null;
            }

            DateTime date = DateTime.Now;

            //string header = string.Format("<div>TEST HEADER ({0}-{1}) - {2} </div>", countryCode, languageCode, date);
            //string footer = string.Format("<div>TEST FOOTER ({0}-{1}) - {2} </div>", countryCode, languageCode, date);

            HpFramesDto hpFrames = new HpFramesDto(header, footer, countryCode, languageCode, date);
            hpFrames.HeaderError = headererror;
            hpFrames.FooterError = footererror;

            return hpFrames;
        }
示例#3
0
        internal static bool StoreHpFramesToCache(HpFramesDto hpFrames, Dictionary<string, Pair<string, string>> Changes)
        {
            bool success = ValidateHpFramesForCache(hpFrames);
            try
            {
                if (success)
                {
                    bool needsDbUpdate = false;
                    HpFramesDto hpFramesCurrent = GetHpFramesFromCache(hpFrames.CountryCode, hpFrames.LanguageCode, true);
                    
                    if (!string.Equals(hpFrames.HeaderFrame, hpFramesCurrent.HeaderFrame))
                    {
                        needsDbUpdate = true;
                        string key = string.Format(_headerFileNameFormat, hpFrames.CountryCode, hpFrames.LanguageCode);
                        Changes[key]= new Pair<string, string>(hpFramesCurrent.HeaderFrame, hpFrames.HeaderFrame);
                    }
                    if (!string.Equals(hpFrames.FooterFrame, hpFramesCurrent.FooterFrame))
                    {
                        needsDbUpdate = true;
                        string key = string.Format(_footerFileNameFormat, hpFrames.CountryCode, hpFrames.LanguageCode);
                        Changes[key]= new Pair<string, string>(hpFramesCurrent.FooterFrame, hpFrames.FooterFrame);
                    }
                    if (needsDbUpdate)
                        FormRegistry.HpFramesDao.Create(hpFrames);
                }
                else
                    FormRegistry.HpFramesDao.Create(hpFrames);
            }
            catch (Exception)
            {
                // TODO: BERND write ErrorLog??
                throw;
            }

            return success;
        }
示例#4
0
 private static bool ValidateHpFramesForCache(HpFramesDto hpFrames)
 {
     return !(string.IsNullOrEmpty(hpFrames.FooterFrame) || string.IsNullOrEmpty(hpFrames.HeaderFrame));
 }
示例#5
0
        public void TestInsertUpdateGetDeleteFrames()
        {
            RemoveTestEntries();

            HpFramesDto returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(null, returnedFrames.HeaderFrame, "FrameParts Table is not clean for testing! Header was not deleted or get failed!");
            Assert.AreEqual(null, returnedFrames.FooterFrame, "FrameParts Table is not clean for testing! Footer was not deleted or get failed!");



            HpFramesDto testFrames = new HpFramesDto(_header_first, _footer_first, _country_test, _language_test);
            FormRegistry.HpFramesDao.Create(testFrames);

            returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(_header_first, returnedFrames.HeaderFrame, "Inserting Header failed or get failed!");
            Assert.AreEqual(_footer_first, returnedFrames.FooterFrame, "Inserting Footer failed or get failed!");



            HpFramesDto testFrames2 = new HpFramesDto(_header_second, _footer_second, _country_test, _language_test);
            FormRegistry.HpFramesDao.Create(testFrames2);
            
            returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(_header_second, returnedFrames.HeaderFrame, "Updating Header or get failed!");
            Assert.AreEqual(_footer_second, returnedFrames.FooterFrame, "Updating Footer or get failed!");



            HpFramesDto testFrames3 = new HpFramesDto(null, _footer_first, _country_test, _language_test);
            FormRegistry.HpFramesDao.Create(testFrames3);

            returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(_header_second, returnedFrames.HeaderFrame, "Old Header destroyed by null-Header or get failed!");
            Assert.AreEqual(_footer_first, returnedFrames.FooterFrame, "Footer update failed with null-Header or get failed!");



            HpFramesDto testFrames4 = new HpFramesDto(_header_first, null, _country_test, _language_test);
            FormRegistry.HpFramesDao.Create(testFrames4);

            returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(_header_first, returnedFrames.HeaderFrame, "Header update failed with null-Footer or get failed!");
            Assert.AreEqual(_footer_first, returnedFrames.FooterFrame, "Old Footer destroyed by null-Footer or get failed!");



            HpFramesDto testFrames5 = new HpFramesDto(null, null, _country_test, _language_test);
            FormRegistry.HpFramesDao.Create(testFrames5);

            returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(_header_first, returnedFrames.HeaderFrame, "Old Header destroyed by two null entries!");
            Assert.AreEqual(_footer_first, returnedFrames.FooterFrame, "Old Footer destroyed by two null entries!");

            // TODO: clean up this test as done above...

            HpFramesDto testFrames6 = new HpFramesDto(_header_second, string.Empty, _country_test, _language_test);
            FormRegistry.HpFramesDao.Create(testFrames6);

            returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(_header_second, returnedFrames.HeaderFrame, "Header update failed with empty-Footer or get failed!");
            Assert.AreEqual(_footer_first, returnedFrames.FooterFrame, "Old Footer destroyed by empty-Footer or get failed!");



            HpFramesDto testFrames7 = new HpFramesDto(string.Empty, _footer_second, _country_test, _language_test);
            FormRegistry.HpFramesDao.Create(testFrames7);

            returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(_header_second, returnedFrames.HeaderFrame, "Old Header destroyed by empty-Header or get failed!");
            Assert.AreEqual(_footer_second, returnedFrames.FooterFrame, "Footer update failed with empty-Header or get failed!");

            RemoveTestEntries();
            returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(null, returnedFrames.HeaderFrame, "Removing Header entry failed!");
            Assert.AreEqual(null, returnedFrames.FooterFrame, "Removing Footer entry failed!");
        }
示例#6
0
        public void TestInsertUpdateGetDeleteErrors()
        {
            RemoveTestEntries();
            IHpFramesDao HFD = FormRegistry.HpFramesDao;

            HpFramesDto returnedFrames = FormRegistry.HpFramesDao.Get(_country_test, _language_test);

            Assert.AreEqual(null, returnedFrames.HeaderFrame, "FrameParts Table is not clean for testing! Header was not deleted or get failed!");
            Assert.AreEqual(null, returnedFrames.FooterFrame, "FrameParts Table is not clean for testing! Footer was not deleted or get failed!");



            HpFramesDto testFrames = new HpFramesDto(null, null, _country_test, _language_test);
            testFrames.HeaderError = _error_header_first;
            testFrames.FooterError = _error_footer_first;
            FormRegistry.HpFramesDao.Create(testFrames);

            returnedFrames = HFD.GetFull(_country_test, _language_test);

            Assert.AreEqual(null, returnedFrames.HeaderFrame, "Header must not be inserted by error!");
            Assert.AreEqual(null, returnedFrames.FooterFrame, "Footer must not be inserted by error!");
            Assert.AreEqual(null, returnedFrames.HeaderError, "Inserting HeaderError must not work! Only updates allowed, as Header in Cache must not be null!");
            Assert.AreEqual(null, returnedFrames.FooterError, "Inserting FooterError must not work! Only updates allowed, as Footer in Cache must not be null!");

            HpFramesDto testFrames1 = new HpFramesDto(_header_first, _footer_first, _country_test, _language_test);
            FormRegistry.HpFramesDao.Create(testFrames1);

            returnedFrames = HFD.GetFull(_country_test, _language_test);

            Assert.AreEqual(_header_first, returnedFrames.HeaderFrame, "Inserting Header or get failed!");
            Assert.AreEqual(_footer_first, returnedFrames.FooterFrame, "Inserting Footer or get failed!");
            Assert.AreEqual(null, returnedFrames.HeaderError, "HeaderError must not be changed by inserting header or footer!");
            Assert.AreEqual(null, returnedFrames.FooterError, "FooterError must not be changed by inserting header or footer!");


            HpFramesDto testFrames2 = new HpFramesDto(null, null, _country_test, _language_test);
            testFrames2.HeaderError = _error_header_first;
            testFrames2.FooterError = _error_footer_first;
            FormRegistry.HpFramesDao.Create(testFrames2);

            returnedFrames = HFD.GetFull(_country_test, _language_test);

            Assert.AreEqual(_header_first, returnedFrames.HeaderFrame, "Header must not be updated by error!");
            Assert.AreEqual(_footer_first, returnedFrames.FooterFrame, "Footer must not be updated by error!");
            Assert.AreEqual(_error_header_first, returnedFrames.HeaderError, "Updating empty HeaderError with Error failed!");
            Assert.AreEqual(_error_footer_first, returnedFrames.FooterError, "Updating empty FooterError with Error failed!");
            
            HpFramesDto testFrames3 = new HpFramesDto(_header_second, _footer_second, _country_test, _language_test);
            FormRegistry.HpFramesDao.Create(testFrames3);

            returnedFrames = HFD.GetFull(_country_test, _language_test);

            Assert.AreEqual(_header_second, returnedFrames.HeaderFrame, "Updating Header or get failed!");
            Assert.AreEqual(_footer_second, returnedFrames.FooterFrame, "Updating Footer or get failed!");
            Assert.AreEqual(_error_header_first, returnedFrames.HeaderError, "HeaderError must not be changed by updating header or footer!");
            Assert.AreEqual(_error_footer_first, returnedFrames.FooterError, "FooterError must not be changed by updating header or footer!");



            HpFramesDto testFrames4 = new HpFramesDto(null, null, _country_test, _language_test);
            testFrames4.HeaderError = _error_header_second;
            testFrames4.FooterError = _error_footer_second;
            FormRegistry.HpFramesDao.Create(testFrames4);

            returnedFrames = HFD.GetFull(_country_test, _language_test);

            Assert.AreEqual(_header_second, returnedFrames.HeaderFrame, "Header must not be updated by error!");
            Assert.AreEqual(_footer_second, returnedFrames.FooterFrame, "Footer must not be updated by error!");
            Assert.AreEqual(_error_header_second, returnedFrames.HeaderError, "Updating existing HeaderError with Error failed!");
            Assert.AreEqual(_error_footer_second, returnedFrames.FooterError, "Updating existing Footer with Error failed!");


            RemoveTestEntries();
            returnedFrames = HFD.GetFull(_country_test, _language_test);

            Assert.AreEqual(null, returnedFrames.HeaderFrame, "Removing Header entry failed!");
            Assert.AreEqual(null, returnedFrames.FooterFrame, "Removing Footer entry failed!");
            Assert.AreEqual(null, returnedFrames.HeaderError, "Removing HeaderError entry failed!");
            Assert.AreEqual(null, returnedFrames.FooterError, "Removing FooterError entry failed!");
        }
示例#7
0
        internal static HP.Rfg.Common.FrameCaches.HpFramesDto fillHpFrames(string countryCode, string languageCode)
        {
            string path = getParameter("path_to_frameparts");
            string headerFile = string.Format("{0}header_{1}_{2}.txt", path, countryCode, languageCode);
            string footerFile = string.Format("{0}footer_{1}_{2}.txt", path, countryCode, languageCode);

            HttpServerUtility server = HttpContext.Current.Server;
            try 
	        {	        
                string header = File.ReadAllText(server.MapPath(headerFile));
                string footer = File.ReadAllText(server.MapPath(footerFile));
                HpFramesDto hpFrames = new HpFramesDto(header, footer, countryCode, languageCode);
                return hpFrames;
	        }
	        catch (Exception)
	        {
#if !DEBUG
		        throw;
#endif
	        }
#if DEBUG
            string format = "<div>NO {0} FOR {1}_{2} IN FILESYSTEM!</div>";
            return new HpFramesDto(
                string.Format(format, "HEADER", countryCode, languageCode),
                string.Format(format, "FOOTER", countryCode, languageCode), 
                countryCode, languageCode);
#endif
        }
示例#8
0
        public HpFramesDto Get(string countryCode, string languageCode)
        {
            HpFramesDto retval = new HpFramesDto(
                            null, null,
                            countryCode,
                            languageCode);

            DbConnection connection = null;
            try
            {
                connection = _dbLayer.GetConnection();
                DbCommand sp = null;
                IDataReader reader = null;
                try
                {
                    sp = connection.CreateCommand();

                    sp.CommandText = "select_frameparts";
                    sp.CommandType = CommandType.StoredProcedure;
                    _dbLayer.AddParameter(sp, "@country", ParameterDirection.Input, DbType.String, countryCode);
                    _dbLayer.AddParameter(sp, "@language", ParameterDirection.Input, DbType.String, languageCode);
                    _dbLayer.AddReturnParameter(sp);
                    reader = sp.ExecuteReader();
                    if (reader.Read())
                    {
                        string type;
                        string content;
                        DateTime date, oldest = DateTime.Now;

                        do
                        {
                            Read(reader, out type, out content, out date);
                            if (DateTime.Compare(oldest, date) > 0)
                                oldest = date;

                            if (!string.IsNullOrEmpty(content))
                            {
                                switch (type)
                                {
                                    case _frameType_header:
                                        retval.HeaderFrame = content;
                                        break;
                                    case _frameType_footer:
                                        retval.FooterFrame = content;
                                        break;
                                    default:
                                        break;
                                }
                            }

                        } while (reader.Read());
                        retval.Date = oldest;
                    }
                    else
                    {
                        int err = _dbLayer.GetReturnValue(sp);
                        //Trace.WriteLine("ResponseDao.CreateSubmitResponse(" + customerId + ", " + responserId + ", " + questionnaireId + ") returned " + err);
                    }
                }
                catch (DbException e)
                {
                    //Trace.WriteLine("ResponseDao.CreateSubmitResponse(" + customerId + ", " + responserId + ", " + questionnaireId + "): " + e.Message);
                }
                finally
                {
                    if (reader != null && !reader.IsClosed)
                    {
                        reader.Close();
                    }

                    if (sp != null)
                    {
                        sp.Dispose();
                    }
                }
            }
            catch (DbException e)
            {
                //Trace.WriteLine("ResponseDao.CreateSubmitResponse(" + customerId + ", " + responserId + ", " + questionnaireId + "): " + e.Message);
            }
            finally
            {
                if (connection != null)
                {
                    _dbLayer.ReturnConnection(connection);
                }
                else
                {
                    _dbLayer.ReturnConnection(connection, true);
                }
            }

            return retval;
        }
示例#9
0
        public HpFramesDto Create(HpFramesDto transient)
        {
            DbConnection connection = null;
            try
            {
                connection = _dbLayer.GetConnection();
                
                if (!string.IsNullOrEmpty(transient.HeaderFrame))
                {
                    Commit(connection, _frameType_header, transient.HeaderFrame, transient.Date, transient.CountryCode, transient.LanguageCode);
                }
                else
                {
                    string errorText = string.IsNullOrEmpty(transient.HeaderError) ? "No Data available" : transient.HeaderError;
                    CommitError(connection, _frameType_header, errorText, transient.Date, transient.CountryCode, transient.LanguageCode);
                }


                if (!string.IsNullOrEmpty(transient.FooterFrame))
                {
                    Commit(connection, _frameType_footer, transient.FooterFrame, transient.Date, transient.CountryCode, transient.LanguageCode);
                }
                else
                {
                    string errorText = string.IsNullOrEmpty(transient.FooterError) ? "No Data available" : transient.FooterError;
                    CommitError(connection, _frameType_footer, errorText, transient.Date, transient.CountryCode, transient.LanguageCode);
                }
            }
            catch (DbException e)
            {
                //Trace.WriteLine("ResponseDao.CreateSubmitResponse(" + customerId + ", " + responserId + ", " + questionnaireId + "): " + e.Message);
            }
            finally
            {
                if (connection != null)
                {
                    _dbLayer.ReturnConnection(connection);
                }
                else
                {
                    _dbLayer.ReturnConnection(connection, true);
                }
            }

            return transient;
        }