How to obtain Handle.ToInt32() in an ASP.NET web application - c#

I am trying to learn and use an SDK for a vendor's product. Unfortunately, the documentation is sketchy and I've run into a void in my own knowledge of the .Net Framework.
I have some working code for a windows forms application and I am trying to get it working in an ASP.NET web form app. The vendor documentation implies you can do this but maybe you cannot..
Snippet from the working windows app:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using TRIMSDK;
private void ConnectUserBtn_Click(object sender, System.EventArgs e)
{
Database db = new Database();
Databases dbChooser = new Databases();
IDatabase dbI = dbChooser.ChooseOneUI(Handle.ToInt32());
if (dbI == null)
{
return;
}
db.Id = dbI.Id;
Now here is my attempt inside click event handler for an .ASPX page:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TRIMSDK;
protected void ConnectUserBtn_Click(object sender, EventArgs e)
{
Database db = new Database();
Databases dbChooser = new Databases();
IDatabase dbI = dbChooser.ChooseOneUI(Handle.ToInt32());
if (dbI == null)
{
return;
}
I get a compile complaint in the line just above that reads "The name 'Handle' does not exist in the current context.
This part of the SDK I am trying to use displays various modal dialogs that reflect the properties of the product to facilitate "client" development. I fear it might be only "Windows clients" and that ASP.NET web apps cannot do this.
Is there something I can add to resolve this?

For web apps, modal dialogs would be done at the client, usually via javascript and dhtml - not at the server (where ASP.NET code executes). So I fear that this product is indeed winforms only.

Just pass it:
int hwnd = 0;
IDatabase dbI = dbChooser.ChooseOneUI(hwnd);

Related

'Debug' does not contain a definition for 'Print'

In the following code I would like to just output "hi" into a console window as a test when both of the check boxes are checked.
using System;
using System.Diagnostics;
private void button_Click(object sender, RoutedEventArgs e)
{
show.Text = inputText.Text;
if (check1_cont && check2_cont == true )
{
Debug.Print("hi");
}
}
The only problem is that in System.Diagnostics, the 'Print' in 'Debug.Print' doesn't seem to exist. I've checked https://msdn.microsoft.com/en-us/library/system.diagnostics.debug.print(v=vs.110).aspx and the Print method does exist. Any help regarding a solution to an absent Paint method would be much appreciated.
EDIT 1:
Apparently Debug.WriteLine doesn't give an error, but when I run the program and check the two boxes and press the button, no console appears.
EDIT 2:
In case it helps anyone, here is the full code for the GUI application that I am using.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using Microsoft;
using System.Threading.Tasks;
using System.Data;
using System.Dynamic;
using System.Xml;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace normieap
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public Boolean check1_cont = false;
public Boolean check2_cont = false;
public MainPage()
{
this.InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
show.Text = inputText.Text;
if (check1_cont && check2_cont == true )
{
MessageBox.Show("hi");
}
}
private void check1_Click(object sender, RoutedEventArgs e)
{
check1_cont = true;
}
private void check2_Click(object sender, RoutedEventArgs e)
{
check2_cont = true;
}
}
}
The button is going to cause multiple things to go at once, one of the things I would like to go at once is an instance of a console window of some sort to open.
EDIT 3:
This is meant to be a application for PC but for some reason when I started the project, Visual Studio 2015 community thought it was an application for a phone and is causing problems with PC exclusive commands. If someone could give information on how to fix that as well, that would be great.
You appear to not be using the full desktop framework and instead are using some kind of mobile framework. For example, if you check Silverlight's documentation you can see Debug.Print is not available.
If you check the "Version information" for Print you will see
Version Information
.NET Framework
Available since 2.0
Switch to Debug.WriteLine("hi") instead, that should work in all frameworks, its version information says
Version Information
Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
If you are not seeing output I would recommend showing what your test variables are instead.
private void button_Click(object sender, RoutedEventArgs e)
{
show.Text = inputText.Text;
Debug.WriteLine(check1_cont.ToString());
Debug.WriteLine(check2_cont.ToString());
}

Form showing nothing. using CefSharp with Windows form in C#

I am trying to show a webpage in a form using C#. I am using CefSharp to show the webpage (as I would like to test & learn how it works). But since I have worked only on inbuilt webbrowser, I have no idea how to get started with CefSharp(Finding it difficult to get any tutorials). I tried to write this code which executes but the form shows nothing in it. Where am I going wrong ?
Here is my Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
namespace chrometest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Cef.Initialize(new CefSettings());
var test = new CefSharp.WinForms.ChromiumWebBrowser("http://www.google.com")
{
Dock = DockStyle.Fill,
};
this.Controls.Add(test);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Edit :
I tried to run the example from https://github.com/cefsharp/CefSharp/tree/cefsharp/41/CefSharp.WinForms.Example
When I try to build the solution, it shows a dialog box saying "Restoring Nuget Package cef.redist.x64 3.2454.1317" with a progresss bar which takes hell lot of time to complete but never completes and after sometime it hangs.
Please help what should I do to get the example running.
The CefSharp project has a few different examples as part of the main project.
Basic Example using Nuget
https://github.com/cefsharp/CefSharp.MinimalExample
More Advanced Examples
https://github.com/cefsharp/CefSharp/tree/cefsharp/41/CefSharp.WinForms.Example
When you installed the project using Nuget it should have opened a Readme.txt file, it contains a lot of useful information.
https://github.com/cefsharp/CefSharp/blob/cefsharp/41/NuGet/Readme.txt
In the context of WinForms there's a few tutorials
http://www.codeguru.com/columns/dotnet/if-you-like-it-put-an-html5-ui-on-it.html
http://thechriskent.com/2014/08/18/embedded-chromium-in-winforms/
For those reading this looking for WPF, there's
http://www.codeproject.com/Articles/881315/Display-HTML-in-WPF-and-CefSharp-Tutorial-Part
http://www.codeproject.com/Articles/887148/Display-HTML-in-WPF-and-CefSharp-Tutorial-Part
More Links
https://github.com/cefsharp/CefSharp.Tutorial
http://thechriskent.com/category/net/cefsharp/

Kentico UserInfoProvider not working as expected in a console app

This code works fine within a Kentico website:
var users = UserInfoProvider.GetUsers();
for (int x = 0; x < users.Count(); x++
{
UserInfo currentUser = users.ElementAt(x);
currentUser.SetValue("AcceptsAlerts", equivalentSubscriber.Status != SubscriberStatus.Unsubscribed);
UserInfoProvider.SetUserInfo(currentUser);
}
When I move the code to a console app, any calls to UserInfoProvider result in the error: "Object type 'cms.usersettings' not found"
For the initial call to get the users, I can do it like this in the console app:
DataSet usersds = new CMS.DataEngine.DataQuery("cms.user.selectall").Execute();
then loop through Table1 of the dataset using the user data:
UserInfo currentUser = new UserInfo(dtUsers.Rows[x]);
All is fine and working, until I come to write the updated user back to the database. I cannot find another way of writing the data apart from calling:
UserInfoProvider.SetUserInfo(currentUser);
Does anyone know another way to save the user data? or to resolve the error. The error is a runtime error and as far as I know, I have referenced everything I need to. The field I am editing is a custom field added to the cmsUser table.
using statements for info:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using CMS;
using CMS.CustomTables;
using CMS.DataEngine;
using CMS.Membership;
Before you start working with Kentico CMS API from an external application make sure you call the following lines:
CMS.DataEngine.ConnectionHelper.ConnectionString = "your connection string";
CMS.Base.SystemContext.WebApplicationPhysicalPath = Application.StartupPath;
CMS.DataEngine.CMSApplication.Init();
Then, you'll be also able to use UserInfoProvider.GetUsers() object query instead of using DataQuery.Execute().
Are you sure you are referencing all necessary assemblies?
Following scenario works on my machine with configuration: Kentico 8.x, Web Application project
Reference in your Console application these assemblies from lib folder
CMS.Base
CMS.DataEngine
CMS.DataProviderSQL
CMS.Membership
Then copy your Connection String from Web Application's web.config to Console Application's App.config.
After that you can use this code to set custom user properties
static void Main(string[] args)
{
var users = UserInfoProvider.GetUsers();
foreach (var user in users)
{
user.SetValue("myTestString", "test");
user.Generalized.SetObject();
}
}
For anyone looking to get a SiteID to use in API calls from an external app such as getting an email template, this might help you. In Kentico 8.1 you can go to Sites > General and get the code name for your site. Then you can do this:
int siteID = CMS.SiteProvider.SiteInfoProvider.GetSiteID("<your site code name>");
Hope it helps!

Intellisense stopped working for Linq to Entities

I have this simple code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Linq;
using GadNameSpace;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GadEntities db = new GadEntities();
var images = db.Images.Where(x => x.isApproved == true).ToList();
Repeater1.DataSource = images;
Repeater1.DataBind();
}
}
Now if I'm trying to edit this line:
var images = db.Images. <--this is where intellisense is not working...
It worked before. Same file, same project, same Solution.
If I'm writing the code manually and run it, its working fine.
I tried start > cmd > "devenv /ResetSettings"
I tried to restart pc also.
The problem is with Linq intellisense only! for anything else intellisense is working fine...
Any good ideas?
Usually this happens to me when a reference to System.Data.Linq.dll is missing from the module.
I bet you have your data context in yet another assembly where the reference is set correctly (so that the code works when you compile it) but in the same time the reference is missing from the web application (and thus VS does not show the intellisense).
Sometimes, reference of EntityFramework could be missing. Please make sure that the same exists in the project you're working on.

ASP.Net and Web Services

I have been searching for 4 days non stop. I am sleep deprived and going crazy. Can someone please help me or at least tell me what I'm doing wrong. This is my project
Develop a client web page app that uses the web service found at http://www.marksmerry.com/peanutbutter/WebService1.asmx.
The service generates a random number m
This service receives a guess , an integer between 1-100 inclusive. It returns a string:
low - if the guess is lower than m
equal – if the guess is correct
high - if the guess is higher than m
I have referenced the web service but I'm lost at the syntax or something please help me! This is what I have so far.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using localhost;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
localhost.WebService1 ws1 = new WebService1();
//What goes in this area. I have been searching and have tried all kinds of combination all have resulted in build errors
}
}
type ws1. and a list of methods will appear.
any service methods that were discovered by visual studio when you referenced the 'peanutbutter' webservice will be available to call on the proxy class (called WebService1 in your code example).
string result = ws1.Guess(42);
If you just type the url in the browser, it wil show you what methods it has.
http://www.marksmerry.com/peanutbutter/WebService1.asmx
I can see a web method Guess which takes an int.
As per your code, You can call it via
string result = ws1.Guess(10); // or input
When you added the reference you should have got the chance to give it a name. It's only semantics but it might be better to give it a different name from localhost.
Previous commentators have made good suggestions so I'd follow them.
Only thing I'd suggest is this.
string result = ws1.Guess("10"); //EDIT: this is wrong of course. It takes an int.
I did some work this morning using a web service.
myCoService.Service1 v24 = new myCoService.Service1();
System.Xml.XmlNode doc = v24.CreateSite(newSiteName);
Should be as simple as that.
If it isn't I'd have a look again at how you set up your web reference. Also please let us know what NET framework you are using.
I added a web Reference to a test project and a button on a page which fires this event.
protected void PeanutGuess_click(object sender, EventArgs e) {
PeanutButter.WebService1 pb = new PeanutButter.WebService1();
string response = pb.Guess(10);
lblResult.Text = string.Format("Response for 10 is " + response);
}
This works fine for me. I'm using VS2010 and the project uses Net Framework 3.5

Categories

Resources