Esempio n. 1
0
 public Context(IDnaDiagnostics dnaDiagnostics, IDnaDataReaderCreator dataReaderCreator, ICacheManager cacheManager, ISiteList siteList)
 {
     DnaDiagnostics = dnaDiagnostics;
     DnaDataReaderCreator = dataReaderCreator;
     CacheManager = cacheManager;
     SiteList = siteList;
 }
Esempio n. 2
0
 /// <summary>
 /// Debug constructor
 /// </summary>
 /// <param name="signInSystem">The sign in system to use</param>
 /// <param name="dnaDataReaderCreator">A DnaDataReaderCreator object for creating the procedure this class needs.
 /// If NULL, it uses the connection stringsfrom the configuration manager</param>
 /// <param name="dnaDiagnostics">A DnaDiagnostics object for logging purposes</param>
 /// <param name="caching">The caching object that the class can use for caching</param>
 /// <param name="debugUserID">A userid for debugging/testing purposes</param>
 /// <param name="siteList">A SiteList object for getting siteoption values</param>
 public CallingUser(SignInSystem signInSystem, IDnaDataReaderCreator dnaDataReaderCreator, IDnaDiagnostics dnaDiagnostics, ICacheManager caching, string debugUserID, ISiteList siteList)
     : base(dnaDataReaderCreator, dnaDiagnostics, caching)
 {
     _signInSystem = signInSystem;
     _debugUserID = debugUserID;
     _siteList = siteList;
 }
Esempio n. 3
0
        public XmlDocument OutputXML(int interval, Page page, IDnaDiagnostics diagnostics)
        {
            XmlDocument xDoc = new XmlDocument();
            XmlNode xmlEl = xDoc.AppendChild(xDoc.CreateElement("H2G2"));
            xmlEl.Attributes.Append(xDoc.CreateAttribute("TYPE"));
            xmlEl.Attributes["TYPE"].InnerText = "STATUSPAGE";
            xmlEl = xmlEl.AppendChild(xDoc.CreateElement("STATUS-REPORT"));
            xmlEl.AppendChild(xDoc.ImportNode(Statistics.CreateStatisticsDocument(interval).FirstChild, true));

            XmlDocument xmlSignal = new XmlDocument();
            xmlSignal.LoadXml(StringUtils.SerializeToXmlUsingXmlSerialiser(SignalHelper.GetStatus(diagnostics)));
            xmlEl.AppendChild(xDoc.ImportNode(xmlSignal.DocumentElement, true));

            try
            {
                var memcachedCacheManager = (MemcachedCacheManager)CacheFactory.GetCacheManager("Memcached");
                xmlEl.AppendChild(xDoc.ImportNode(memcachedCacheManager.GetStatsXml(), true));
            }
            catch (Exception e)
            {
                var childNode = xmlEl.AppendChild(xDoc.CreateElement("MEMCACHED_STATUS"));
                childNode.InnerText = "Error getting memcached stats:" + e.Message;
            }

            return xDoc;
        }
Esempio n. 4
0
 /// <summary>
 /// Constructs objects
 /// </summary>
 public User(IDnaDataReaderCreator dnaDataReaderCreator, IDnaDiagnostics dnaDiagnostics, ICacheManager cacheManager)
 {
     _dnaDataReaderCreator = dnaDataReaderCreator;
     _dnaDiagnostics = dnaDiagnostics;
     _cacheManager = cacheManager;
     Groups = new List<Group>();
 }
Esempio n. 5
0
 /// <summary>
 /// Constructs objects
 /// </summary>
 public User()
 {
     _dnaDataReaderCreator = null;
     _dnaDiagnostics = null;
     _cacheManager = null;
     Groups = new List<Group>();
 }
Esempio n. 6
0
        /// <summary>
        /// Creates a reader using default querystring from config
        /// </summary>
        /// <param name="name">The stored procedure name</param>
        /// <param name="dnaDiagnostics">The dna diagnostic object to be used for logging</param>
        /// <returns>valid StoredProcedureReader object</returns>
        public static StoredProcedureReader Create(string name, IDnaDiagnostics dnaDiagnostics)
        {
            string connString = string.Empty;
            if (ConfigurationManager.ConnectionStrings["Database"] != null)
                connString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;

            return Create(name, connString, dnaDiagnostics);
        }
Esempio n. 7
0
		/// <summary>
		/// Get a string from a file cache if it's newer than a given expiry date
		/// </summary>
		/// <param name="cacheRoot">path to the root of the cache directory</param>
		/// <param name="cacheName">Name of the subdirectory in which to look for this item</param>
		/// <param name="itemName">Name of the cache file to create</param>
		/// <param name="Expires">If the date on the file is older than this date, don't return the string. 
		/// This value will contain the actual date of the file on return from this method</param>
		/// <param name="Value">String containing the contents of this cache item</param>
		/// <returns>True if a valid item is returned from the cache, false if no item found or it's out of date</returns>
		public static bool GetItem(IDnaDiagnostics diagnostics, string cacheRoot, string cacheName, string itemName, ref DateTime Expires, ref string Value)
		{
			if (cacheRoot.Length == 0)
			{
				// Can't cache if we don't have a root directory
				return false;
			}

            string safeItemName = StringUtils.MakeStringFileNameSafe(itemName);

            string fullPath = Path.Combine(Path.Combine(cacheRoot, cacheName), safeItemName);

			//	WIN32_FIND_DATA FindFileData;
			FileInfo info = new System.IO.FileInfo(fullPath);

			bool gotCachedFile = false;

			if (info.Exists)
			{
				// Check the expiry date
				DateTime fileDate = info.LastWriteTime;
				if (fileDate >= (Expires))
				{
					gotCachedFile = true;
                    try
                    {
                        using (StreamReader reader = new StreamReader(fullPath))
                        {
                            Value = reader.ReadToEnd();
                        }
                    }
                    catch (System.IO.IOException ex)
                    {
                        ex.Data["MethodName"] = "CacheGetItem";
                        diagnostics.WriteExceptionToLog(ex);
                        return false;
                    }
				}
				Expires = fileDate;
			}
			else
			{
                diagnostics.WriteWarningToLog("CacheGetItem", "Cannot find " + fullPath);
				return false;
			}

			if (gotCachedFile)
			{
				Statistics.AddCacheHit();
			}
			else
			{
				Statistics.AddCacheMiss();
			}
			return gotCachedFile;
		}
Esempio n. 8
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="connectionString">Connection details for accessing the database</param>
        /// <param name="caching">The caching object that the class can use for caching</param>
        public UserGroups(IDnaDataReaderCreator dnaDataReaderCreator, IDnaDiagnostics dnaDiagnostics, ICacheManager caching)
        {
            _dnaDataReaderCreator = dnaDataReaderCreator;
            _dnaDiagnostics = dnaDiagnostics;


            _cachedGroups = caching;
            if (_cachedGroups == null)
            {
                _cachedGroups = new StaticCacheManager();
            }
        }
        public void SetUp()
        {
            // Create the mockery object
            _mock = new Mockery();

            // Now create a mocked DataReader. This will be returned by the mocked input context method CreateDnaDataReader
            _mockedDataReader = _mock.NewMock<IDnaDataReader>();
            _mockedDiagnostics = _mock.NewMock<IDnaDiagnostics>();
            Stub.On(_mockedDiagnostics).Method("WriteWarningToLog").Will(Return.Value(null));

            // Ensure the Statistics object is initialised
            Statistics.ResetCounters();
        }
Esempio n. 10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dnaDiagnostics"></param>
        /// <param name="dataReaderCreator"></param>
        /// <param name="cacheManager"></param>
        /// <param name="siteList"></param>
        public Context(IDnaDiagnostics dnaDiagnostics, IDnaDataReaderCreator dataReaderCreator, ICacheManager cacheManager, ISiteList siteList)
        {
            BasePath = String.Empty;
            IpAddress = string.Empty;
            SummaryLength = 256;
            FilterBy = FilterBy.None;
            SortDirection = SortDirection.Ascending;
            SortBy = SortBy.Created;
            SignOnType = String.Empty;
            ItemsPerPage = 20;
            _dnaDiagnostics = dnaDiagnostics;
            _dnaDataReaderCreator = dataReaderCreator;

            if (_dnaDiagnostics == null)
            {
                _dnaDiagnostics = new DnaDiagnostics(RequestIdGenerator.GetNextRequestId(), DateTime.Now);
            }

            _cacheManager = cacheManager;
            _siteList = siteList;
        }
Esempio n. 11
0
 /// <summary>
 /// Constructor with dna diagnostic object
 /// </summary>
 /// <param name="dnaDiagnostics"></param>
 /// <param name="dataReaderCreator"></param>
 /// <param name="cacheManager"></param>
 /// <param name="siteList"></param>
 public Comments(IDnaDiagnostics dnaDiagnostics, IDnaDataReaderCreator dataReaderCreator, ICacheManager cacheManager, ISiteList siteList)
     : base(dnaDiagnostics, dataReaderCreator, cacheManager, siteList)
 {
 }
Esempio n. 12
0
        /// <summary>
        /// Returns the status of the objects within the signal
        /// </summary>
        /// <returns></returns>
        static public SignalStatus GetStatus(IDnaDiagnostics dnaDiagnostics)
        {
            var signalStatus = new SignalStatus();

            foreach (var signalObj in signalObjects)
            {
                try
                {
                    var obj = (ISignalBase)signalObj.Value;
                    signalStatus.Members.Add(obj.GetStats(obj.GetType()));
                }
                catch (Exception e)
                {
                    dnaDiagnostics.WriteExceptionToLog(e);
                }
            }

            return signalStatus;
        }
Esempio n. 13
0
 /// <summary>
 /// Overloaded constructor that takes in the context, DnaDataReaderCreator and DnaDiagnostics
 /// </summary>
 /// <param name="context"></param>
 /// <param name="dnaReaderCreator"></param>
 /// <param name="dnaDiagnostics"></param>
 public TwitterProfile(IInputContext context, IDnaDataReaderCreator dnaReaderCreator, IDnaDiagnostics dnaDiagnostics)
     : base(context)
 {
     this.readerCreator = dnaReaderCreator;
     this.dnaDiagnostic = dnaDiagnostics;
 }
Esempio n. 14
0
 public ExternalLinkModeration(IDnaDiagnostics dnaDiagnostics, IDnaDataReaderCreator dataReaderCreator, ICacheManager cacheManager, ISiteList siteList)
     : base(dnaDiagnostics, dataReaderCreator, cacheManager, siteList)
 {
 }
Esempio n. 15
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="dnaDiagnostics"></param>
 /// <returns></returns>
 public IDnaDataReader CreateDnaDataReader(string name, IDnaDiagnostics dnaDiagnostics)
 {
     throw new NotImplementedException();
 }
Esempio n. 16
0
        /// <summary>
        /// Creates a reader
        /// </summary>
        /// <param name="name">The stored procedure name</param>
        /// <param name="connectionString">The specific connection string to use</param>
        /// <param name="dnaDiagnostics">The dna diagnostic object to be used for logging</param>
        /// <returns>valid StoredProcedureReader object</returns>
        public static StoredProcedureReader Create(string name, string connectionString, IDnaDiagnostics dnaDiagnostics)
        {
            if (String.IsNullOrEmpty(connectionString) && ConfigurationManager.ConnectionStrings["Database"] != null)
                connectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;


            return new StoredProcedureReader(name, connectionString, dnaDiagnostics);
        }
Esempio n. 17
0
        protected bool _internalRequest = false; //if request comes from bbc servers or not

        public baseService(string connectionString, ISiteList siteList, IDnaDiagnostics dnaDiag)
        {
            if (ConfigurationManager.AppSettings["MaintenanceMode"] == "1")
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.MaintenanceMode));
            }

            _connectionString = connectionString;
            this.siteList = siteList;
            readerCreator = new DnaDataReaderCreator(connectionString, dnaDiag);
            dnaDiagnostic = dnaDiag;
            cacheManager = CacheFactory.GetCacheManager();

            if (WebOperationContext.Current == null)
            {
                throw new Exception("Error creating web operation context object.");
            }

            WebFormat.getReturnFormat((WebOperationContext.Current.IncomingRequest.ContentType == null ? "" : WebOperationContext.Current.IncomingRequest.ContentType),
                ref outputContentType, ref format);

            if (format == WebFormat.format.UNKNOWN)
            {
                throw new DnaWebProtocolException(ApiException.GetError(ErrorType.UnknownFormat));
            }
            itemsPerPage = QueryStringHelper.GetQueryParameterAsInt("itemsPerPage", 20);
            startIndex = QueryStringHelper.GetQueryParameterAsInt("startIndex", 0);
            try
            {
                sortBy = (SortBy)Enum.Parse(typeof(SortBy), QueryStringHelper.GetQueryParameterAsString("sortBy", ""));
            }
            catch { }

            try
            {
                sortDirection = (SortDirection)Enum.Parse(typeof(SortDirection), QueryStringHelper.GetQueryParameterAsString("sortDirection", ""));
            }
            catch { }

            string filter = QueryStringHelper.GetQueryParameterAsString("filterBy", "");
            if (!String.IsNullOrEmpty(filter))
            {
                try
                {
                    filterBy = (FilterBy)Enum.Parse(typeof(FilterBy), filter);
                }
                catch { }
            }

            switch (filterBy)
            {//add parsing of filter by data here.
                case FilterBy.UserList: filterByData = QueryStringHelper.GetQueryParameterAsString("userList", ""); break;
                case FilterBy.PostsWithinTimePeriod: filterByData = QueryStringHelper.GetQueryParameterAsString("timeperiod", ""); break;
            }

            prefix = QueryStringHelper.GetQueryParameterAsString("prefix", "");
            signOnType = QueryStringHelper.GetQueryParameterAsString("signOnType", "identity");
            summaryLength= QueryStringHelper.GetQueryParameterAsInt("summaryLength", 256);
            if(!String.IsNullOrEmpty(QueryStringHelper.GetCookieValueAsString("BGUID", Guid.Empty.ToString())))
            {//try for BGUID first
                try
                {
                    bbcUidCookie = new Guid(QueryStringHelper.GetCookieValueAsString("BGUID", Guid.Empty.ToString()));
                }
                catch
                {
                    bbcUidCookie = Guid.Empty;
                }
            }
            if(bbcUidCookie == Guid.Empty)
            {
                string cookie = QueryStringHelper.GetCookieValueAsString("BBC-UID", Guid.Empty.ToString());
                bbcUidCookie = UidCookieDecoder.Decode(cookie, ConfigurationManager.AppSettings["SecretKey"]);
            }
            _iPAddress = QueryStringHelper.GetQueryParameterAsString("clientIP", "");
            if (string.IsNullOrEmpty(_iPAddress))
            {
                _iPAddress = QueryStringHelper.GetHeaderValueAsString("REMOTE_ADDR", "");
            }
            _internalRequest = (QueryStringHelper.GetQueryParameterAsString("_bbc_", "") == "1");
            debugDnaUserId = "";
#if DEBUG
            debugDnaUserId = QueryStringHelper.GetQueryParameterAsString("d_identityuserid", "");
            if (debugDnaUserId.Length == 0)
            {
                debugDnaUserId = QueryStringHelper.GetCookieValueAsString("DNADEBUGUSER", "");
            }

            if (debugDnaUserId.Length > 0)
            {
                debugDnaUserId = debugDnaUserId.Replace("ID-","");
            }
#endif
            
        }
Esempio n. 18
0
		/// <summary>
		/// Puts a string value into a file-based cache. Compatible with Ripley's caching methods
		/// </summary>
		/// <param name="cacheRoot">Directory root of the global file cache</param>
		/// <param name="cacheName">Name of subdirectory to cache in</param>
		/// <param name="itemName">Name of file to cache</param>
		/// <param name="Text">String value to store in cache (usualy XML but doesn't have to be</param>
		/// <returns>True if cached successfully. False otherwise.</returns>
		public static bool PutItem(IDnaDiagnostics diagnostics, string cacheRoot, string cacheName, string itemName, string Text)
		{
            if (cacheRoot.Length == 0)
			{
				// Can't cache if we don't have a root directory
				return false;
			}
            string safeItemName = StringUtils.MakeStringFileNameSafe(itemName);

            string cacheDir = Path.Combine(cacheRoot, cacheName);

            string fullPath = Path.Combine(cacheDir, safeItemName);


			bool directoryExists = false;

            try
            {
                DirectoryInfo hFind = new DirectoryInfo(cacheDir);

                if (hFind.Exists)
                {
                    directoryExists = true;
                }
                else
                {
                    directoryExists = Directory.CreateDirectory(cacheDir).Exists;	// Gosh that's so much simpler
                }
                if (directoryExists)
                {
                    using (StreamWriter writer = new StreamWriter(fullPath))
                    {
                        writer.Write(Text);
                    }
                }
                else
                {
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                ex.Data["MethodName"] = "CachePutItem";
                diagnostics.WriteExceptionToLog(ex);
                return false;
            }
		}
Esempio n. 19
0
		/// <summary>
		/// Create a DnaDataReader for this input context.
		/// </summary>
		/// <param name="name">Name passed to DnaDataReader constructor</param>
		/// <param name="dnaDiagnostics">The diagnostics object that's used for log writing</param>
		/// <returns>Instance of a DnaDataReader.</returns>
		public IDnaDataReader CreateDnaDataReader(string name, IDnaDiagnostics dnaDiagnostics)
		{
			return StoredProcedureReader.Create(name, _dnaConfig.ConnectionString, dnaDiagnostics);
		}
Esempio n. 20
0
 /// <summary>
 /// Overloaded constructor that takes in the context, DnaDataReaderCreator and DnaDiagnostics
 /// </summary>
 /// <param name="context"></param>
 /// <param name="dnaReaderCreator"></param>
 /// <param name="dnaDiagnostics"></param>
 public MemberList(IInputContext context, IDnaDataReaderCreator dnaReaderCreator, IDnaDiagnostics dnaDiagnostics)
     : base(context)
 {
     this.readerCreator = dnaReaderCreator;
     this.dnaDiagnostic = dnaDiagnostics;
 }
Esempio n. 21
0
 /// <summary>
 /// Create a DnaDataReader for this input context.
 /// </summary>
 /// <param name="name">Name passed to DnaDataReader constructor</param>
 /// <param name="dnaDiagnostics">The diagnostics object to use for log writing</param>
 /// <returns>Instance of a DnaDataReader.</returns>
 public IDnaDataReader CreateDnaDataReader(string name, IDnaDiagnostics dnaDiagnostics)
 {
     return AppContext.TheAppContext.CreateDnaDataReader(name, dnaDiagnostics);
 }
Esempio n. 22
0
        private void SetupCallingUserSenario(int siteID, string dnaUserName, string siteSuffix, bool isKidsSite, bool useIdV4, string useUDNG, out ICacheManager mockedCacheManager, out IDnaDiagnostics mockedDiagnostics, out ISiteList mockedSiteList, out IDnaDataReaderCreator mockedCreator)
        {
            mockedCacheManager = _mocks.DynamicMock<ICacheManager>();
            mockedDiagnostics = _mocks.DynamicMock<IDnaDiagnostics>();

            mockedSiteList = _mocks.DynamicMock<ISiteList>();
            mockedSiteList.Stub(x => x.GetSiteOptionValueBool(siteID, "General", "IsKidsSite")).Return(isKidsSite);
            mockedSiteList.Stub(x => x.GetSiteOptionValueBool(siteID, "CommentForum", "UseIDv4")).Return(useIdV4);
            mockedSiteList.Stub(x => x.GetSiteOptionValueString(siteID, "User", "AutoGeneratedNames")).Return(useUDNG);

            mockedCreator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            var mockedReader = _mocks.DynamicMock<IDnaDataReader>();
            var mockedUserReader = _mocks.DynamicMock<IDnaDataReader>();
            var mockedProfileReader = _mocks.DynamicMock<IDnaDataReader>();

            var mockedUpdateReader = _mocks.DynamicMock<IDnaDataReader>();
            mockedCreator.Stub(x => x.CreateDnaDataReader("updateuser2")).Return(mockedUpdateReader);
            mockedUserReader.Stub(x => x.GetInt32("userid")).Return(TestUserAccounts.GetNormalUserAccount.UserID);
            mockedUserReader.Stub(x => x.GetString("username")).Return(dnaUserName);
            mockedUserReader.Stub(x => x.GetStringNullAsEmpty("SiteSuffix")).Return(siteSuffix);
            mockedUserReader.Stub(x => x.Read()).Return(true);
            mockedUserReader.Stub(x => x.HasRows).Return(true);

            mockedCreator.Stub(x => x.CreateDnaDataReader("getbannedemails")).Return(mockedReader);
            mockedCreator.Stub(x => x.CreateDnaDataReader("createnewuserfromidentityid")).Return(mockedUserReader);
            mockedCreator.Stub(x => x.CreateDnaDataReader("synchroniseuserwithprofile")).Return(mockedProfileReader);
        }
Esempio n. 23
0
 public CallingTwitterUser(IDnaDataReaderCreator dnaDataReaderCreator, IDnaDiagnostics dnaDiagnostics, ICacheManager caching)
     : base(dnaDataReaderCreator, dnaDiagnostics, caching)
 {
 }
Esempio n. 24
0
 /// <summary>
 /// Constructor to create a reader to the named Stored Procedure with the given connection string
 /// </summary>
 /// <param name="name">Stored procedure name</param>
 /// <param name="connectionString">Connection string to the data source.</param>
 /// <param name="dnaDiagnostics">A diagnostics object for writing trace data to</param>
 public StoredProcedureReader(string name, string connectionString, IDnaDiagnostics dnaDiagnostics)
 {
     _name = name;
     _connectionString = connectionString;
     _dnaDiagnostics = dnaDiagnostics;
 }
Esempio n. 25
0
        public User(IDnaDataReaderCreator dnaDataReaderCreator, IDnaDiagnostics dnaDiagnostics, ICacheManager caching, UserGroups userGroups)
        {
            _dnaDataReaderCreator = dnaDataReaderCreator;
            _dnaDiagnostics = dnaDiagnostics;
            if (_dnaDataReaderCreator == null)
            {
                _databaseConnectionDetails = ConfigurationManager.ConnectionStrings["Database"].ConnectionString;
            }

            Trace.WriteLine("User() - connection details = " + _databaseConnectionDetails);
            _cachingObject = caching;
            _userGroupsManager = userGroups;
        }