Visual Studio project to call Azure ML Endpoint, namespace how-to - visual-studio-code

I have a Visual Studio WebForm C# project that loads in a browser. I also have a snippet of code from Azure ML to call my endpoint model. How should the *.aspx.cs file look? Thank you.
screen shot of my visual studio *.aspx.cs file
Here is how I plan to call it from the carprice.aspx file:
<asp:Label ID="lblResults" runat="server" Text="here is where results will go"></asp:Label>
Here is the Namespace template from Visual Studio project, the carprice.aspx.cs file:
namespace web13
{
public partial class carprice : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
And here is the snippet from Azure, a different kind of namespace syntax:
namespace CallRequestResponseService
{
class Program
{
static void Main(string[] args)
{
InvokeRequestResponseService().Wait();
}
static async Task InvokeRequestResponseService()
{
var handler = new HttpClientHandler()
{
ClientCertificateOptions = ClientCertificateOption.Manual,
ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) => { return true; }
};
using (var client = new HttpClient(handler))
{
// Request data goes here
var scoreRequest = new
{
Inputs = new Dictionary<string, List<Dictionary<string, string>>>()
{
{
"input1",
new List<Dictionary<string, string>>()
{
new Dictionary<string, string>()
{
{
"price", "5800"
},
{
"year", "2013"......etc
The next day, I tried calling HTML label control from the Azure snippet of code, but I get an error, "the name lblResults2 does not exist in the current context." I've also tried changing the Azure snippet to Public classes. Here is another screen shot. thank you.
Visual Studio connecting Azure Results to form
Then further along, I'm adding newer screen shots
Visual Studio webform controls
Visual Studio namespace
further days along, this is what gets Visual Studio to compile and load in browser. screen shot is:
working syntax for calling endpoint

Related

Tweetinvi - User.GetAuthenticatedUser is not being recognized by Visual Studio

I am using Tweetinvi api in Visual Studio and trying to fetch my profile name and profile photo.I followed the documentation on git and was trying to replicate the same in my code ,however it is not recognizing the method GetAuthenticatedUser
var authenticateduser = User.GetAuthenticatedUser();
I have seen some questions like this that said ,you need to give your keys to the method below, however i am doing that and am able to post and fetch tweets
Auth.SetUserCredentials("key1",key2","key3,"key4")
This is my Pageload code
protected void Page_Load(object sender, EventArgs e)
{
Auth.SetUserCredentials("key1",key2","key3,"key4")
var authenticateduser = User.GetAuthenticatedUser();
FetchTweets();
}
i had imported Tweetinvi but somehow this particular function is not being picked up
so have to use code with
var authenticateduser = Tweetinvi.User.GetAuthenticatedUser();
LblProfileName.Text = authenticateduser.Name;
ImgProfile.ImageUrl = authenticateduser.ProfileImageUrl;

Jasper Report 6.3 Hyperlink Extension

I have recently upgraded Jasper Report API from 4.5.1 to 6.3. With 4.5.1, reports are exported to HTML, PDF format. For HTML reports, there is a facility to drill down to child report. In order to customise links to handle request parameters and pre processing of opening child report have created ExtensionRegistryFactory and registered JRHyperlinkProducerMapFactory to handle Hyperlinks.
I've noticed that extension is registered properly but it does not getting used. Checked source code of Jasper Report 6.3 and try to debug why, then observed that method: net.sf.jasperreports.engine.JRAbstractExporter.getHyperlinkProducer(JRPrintHyperlink) does not return JRHyperlinkProducer.
Here is the code of ExtensionsRegistryFactory:
public class HyperlinkExtensionsRegistryFactory implements ExtensionsRegistryFactory
{
#Override
public ExtensionsRegistry createRegistry(String registryId, JRPropertiesMap properties)
{
return new ExtensionsRegistry()
{
#Override
public List getExtensions(Class extensionType)
{
if (extensionType.equals(JRHyperlinkProducerFactory.class))
{
JRHyperlinkProducerMapFactory producerFactory = new JRHyperlinkProducerMapFactory();
producerFactory.addProducer("ReportExecution", new RemoteExecutionHyperlinkProducer());
producerFactory.addProducer("Custom", new ExpandCollapseHyperlinkProducer());
return Arrays.asList(producerFactory);
}
return null;
}
};
}
public static class RemoteExecutionHyperlinkProducer implements JRHyperlinkProducer
{
#Override
public String getHyperlink(JRPrintHyperlink hyperlink)
{
return [custom link generation logic];
}
}
public static class ExpandCollapseHyperlinkProducer implements JRHyperlinkProducer
{
#Override
public String getHyperlink(JRPrintHyperlink hyperlink)
{
return [custom link generation logic];
}
}
}
With this class, have created an entry for jasperreports_extension.properties file. Here is its content:
net.sf.jasperreports.extension.registry.factory.HyperlinkExtensionFactory=<fully_qualified_path_to_HyperlinkExtensionsRegistryFactory>
Am I missing anything? If there is any mistake I am making then kindly help to find out the one.
Thanks Narcis for input.
I've checked source code of Jasper Report 6.3.0 and tried to understand how Hyperlink registry is replaced. Found a work around for this one. Hope it will be helpful to others. Here is code snippet to register Hyperlink extension.
Exporter
AbstractHtmlExporter<HtmlReportConfiguration,HtmlExporterConfiguration> exporter = new HtmlExporter();
SimpleHtmlReportConfiguration htmlReportConfig = new SimpleHtmlReportConfiguration();
htmlReportConfig.setHyperlinkProducerFactory(HyperlinkExtensionsRegistryFactory.hyperlinkProducerFactory());
exporter.setConfiguration(htmlReportConfig);
HyperlinkExtensionsRegistryFactory.hyperlinkProducerFactory()
public JRHyperlinkProducerFactory hyperlinkProducerFactory() {
JRHyperlinkProducerMapFactory producerFactory = new JRHyperlinkProducerMapFactory();
producerFactory.addProducer("ReportExecution", new <Class_implements_JRHyperlinkProducer>());
producerFactory.addProducer("Custom", new <Class_implements_JRHyperlinkProducer>());
return producerFactory;
}

Rx undefined error while using signalR Hubs

I am trying to implement push notifications using signalR hubs. I have a sample code, which when I run, I get an error saying
JavaScript runtime error: 'Rx' is undefined
This error comes in the dynamic signalr/hubs file.
I have added all the necessary Javascript references i.e., jquery, signalR and signalr/hubs.
What am i missing ?
My code looks something like this:
Global.asax file has this
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHubs("~/signalr");
}
My Hub is defined like this
[HubName("HealthCheck")]
public class MyConnectionClass : Hub
{
public static List<string> messages = new List<string>();
public void GetServiceState()
{
Clients.updateMessages(messages);
}
public void UpdateServiceState()
{
messages.Add(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
Clients.updateMessages(messages);
}
And my client in javascript like this
$(function () {
// creates a proxy to the health check hub
var healthCheckHub = $.connection.healthCheck;
// handles the callback sent from the server
healthCheckHub.updateMessages = function (data) {
$("li").remove();
$.each(data, function () {
$('#messages').append('<li>' + this + '</li>');
});
};
$("#trigger").click(function () {
healthCheckHub.server.updateServiceState();
});
// Start the connection and request current state
$.connection.hub.start(function () {
healthCheckHub.server.getServiceState();
});
});
Also I have added all the necessary js references in the client.
I have picked this sample from here
Is this enough or am i missing something ?
Thanks
Given that the error is about Rx not being defined I'm wondering if you may have installed the wrong NuGet package. It sounds like you installed SignalR.Reactive instead.
I think this is the package you really want. (Note that this is a prerelease version and I think the package names changed quite recently so it's possible the tutorial you're following is slightly out of date, which may have been what's caused the confusion.)

Where can I find the console or debug output from code executed in the package manager window?

I'm using EntityFramework code first with migrations. From the package manager console, I'm running "update-database". This executes Configuration.Seed(context) which I have overridden.
protected override void Seed(WebContext context)
{
Console.WriteLine("Console Test");
Debug.WriteLine("Debug Test");
Trace.WriteLine("Trace Test");
}
Where can I find that output?
Better yet, How do I output back to the package manager window?
Thx,
Dan
A quick hack I use to be able to quickly find a value in my Seed method is simply to throw an exception with a value I care about, e.g.
throw new Exception(yourValue);
This errors out the Seed, but my exception/value appears in my package manager console.
Where can I find that output?
Sorry, but the quick answer is basically nowhere.
To be precise at least not in the package manager console.
Debug.WriteLine("Debug Test");
Trace.WriteLine("Trace Test");
You can see the output of the Debug... and Trace... methods if you attach another Visual Studio to debug the Visual Studio instance which is running the update-database command. Then in the debuggin VS you can see the output in the Output Window.
Console.WriteLine("Console Test");
You can see the output of the Console... methods if you run the migrations with the
migrate.exe command line tool which comes with EF:
How do I output back to the package manager window?
I have here also bad news, after a quick "reflectoring": with the current implementation of the EF migrations it's not supported to display custom information during execution of the update-database (or any other command).
Running a SQL print command will write to the Package Manager Console. Here is a helper method that I use:
/// <summary>
/// write a message to the Package Manager Console
/// </summary>
public void Debug(string s, params object[] args)
{
var fullString = string.Format(s, args).Replace("'", "''");
Sql(string.Format("print '{0}'", fullString));
}
My needs were similar to yours so I figured I'd document them here in case they could help someone else out. My goal was to display all of the output from the migrations including all of the sql run as part of the Seed method. As a side effect of this solution, you will also be able to see any Debug.Write message in your code.
First create a DebugMigrationsLogger that will write all migration output to Debug.WriteLine (thanks to http://whiteknight.github.io/2013/01/26/efcodeonlymigrations.html):
public class DebugMigrationsLogger : System.Data.Entity.Migrations.Infrastructure.MigrationsLogger
{
public override void Info(string message)
{
Debug.WriteLine(message);
}
public override void Verbose(string message)
{
Debug.WriteLine(message);
}
public override void Warning(string message)
{
Debug.WriteLine("WARNING: " + message);
}
}
Next make sure you have a subclass of DbMigrationsConfiguration for your DbContext:
public class MyDbMigrationsConfiguration : DbMigrationsConfiguration<MyDbContext>
{
public MyDbMigrationsConfiguration()
{
}
protected override void Seed(MartusDb db)
{
//...
}
}
Next you run your migrations as an on-demand unit test so your test runner can capture the output. My unit test looks something like this:
public void MigrateDb_Test()
{
var config = new MyDbMigrationsConfiguration { AutomaticMigrationDataLossAllowed = true };
var migrator = new DbMigrator(config);
var loggingDecorator = new MigratorLoggingDecorator(migrator, new DebugMigrationsLogger());
loggingDecorator.Update();
}
Lastly, set the Database.Log in your DbContext constructor:
public class MyDbContext : DbContext
{
public MyDbContext()
{
Database.Log = message => Debug.WriteLine(message);
}
}
Now whenever you run the MigrateDb_Test() you will see all the output, it has made debugging migrations so much easier for me!
Dirty workaround extending George's answer.
protected override void Seed(YourContext context)
{
using (var seedout = new StringWriter())
{
// do your work
context.Authors.AddOrUpdate(x => x.Id,
new Author() { Id = 1, Name = "Jane Austen" }
);
// some message
seedout.WriteLine("some message");
// commit your work
context.SaveChanges();
seedout.WriteLine("Seed successfully completed.");
// dummy exception to show message on package manager console
throw new Exception(seedout.ToString());
}
}

Is there a standard dialog for constructing an ADO.Net connection string (that is redistributable)?

I want to use a standard dialog to solicit user input of an ADO.net connection string. It is trivial to do for the oledb connection string as described here:
MSDN Article on MSDASC.DataLinks().Prompt
I've also found examples that use Microsoft.Data.ConnectionUI.dll and MicrosoftData.ConnectionUI.Dialog.dll from VS (HOWTO: Using the Choose Data Source dialog of Visual Studio 2005 from your own code).
Unfortunately these DLLs are not licensed for redistribution.
Is there a standard dialog for choosing a data source that can be distributed with my application?
#rathkopf, it looks like these DLLs have been authorized for redistribution since Feb 2010:
http://connect.microsoft.com/VisualStudio/feedback/details/423104/redistributable-microsoft-data-connectionui-dll-and-microsoft-data-connectionui-dialog-dll
http://code.msdn.microsoft.com/Connection
The source code for these DLLs is now available: http://blogs.msdn.com/b/vsdata/archive/2010/02/02/data-connection-dialog-source-code-is-released-on-code-gallery.aspx
Also you can do this programmatically using the DataLink Properties:
Add the reference to ADODB.DLL (from .NET reference) and Microsoft OLE DB Service Component 1.0 Type Library from the COM tab in your visual studio reference tab.
using ADODB;
using Microsoft.Win32;
public partial class ConnectionStringStep : Form
{
private const string MSSQL_PROVIDER = "Provider=SQLOLEDB.1";
private const string ORACLE_PROVIDER = "Provider=MSDAORA.1";
private const string MSSQL = "MSSQL";
public ConnectionStringStep()
{
InitializeComponent();
}
private static string DataBaseType()
{
//get the data from some previous screen or some kind of storage
return MyStorage.GetProperty("DATABASE_TYPE") ?? "MSSQL";
}
private void button1_Click(object sender, EventArgs e)
{
var dataBaseType = DataBaseType();
var adodbConnection = new Connection
{
ConnectionString = dataBaseType == MSSQL ? MSSQL_PROVIDER : ORACLE_PROVIDER
};
object connection = (object) adodbConnection;
var dialog = new MSDASC.DataLinks();
dialog.PromptEdit(ref connection);
connectionTextBox.Text = adodbConnection.ConnectionString;
}
}
DataLink Properties Reference
There is now a NuGet package by Microsoft providing this dialog:
DataConnectionDialog.
Sample usage:
var dialog = new DataConnectionDialog();
dialog.DataSources.Add(DataSource.SqlDataSource);
dialog.ConnectionString = connectionString;
if (DataConnectionDialog.Show(dialog) == System.Windows.Forms.DialogResult.OK)
{
connectionString = dialog.ConnectionString;
}
It's related, but I'm now sure how you can embed this behavior inside your application.
Every time I need one, I create an empty text file, changed its file extension to ".udl" and double-click it; when I'm done, I close that application, rename that file back to ".txt" and open with Notepad.
It appears that such a beast does not exist. I've written my own dialog and can include it in projects as needed.
Update:
The source code for these DLLs are now available as per #code4life's answer.