Example #1
0
		public UnauthorizedUserException( string message, Exception innerException, User user )
			: base( message, innerException )
		{
			User = user;
		}
Example #2
0
		static Config()
		{
			DOMConfigurator.Configure();
			try
			{
				AttemptHttpRequestCount = Convert.ToInt32(ConfigurationSettings.AppSettings["AttemptHttpRequestCount"]);
			}
			catch{}
			try
			{
				MaxResumeCountInList = Convert.ToInt32(ConfigurationSettings.AppSettings["MaxResumeCountInList"]);
			}
			catch { }
			IDictionary resumes = (IDictionary)ConfigurationSettings.GetConfig("Resumes");
			try
			{
				ResumeFilePattern = resumes["filePattern"].ToString();
			}
			catch { }
			try
			{
				TotalResumeCount = Convert.ToInt32(resumes["count"]);
			}
			catch { }
			Hashtable StringConstants = (Hashtable)ConfigurationSettings.GetConfig("StringConstants");
			try
			{
				xPathPubDate = StringConstants["xPathPubDate"].ToString();
			}
			catch { }
			try
			{
				xPathItem = StringConstants["xPathItem"].ToString();
			}
			catch { }
			try
			{
				DateFormat = StringConstants["DateFormat"].ToString();
			}
			catch { }
			try
			{
				xPathId = StringConstants["xPathId"].ToString();
			}
			catch { }
			try
			{
				xPathIdRegex = StringConstants["xPathIdRegex"].ToString();
			}
			catch { }
			try
			{
				URI = StringConstants["URI"].ToString();
			}
			catch { }
			try
			{
				GET_RESUME_LIST_URI = StringConstants["GET_RESUME_LIST_URI"].ToString();
			}
			catch { }
			try
			{
				GET_RESUME_URI = StringConstants["GET_RESUME_URI"].ToString();
			}
			catch { }
			try
			{
				xPathLink = StringConstants["xPathLink"].ToString();
			}
			catch { }
			try
			{
				UseRssLink = StringConstants["UseRssLink"].ToString();
			}
			catch { }


			Hashtable loginList = (Hashtable)ConfigurationSettings.GetConfig("Logins");
			foreach( string key in loginList.Keys )
			{
				string password = loginList[ key ].ToString();
				if( password == null || password == "" )
				{
					throw new ConfigurationException( "Password cannot be empty" );
				}
				User user = new User( key, password );
				UserList.Add( user );
			}
			if( loginList.Count < 1 )
			{
				throw new ConfigurationException( "Empty the user login list" );
			}
			IDictionary sessions = (IDictionary)ConfigurationSettings.GetConfig( "Sessions" );
			try
			{
				SessionCount = Convert.ToInt32( sessions[ "count" ] );
			}
			catch
			{
			}
			try
			{
				SessionDelayMin = TimeSpan.Parse( sessions[ "delayMin" ].ToString() );
			}
			catch
			{
			}
			try
			{
				SessionDelayMax = TimeSpan.Parse( sessions[ "delayMax" ].ToString() );
			}
			catch
			{
			}
			if( SessionDelayMin > SessionDelayMax )
			{
				throw new ConfigurationException( "The session delay max value must be greater than or equal to min value" );
			}
			try
			{
				using( StreamReader readStream = new StreamReader( LAST_PROCESSED_DATETIME_FILE, Encoding.UTF8 ) )
				{
					LastProcessedResumeTimestamp = DateTime.Parse( readStream.ReadLine() );
				}
			}
			catch
			{
			}
		}
Example #3
0
		public UnauthorizedUserException( User user ): base()
		{
			User = user;
		}
Example #4
0
		public static Stream GetFromWeb( string requestUri, User user )
		{
			Stream result;
			CredentialCache myCredentialCache = new CredentialCache();
			myCredentialCache.Add( new Uri( Config.URI ), "Basic", new NetworkCredential( user.Login, user.Password ) );
			int count = 0;
			while( true )
			{
				try
				{
					HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create( requestUri );
					httpWebRequest.PreAuthenticate = true;
					httpWebRequest.Credentials = myCredentialCache;
					httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
					httpWebRequest.Accept = "text/html";
					httpWebRequest.Headers.Add( "Accept-Language", "ru" );
					result = httpWebRequest.GetResponse().GetResponseStream();
					break;
				}
				catch( WebException ex )
				{
					if( ex.Status == WebExceptionStatus.ProtocolError &&
					    ( ex.Response as HttpWebResponse ).StatusCode == HttpStatusCode.Unauthorized )
					{
						throw new UnauthorizedUserException( user );
					}
					else
					{
						if( count < Config.AttemptHttpRequestCount )
						{
							count++;
						}
						else
						{
							throw;
						}
					}
				}
			}
			return result;
		}