Skip to content

Commit ccb7108

Browse files
authored
Merge pull request #775 from AntonyCorbett/fix/external-preview
Fix/external preview
2 parents c715642 + b39f000 commit ccb7108

13 files changed

Lines changed: 106 additions & 74 deletions

File tree

AddIns/ScreenCaptureAddin/SnagItAutomation.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,14 @@ protected void SetError(Exception ex, bool checkInner = false)
489489
{
490490
if (ex == null)
491491
ErrorMessage = string.Empty;
492+
else
493+
{
494+
Exception e = ex;
495+
if (checkInner)
496+
e = e.GetBaseException();
492497

493-
Exception e = ex;
494-
if (checkInner)
495-
e = e.GetBaseException();
496-
497-
ErrorMessage = e.Message;
498+
ErrorMessage = e.Message;
499+
}
498500
}
499501

500502
}

AddIns/WebLogAddin/LocalJekyll/LocalJekyllPublisher.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,14 @@ protected void SetError(Exception ex, bool checkInner = false)
580580
{
581581
if (ex == null)
582582
ErrorMessage = string.Empty;
583+
else
584+
{
585+
Exception e = ex;
586+
if (checkInner)
587+
e = e.GetBaseException();
583588

584-
Exception e = ex;
585-
if (checkInner)
586-
e = e.GetBaseException();
587-
588-
ErrorMessage = e.Message;
589+
ErrorMessage = e.Message;
590+
}
589591
}
590592
#endregion
591593
}

AddIns/WebLogAddin/MetaWebLogApi/helpers/FileSystemHelper.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ static class FileSystemHelper
1616
/// <returns></returns>
1717
public static byte[] GetFileBytes(string pathToFile)
1818
{
19-
var fs = new FileStream(pathToFile, FileMode.Open, FileAccess.Read);
20-
byte[] filebytes = new byte[fs.Length];
21-
fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
22-
return filebytes;
19+
using (var fs = new FileStream(pathToFile, FileMode.Open, FileAccess.Read))
20+
{
21+
byte[] filebytes = new byte[fs.Length];
22+
fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
23+
return filebytes;
24+
}
2325
}
2426
}
2527
}

MarkdownMonster/Controls/ContextMenus/EditorContextMenu.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,10 @@ private bool CheckForImageLink(string line, AcePosition pos)
573573

574574
try
575575
{
576-
var wc = new WebClient();
577-
await wc.DownloadFileTaskAsync(new Uri(imageLink), sd.FileName);
576+
using (var wc = new WebClient())
577+
{
578+
await wc.DownloadFileTaskAsync(new Uri(imageLink), sd.FileName);
579+
}
578580

579581
string filename;
580582
if (doc.Filename.Equals("untitled", StringComparison.OrdinalIgnoreCase))

MarkdownMonster/Windows/ConfigurationEditor/ConfigurationParser.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ protected void SetError(Exception ex, bool checkInner = false)
109109
{
110110
if (ex == null)
111111
ErrorMessage = string.Empty;
112+
else
113+
{
114+
Exception e = ex;
115+
if (checkInner)
116+
e = e.GetBaseException();
112117

113-
Exception e = ex;
114-
if (checkInner)
115-
e = e.GetBaseException();
116-
117-
ErrorMessage = e.Message;
118+
ErrorMessage = e.Message;
119+
}
118120
}
119121

120122

MarkdownMonster/Windows/PreviewBrowser/PreviewBrowserWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ protected override void OnClosing(CancelEventArgs e)
8484
{
8585
IsClosed = true;
8686

87-
var config = mmApp.Model.Configuration.WindowPosition;
87+
mmApp.Model.IsPreviewBrowserVisible = false;
8888

89+
var config = mmApp.Model.Configuration.WindowPosition;
8990

9091
config.PreviewLeft = Convert.ToInt32(Left);
9192
config.PreviewTop = Convert.ToInt32(Top);

MarkdownMonster/Windows/TableEditor/TableEditor.xaml.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ public void CreateTableFromClipboardHtml(string html = null)
292292
{
293293
data = parser.ParseMarkdownToData(html);
294294
}
295-
else if (html.Contains("-|-") || html.Contains("- | -") || html.Contains(""))
296-
{
297-
data = parser.ParseMarkdownToData(html);
298-
}
299295
else if (html.Contains("-+-"))
300296
{
301297
data = parser.ParseMarkdownGridTableToData(html);

MarkdownMonster/_Classes/BrowserComInterop/BaseBrowserInterop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public object Instance
3434
set
3535
{
3636
_instance = value;
37-
InstanceType = _instance.GetType();
37+
InstanceType = _instance?.GetType();
3838
}
3939
}
4040
private object _instance;
@@ -74,7 +74,7 @@ public object Invoke(string method, params object[] parameters)
7474
try
7575
{
7676
#endif
77-
return InstanceType.InvokeMember(method, flags | BindingFlags.InvokeMethod, null, Instance,
77+
return InstanceType?.InvokeMember(method, flags | BindingFlags.InvokeMethod, null, Instance,
7878
parameters );
7979
#if DEBUG
8080
}

MarkdownMonster/_Classes/Utilities/GitHelper.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,12 +1002,14 @@ protected void SetError(Exception ex, bool checkInner = false)
10021002
{
10031003
if (ex == null)
10041004
this.ErrorMessage = string.Empty;
1005+
else
1006+
{
1007+
Exception e = ex;
1008+
if (checkInner)
1009+
e = e.GetBaseException();
10051010

1006-
Exception e = ex;
1007-
if (checkInner)
1008-
e = e.GetBaseException();
1009-
1010-
ErrorMessage = e.Message;
1011+
ErrorMessage = e.Message;
1012+
}
10111013
}
10121014
#endregion
10131015

MarkdownMonster/_Classes/Utilities/HtmlPackager.cs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,10 @@ private void ProcessCss(HtmlDocument doc)
345345
{
346346
if (url.StartsWith("http"))
347347
{
348-
var http = new WebClient();
349-
cssText = http.DownloadString(url);
348+
using (var http = new WebClient())
349+
{
350+
cssText = http.DownloadString(url);
351+
}
350352
}
351353
else if (url.StartsWith("file:///"))
352354
{
@@ -359,8 +361,10 @@ private void ProcessCss(HtmlDocument doc)
359361
url = uri.AbsoluteUri;
360362
if (url.StartsWith("http") && url.Contains("://"))
361363
{
362-
var http = new WebClient();
363-
cssText = http.DownloadString(url);
364+
using (var http = new WebClient())
365+
{
366+
cssText = http.DownloadString(url);
367+
}
364368
}
365369
else
366370
cssText = File.ReadAllText(uri.LocalPath);
@@ -418,8 +422,10 @@ private void ProcessScripts(HtmlDocument doc)
418422
{
419423
if (url.StartsWith("http"))
420424
{
421-
var http = new WebClient();
422-
scriptData = http.DownloadData(url);
425+
using (var http = new WebClient())
426+
{
427+
scriptData = http.DownloadData(url);
428+
}
423429
}
424430
else if (url.StartsWith("file:///"))
425431
{
@@ -432,8 +438,10 @@ private void ProcessScripts(HtmlDocument doc)
432438
url = uri.AbsoluteUri;
433439
if (url.StartsWith("http") && url.Contains("://"))
434440
{
435-
var http = new WebClient();
436-
scriptData = http.DownloadData(url);
441+
using (var http = new WebClient())
442+
{
443+
scriptData = http.DownloadData(url);
444+
}
437445
}
438446
else
439447
scriptData = File.ReadAllBytes(uri.LocalPath);
@@ -483,9 +491,11 @@ private void ProcessImages(HtmlDocument doc)
483491
{
484492
if (url.StartsWith("http"))
485493
{
486-
var http = new WebClient();
487-
imageData = http.DownloadData(url);
488-
contentType = http.ResponseHeaders[System.Net.HttpResponseHeader.ContentType];
494+
using (var http = new WebClient())
495+
{
496+
imageData = http.DownloadData(url);
497+
contentType = http.ResponseHeaders[System.Net.HttpResponseHeader.ContentType];
498+
}
489499
}
490500
else if (url.StartsWith("file:///"))
491501
{
@@ -499,8 +509,10 @@ private void ProcessImages(HtmlDocument doc)
499509

500510
if (uri.Scheme.StartsWith("http"))
501511
{
502-
var http = new WebClient();
503-
imageData = http.DownloadData(uri.AbsoluteUri);
512+
using (var http = new WebClient())
513+
{
514+
imageData = http.DownloadData(uri.AbsoluteUri);
515+
}
504516
}
505517
else
506518
imageData = File.ReadAllBytes(uri.LocalPath);
@@ -581,9 +593,11 @@ private string ProcessUrls(string html, string baseUrl)
581593
{
582594
if (url.StartsWith("http"))
583595
{
584-
var http = new WebClient();
585-
linkData = http.DownloadData(url);
586-
contentType = http.ResponseHeaders[HttpResponseHeader.ContentType];
596+
using (var http = new WebClient())
597+
{
598+
linkData = http.DownloadData(url);
599+
contentType = http.ResponseHeaders[HttpResponseHeader.ContentType];
600+
}
587601
}
588602
else if (url.StartsWith("file:///"))
589603
{
@@ -602,8 +616,10 @@ private string ProcessUrls(string html, string baseUrl)
602616
url = uri.AbsoluteUri;
603617
if (url.StartsWith("http") && url.Contains("://"))
604618
{
605-
var http = new WebClient();
606-
linkData = http.DownloadData(url);
619+
using (var http = new WebClient())
620+
{
621+
linkData = http.DownloadData(url);
622+
}
607623
}
608624
else
609625
linkData = File.ReadAllBytes(uri.LocalPath);
@@ -673,12 +689,14 @@ protected void SetError(Exception ex, bool checkInner = false)
673689
{
674690
if (ex == null)
675691
this.ErrorMessage = string.Empty;
692+
else
693+
{
694+
Exception e = ex;
695+
if (checkInner)
696+
e = e.GetBaseException();
676697

677-
Exception e = ex;
678-
if (checkInner)
679-
e = e.GetBaseException();
680-
681-
ErrorMessage = e.Message;
698+
ErrorMessage = e.Message;
699+
}
682700
}
683701
#endregion
684702
}

0 commit comments

Comments
 (0)