This repository was archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 805
Expand file tree
/
Copy pathDesignerBinding.cs
More file actions
83 lines (66 loc) · 1.92 KB
/
DesignerBinding.cs
File metadata and controls
83 lines (66 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 11.02.2014
* Time: 20:19
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.IO;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.Reporting.Factories;
using ICSharpCode.Reporting.Items;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Workbench;
using ICSharpCode.Reporting.Addin.Commands;
using ICSharpCode.Reporting.Addin.Factory;
namespace ICSharpCode.Reporting.Addin.DesignerBinding {
public class ReportDesignerBinding:IDisplayBinding {
public bool IsPreferredBindingForFile(FileName fileName)
{
return true;
}
public bool CanCreateContentForFile(FileName fileName)
{
return Path.GetExtension(fileName).Equals(".srd", StringComparison.OrdinalIgnoreCase);
}
public double AutoDetectFileContent(FileName fileName, System.IO.Stream fileContent, string detectedMimeType)
{
throw new System.NotImplementedException();
}
public IViewContent CreateContentForFile(OpenedFile file)
{
bool hasContent = false;
using (var sr = new StreamReader(file.OpenRead()))
{
string line;
while (!hasContent && (line = sr.ReadLine()) != null)
if (line.Length != 0)
hasContent = true;
}
if (!hasContent) {
var reportModel = ReportModelFactory.Create();
var reportFactory = new CreateFormSheetFromModel();
var xml = reportFactory.ToXml(reportModel);
var doc = new XmlDocument();
doc.LoadXml(xml.ToString());
var ar = XmlToArray(doc);
file.SetData(ar);
file.MakeDirty();
}
var viewCmd = new CreateDesignerCommand(file);
viewCmd.Run();
LoggingService.Info("return DesignerView");
return viewCmd.DesignerView;
}
static byte[] XmlToArray(XmlDocument doc)
{
using (var stream = new MemoryStream()) {
doc.Save(stream);
return stream.ToArray();
}
}
}
}