Skip to content

Commit 4f6f727

Browse files
authored
Revert "Switch from serializing Declarations to Serializing ComProjects."
1 parent f2837c9 commit 4f6f727

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+966
-793
lines changed

Rubberduck.Core/Rubberduck.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@
539539
<Compile Include="UI\Command\MenuItems\CommandBars\ReferenceCounterLabelMenuItem.cs" />
540540
<Compile Include="UI\Command\MenuItems\CommandBars\ReparseCommandMenuItem.cs" />
541541
<Compile Include="UI\Command\MenuItems\CommandBars\RubberduckCommandBar.cs" />
542-
<Compile Include="UI\Command\MenuItems\CommandBars\SerializeProjectsCommandMenuItem.cs" />
542+
<Compile Include="UI\Command\MenuItems\CommandBars\SerializeDeclarationsCommandMenuItem.cs" />
543543
<Compile Include="UI\Command\MenuItems\CommandBars\ShowParserErrorsCommandMenuItem.cs" />
544544
<Compile Include="UI\Command\MenuItems\CommandBars\IAppCommandBar.cs" />
545545
<Compile Include="UI\Command\RegexAssistantCommand.cs" />
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using NLog;
5+
using Rubberduck.Parsing.ComReflection;
6+
using Rubberduck.Parsing.Symbols;
7+
using Rubberduck.Parsing.VBA;
8+
using Rubberduck.SettingsProvider;
9+
10+
namespace Rubberduck.UI.Command.MenuItems.CommandBars
11+
{
12+
public class SerializeDeclarationsCommandMenuItem : CommandMenuItemBase
13+
{
14+
public SerializeDeclarationsCommandMenuItem(SerializeDeclarationsCommand command) : base(command)
15+
{
16+
}
17+
18+
public override Func<string> Caption { get { return () => "Serialize"; } }
19+
public override string Key => "SerializeDeclarations";
20+
}
21+
22+
public class SerializeDeclarationsCommand : CommandBase
23+
{
24+
private readonly RubberduckParserState _state;
25+
private readonly IPersistable<SerializableProject> _service;
26+
private readonly ISerializableProjectBuilder _serializableProjectBuilder;
27+
28+
public SerializeDeclarationsCommand(RubberduckParserState state, IPersistable<SerializableProject> service, ISerializableProjectBuilder serializableProjectBuilder)
29+
: base(LogManager.GetCurrentClassLogger())
30+
{
31+
_state = state;
32+
_service = service;
33+
_serializableProjectBuilder = serializableProjectBuilder;
34+
}
35+
36+
protected override bool EvaluateCanExecute(object parameter)
37+
{
38+
return _state.Status == ParserState.Ready;
39+
}
40+
41+
private static readonly string BasePath =
42+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Rubberduck");
43+
44+
protected override void OnExecute(object parameter)
45+
{
46+
var path = Path.Combine(BasePath, "Declarations");
47+
if (!Directory.Exists(path)) { Directory.CreateDirectory(path); }
48+
49+
foreach (var project in _state.DeclarationFinder.BuiltInDeclarations(DeclarationType.Project).OfType<ProjectDeclaration>())
50+
{
51+
System.Diagnostics.Debug.Assert(path != null, "project path isn't supposed to be null");
52+
53+
var tree = _serializableProjectBuilder.SerializableProject(project);
54+
var filename = $"{tree.Node.QualifiedMemberName.QualifiedModuleName.ProjectName}.{tree.MajorVersion}.{tree.MinorVersion}.xml";
55+
var fullFilename = Path.Combine(path, filename);
56+
_service.Persist(fullFilename, tree);
57+
}
58+
}
59+
}
60+
}

Rubberduck.Core/UI/Command/MenuItems/CommandBars/SerializeProjectsCommandMenuItem.cs

Lines changed: 0 additions & 81 deletions
This file was deleted.

Rubberduck.Main/Root/RubberduckIoCInstaller.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ private void RegisterConfiguration(IWindsorContainer container, Assembly[] assem
220220
// .LifestyleSingleton()
221221
// .Instance(experimentalTypes));
222222

223-
container.Register(Component.For<IComProjectSerializationProvider>()
224-
.ImplementedBy<XmlComProjectSerializer>()
223+
container.Register(Component.For<IPersistable<SerializableProject>>()
224+
.ImplementedBy<XmlPersistableDeclarations>()
225225
.LifestyleTransient());
226226
container.Register(Component.For(typeof(IPersistanceService<>), typeof(IFilePersistanceService<>))
227227
.ImplementedBy(typeof(XmlPersistanceService<>))
@@ -514,7 +514,7 @@ private Type[] RubberduckCommandBarItems()
514514
typeof(ContextDescriptionLabelMenuItem),
515515
typeof(ReferenceCounterLabelMenuItem),
516516
#if DEBUG
517-
typeof(SerializeProjectsCommandMenuItem)
517+
typeof(SerializeDeclarationsCommandMenuItem)
518518
#endif
519519
};
520520
}

Rubberduck.Parsing/ComReflection/ComAlias.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
using System.Diagnostics;
22
using System.Runtime.InteropServices.ComTypes;
3-
using System.Runtime.Serialization;
43
using Rubberduck.Parsing.Grammar;
54
using TYPEATTR = System.Runtime.InteropServices.ComTypes.TYPEATTR;
65
using TYPEFLAGS = System.Runtime.InteropServices.ComTypes.TYPEFLAGS;
76

87
namespace Rubberduck.Parsing.ComReflection
98
{
10-
[DataContract]
11-
[KnownType(typeof(ComBase))]
129
[DebuggerDisplay("{Name} As {TypeName}")]
1310
public class ComAlias : ComBase
1411
{
15-
[DataMember(IsRequired = true)]
16-
public string TypeName { get; private set; }
17-
18-
[DataMember(IsRequired = true)]
19-
public bool IsHidden { get; private set; }
20-
21-
[DataMember(IsRequired = true)]
22-
public bool IsRestricted { get; private set; }
12+
public string TypeName { get; }
13+
public bool IsHidden { get; }
14+
public bool IsRestricted { get; }
2315

2416
public ComAlias(IComBase parent, ITypeLib typeLib, ITypeInfo info, int index, TYPEATTR attributes) : base(parent, typeLib, index)
2517
{

Rubberduck.Parsing/ComReflection/ComBase.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Diagnostics;
33
using System.Runtime.InteropServices.ComTypes;
4-
using System.Runtime.Serialization;
54
using Rubberduck.Parsing.Symbols;
65
using FUNCDESC = System.Runtime.InteropServices.ComTypes.FUNCDESC;
76

@@ -18,26 +17,14 @@ public interface IComBase
1817
ComProject Project { get; }
1918
}
2019

21-
[DataContract]
2220
public abstract class ComBase : IComBase
2321
{
24-
[DataMember(IsRequired = true)]
2522
public Guid Guid { get; protected set; }
26-
27-
[DataMember(IsRequired = true)]
2823
public int Index { get; protected set; }
29-
30-
[DataMember(IsRequired = true)]
3124
public ComDocumentation Documentation { get; protected set; }
32-
3325
public string Name => Documentation == null ? string.Empty : Documentation.Name;
34-
35-
[DataMember(IsRequired = true)]
3626
public DeclarationType Type { get; protected set; }
37-
38-
[DataMember(IsRequired = true)]
3927
public IComBase Parent { get; protected set; }
40-
4128
public ComProject Project => Parent != null ? Parent.Project : this as ComProject;
4229

4330
protected ComBase(IComBase parent, ITypeLib typeLib, int index)

Rubberduck.Parsing/ComReflection/ComCoClass.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using System.Runtime.InteropServices;
66
using System.Runtime.InteropServices.ComTypes;
7-
using System.Runtime.Serialization;
87
using Rubberduck.Parsing.Symbols;
98
using Rubberduck.VBEditor.Utility;
109
using TYPEATTR = System.Runtime.InteropServices.ComTypes.TYPEATTR;
@@ -13,22 +12,15 @@
1312

1413
namespace Rubberduck.Parsing.ComReflection
1514
{
16-
[DataContract]
17-
[KnownType(typeof(ComType))]
1815
public class ComCoClass : ComType, IComTypeWithMembers
1916
{
20-
[DataMember(IsRequired = true)]
21-
private Dictionary<ComInterface, bool> _interfaces = new Dictionary<ComInterface, bool>();
17+
private readonly Dictionary<ComInterface, bool> _interfaces = new Dictionary<ComInterface, bool>();
18+
private readonly List<ComInterface> _events = new List<ComInterface>();
2219

23-
[DataMember(IsRequired = true)]
24-
private List<ComInterface> _events = new List<ComInterface>();
25-
26-
[DataMember(IsRequired = true)]
27-
public bool IsControl { get; private set; }
20+
public bool IsControl { get; }
2821

2922
public bool IsExtensible => _interfaces.Keys.Any(i => i.IsExtensible);
3023

31-
[DataMember(IsRequired = true)]
3224
public ComInterface DefaultInterface { get; private set; }
3325

3426
public IEnumerable<ComInterface> EventInterfaces => _events;
@@ -99,11 +91,6 @@ private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr)
9991
_interfaces.Add(intface, flags.HasFlag(IMPLTYPEFLAGS.IMPLTYPEFLAG_FRESTRICTED));
10092
}
10193
}
102-
103-
if (DefaultInterface == null)
104-
{
105-
DefaultInterface = VisibleInterfaces.FirstOrDefault();
106-
}
10794
}
10895
}
10996
}
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
using System.Runtime.InteropServices.ComTypes;
2-
using System.Runtime.Serialization;
32

43
namespace Rubberduck.Parsing.ComReflection
54
{
6-
[DataContract]
75
public class ComDocumentation
86
{
97
public const int LibraryIndex = -1;
10-
[DataMember(IsRequired = true)]
11-
public string Name { get; private set; }
128

13-
[DataMember(IsRequired = true)]
14-
public string DocString { get; private set; }
15-
16-
[DataMember(IsRequired = true)]
17-
public string HelpFile { get; private set; }
18-
19-
[DataMember(IsRequired = true)]
20-
public int HelpContext { get; private set; }
9+
public string Name { get; }
10+
public string DocString { get; }
11+
public string HelpFile { get; }
12+
public int HelpContext { get; }
2113

2214
public ComDocumentation(ITypeLib typeLib, int index)
2315
{
2416
typeLib.GetDocumentation(index, out string name, out string docString, out int helpContext, out string helpFile);
2517
Name = name;
2618
DocString = docString;
2719
HelpContext = helpContext;
28-
HelpFile = helpFile?.Trim('\0');
20+
HelpFile = helpFile;
2921
}
3022

3123
public ComDocumentation(ITypeInfo info, int index)
@@ -34,7 +26,7 @@ public ComDocumentation(ITypeInfo info, int index)
3426
Name = name;
3527
DocString = docString;
3628
HelpContext = helpContext;
37-
HelpFile = helpFile?.Trim('\0');
29+
HelpFile = helpFile;
3830
}
3931
}
4032
}

Rubberduck.Parsing/ComReflection/ComEnumeration.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@
22
using System.Collections.Generic;
33
using System.Runtime.InteropServices;
44
using System.Runtime.InteropServices.ComTypes;
5-
using System.Runtime.Serialization;
65
using Rubberduck.Parsing.Symbols;
76
using Rubberduck.VBEditor.Utility;
87
using TYPEATTR = System.Runtime.InteropServices.ComTypes.TYPEATTR;
98
using VARDESC = System.Runtime.InteropServices.ComTypes.VARDESC;
109

1110
namespace Rubberduck.Parsing.ComReflection
1211
{
13-
[DataContract]
14-
[KnownType(typeof(ComType))]
1512
public class ComEnumeration : ComType
1613
{
17-
[DataMember(IsRequired = true)]
18-
public List<ComEnumerationMember> Members { get; private set; }
14+
public List<ComEnumerationMember> Members { get; }
1915

2016
public ComEnumeration(IComBase parent, ITypeLib typeLib, ITypeInfo info, TYPEATTR attrib, int index) : base(parent, typeLib, attrib, index)
2117
{

Rubberduck.Parsing/ComReflection/ComEnumerationMember.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
using System.Diagnostics;
22
using System.Runtime.InteropServices;
33
using System.Runtime.InteropServices.ComTypes;
4-
using System.Runtime.Serialization;
54
using VARDESC = System.Runtime.InteropServices.ComTypes.VARDESC;
65

76
namespace Rubberduck.Parsing.ComReflection
87
{
9-
[DataContract]
10-
[KnownType(typeof(ComEnumeration))]
118
[DebuggerDisplay("{Name} = {Value} ({ValueType})")]
129
public class ComEnumerationMember
1310
{
14-
[DataMember(IsRequired = true)]
15-
public string Name { get; private set; }
16-
17-
[DataMember(IsRequired = true)]
18-
public int Value { get; private set; }
19-
20-
[DataMember(IsRequired = true)]
21-
public VarEnum ValueType { get; private set; }
22-
23-
[DataMember(IsRequired = true)]
24-
ComEnumeration Parent { get; set; }
25-
11+
public string Name { get; }
12+
public int Value { get; }
13+
public VarEnum ValueType { get; }
14+
ComEnumeration Parent { get; }
2615
public ComProject Project => Parent?.Project;
2716

2817
public ComEnumerationMember(ComEnumeration parent, ITypeInfo info, VARDESC varDesc)

0 commit comments

Comments
 (0)