Skip to content

Commit

Permalink
dynamics: handle null-refs error
Browse files Browse the repository at this point in the history
  • Loading branch information
rollrat committed Nov 11, 2022
1 parent 33f3a38 commit 47e1dc0
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CustomCrawler/CustomCrawler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@
</Compile>
<Compile Include="SeleniumWrapper.cs" />
<Compile Include="URLHelper.cs" />
<Compile Include="URLTools.xaml.cs">
<DependentUpon>URLTools.xaml</DependentUpon>
</Compile>
<Compile Include="Utils.cs" />
<Page Include="CustomCrawler.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -299,6 +302,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="URLTools.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down
2 changes: 2 additions & 0 deletions CustomCrawler/CustomCrawler.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@
<Button x:Name="Diff" Content="Diff" Click="Diff_Click"/>
<Button x:Name="Cluster" Margin="0 4 0 0" Content="Cluster" Click="Cluster_Click"/>
<Button x:Name="Dynamics" Margin="0 4 0 0" Content="Dynamics" Click="Dynamics_Click"/>
<Button x:Name="URL" Margin="0 4 0 0" Content="URL Disasm" Click="URL_Click"/>
<TextBlock Text="Options" Margin="0 4 0 0"/>
<CheckBox x:Name="driverCheck" Margin="0 4 0 0" Content="Using driver" IsChecked="False"/>
<CheckBox x:Name="EucKR" Content="Using EUC-KR" IsChecked="False"/>
<CheckBox x:Name="Mobile" Content="Mobile Agent" IsChecked="False"/>
<TextBlock Text="Documents" Margin="0 16 0 0"/>
<Button x:Name="Manual" Content="Manual" Click="Manual_Click" IsEnabled="False"/>
</StackPanel>
Expand Down
7 changes: 7 additions & 0 deletions CustomCrawler/CustomCrawler.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ private void URLButton_Click(object sender, RoutedEventArgs e)
var client = NetCommon.GetDefaultClient();
if (EucKR.IsChecked == true)
client.Encoding = Encoding.GetEncoding(51949);
if (Mobile.IsChecked == true)
client.Headers["User-Agent"] = "Mozilla/5.0 (Android 7.0; Mobile; rv:54.0) Gecko/54.0 Firefox/54.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/603.2.4"; ;
html = client.DownloadString(URLText.Text);
}
else
Expand Down Expand Up @@ -509,5 +511,10 @@ private void Dynamics_Click(object sender, RoutedEventArgs e)
if (CustomCrawlerDynamics.opened == false)
new CustomCrawlerDynamics().Show();
}

private void URL_Click(object sender, RoutedEventArgs e)
{
new URLTools().Show();
}
}
}
2 changes: 1 addition & 1 deletion CustomCrawler/CustomCrawlerDiff.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void marking(HtmlTree tree)

private void DiffList_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
if (DiffList.SelectedItems.Count > 0)
if (DiffList.SelectedItems.Count > 0 && browser.IsLoaded)
{
var node = (DiffList.SelectedItems[0] as CustomCrawlerDiffDataGridItemViewModel).Location;

Expand Down
46 changes: 41 additions & 5 deletions CustomCrawler/CustomCrawlerDynamics.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private void Hyperlink_MouseLeftButtonDown(object sender, MouseButtonEventArgs e

#region Build for Hover

public Dictionary<string, StackTrace> stacks = new Dictionary<string, StackTrace>();
public Dictionary<long, StackTrace> stacks = new Dictionary<long, StackTrace>();
//private async Task find_source(Node nn)
//{
// _ = Application.Current.Dispatcher.BeginInvoke(new Action(
Expand Down Expand Up @@ -259,6 +259,26 @@ private void Hyperlink_MouseLeftButtonDown(object sender, MouseButtonEventArgs e
// }
// }
//}
private async Task find_source(Node nn)
{
_ = Application.Current.Dispatcher.BeginInvoke(new Action(
delegate
{
URLText.Text = nn.NodeId.ToString();
}));
var st = await ss.SendAsync(new GetNodeStackTracesCommand { NodeId = nn.NodeId });
if (st.Result != null && st.Result.Creation != null)
{
stacks.Add(nn.NodeId, st.Result.Creation);
}
if (nn.Children != null)
{
foreach (var child in nn.Children)
{
await find_source(child);
}
}
}

private void init_overlay()
{
Expand Down Expand Up @@ -338,13 +358,29 @@ await Application.Current.Dispatcher.BeginInvoke(new Action(
Build.IsEnabled = false;
}));

var doc = await ss.SendAsync(new GetDocumentCommand { Depth = -1 });
var docTask = ss.SendAsync(new GetDocumentCommand { Depth = -1 });
var whenAnyTask = await Task.WhenAny(docTask, Task.Delay(TimeSpan.FromSeconds(10)));

if (doc.Result != null)
if (whenAnyTask != docTask)
{
//stacks = new Dictionary<string, StackTrace>();
//await find_source(doc.Result.Root);
await Application.Current.Dispatcher.BeginInvoke(new Action(
delegate
{
MessageBox.Show("Please try again later! " +
"If this error persists, restart the program. " +
"If that continues, please open new issue to https://github.com/rollrat/custom-crawler.",
"Custom Craweler", MessageBoxButton.OK, MessageBoxImage.Error);
Build.IsEnabled = true;
}));
return;
}

var doc = await docTask;

if (doc.Result != null)
{
stacks = new Dictionary<long, StackTrace>();
await find_source(doc.Result.Root);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion CustomCrawler/JSManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void find_internal(ref List<INode> result, IEnumerable<INode> node, int line, in

var z = node.ElementAt(ii);

if (z.Location.Start.Line > line || z.Location.End.Line < line)
if (z == null || z.Location.Start.Line > line || z.Location.End.Line < line)
return;

if (z.Location.Start.Line == z.Location.End.Line)
Expand Down
36 changes: 36 additions & 0 deletions CustomCrawler/URLTools.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Window x:Class="CustomCrawler.URLTools"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CustomCrawler"
mc:Ignorable="d"
Title="URLTools" Height="450" Width="800">
<Grid Margin="8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<Grid.Resources>
<Style x:Key="TextBlockStyleKey" TargetType="{x:Type TextBlock}">
<Setter Property="TextTrimming" Value="CharacterEllipsis"/>
<Setter Property="Margin" Value="5 0 0 0" />
</Style>
</Grid.Resources>

<TextBlock Grid.Row="0" Grid.Column="0" Text="URL: " FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Right"/>
<TextBox x:Name="URLText" Grid.Row="0" Grid.Column="1" FontSize="15"/>
<Button x:Name="URLButton" Content="Process" Grid.Row="0" Grid.Column="2" Width="120" Click="URLButton_Click" Margin="8 0 8 0"/>

<TextBlock Grid.Row="1" Grid.Column="0" Text="Value: " FontSize="15" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0 4 0 0"/>
<TextBox x:Name="Process" Grid.Row="1" Grid.Column="1" FontSize="15" Margin="0 4 0 0"/>
</Grid>
</Window>
38 changes: 38 additions & 0 deletions CustomCrawler/URLTools.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CustomCrawler
{
/// <summary>
/// URLTools.xaml에 대한 상호 작용 논리
/// </summary>
public partial class URLTools : Window
{
public URLTools()
{
InitializeComponent();
}

private void URLButton_Click(object sender, RoutedEventArgs e)
{

var uh = new URLHelper(URLText.Text);

foreach (var param in uh.Parameters)
{
Process.Text += $"{param.Key} = {param.Value}\n";
}
}
}
}

0 comments on commit 47e1dc0

Please sign in to comment.