public void CanDeserializeCollections() { var xml = Assembly.GetExecutingAssembly() .GetManifestResourceStream(@"SquaredInfinity.Foundation.Serialization.FlexiXml.Resources.Deserialization.collection_tests.xml") .ReadToEnd(); var s = new FlexiXmlSerializer(); var root = s.Deserialize<Root>(xml); Assert.IsNotNull(root); Assert.AreEqual(13, (root.CollectionReadOnlyPropertyCreatedInConstructor as CollectionItemCollection).IntProperty); Assert.AreEqual("string value 1", (root.CollectionReadOnlyPropertyCreatedInConstructor as CollectionItemCollection).StringProperty); Assert.AreEqual(3, root.CollectionReadOnlyPropertyCreatedInConstructor.Count); Assert.AreEqual(14, root.CollectionReadOnlyPropertyCreatedInConstructor[0].IntProperty); Assert.AreEqual(15, root.CollectionReadOnlyPropertyCreatedInConstructor[1].IntProperty); Assert.AreEqual(16, root.CollectionReadOnlyPropertyCreatedInConstructor[2].IntProperty); Assert.AreEqual(23, (root.Collection as CollectionItemCollection).IntProperty); Assert.AreEqual("string value 2", (root.Collection as CollectionItemCollection).StringProperty); Assert.AreEqual(3, root.Collection.Count); Assert.AreEqual(24, root.Collection[0].IntProperty); Assert.AreEqual(25, root.Collection[1].IntProperty); Assert.AreEqual(26, root.Collection[2].IntProperty); Assert.AreEqual(33, root.NonGenericCollection.IntProperty); Assert.AreEqual("string value 3", root.NonGenericCollection.StringProperty); Assert.AreEqual(3, root.NonGenericCollection.Count); Assert.AreEqual(34, root.NonGenericCollection[0].IntProperty); Assert.AreEqual(35, root.NonGenericCollection[1].IntProperty); Assert.AreEqual(36, root.NonGenericCollection[2].IntProperty); }
public void CanCustomizeHowReferencesAreResolved() { var xml = Assembly.GetExecutingAssembly() .GetManifestResourceStream(@"SquaredInfinity.Foundation.Serialization.UnitTests.Serialization.FlexiXml.Repository.Resources.repository.xml") .ReadToEnd(); var xDoc = XDocument.Parse(xml); var s = new FlexiXmlSerializer(); var options = new FlexiXmlSerializationOptions(); options.UniqueIdAttributeName = XName.Get("name"); options.UniqueIdReferenceAttributeName = XName.Get("ref"); var o = s.Deserialize<Configuration>(xDoc, options); Assert.IsNotNull(o); Assert.AreEqual(2, o.Repository.Formatters.Count); Assert.AreEqual(2, o.Emails.Count); Assert.AreSame(o.Repository.Formatters[0], o.Emails[0].BodyFormatter); Assert.AreSame(o.Repository.Formatters[1], o.Emails[0].SubjectFormatter); Assert.AreSame(o.Repository.Formatters[0], o.Emails[1].BodyFormatter); Assert.AreSame(o.Repository.Formatters[1], o.Emails[1].SubjectFormatter); }
public void XmlRootNameCanBeAnything() { var xml = Assembly.GetExecutingAssembly() .GetManifestResourceStream(@"SquaredInfinity.Foundation.Serialization.FlexiXml.Resources.Deserialization.XmlRootNameCanBeAnything.xml") .ReadToEnd(); var s = new FlexiXmlSerializer(); var root = s.Deserialize<Root>(xml); Assert.IsNotNull(root); Assert.AreEqual("string value 1", root.StringProperty); }
public void AttachedElementsCanBeUsedToMapProperties() { var xml = Assembly.GetExecutingAssembly() .GetManifestResourceStream(@"SquaredInfinity.Foundation.Serialization.FlexiXml.Resources.Deserialization.AttachedElementsCanBeUsedToMapProperties.xml") .ReadToEnd(); var s = new FlexiXmlSerializer(); var root = s.Deserialize<Root>(xml); Assert.IsNotNull(root); Assert.AreEqual("string value 1", root.StringProperty); Assert.AreEqual(13, root.IntProperty); Assert.AreEqual(14, root.NullableIntProperty); Assert.AreEqual(new Guid("9763C96B-5AC4-4ACA-AE4E-5D71EDDBE0DD"), root.GuidProperty); }
public void UsesKnownTypesLookup() { // in this test Entity on root is serialized as TestEntityA, but KnownTypes mappign is set (all in xml) to TestEntityB // Entity should therefore resolve to TestEntityB var xml = Assembly.GetExecutingAssembly() .GetManifestResourceStream(@"SquaredInfinity.Foundation.Serialization.FlexiXml.KnownTypesLookup.KnownTypesLookup.xml") .ReadToEnd(); var s = new FlexiXmlSerializer(); var op = new FlexiXmlSerializationOptions(); op.TypeInformation = TypeInformation.LookupOnly; var root = s.Deserialize<TestRoot>(xml, op); Assert.IsNotNull(root); Assert.AreEqual(typeof(TestEntityB), root.Entity.GetType()); Assert.AreEqual(13, root.Entity.Id); }
public void TypeWithInterfaceProperty__CanDeserialize() { var o = new InterfaceTypeProperty(); o.MyDispsableProperty = new InterfaceTypeProperty(); var s = new FlexiXmlSerializer(); var xml = s.Serialize(o); var o2 = s.Deserialize<InterfaceTypeProperty>(xml); Assert.IsNotNull(o2); Assert.IsNotNull(o2.MyDispsableProperty); Assert.AreNotSame(o2, o2.MyDispsableProperty); }
public void Bug001__ChildElementNamesWrong() { // read-only collection has a member DefaultItem // it should be serialized as: // // <root> // <root.items> // <items.defaultitem>.. // // instead is serialzied as: // // <root> // <root.items> // <root.items.defaultitem> var root = new Root(); (root.CollectionReadOnlyPropertyCreatedInConstructor as CollectionItemCollection).StringProperty = "string value 1"; (root.CollectionReadOnlyPropertyCreatedInConstructor as CollectionItemCollection).DefaultItem = new CollectionItem() { IntProperty = 13, StringProperty = "07" }; var s = new FlexiXmlSerializer(); var xml = s.Serialize(root); Assert.IsNotNull(xml); // there should be no elements with more than 1 '.' in the name foreach(var el in xml.Descendants()) { Assert.IsTrue(el.Name.LocalName.Count(c => c == '.') <= 1); } }
static void Main(string[] args) { //# DiagnosticLogger can be used quickly without any configuration. // By default diagnostic data will be logged to "Logs" directory. DiagnosticLogger.Global.Information("This required no configuration at all."); //# Custom configuration can be applied from xml file // var config = SquaredInfinity.Foundation.Diagnostics.Configuration.XmlConfigurationProvider var config = DiagnosticLogger.Global.GetConfigurationClone(); //# add default filters // exclude everything config.Repository.Filters.Add(new LoggerNameFilter { Name = "exclude-all", Mode = FilterMode.Exclude }); // include everything config.Repository.Filters.Add(new LoggerNameFilter { Name = "include-all", Mode = FilterMode.Include }); // Include messages with specific Severity Level config.Repository.Filters.Add(new SeverityFilter { Name = "critical", Mode = FilterMode.Include, Severity = KnownSeverityLevels.Critical }); config.Repository.Filters.Add(new SeverityFilter { Name = "error", Mode = FilterMode.Include, Severity = KnownSeverityLevels.Error }); config.Repository.Filters.Add(new SeverityFilter { Name = "warning", Mode = FilterMode.Include, Severity = KnownSeverityLevels.Warning }); config.Repository.Filters.Add(new SeverityFilter { Name = "information", Mode = FilterMode.Include, Severity = KnownSeverityLevels.Information }); config.Repository.Filters.Add(new SeverityFilter { Name = "verbose", Mode = FilterMode.Include, Severity = KnownSeverityLevels.Verbose }); // Exclude messages with specific Severity Level config.Repository.Filters.Add(new SeverityFilter { Name = "!critical", Mode = FilterMode.Exclude, Severity = KnownSeverityLevels.Critical }); config.Repository.Filters.Add(new SeverityFilter { Name = "!error", Mode = FilterMode.Exclude, Severity = KnownSeverityLevels.Error }); config.Repository.Filters.Add(new SeverityFilter { Name = "!warning", Mode = FilterMode.Exclude, Severity = KnownSeverityLevels.Warning }); config.Repository.Filters.Add(new SeverityFilter { Name = "!information", Mode = FilterMode.Exclude, Severity = KnownSeverityLevels.Information }); config.Repository.Filters.Add(new SeverityFilter { Name = "!verbose", Mode = FilterMode.Exclude, Severity = KnownSeverityLevels.Verbose }); // // Include only messages from specific Severity Level ranges // Naming Convention: // [a,b] - closed interval from a (included) to b (included) // (a,b] - left half-open interval from a (excluded) to b (included) // [a,b) - right half-open interval from a (included) to b (excluded) // (a,b) - open interval from a (excluded) to b (excluded) config.Repository.Filters.Add(new SeverityFilter { Name = "[warning,error]", Mode = FilterMode.Include, From = KnownSeverityLevels.Warning, To = KnownSeverityLevels.Error }); config.Repository.Filters.Add(new SeverityFilter { Name = "[warning,error)", Mode = FilterMode.Include, From = KnownSeverityLevels.Error, ExclusiveTo = KnownSeverityLevels.Error }); config.Repository.Filters.Add(new SeverityFilter { Name = "(warning,max]", Mode = FilterMode.Include, ExclusiveFrom = KnownSeverityLevels.Warning }); config.Repository.Filters.Add(new SeverityFilter { Name = "[warning,max]", Mode = FilterMode.Include, From = KnownSeverityLevels.Warning }); config.Repository.Filters.Add(new SeverityFilter { Name = "(information,max]", Mode = FilterMode.Include, ExclusiveFrom = KnownSeverityLevels.Information }); config.Repository.Filters.Add(new SeverityFilter { Name = "[information,max]", Mode = FilterMode.Include, From = KnownSeverityLevels.Information }); config.Repository.Filters.Add(new SeverityFilter { Name = "(verbose,max]", Mode = FilterMode.Include, ExclusiveFrom = KnownSeverityLevels.Verbose }); config.Repository.Filters.Add(new SeverityFilter { Name = "[verbose,max]", Mode = FilterMode.Include, From = KnownSeverityLevels.Verbose }); config.Repository.Filters.Add(new SeverityFilter { Name = "[min,max]", Mode = FilterMode.Include, From = KnownSeverityLevels.Minimum }); // Include messages based on property values config.Repository.Filters.Add(new PropertyFilter { Name = "contains-raw-message", Mode = FilterMode.Include, Property = "Event.HasRawMessage", Value = "true" }); config.Repository.Filters.Add(new PropertyFilter { Name = "!contains-raw-message", Mode = FilterMode.Exclude, Property = "Event.HasRawMessage", Value = "true" }); // Filter events based on event source!! // messages logged using System.Diagnostics namespace (e.g. Trace.WriteLine) config.Repository.Filters.Add(new PropertyFilter { Name = "system.diagnostics.trace", Mode = FilterMode.Include, Property = "Event.Source", Value = "System.Diagnostics.Trace" }); config.Repository.Filters.Add(new PropertyFilter { Name = "system.diagnostics.debug", Mode = FilterMode.Include, Property = "Event.Source", Value = "System.Diagnostics.Debug" }); config.Repository.Filters.Add(new PropertyFilter { Name = "system.diagnostics", Mode = FilterMode.Include, Property = "Event.Source", Value = "System.Diagnostics" }); config.Repository.Filters.Add(new PropertyFilter { Name = "!system.diagnostics", Mode = FilterMode.Exclude, Property = "Event.Source", Value = "System.Diagnostics" }); // internal config.Repository.Filters.Add(new PropertyFilter { Name = "internal", Mode = FilterMode.Include, Property = "Event.Source", Value = "SquaredInfinity.Foundation.Diagnostics.*" }); config.Repository.Filters.Add(new PropertyFilter { Name = "!internal", Mode = FilterMode.Exclude, Property = "Event.Source", Value = "SquaredInfinity.Foundation.Diagnostics.*" }); // Filters based on event category config.Repository.Filters.Add(new PropertyFilter { Name = "application-lifecycle", Mode = FilterMode.Include, Property = "Event.Category", Value = "Application-Lifecycle.*" }); config.Repository.Filters.Add(new PropertyFilter { Name = "!application-lifecycle", Mode = FilterMode.Exclude, Property = "Event.Category", Value = "Application-Lifecycle.*" }); config.Repository.Filters.Add(new PropertyFilter { Name = "application-lifecycle.install", Mode = FilterMode.Include, Property = "Event.Category", Value = "Application-Lifecycle.Install" }); config.Repository.Filters.Add(new PropertyFilter { Name = "!application-lifecycle.install", Mode = FilterMode.Exclude, Property = "Event.Category", Value = "Application-Lifecycle.Install" }); // add common data collectors // those will be used if referenced from sinks var edc = new EnvironmentDataCollector(); config.ContextDataCollectors.Add(edc); // add additional data collectors // those will be used if specific event occurs var edc_application_lifecycle = new EnvironmentDataCollector(); // todo: quick lookup by name edc_application_lifecycle.Filter = (from f in config.Repository.Filters where f.Name == "(warning,max]" select f).Single(); edc_application_lifecycle.RequestedData.Add(EnvironmentData.ApplicationVersion); edc_application_lifecycle.RequestedData.Add(EnvironmentData.ThreadUICulture); edc_application_lifecycle.RequestedData.Add(EnvironmentData.ThreadCulture); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentUserDomainName); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentUserName); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentMachineName); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentOsVersion); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentOsVersionPlatform); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentOsVersionVersion); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentOsVersionServicePack); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentVersion); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentCurrentDirectory); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentSystemDirectory); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentIs64BitOperatingSystem); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentIs64BitProcess); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentProcessorCount); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentCommandLineArgs); edc_application_lifecycle.RequestedData.Add(EnvironmentData.EnvironmentUserInteractive); edc_application_lifecycle.RequestedData.Add(EnvironmentData.DeploymentIsNetworkDeplyed); edc_application_lifecycle.RequestedData.Add(EnvironmentData.DeploymentActivationUri); edc_application_lifecycle.RequestedData.Add(EnvironmentData.DeploymentCurrentVersion); edc_application_lifecycle.RequestedData.Add(EnvironmentData.DeploymentDataDirectory); edc_application_lifecycle.RequestedData.Add(EnvironmentData.DeploymentIsFirstRun); edc_application_lifecycle.RequestedData.Add(EnvironmentData.DeploymentTimeOfLastUpdateCheck); edc_application_lifecycle.RequestedData.Add(EnvironmentData.DeploymentUpdatedApplicationFullName); edc_application_lifecycle.RequestedData.Add(EnvironmentData.DeploymentUpdatedVersion); edc_application_lifecycle.RequestedData.Add(EnvironmentData.DeploymentUpdateLocation); config.AdditionalContextDataCollectors.Add(edc_application_lifecycle); var fileSink = new FileSink(); fileSink.Name = "default.file"; fileSink.FileNamePattern = "log.txt"; fileSink.FileLocationPattern = @"{AppDomain.CurrentDomain.BaseDirectory}\Logs\"; fileSink.Formatter = new PatternFormatter() { Pattern = @" {NewLine} -- {NewLine} [{Event.Level}{?Event.HasCategory=>'\:'}{?Event.HasCategory=>Event.Category} thread:{Thread.Id}] {?Event.HasMessage=>Event.Message} {?Event.HasLoggerName=>NewLine} {?Event.HasLoggerName=>'Logger\:'} {?Event.HasLoggerName=>Event.LoggerName} {?Event.HasCallerInfo=>NewLine} {?Event.HasCallerInfo=>'Caller\:'} {?Event.HasCallerInfo=>Caller.FullName} {?Event.HasCallerInfo=>Caller.File} {?Event.HasCallerInfo=>'\:'} {?Event.HasCallerInfo=>Caller.LineNumber} {?Event.HasException=>NewLine} {?Event.HasException=>Event.Exception:dumpWithHeader('Exception')} {?Event.HasAdditionalContextData=>NewLine} {?Event.HasAdditionalContextData=>Event.AdditionalContextData:dumpWithHeader('Context Data')} {?Event.HasAttachedObjects=>NewLine} {?Event.HasAttachedObjects=>Event.AttachedObjects:dumpWithHeader('Attached Objects')}" }; config.Sinks.Add(fileSink); var serializer = new FlexiXmlSerializer(new ReflectionBasedTypeDescriptor()); serializer.GetOrCreateTypeSerializationStrategy<Filter>() .IgnoreAllMembers() .SerializeMember(x => x.Name, x => x.Name != null); serializer.GetOrCreateTypeSerializationStrategy<LoggerNameFilter>() .IgnoreAllMembers() .CopySerializationSetupFromBaseClass() .SerializeMember(x => x.Pattern, x => x.Pattern != null); serializer.GetOrCreateTypeSerializationStrategy<PropertyFilter>() .IgnoreAllMembers() .CopySerializationSetupFromBaseClass() .SerializeMember(x => x.Property, x => x.Property != null) .SerializeMember(x => x.Value, x => x.Value != null); serializer.GetOrCreateTypeSerializationStrategy<SeverityFilter>() .IgnoreAllMembers() .CopySerializationSetupFromBaseClass() .SerializeMemberAsAttribute(x => x.Severity, x => x.Severity != null, (x, y) => y.ToString(), s => KnownSeverityLevels.Parse(s.Value)) .SerializeMemberAsAttribute(x => x.To, x => x.To != null, (x, y) => y.ToString(), s => KnownSeverityLevels.Parse(s.Value)) .SerializeMemberAsAttribute(x => x.From, x => x.From != null, (x, y) => y.ToString(), s => KnownSeverityLevels.Parse(s.Value)) .SerializeMemberAsAttribute(x => x.ExclusiveTo, x => x.ExclusiveTo != null, (x, y) => y.ToString(), s => KnownSeverityLevels.Parse(s.Value)) .SerializeMemberAsAttribute(x => x.ExclusiveFrom, x => x.ExclusiveFrom != null, (x, y) => y.ToString(), s => KnownSeverityLevels.Parse(s.Value)); serializer.GetOrCreateTypeSerializationStrategy<ContextDataCollector>() .SerializeMemberAsAttribute<IFilter>(x => x.Filter, x => x.Filter != null, (x, y) => y.Name, s => null); var so = new FlexiXmlSerializationOptions(); so.SerializeNonPublicTypes = false; so.TypeInformation = TypeInformation.None; var xml = serializer.Serialize(config, so); File.WriteAllText("1.config", xml.ToString()); DiagnosticLogger.Global.ApplyConfiguration(config); DiagnosticLogger.Global.Information("Let's start!"); DiagnosticLogger.Global.Warning("Let's start!"); DiagnosticLogger.Global.Critical("Let's start!"); DiagnosticLogger.Global .AsInformation() .ApplicationLifecycleEvent .Startup(); //using(var pdc = DiagnosticLogger.Global.BeginPerformanceDataCollection()) { } DiagnosticLogger.Global .AsInformation() .ApplicationLifecycleEvent .Shutdown(); DiagnosticLogger.Global.AsCritical().AppendObject("entry assembly", Assembly.GetEntryAssembly()).Log(); }
public void InitializeServices(IVsPackage package) { // TODO: eventually perhaps most of it could be done using MEF alone // but for know do what worked so far. // Need to find out how to register custom instance with VS MEF //# IoC var container = new UnityContainer(); container.RegisterInstance<IUnityContainer>(container); //# Service Provider from package var service_provider = (IServiceProvider)package; container.RegisterInstance<IServiceProvider>(service_provider); //# Service Container from package var service_container = (IServiceContainer)package; container.RegisterInstance<IServiceContainer>(service_container); // VS MEF var componentModel = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)) as IComponentModel2; container.RegisterInstance<IComponentModel>(componentModel); container.RegisterInstance<IComponentModel2>(componentModel); //# Settings Service var settings_serializer = new FlexiXmlSerializer(); settings_serializer.GetOrCreateTypeSerializationStrategy<VersionInstallationInfo>() .SerializeMemberAsAttribute(x => x.Version, x => x.Version != null, (x, _v) => _v.ToString(), _a => new Version(_a.Value)); var settings_location = StaticSettings.AppDataDirectory; IVscSettingsService settings_service = new VscSettingsService(settings_serializer, StaticSettings.AppDataDirectory); container.RegisterInstance<IVscSettingsService>(settings_service); var vscservices = new VscServices(); vscservices.Container = container; componentModel.DefaultCompositionService.SatisfyImportsOnce(vscservices); VscServices.Initialise(vscservices); //# UI Service var vscUIService = new VscUIService(); container.RegisterInstance<IVscUIService>(vscUIService); //# Visual Studio Events Service var vs_events_service = container.Resolve<VisualStudioEventsService>(); container.RegisterInstance<IVisualStudioEventsService>(vs_events_service); //# Fonts And Color var fonts_and_colors = container.Resolve<VSCFontAndColorDefaultsProvider>(); #if DEBUG // fonts_and_colors.TryClearFontAndColorCache(); #endif fonts_and_colors.RegisterCollorableItem(ClassificationNames.OutputText, "Output Window Text"); fonts_and_colors.RegisterCollorableItem(ClassificationNames.OutputInformation, "Output Window Information"); fonts_and_colors.RegisterCollorableItem(ClassificationNames.OutputWarning, "Output Window Warning"); fonts_and_colors.RegisterCollorableItem(ClassificationNames.OutputError, "Output Window Error"); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputBuildSummary, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputBuildSummarySuccess, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputBuildSummaryFailed, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputBuildSummaryTotal, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputCodeContractsInformation, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputProjectBuildStart, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputProjectBuildSkipped, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.TfsOutputError, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.TfsOutputWarning, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.TfsOutputSuccess, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.FindResultsOutputMatch, "Find Results Match", isBold: true); fonts_and_colors.Initialise(); container.RegisterInstance<VSCFontAndColorDefaultsProvider>(fonts_and_colors); //# Initialize User Interface vs_events_service.RegisterVisualStudioUILoadedAction(() => InitializeUserInterface(container, vscUIService)); //# Solution Badges Service var solution_badges_service = container.Resolve<SolutionBadgesService>(); componentModel.DefaultCompositionService.SatisfyImportsOnce(solution_badges_service); solution_badges_service.Initialise(); container.RegisterInstance<ISolutionBadgesService>(solution_badges_service); //# Update Settings with local context info var deployment_info = (DeploymentInfo)null; var has_just_been_upgraded = false; if(!settings_service.TryGetSetting<DeploymentInfo>("internal.deployment", VscSettingScope.User, out deployment_info)) { deployment_info = new DeploymentInfo(); deployment_info.InitialVersion = VersionInstallationInfo.GetCurrent(); has_just_been_upgraded = true; } if (deployment_info.CurrentVersion == null) { deployment_info.CurrentVersion = VersionInstallationInfo.GetCurrent(); has_just_been_upgraded = true; } else if (deployment_info.CurrentVersion.Version != StaticSettings.CurrentVersion) { deployment_info.PreviousVersion = deployment_info.CurrentVersion; deployment_info.CurrentVersion = VersionInstallationInfo.GetCurrent(); has_just_been_upgraded = true; } if (has_just_been_upgraded) { settings_service.SetSetting("internal.deployment", VscSettingScope.User, deployment_info); // clear fotn and color cache as new items may have been added. // cache rebuilding can be an expensive operation fonts_and_colors.TryClearFontAndColorCache(); } }
public void InitializeServices(IVsPackage package) { // TODO: eventually perhaps most of it could be done using MEF alone // but for know do what worked so far. // Need to find out how to register custom instance with VS MEF //# IoC var container = new UnityContainer(); container.RegisterInstance <IUnityContainer>(container); //# Service Provider from package var service_provider = (IServiceProvider)package; container.RegisterInstance <IServiceProvider>(service_provider); //# Service Container from package var service_container = (IServiceContainer)package; container.RegisterInstance <IServiceContainer>(service_container); // VS MEF var componentModel = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)) as IComponentModel2; container.RegisterInstance <IComponentModel>(componentModel); container.RegisterInstance <IComponentModel2>(componentModel); //# Settings Service var settings_serializer = new FlexiXmlSerializer(); settings_serializer.GetOrCreateTypeSerializationStrategy <VersionInstallationInfo>() .SerializeMemberAsAttribute(x => x.Version, x => x.Version != null, (x, _v) => _v.ToString(), _a => new Version(_a.Value)); var settings_location = StaticSettings.AppDataDirectory; IVscSettingsService settings_service = new VscSettingsService(settings_serializer, StaticSettings.AppDataDirectory); container.RegisterInstance <IVscSettingsService>(settings_service); var vscservices = new VscServices(); vscservices.Container = container; componentModel.DefaultCompositionService.SatisfyImportsOnce(vscservices); VscServices.Initialise(vscservices); //# UI Service var vscUIService = new VscUIService(); container.RegisterInstance <IVscUIService>(vscUIService); //# Visual Studio Events Service var vs_events_service = container.Resolve <VisualStudioEventsService>(); container.RegisterInstance <IVisualStudioEventsService>(vs_events_service); //# Fonts And Color var fonts_and_colors = container.Resolve <VSCFontAndColorDefaultsProvider>(); #if DEBUG // fonts_and_colors.TryClearFontAndColorCache(); #endif fonts_and_colors.RegisterCollorableItem(ClassificationNames.OutputText, "Output Window Text"); fonts_and_colors.RegisterCollorableItem(ClassificationNames.OutputInformation, "Output Window Information"); fonts_and_colors.RegisterCollorableItem(ClassificationNames.OutputWarning, "Output Window Warning"); fonts_and_colors.RegisterCollorableItem(ClassificationNames.OutputError, "Output Window Error"); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputBuildSummary, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputBuildSummarySuccess, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputBuildSummaryFailed, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputBuildSummaryTotal, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputCodeContractsInformation, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputProjectBuildStart, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.BuildOutputProjectBuildSkipped, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.TfsOutputError, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.TfsOutputWarning, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.TfsOutputSuccess, ""); fonts_and_colors.RegisterCollorableItem(ClassificationNames.FindResultsOutputMatch, "Find Results Match", isBold: true); fonts_and_colors.Initialise(); container.RegisterInstance <VSCFontAndColorDefaultsProvider>(fonts_and_colors); //# Initialize User Interface vs_events_service.RegisterVisualStudioUILoadedAction(() => InitializeUserInterface(container, vscUIService)); //# Solution Badges Service var solution_badges_service = container.Resolve <SolutionBadgesService>(); componentModel.DefaultCompositionService.SatisfyImportsOnce(solution_badges_service); solution_badges_service.Initialise(); container.RegisterInstance <ISolutionBadgesService>(solution_badges_service); //# Update Settings with local context info var deployment_info = (DeploymentInfo)null; var has_just_been_upgraded = false; if (!settings_service.TryGetSetting <DeploymentInfo>("internal.deployment", VscSettingScope.User, out deployment_info)) { deployment_info = new DeploymentInfo(); deployment_info.InitialVersion = VersionInstallationInfo.GetCurrent(); has_just_been_upgraded = true; } if (deployment_info.CurrentVersion == null) { deployment_info.CurrentVersion = VersionInstallationInfo.GetCurrent(); has_just_been_upgraded = true; } else if (deployment_info.CurrentVersion.Version != StaticSettings.CurrentVersion) { deployment_info.PreviousVersion = deployment_info.CurrentVersion; deployment_info.CurrentVersion = VersionInstallationInfo.GetCurrent(); has_just_been_upgraded = true; } if (has_just_been_upgraded) { settings_service.SetSetting("internal.deployment", VscSettingScope.User, deployment_info); // clear fotn and color cache as new items may have been added. // cache rebuilding can be an expensive operation fonts_and_colors.TryClearFontAndColorCache(); } }
public void InitializeServices(IVsPackage package) { // TODO: eventually perhaps most of it could be done using MEF alone // but for know do what worked so far //# IoC var container = new UnityContainer(); container.RegisterInstance<IUnityContainer>(container); //# Service Provider from package container.RegisterInstance<IServiceProvider>((IServiceProvider) package); // VS MEF var componentModel = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)) as IComponentModel2; container.RegisterInstance<IComponentModel>(componentModel); container.RegisterInstance<IComponentModel2>(componentModel); //# Settings Service var settings_serializer = new FlexiXmlSerializer(); settings_serializer.GetOrCreateTypeSerializationStrategy<VersionInstallationInfo>() .SerializeMemberAsAttribute(x => x.Version, x => x.Version != null, (x, _v) => _v.ToString(), _a => new Version(_a.Value)); var settings_location = StaticSettings.AppDataDirectory; IVscSettingsService settings_service = new VscSettingsService(settings_serializer, StaticSettings.AppDataDirectory); container.RegisterInstance<IVscSettingsService>(settings_service); //# UI Service var vscUIService = new VscUIService(); container.RegisterInstance<IVscUIService>(vscUIService); //# Visual Studio Events Service var vs_events_service = container.Resolve<VisualStudioEventsService>(); container.RegisterInstance<IVisualStudioEventsService>(vs_events_service); //# Initialize User Interface vs_events_service.RegisterVisualStudioUILoadedAction(InitializeUserInterface); //# Solution Badges Service var solution_badges_service = container.Resolve<SolutionBadgesService>(); componentModel.DefaultCompositionService.SatisfyImportsOnce(solution_badges_service); solution_badges_service.Initialise(); container.RegisterInstance<ISolutionBadgesService>(solution_badges_service); //# Update Settings with local context info var deployment_info = (DeploymentInfo)null; var update_deployment_info = false; if(!settings_service.TryGetSetting<DeploymentInfo>("internal.deployment", VscSettingScope.User, out deployment_info)) { deployment_info = new DeploymentInfo(); deployment_info.InitialVersion = VersionInstallationInfo.GetCurrent(); update_deployment_info = true; } if (deployment_info.CurrentVersion == null) { deployment_info.CurrentVersion = VersionInstallationInfo.GetCurrent(); update_deployment_info = true; } else if (deployment_info.CurrentVersion.Version != StaticSettings.CurrentVersion) { deployment_info.PreviousVersion = deployment_info.CurrentVersion; deployment_info.CurrentVersion = VersionInstallationInfo.GetCurrent(); update_deployment_info = true; } if (update_deployment_info) settings_service.SetSetting("internal.deployment", VscSettingScope.User, deployment_info); }
public void SupportsDictionarySerialization() { var o = new SimpleDictionary(); o.Add(1, "one"); o.Add(2, "two"); o.CustomProperty = "Numbers"; var s = new FlexiXmlSerializer(); var xml = s.Serialize(o); var has_keys_element = (from e in xml.Elements() where e.Name == "Keys" select e).Any(); var has_values_element = (from e in xml.Elements() where e.Name == "Values" select e).Any(); // keys and values are skipped from serialization by default Assert.IsFalse(has_keys_element); Assert.IsFalse(has_values_element); var o2 = s.Deserialize<SimpleDictionary>(xml); Assert.IsNotNull(o2); Assert.AreNotSame(o, o2); Assert.AreEqual(o.CustomProperty, o2.CustomProperty); Assert.AreEqual(2, o2.Count); Assert.AreEqual(1, o2.Keys.First()); Assert.AreEqual("one", o2.Values.First()); Assert.AreEqual(2, o2.Keys.Skip(1).First()); Assert.AreEqual("two", o2.Values.Skip(1).First()); }