Skip to content

Commit 47e1dc0

Browse files
committed
dynamics: handle null-refs error
1 parent 33f3a38 commit 47e1dc0

8 files changed

+133
-7
lines changed

CustomCrawler/CustomCrawler.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@
208208
</Compile>
209209
<Compile Include="SeleniumWrapper.cs" />
210210
<Compile Include="URLHelper.cs" />
211+
<Compile Include="URLTools.xaml.cs">
212+
<DependentUpon>URLTools.xaml</DependentUpon>
213+
</Compile>
211214
<Compile Include="Utils.cs" />
212215
<Page Include="CustomCrawler.xaml">
213216
<Generator>MSBuild:Compile</Generator>
@@ -299,6 +302,10 @@
299302
<SubType>Designer</SubType>
300303
<Generator>MSBuild:Compile</Generator>
301304
</Page>
305+
<Page Include="URLTools.xaml">
306+
<SubType>Designer</SubType>
307+
<Generator>MSBuild:Compile</Generator>
308+
</Page>
302309
</ItemGroup>
303310
<ItemGroup>
304311
<Compile Include="Properties\AssemblyInfo.cs">

CustomCrawler/CustomCrawler.xaml

+2
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@
8787
<Button x:Name="Diff" Content="Diff" Click="Diff_Click"/>
8888
<Button x:Name="Cluster" Margin="0 4 0 0" Content="Cluster" Click="Cluster_Click"/>
8989
<Button x:Name="Dynamics" Margin="0 4 0 0" Content="Dynamics" Click="Dynamics_Click"/>
90+
<Button x:Name="URL" Margin="0 4 0 0" Content="URL Disasm" Click="URL_Click"/>
9091
<TextBlock Text="Options" Margin="0 4 0 0"/>
9192
<CheckBox x:Name="driverCheck" Margin="0 4 0 0" Content="Using driver" IsChecked="False"/>
9293
<CheckBox x:Name="EucKR" Content="Using EUC-KR" IsChecked="False"/>
94+
<CheckBox x:Name="Mobile" Content="Mobile Agent" IsChecked="False"/>
9395
<TextBlock Text="Documents" Margin="0 16 0 0"/>
9496
<Button x:Name="Manual" Content="Manual" Click="Manual_Click" IsEnabled="False"/>
9597
</StackPanel>

CustomCrawler/CustomCrawler.xaml.cs

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ private void URLButton_Click(object sender, RoutedEventArgs e)
9292
var client = NetCommon.GetDefaultClient();
9393
if (EucKR.IsChecked == true)
9494
client.Encoding = Encoding.GetEncoding(51949);
95+
if (Mobile.IsChecked == true)
96+
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"; ;
9597
html = client.DownloadString(URLText.Text);
9698
}
9799
else
@@ -509,5 +511,10 @@ private void Dynamics_Click(object sender, RoutedEventArgs e)
509511
if (CustomCrawlerDynamics.opened == false)
510512
new CustomCrawlerDynamics().Show();
511513
}
514+
515+
private void URL_Click(object sender, RoutedEventArgs e)
516+
{
517+
new URLTools().Show();
518+
}
512519
}
513520
}

CustomCrawler/CustomCrawlerDiff.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private void marking(HtmlTree tree)
123123

124124
private void DiffList_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
125125
{
126-
if (DiffList.SelectedItems.Count > 0)
126+
if (DiffList.SelectedItems.Count > 0 && browser.IsLoaded)
127127
{
128128
var node = (DiffList.SelectedItems[0] as CustomCrawlerDiffDataGridItemViewModel).Location;
129129

CustomCrawler/CustomCrawlerDynamics.xaml.cs

+41-5
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private void Hyperlink_MouseLeftButtonDown(object sender, MouseButtonEventArgs e
217217

218218
#region Build for Hover
219219

220-
public Dictionary<string, StackTrace> stacks = new Dictionary<string, StackTrace>();
220+
public Dictionary<long, StackTrace> stacks = new Dictionary<long, StackTrace>();
221221
//private async Task find_source(Node nn)
222222
//{
223223
// _ = Application.Current.Dispatcher.BeginInvoke(new Action(
@@ -259,6 +259,26 @@ private void Hyperlink_MouseLeftButtonDown(object sender, MouseButtonEventArgs e
259259
// }
260260
// }
261261
//}
262+
private async Task find_source(Node nn)
263+
{
264+
_ = Application.Current.Dispatcher.BeginInvoke(new Action(
265+
delegate
266+
{
267+
URLText.Text = nn.NodeId.ToString();
268+
}));
269+
var st = await ss.SendAsync(new GetNodeStackTracesCommand { NodeId = nn.NodeId });
270+
if (st.Result != null && st.Result.Creation != null)
271+
{
272+
stacks.Add(nn.NodeId, st.Result.Creation);
273+
}
274+
if (nn.Children != null)
275+
{
276+
foreach (var child in nn.Children)
277+
{
278+
await find_source(child);
279+
}
280+
}
281+
}
262282

263283
private void init_overlay()
264284
{
@@ -338,13 +358,29 @@ await Application.Current.Dispatcher.BeginInvoke(new Action(
338358
Build.IsEnabled = false;
339359
}));
340360

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

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

378+
var doc = await docTask;
379+
380+
if (doc.Result != null)
381+
{
382+
stacks = new Dictionary<long, StackTrace>();
383+
await find_source(doc.Result.Root);
348384
}
349385
else
350386
{

CustomCrawler/JSManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void find_internal(ref List<INode> result, IEnumerable<INode> node, int line, in
9393

9494
var z = node.ElementAt(ii);
9595

96-
if (z.Location.Start.Line > line || z.Location.End.Line < line)
96+
if (z == null || z.Location.Start.Line > line || z.Location.End.Line < line)
9797
return;
9898

9999
if (z.Location.Start.Line == z.Location.End.Line)

CustomCrawler/URLTools.xaml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Window x:Class="CustomCrawler.URLTools"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:CustomCrawler"
7+
mc:Ignorable="d"
8+
Title="URLTools" Height="450" Width="800">
9+
<Grid Margin="8">
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="Auto"/>
12+
<RowDefinition Height="*"/>
13+
<RowDefinition Height="Auto"/>
14+
</Grid.RowDefinitions>
15+
16+
<Grid.ColumnDefinitions>
17+
<ColumnDefinition Width="Auto"/>
18+
<ColumnDefinition Width="*"/>
19+
<ColumnDefinition Width="Auto"/>
20+
</Grid.ColumnDefinitions>
21+
22+
<Grid.Resources>
23+
<Style x:Key="TextBlockStyleKey" TargetType="{x:Type TextBlock}">
24+
<Setter Property="TextTrimming" Value="CharacterEllipsis"/>
25+
<Setter Property="Margin" Value="5 0 0 0" />
26+
</Style>
27+
</Grid.Resources>
28+
29+
<TextBlock Grid.Row="0" Grid.Column="0" Text="URL: " FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Right"/>
30+
<TextBox x:Name="URLText" Grid.Row="0" Grid.Column="1" FontSize="15"/>
31+
<Button x:Name="URLButton" Content="Process" Grid.Row="0" Grid.Column="2" Width="120" Click="URLButton_Click" Margin="8 0 8 0"/>
32+
33+
<TextBlock Grid.Row="1" Grid.Column="0" Text="Value: " FontSize="15" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0 4 0 0"/>
34+
<TextBox x:Name="Process" Grid.Row="1" Grid.Column="1" FontSize="15" Margin="0 4 0 0"/>
35+
</Grid>
36+
</Window>

CustomCrawler/URLTools.xaml.cs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Shapes;
14+
15+
namespace CustomCrawler
16+
{
17+
/// <summary>
18+
/// URLTools.xaml에 대한 상호 작용 논리
19+
/// </summary>
20+
public partial class URLTools : Window
21+
{
22+
public URLTools()
23+
{
24+
InitializeComponent();
25+
}
26+
27+
private void URLButton_Click(object sender, RoutedEventArgs e)
28+
{
29+
30+
var uh = new URLHelper(URLText.Text);
31+
32+
foreach (var param in uh.Parameters)
33+
{
34+
Process.Text += $"{param.Key} = {param.Value}\n";
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)