Skip to content

Commit

Permalink
Exception Download Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Walterwhatwater committed May 4, 2016
1 parent a1faba1 commit 14c650b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<DefineConstants>TRACE;DEBUG;NET_45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<DefineConstants>TRACE;DEBUG;NET_45;TEST</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public abstract class DownloadValidation
[Flags]
public enum Types
{
Contains
Contains,
Exception
}

public abstract Types Type { get; internal set; }
Expand All @@ -26,7 +27,7 @@ public class ContainsDownloadValidation : DownloadValidation
public override bool Validate(Page page, out DownloadValidationResult result)
{
string rawText = page.Content;
if(string.IsNullOrEmpty(rawText))
if (string.IsNullOrEmpty(rawText))
{
throw new SpiderExceptoin("Download failed or response is null.");
}
Expand All @@ -42,4 +43,35 @@ public override bool Validate(Page page, out DownloadValidationResult result)
}
}
}

public class ExceptionDownloadValidation : DownloadValidation
{
public override Types Type { get; internal set; } = Types.Exception;

public string ExceptionMessage { get; set; } = string.Empty;

public override bool Validate(Page page, out DownloadValidationResult result)
{
string rawText = page.Content;
if (string.IsNullOrEmpty(rawText))
{
throw new SpiderExceptoin("Download failed or response is null.");
}
if (page.Exception != null)
{
if (string.IsNullOrEmpty(ExceptionMessage))
{
result = Result;
return false;
}
if (page.Exception.Message.Contains(ExceptionMessage))
{
result = Result;
return false;
}
}
result = DownloadValidationResult.Success;
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<DefineConstants>TRACE;DEBUG;NET_45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<DefineConstants>TRACE;DEBUG;NET_45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<DefineConstants>TRACE;DEBUG;NET_45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<DefineConstants>TRACE;DEBUG;NET_45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
Expand Down

0 comments on commit 14c650b

Please sign in to comment.