Datei: NDOPackage/Commands/AddPersistentClassVb.cs

Last Commit (3030986)
1 //
2 // Copyright (c) 2002-2019 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.IO;
25 using System.Windows.Forms;
26 using EnvDTE;
27 using EnvDTE80;
28 using Microsoft.VisualStudio.CommandBars;
29
30 namespace NDOVsPackage.Commands
31 {
32 ····/// <summary>
33 ····/// Zusammenfassung für AddPersistentClassVb.
34 ····/// </summary>
35 ····internal class AddPersistentClassVb
36 ····{
37 ········Project project;
38 ········string className;
39 ········bool isSerializable;
40 ········ProjectItem parentItem;
41
42 ········public AddPersistentClassVb(Project project, string className, bool isSerializable, ProjectItem parentItem)
43 ········{
44 ············this.project = project;
45 ············this.className = className;
46 ············this.isSerializable = isSerializable;
47 ············this.parentItem = parentItem;
48 ········}
49
50 ········public void DoIt()
51 ········{
52 ············try
53 ············{
54 ················StreamWriter sw;
55 ················string fileName = Path.GetDirectoryName( project.FileName ) + "\\" + className + ".vb";
56 ················string partialFileName = fileName.Substring( 0, fileName.Length - 3 );
57 ················partialFileName += ".ndo.vb";
58 ················using (sw = new StreamWriter( fileName, false, System.Text.Encoding.UTF8 ))
59 ················{
60
61 ····················sw.WriteLine( "Imports System.Linq" );
62 ····················sw.WriteLine( "Imports System.Collections.Generic" );
63 ····················sw.WriteLine( "Imports NDO\n" );
64
65 ····················sw.WriteLine( "''' <summary>" );
66 ····················sw.WriteLine( "'''" );
67 ····················sw.WriteLine( "''' </summary>" );
68 ····················sw.WriteLine( "''' <remarks></remarks>" );
69 ····················sw.Write( "<NDOPersistent" );
70 ····················if (isSerializable)
71 ························sw.Write( ", Serializable" );
72 ····················sw.WriteLine( "> _" );
73 ····················sw.WriteLine( "Partial Public Class " + className );
74 ····················sw.WriteLine( "End Class" );
75 ················}
76 ················ProjectItem pi = null;
77 ················if ( parentItem == null )
78 ····················pi = project.ProjectItems.AddFromFile( fileName );
79 ················else
80 ····················pi = parentItem.ProjectItems.AddFromFile( fileName );
81 ················using (sw = new StreamWriter( partialFileName ))
82 ················{
83 ····················string newPartial = partialTemplate.Replace( "#cl#", className );
84 ····················sw.Write( newPartial );
85 ················}
86 ················pi.ProjectItems.AddFromFile( partialFileName );
87 ················CodeGenHelper.ActivateAndGetTextDocument(project, Path.GetFileName(fileName));
88 ············}
89 ············catch(Exception ex)
90 ············{
91 ················MessageBox.Show(ex.Message);
92 ············}
93 ········}
94
95 ········readonly string partialTemplate = @"Imports NDO
96 ' Don't change this code.
97 ' This interface implementation exists only for intellisense support.
98 ' Any code in this file will be replaced by the enhancer.
99 Partial Public Class #cl#
100 ····Implements IPersistentObject
101
102 ····Public Sub NDOMarkDirty() Implements NDO.IPersistentObject.NDOMarkDirty
103
104 ····End Sub
105
106 ····Public Property NDOObjectId() As NDO.ObjectId Implements NDO.IPersistentObject.NDOObjectId
107 ········Get
108 ············Throw New NotImplementedException
109 ········End Get
110 ········Set(ByVal value As NDO.ObjectId)
111 ············Throw New NotImplementedException
112 ········End Set
113 ····End Property
114
115 ····Public Property NDOObjectState() As NDO.NDOObjectState Implements NDO.IPersistentObject.NDOObjectState
116 ········Get
117 ············Throw New NotImplementedException
118 ········End Get
119 ········Set(ByVal value As NDO.NDOObjectState)
120 ············Throw New NotImplementedException
121 ········End Set
122 ····End Property
123
124 ····Public Property NDOTimeStamp() As System.Guid Implements NDO.IPersistentObject.NDOTimeStamp
125 ········Get
126 ············Throw New NotImplementedException
127 ········End Get
128 ········Set(ByVal value As System.Guid)
129 ············Throw New NotImplementedException
130 ········End Set
131 ····End Property
132 End Class
133 ";
134 ····}
135 }
136
New Commit (ed9120d)
1 //
2 // Copyright (c) 2002-2019 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.IO;
25 using System.Windows.Forms;
26 using EnvDTE;
27 using Project = EnvDTE. Project;
28 using Microsoft.VisualStudio.CommandBars;
29
30 namespace NDOVsPackage.Commands
31 {
32 ····/// <summary>
33 ····/// Zusammenfassung für AddPersistentClassVb.
34 ····/// </summary>
35 ····internal class AddPersistentClassVb
36 ····{
37 ········Project project;
38 ········string className;
39 ········bool isSerializable;
40 ········ProjectItem parentItem;
41
42 ········public AddPersistentClassVb(Project project, string className, bool isSerializable, ProjectItem parentItem)
43 ········{
44 ············this.project = project;
45 ············this.className = className;
46 ············this.isSerializable = isSerializable;
47 ············this.parentItem = parentItem;
48 ········}
49
50 ········public void DoIt()
51 ········{
52 ············try
53 ············{
54 ················StreamWriter sw;
55 ················string fileName = Path.GetDirectoryName( project.FileName ) + "\\" + className + ".vb";
56 ················string partialFileName = fileName.Substring( 0, fileName.Length - 3 );
57 ················partialFileName += ".ndo.vb";
58 ················using (sw = new StreamWriter( fileName, false, System.Text.Encoding.UTF8 ))
59 ················{
60
61 ····················sw.WriteLine( "Imports System.Linq" );
62 ····················sw.WriteLine( "Imports System.Collections.Generic" );
63 ····················sw.WriteLine( "Imports NDO\n" );
64
65 ····················sw.WriteLine( "''' <summary>" );
66 ····················sw.WriteLine( "'''" );
67 ····················sw.WriteLine( "''' </summary>" );
68 ····················sw.WriteLine( "''' <remarks></remarks>" );
69 ····················sw.Write( "<NDOPersistent" );
70 ····················if (isSerializable)
71 ························sw.Write( ", Serializable" );
72 ····················sw.WriteLine( "> _" );
73 ····················sw.WriteLine( "Partial Public Class " + className );
74 ····················sw.WriteLine( "End Class" );
75 ················}
76 ················ProjectItem pi = null;
77 ················if ( parentItem == null )
78 ····················pi = project.ProjectItems.AddFromFile( fileName );
79 ················else
80 ····················pi = parentItem.ProjectItems.AddFromFile( fileName );
81 ················using (sw = new StreamWriter( partialFileName ))
82 ················{
83 ····················string newPartial = partialTemplate.Replace( "#cl#", className );
84 ····················sw.Write( newPartial );
85 ················}
86 ················pi.ProjectItems.AddFromFile( partialFileName );
87 ················CodeGenHelper.ActivateAndGetTextDocument(project, Path.GetFileName(fileName));
88 ············}
89 ············catch(Exception ex)
90 ············{
91 ················MessageBox.Show(ex.Message);
92 ············}
93 ········}
94
95 ········readonly string partialTemplate = @"Imports NDO
96 ' Don't change this code.
97 ' This interface implementation exists only for intellisense support.
98 ' Any code in this file will be replaced by the enhancer.
99 Partial Public Class #cl#
100 ····Implements IPersistentObject
101
102 ····Public Sub NDOMarkDirty() Implements NDO.IPersistentObject.NDOMarkDirty
103
104 ····End Sub
105
106 ····Public Property NDOObjectId() As NDO.ObjectId Implements NDO.IPersistentObject.NDOObjectId
107 ········Get
108 ············Throw New NotImplementedException
109 ········End Get
110 ········Set(ByVal value As NDO.ObjectId)
111 ············Throw New NotImplementedException
112 ········End Set
113 ····End Property
114
115 ····Public Property NDOObjectState() As NDO.NDOObjectState Implements NDO.IPersistentObject.NDOObjectState
116 ········Get
117 ············Throw New NotImplementedException
118 ········End Get
119 ········Set(ByVal value As NDO.NDOObjectState)
120 ············Throw New NotImplementedException
121 ········End Set
122 ····End Property
123
124 ····Public Property NDOTimeStamp() As System.Guid Implements NDO.IPersistentObject.NDOTimeStamp
125 ········Get
126 ············Throw New NotImplementedException
127 ········End Get
128 ········Set(ByVal value As System.Guid)
129 ············Throw New NotImplementedException
130 ········End Set
131 ····End Property
132 End Class
133 ";
134 ····}
135 }
136