How to get build configuration ("release", "debug") from InvokeProcess activity - configuration

I added an InvokeProcess activity to generate a zip file after building (I couldn't get a good result with the "package on publish" option) and since my build definition builds my solution for 3 differents configuration ("Preproduction", "Production1", "Production2") I would like to write the configuration name into the zip file name.
I am not able to get the configuration name to write it into my zip name. I would like to name my zip file in this way: proyectName_Preproduction.zip. I don't know how to use defined keyword. $(Configuration) does not work.
Thks for your help.
Sébastien

I have found a way to access the list of build configurations but I am not sure how to detect the which configuration is current.
You can pass the pre-defined BuildSettings object as a parameter to your custom activity.
[RequiredArgument]
public InArgument<BuildSettings> BuildSettings { get; set; }
You can use the PlatformConfigurations property of BuildSettings to get the configuration details.
BuildSettings buildSettings = context.GetValue(this.BuildSettings);
if (buildSettings.HasPlatformConfigurations)
{
foreach (var platformConfiguration in buildSettings.PlatformConfigurations)
{
var config = platformConfiguration.Configuration;
}
}

Related

Startup.cs error (ASP.Net Core configuration)

I am trying to set up an ASP.Net Core application to read in configuration settings from a json file. I am using VS2015 and .NetCore 1.0 (with .Net Core Tools preview 2). I am having problems getting a simple piece of boiler plate code to compile.
I am using the following code, which was published at
http://asp.net-hacker.rocks/2016/03/21/configure-aspnetcore.html
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
// This will push telemetry data through Application Insights
// pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(developerMode: true);
}
Configuration = builder.Build();
}
However, the IDE/compiler complains that 'the name "Configuration" does not exist in the current context' (last line of code). The only suggestion from the IDE is to include Microsoft.Extensions.Configuration. However this is a namespace which does not contain an object or property named "Configuration".
In addition 'AddApplicationInsightsSettings' fails with does IConfigurationBuilder not contain a definition for AddApplicationInsightsSettings and no extension method AddApplicationInsightsSettings accepting a first argument of type IConfigurationBuilder could be found
Any suggestions please ?
Thanks
Simply add Configuration property to your Startup class, tutorial has missed this 'step':
public IConfigurationRoot Configuration { get; set; }
ConfigurationBuilder.Build() method just returns instance of IConfigurationRoot, that you should save, if need to get settings further in Startup class (in ConfigureServices method for example).
Regarding second error, looks like you didn't add the Application Insights dependency:
{
"dependencies": {
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0"
}
}

How can I represent a json array in an Environment Variable for aspnet vnext configuration

I have the following section in my appsettings.json file for my aspnet vnext application.
"Settings": {
"IgnoredServices" : ["ignore1", "ignore2"]
}
}
This works quite happily in mapping using IOptions<Settings>, where the settings class is
public class Settings
{
public List<string> IgnoredServices { get; set; }
}
However, I am struggling to override this json file option with an environment variable form. I have tried
Name Settings:IgnoredServices
Value "ignore1", "ignore2"
and
Name Settings:IgnoredServices
Value ["ignore1", "ignore2"]
Neither seem to map correctly and I get the following error message
System.InvalidOperationException: Failed to convert '["ignore1", "ignore2"]'
to type 'System.Collections.Generic.List`1[System.String]
What format should I put my values into environment variables to be successfully interpreted as the correct list of strings?
Try this:
Name Settings:IgnoredServices:0
Value ignore1
Name Settings:IgnoredServices:1
Value ignore2

How can I get a report URL via the SSRS Web Service?

In my project I have a web reference to SSRS (2005). I would like to display links that can take users directly to rendered reports. I know I can provide a link such as this one:
http://server/ReportServer/Pages/ReportViewer.aspx?/path/to/report&rs:Command=Render&rc:parameters=false&rs:format=HTML4.0
The question is how can I get that URL from the web service? And if the report takes parameters is there a way to provide values to the web service and have it format the URL for me?
I know I can build the URL myself, but I don't like reinventing wheels.
There are a few things to think of about HOW SSRS works and HOW MUCH TIME you want to invest in monkeying with it.
I. You can traverse the root but I highly doubt you meant that. From the root you can add items whether they are directories or reports. And to add to that you can add the parameter directly to the Rest URI to render a report and you may also output a value as well. For example:
Main part of address root:
http:// <server>/ReportServer/Pages/ReportViewer.aspx?
path to directory:
%2fTest
path to report (labeled it the same name lol)
%2fTest
what to do with it? (render it)
&rs:Command=Render
Put a paremeter in and execute it as well (Yes I called my parameter Test too!)
&Test=Value
Put it all together:
http:// <servername>/ReportServer/Pages/ReportViewer.aspx?%2fTest%2fTest&rs:Command=Render&Test=Value
II. You have a database you can query for traversing things but I believe MS does NOT document it well. Generally it is a SQL Server database named 'ReportServer' on whatever server you installed SSRS on. Generally most items are in the table 'dbo.Catalog' with 'Type' of 2 for reports. You can get their info and even parameters from them there.
III. You want to go full bore and dive into .NET and just talk to the service directly? You can do that too. You need the two main services though to do that:
A: http://<Server Name>/reportserver/reportservice2010 (gets info on existing items on server)
B: http:// <Server Name>reportserver/reportexecution2005 (gets info for in code creating reports to types directly in code)
I had another thread on exporting this here: Programmatically Export SSRS report from sharepoint using ReportService2010.asmx; but you will to get info as well probably. ONCE you have created the proxy classes (or made a reference to the web services) you can do code in .NET like so. These services do all the magic so without them you can't really model much in SSRS. Basically I create a class that you pass the 'SERVER' you need to reference to the class like 'http:// /ReportServer'.
private ReportingService2010 _ReportingService = new ReportingService2010();
private ReportExecutionService _ReportingExecution = new ReportExecutionService();
private string _server { get; set; }
public ReaderWriter(string server)
{
_server = server;
_ReportingService.Url = _server + #"/ReportService2010.asmx";
_ReportingService.Credentials = System.Net.CredentialCache.DefaultCredentials;
_ReportingExecution.Url = _server + #"/ReportExecution2005.asmx";
_ReportingExecution.Credentials = System.Net.CredentialCache.DefaultCredentials;
}
public List<ItemParameter> GetReportParameters(string report)
{
try
{
return _ReportingService.GetItemParameters(report, null, false, null, null).ToList();
}
catch (Exception ex)
{
MessageBox.Show("Getting Parameter info threw an error:\n " + ex.Message);
return new List<ItemParameter> { new ItemParameter { Name = "Parameter Not Found" } };
}
}
public List<CatalogItem> GetChildInfo(string dest)
{
try
{
return _ReportingService.ListChildren("/" + dest, false).ToList();
}
catch (Exception ex)
{
MessageBox.Show("Getting Child info of location threw an error:\n\n" + ex.Message);
return new List<CatalogItem> { new CatalogItem { Name = "Path Does Not exist", Path = "Path Does not exist" } };
}
}
ListChildren is the way to go. You can always set the second parameter to true to return all catalog items when you have reports in many folders.
Dim items As CatalogItem() = rs.ListChildren(reportPath, True)

Sitecore Configuration Factory - Call method with more than one argument

I have read John West's article on the Site Configuration Factory (http://www.sitecore.net/unitedkingdom/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/02/The-Sitecore-ASPNET-CMS-Configuration-Factory.aspx)
I'm trying implement it in a custom link provider.
I want the Configuration Factory to call the following method in the link provider:
public void AddSitePath(String site, String path)
{
// do stuff
}
Here's the config (although I've tried several similar variations).
<add name="sitecore" type="MyProject.Providers.CustomLinkProvider, MyProject" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="never" languageLocation="filePath" shortenUrls="true" useDisplayName="false">
<sitePaths hint="list:AddSitePath">
<sitePath>
<site>SiteOneName</site>
<path>/product-range/</path>
</sitePath>
<sitePath >
<site>SiteTwoName</site>
<path>/items-for-sale/</path>
</sitePath>
</sitePaths>
</add >
I'm getting the following error message:
Could not find add method: AddSitePath (type: MyProject.Providers.CustomLinkProvider)
I suspected that the problem was that I was trying to pass 2 parameters into the method, and sure enough, when I tested it with a single parameter version it worked.
What do I need to change in either the config or the class code to achieve what I need?
So it looks like you can't supply 2 arguments. Instead, you pass in a single XmlNode object, which contains everything you you need. You have to extract the information from the XmlNode within the method.
Something along the lines of:
public void AddSitePath(XmlNode arg)
{
// pick apart the XmlNode and do stuff
}
<sitePaths hint="raw:AddSitePath">
<sitePath site="SiteNameOne" path="/product-range/">
<sitePath site="SiteNameTwo" path="/items-for-sale/">
</sitePaths>
Note that you have to use the 'raw' prefix instead of 'list'

Error in ServiceStack JSON processing under MonoDroid

I'm trying to use ServiceStack for Json serialization/deserialization in MonoDroid project.
I've built ServiceStack to run it in MonoDroid environment, but now I have issue with JSON deserialization.
Example code:
public class Track
{
public string Id { get; set; }
public string Title { get; set; }
public string Artist { get; set; }
public string Hash { get; set; }
public string Type { get; set; }
}
}
...
var track = new Track { Id = "1", Artist = "artist name", Hash = "654874", Title = "song title", Type = "mp3", };
var json = ServiceStack.Text.JsonSerializer.SerializeToString(track);
var track1 = ServiceStack.Text.JsonSerializer.DeserializeFromString<Track>(json);
On deserialization I have an exception:
Unhandled Exception:
System.ArgumentNullException: Argument cannot be null.
Parameter name: method
Stacktrace:
[External Code]
0x5E in ServiceStack.Text.Json.JsonReader.GetParseFn at [...]\Android\ServiceStack.Text\src\ServiceStack.Text\Json\JsonReader.Generic.cs:36 C#
0x2 in ServiceStack.Text.Json.JsonTypeSerializer.GetParseFn at [...]\Android\ServiceStack.Text\src\ServiceStack.Text\Json\JsonTypeSerializer.cs:283 C#
0xF in ServiceStack.Text.Common.TypeAccessor.Create at [...]\Android\ServiceStack.Text\src\ServiceStack.Text\Common\DeserializeType.cs:146 C#
0x142 in ServiceStack.Text.Common.DeserializeType`1[[ServiceStack.Text.Json.JsonTypeSerializer, ServiceStack.Text, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetParseMethod at [...]\Android\ServiceStack.Text\src\ServiceStack.Text\Common\DeserializeType.cs:60 C#
0x43A in ServiceStack.Text.Common.JsReader`1[[ServiceStack.Text.Json.JsonTypeSerializer, ServiceStack.Text, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetParseFn at [...]\Android\ServiceStack.Text\src\ServiceStack.Text\Common\JsReader.cs:100 C#
0x6 in ServiceStack.Text.Json.JsonReader`1[[Database.Models.Track, AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]..cctor at [...]\Android\ServiceStack.Text\src\ServiceStack.Text\Json\JsonReader.Generic.cs:58 C#
0x1B in ServiceStack.Text.JsonSerializer.DeserializeFromString at [...]\Android\ServiceStack.Text\src\ServiceStack.Text\JsonSerializer.cs:33 C#
As I see there is:
var genericType = typeof(JsonReader<>).MakeGenericType(type);
var mi = genericType.GetMethod("GetParseFn", BindingFlags.Public | BindingFlags.Static);
parseFactoryFn = (ParseFactoryDelegate)Delegate.CreateDelegate(typeof(ParseFactoryDelegate), mi);
genericType is "ServiceStack.Text.Json.JsonReader`1[System.String]"
type is "System.String"
So, there "mi" variable is null
Are any ideas how to fix it, or where to look?
Thanks.
The problem here was that you had linking enabled in your build configuration, and the GetParseFn() method was being linked away, as it wasn't explicitly being referenced.
The linker is a static analysis tool that is included as part of Mono for Android's build process. It will scan through your compiled application and actually strip out any pieces of .NET (or in this case, your compiled ServiceStack class library) that aren't explicitly being referenced. This goes a long way to cut down the size of your application, but you can run into problems, as seen here. Since the GetParseFn() method was never being explicitly referenced (it is being called via reflection), the linker had no idea it was needed and linked it away.
There are several ways you can handle this problem going forward.
Disable linking entirely: you can turn off linking in the project's properties. In general it's easier to leave it off for debug builds, and turn it on for release builds. This obviously isn't a full solution if you ever plan on doing a release build, of course.
Link only SDK assemblies: this option will tell the linker only to operate on the .NET BCL and Android SDKs, and will leave your libraries alone.
Use PreserveAttribute: Using this attribute you can tell the linker to leave in certain pieces that you know are required, even though they're not explicitly referenced. Since ServiceStack is an external library and not your own, this probably isn't the best solution in this case.
Use Linkskip: This option allows you to specify specific assemblies that shouldn't be touched by the linker, allowing you to leave the linker on but simply opt out when needed.
Personally, in your situation here I could suggest going the Linkskip route. It would allow you to still get all the benefits of the linker, but have it ignore ServiceStack to avoid problems like this. In your project file, you would end up with something along the lines of this:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AndroidLinkMode>Full</AndroidLinkMode>
<AndroidLinkSkip>ServiceStack.Text</AndroidLinkSkip>
</PropertyGroup>