I'm trying to use XmlMassUpdate to update my config files based on build Version type. There seems to be no documentation on how to update the new app.config (vs2008) settings formats anywhere.
This is the config section:
<applicationSettings>
<CTC.Mica.ClientService.Properties.Settings>
<setting name="PipeName" serializeAs="String">
<value>\\.\pipe\micaPipe</value>
</setting>
<setting name="CTC_Mica_ClientService_MicaWebService_MicaWebService"
serializeAs="String">
<value>URL</value>
</setting>
</CTC.Mica.ClientService.Properties.Settings>
</applicationSettings>
And i am trying to update the URL value from this file:
<Debug>
<setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
<value>DEVURL</value>
</setting>
</Debug>
<Test>
<setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
<value>TESTURL</value>
</setting>
</Test>
<Release>
<setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
<value>LIVEURL</value>
</setting>
</Release>
Running the script, i can replace either the "name" or the "serializeAs" attributes, but not the value node.
How would i go about replacing the value node?
Regards
Tris
The following scripts work fine for me (running on 1.3.0.471 which might be a nightly build):
build.proj
<Project DefaultTargets="Run" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.targets" />
<Target Name="Run">
<Delete Condition="Exists('output.xml')" Files="output.xml"/>
<XmlMassUpdate
ContentFile="input.xml"
ContentRoot="/test"
SubstitutionsFile="subs.xml"
SubstitutionsRoot="/substitutions/release"
MergedFile="output.xml"
/>
</Target>
</Project>
input.xml
<test>
<setting name="PipeName" serializeAs="String">
<value>\\.\pipe\micaPipe</value>
</setting>
<setting name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="String">
<value>URL</value>
</setting>
</test>
subs.xml
<substitutions xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">
<release>
<setting xmu:key="name" name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="Testing">
<value>LIVEURL</value>
</setting>
</release>
</substitutions>
output.xml (generated by build)
<test>
<setting name="PipeName" serializeAs="String">
<value>\\.\pipe\micaPipe</value>
</setting>
<setting name="CTC_Mica_ClientService_MicaWebService_MicaWebService" serializeAs="Testing">
<value>LIVEURL</value>
</setting>
</test>
Related
I am making an api and I want to read from the web.config an integer value. I tried to do it like this:
<applicationSettings>
<HHH.Properties.Settings>
<setting name="loggerPath" serializeAs="String">
<value>Logs</value>
</setting>
<setting name="querytime" serializeAs="String">
<value>30</value>
</setting>
<setting name="windowstime" serializeAs="String">
<value>86400</value>
</setting>
<setting name="alarmarmingtime" serializeAs="String">
<value>300</value>
</setting>
</HHH.Properties.Settings>
</applicationSettings>
The value I want to read is the windowstime but it throws me an error.
In the serializeAs property I cannot choose "integer" for example because it is an enumerated one and it does not have this option. How should I do it?
I already resolved it. I used this:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="windowstime" value="86400"/>
</appSettings>
I have two projects:
The first one (VTB_Terminliste) was build as a class library (.dll) with Entity Framework.
The second one is the main application, which include VTB_Terminliste as .dll, which I want to show after click button, like:
Private Sub btnTerminliste_Click(sender As Object, e As EventArgs) Handles btnTerminliste.Click
Dim l As New VTB_Terminliste.MainView
l.Show()
End Sub
In my App.Config from main application I insert the connection string for my Entites
<add name="ATX_PLSNGEntities" connectionString="metadata=res://*/DBA_Terminliste.csdl|res://*/DBA_Terminliste.ssdl|res://*/DBA_Terminliste.msl;provider=System.Data.SqlClient;provider connection string="data source=atx-srv-58;initial catalog=ATX_PLSNG;persist security info=True;user id=SomeUser;password=SomePW;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
After start and click the button btnTerminliste I get an error "No connection string named 'ATX_PLSNGEntities' could be found in the application config file"
If I start VTB_Terminliste project as WinForm every thing is working.
Here are my App.Config from project VTB_Terminliste and the main application
VTB_Terminliste
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System">
<section name="DevExpress.LookAndFeel.Design.AppSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<DevExpress.LookAndFeel.Design.AppSettings>
<setting name="DefaultAppSkin" serializeAs="String">
<value>Skin/The Bezier</value>
</setting>
<setting name="DefaultPalette" serializeAs="String">
<value>Gloom Gloom</value>
</setting>
<setting name="TouchUI" serializeAs="String">
<value></value>
</setting>
<setting name="TouchScaleFactor" serializeAs="String">
<value></value>
</setting>
<setting name="DirectX" serializeAs="String">
<value>True</value>
</setting>
<setting name="RegisterUserSkins" serializeAs="String">
<value></value>
</setting>
<setting name="FontBehavior" serializeAs="String">
<value></value>
</setting>
<setting name="DefaultAppFont" serializeAs="String">
<value></value>
</setting>
<setting name="DPIAwarenessMode" serializeAs="String">
<value>System</value>
</setting>
</DevExpress.LookAndFeel.Design.AppSettings>
</applicationSettings>
<system.diagnostics>
<sources>
<!-- Dieser Abschnitt definiert die Protokollierungskonfiguration für My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog" />
<!-- Auskommentierung des nachfolgenden Abschnitts aufheben, um in das Anwendungsereignisprotokoll zu schreiben -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
<!-- Auskommentierung des nachfolgenden Abschnitts aufheben und APPLICATION_NAME durch den Namen der Anwendung ersetzen, um in das Anwendungsereignisprotokoll zu schreiben -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<connectionStrings>
<add name="ATX_PLSNGEntities" connectionString="metadata=res://*/DBA_Terminliste.csdl|res://*/DBA_Terminliste.ssdl|res://*/DBA_Terminliste.msl;provider=System.Data.SqlClient;provider connection string="data source=atx-srv-58;initial catalog=ATX_PLSNG;persist security info=True;user id=SomeUser;password=SomePW;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Main application
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="ATX_DBA_Test_Connection" connectionString="XpoProvider=MSSqlServer;data source=atx-srv-28;user id=sa;password=Zu3545Uz;initial catalog=ATX_DBA_Test;Persist Security Info=true" />
<add name="ATX_PLSNGEntities" connectionString="metadata=res://*/DBA_Terminliste.csdl|res://*/DBA_Terminliste.ssdl|res://*/DBA_Terminliste.msl;provider=System.Data.SqlClient;provider connection string="data source=atx-srv-58;initial catalog=ATX_PLSNG;persist security info=True;user id=SomeUser;password=SomePW;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
I hope someone can help find me a solution.
I solve my problem adding the connection string inside .Context.vb
Partial Public Class ATX_PLSNGEntities
Inherits DbContext
Public Sub New()
MyBase.New("metadata=res://*/DBA_Terminliste.csdl|res://*/DBA_Terminliste.ssdl|res://*/DBA_Terminliste.msl;provider=System.Data.SqlClient;provider connection string='data source=SomeServer;initial catalog=ATX_PLSNG;persist security info=True;user id=SomeUser;password=SomePW;MultipleActiveResultSets=True;App=EntityFramework'")
End Sub
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
Throw New UnintentionalCodeFirstException()
End Sub
Public Overridable Property Terminliste() As DbSet(Of Terminliste)
End Class
Using the object mapper feature of FasterXML Jackson, I would like to parse this XML snippet:
<?xml version="1.0" encoding="utf-8"?>
<categories>
<category name="A">
<category name="B">
<setting type="Float">
<name>Bar</name>
</setting>
</category>
<setting type="Float">
<name>Foo</name>
</setting>
<category name="C">
<setting type="Float">
<name>Baz</name>
</setting>
</category>
</category>
</categories>
using the following Scala code:
case class Categories(#JacksonXmlProperty(localName = "category") categories: List[Category])
case class Category(name: String, #JacksonXmlProperty(localName = "category") categories: List[Category], #JacksonXmlProperty(localName = "setting") settings: List[Setting])
case class Setting(`type`: String, name: String)
val xmlMapper = new XmlMapper()
xmlMapper.registerModule(DefaultScalaModule)
xmlMapper.setDefaultUseWrapper(false)
val categories = xmlMapper.readValue(snippet, classOf[Categories])
println(categories)
// Categories(List(Category(A,List(Category(C,null,List(Setting(Float,Baz)))),List(Setting(Float,Foo)))))
I can see that Category B is missing from the result. If I change the order and move setting after the categories, it works as intended.
// Categories(List(Category(A,List(Category(B,null,List(Setting(Float,Bar))), Category(C,null,List(Setting(Float,Baz)))),List(Setting(Float,Foo)))))
<?xml version="1.0" encoding="utf-8"?>
<categories>
<category name="A">
<category name="B">
<setting type="Float">
<name>Bar</name>
</setting>
</category>
<category name="C">
<setting type="Float">
<name>Baz</name>
</setting>
</category>
<setting type="Float">
<name>Foo</name>
</setting>
</category>
</categories>
So it appears to be skipping elements if child list are mixed together. Is there a property I can set on the Mapper to fix this?
I have an XML column UserDetails in a SQL Server database which has value like this:
<fleet>
<Setting name="city"/>
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email"/>
<setting value="user"/>
</UserSettings>
<UserSettings name="A2">
<setting type="2" name="phone"/>
<setting value="technician"/>
</UserSettings>
</UserSettings>
</fleet>
I would to read from the db and add a new setting in
<UserSettings name="A2"> .
Can someone point me to what I should be doing?
You might use sql:variable() to introduce a value you've created externally. And you can use Xml.exist() to find XMLs which haven't got this new entry before:
DECLARE #myTbl TABLE(Descr VARCHAR(100),TheXml XML);
INSERT INTO #myTbl VALUES
(
'Setting "A3" doesn''t exist','<fleet>
<Setting name="city" />
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email" />
<setting value="user" />
</UserSettings>
<UserSettings name="A2">
<setting type="2" name="phone" />
<setting value="technician" />
</UserSettings>
</UserSettings>
</fleet>'
)
,(
'Setting "A3" exists already','<fleet>
<Setting name="city" />
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email" />
<setting value="user" />
</UserSettings>
<UserSettings name="A2">
<setting type="2" name="phone" />
<setting value="technician" />
</UserSettings>
<UserSettings name="A3">
<setting type="3" name="A3 setting" />
<setting value="this exists already" />
</UserSettings>
</UserSettings>
</fleet>'
);
DECLARE #NewSetting XML=
N'<UserSettings name="A3">
<setting type="3" name="new A3" />
<setting value="new data" />
</UserSettings>';
UPDATE #myTbl
SET TheXml.modify('
insert sql:variable("#NewSetting")
as last into (/fleet/UserSettings)[1]')
WHERE TheXml.exist(N'/fleet/UserSettings[#name="details"]/UserSettings[#name="A3"]')=0;
SELECT * FROM #myTbl
SQL SERVER provides methods to modify XML data, and a language to do it (XML DML).
You need to use the modify method with an insert xml dml statement.
Here is the complete example:
Sample data:
DECLARE #myDoc xml;
SET #myDoc =
'<fleet>
<Setting name="city" />
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email" />
<setting value="user" />
</UserSettings>
<UserSettings name="A2">
<setting type="2" name="phone" />
<setting value="technician" />
</UserSettings>
</UserSettings>
</fleet>';
The statement:
SET #myDoc.modify('
insert <setting value="NEW SETTINGS" />
as first into (/fleet/UserSettings/UserSettings[#name="A2"])[1] ') ;
SELECT #myDoc;
Result:
<fleet>
<Setting name="city" />
<UserSettings name="details">
<UserSettings name="A1">
<setting type="1" name="email" />
<setting value="user" />
</UserSettings>
<UserSettings name="A2">
<setting value="NEW SETTINGS" />
<setting type="2" name="phone" />
<setting value="technician" />
</UserSettings>
</UserSettings>
</fleet>
I have upgraded my web service project from vs 2005 to 2012. My webservice uses a project to log status in event viewer, which inturn uses enterprise library 2.0. Now that i have upgraded, i changed all my configs and dlls to newer version but while debugging i get this following exception.
{"Activation error occurred while trying to get instance of type LogWriter, key """}
InnerException:
{"Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value.
At the time of the exception, the container was:
Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)
"}
StackTrace :
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
Could you please help me out with this, as i ve been working on this issue for 3 days now with no luck.
app.config:
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<section name="EnService.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" requirePermission="false" />
</sectionGroup>
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="EnService" formatter="Text Formatter" log="MPASLog"
machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
Title:{title}
Machine: {machine}
Application Domain: {appDomain}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread Name: {threadName}
Extended Properties: {dictionary({key} - {value}
)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog" />
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<applicationSettings>
<EnService.My.MySettings>
<setting name="CONST_PRINT_LOG" serializeAs="String">
<value>1</value>
</setting>
<setting name="CONST_JOB_STATUS_SUCCESS" serializeAs="String">
<value>1</value>
</setting>
<setting name="CONST_WEB_SERVICE_TIME_OUT" serializeAs="String">
<value>10800000</value>
</setting>
<setting name="Seperater" serializeAs="String">
<value>.</value>
</setting>
<setting name="EnService_EnServiceWebReference_EnServiceService" serializeAs="String">
<value>http://localhost/EnServiceService.asmx</value>
</setting>
<setting name="PrintFolder" serializeAs="String">
<value>C:\Jobs\PrintDocuments\</value>
</setting>
<setting name="ResultLocation" serializeAs="String">
<value>C:\Jobs\EnService\Result</value>
</setting>
<setting name="ArchiveFilePrefix" serializeAs="String">
<value>EnService_Report_</value>
</setting>
<setting name="ExceptionArchiveFilePrefix" serializeAs="String">
<value>EnService_Exception_Report_</value>
</setting>
<setting name="CONST_PRINT_REPORT" serializeAs="String">
<value>X</value>
</setting>
<setting name="ReportArchiveLocation" serializeAs="String">
<value>C:\Jobs\EnService\OUT</value>
</setting>
<setting name="CommonWebServiceURL" serializeAs="String">
<value>http://localhost/WebService/Service.asmx</value>
</setting>
</EnService.My.MySettings>
</applicationSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
Appreciate your help,
Vinay
I was using logger.write() in my application
When i added
" Logger.SetLogWriter(New LogWriterFactory().Create(), False) "`
My application worked fine.