I am new to Microsoft CRM CCA . Currently i am faceing some problems .
i created an winform and hosted it in my Agent Desktop . The winform is supposed to show the contents of a notepad in the winform's text area . How to achieve it ? I have no clue at all as there is not a much documentation on this topic . .....Plz help me out here .
here you go the complete code
using System;
using Microsoft.Uii.Csr;
namespace Microsoft.Uii.QuickStarts
{
public partial class QsHostedControl : HostedControl
{
public QsHostedControl()
{
InitializeComponent();
}
// Necessary constructor
public QsHostedControl(Guid appID, string appName, string initString)
: base(appID, appName, initString)
{
InitializeComponent();
}
private void QSHostedControl_Load(object sender, EventArgs e) {}
// This is the context change event handler.
public override void NotifyContextChange(Context context)
{
// This is the context change handler.
// Populating text fields from context information.
txtFirstName.Text = context["CustomerFirstName"];
txtLastName.Text = context["CustomerLastName"];
txtAddress.Text = context["Street"];
txtID.Text = context["CustomerID"];
// Hands control back over to the base class to notify next app of context change.
base.NotifyContextChange(context);
}
protected override void DoAction(RequestActionEventArgs args)
{
//Check the action name to see if it's something we know how to handle and perform appropriate work
switch (args.Action)
{
case "UpdateFirstName":
txtFirstName.Text = args.Data;
break;
case "UpdateLastName":
txtLastName.Text = args.Data;
break;
}
}
private void updateData_Click(object sender, EventArgs e)
{
// This is how you fire an action to other hosted applications. Your DoAction() code
// in your other application or application adapter will get called via this.
FireRequestAction(new RequestActionEventArgs("QSExternalApplication", "UpdateFirstName", txtFirstName.Text));
FireRequestAction(new RequestActionEventArgs("QSExternalApplication", "UpdateLastName", txtLastName.Text));
FireRequestAction(new RequestActionEventArgs("QSWebApplication", "UpdateFirstName", txtFirstName.Text));
FireRequestAction(new RequestActionEventArgs("QSWebApplication", "UpdateLastName", txtLastName.Text));
FireRequestAction(new RequestActionEventArgs("QSWebApplication", "UpdateAddress", txtAddress.Text));
FireRequestAction(new RequestActionEventArgs("QSWebApplication", "UpdateID", txtID.Text));
}
private void btnFireContextChange_Click(object sender, EventArgs e)
{
// Get the current context and create a new context object from it.
string temp = Context.GetContext();
Context updatedContext = new Context(temp);
// Update the new context with the changed information.
updatedContext["CustomerFirstName"] = txtFirstName.Text;
updatedContext["CustomerLastName"] = txtLastName.Text;
// Notify everyone of this new context information
FireChangeContext(new ContextEventArgs(updatedContext));
// Tell self about this change
NotifyContextChange(updatedContext);
}
}
}
you can find it in sdk also
If you wan to create an hosted application with an adapter then yoou have to use AIF(application intregation frame work) yOU CAN CHECK OUT THIS LINK hosted control
and application adapter
Related
I have a console application which either invokes a class and runs as a console application or triggers a windows form. The windows form inturn sends parameters and invokes the same operation done otherwise.
Invocation point:
static void Main(string[] args)
{
if(AppSettingsHelper.GetValue<bool>("EnableWindowsForm"))
{
System.Console.WriteLine("EnableWindowsForm is set to true - Running Windows form");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1(0));
//First Time
var form = new ReportGeneratorForm();
Application.Run(form);
}
else
{
System.Console.WriteLine("EnableWindowsForm is set to false - Running direct program in console");
PortalMonitoring monitoring = new PortalMonitoring();
monitoring.Process();
}
}
Now In Click of Button the Same Class is triggered
private void button1_Click(object sender, EventArgs e)
{
PortalMonitoring monitoring = new PortalMonitoring();
monitoring.Process(DateTime.Now); //Date as paramater- Default is null
}
If i trigger the console app, it works well.
However if i click the button the code is stuck at point of async web api call -below code
int reportID = GetReportIDAsync().Result;
private static async System.Threading.Tasks.Task<int> GetReportIDAsync()
{
var reportName = "Portal name";
var reportID = await ops.GetReportId(reportName);
LogAndWriteToConsole("Report ID Feched : " + reportID.ToString());
return reportID;
}
Kindly help me here, i think windows form doesnt seem to allow multi threads by defauly. How to fix this ?
You don't show the complete path from monitoring.Process() to GetReportIDAsync() but it needs to be async/await all the way.
The top level should look like this:
private async void button1_Click(object sender, EventArgs e)
{
// probably add a try/catch here
PortalMonitoring monitoring = new PortalMonitoring();
await monitoring.Process(DateTime.Now); //Date as paramater- Default is null
}
Your no-winforms branch shoud then use monitoring.Process().Wait()
I get the link in "https://www.youtube.com/watch?v=SIs7ZsMCUWA&t=327s"
I want to change from aspx to winform
the problem:
in aspx
protected void Page_Load(object sender, EventArgs e)
{
if (Session["TokenQueue"] == null)
{
Queue<int> queueTokens = new Queue<int>();
Session["TokenQueue"] = queueTokens;
}
}
protected void btnPrinToken_Click(object sender, EventArgs e)
{
Queue<int> tokenQueue = (Queue<int>)Session["TokenQueue"];
lblStatus.Text = " Terdapat " + tokenQueue.Count.ToString() + " Antrian ";
if (Session["LastTokenNumberIssued"] == null)
{
Session["LastTokenNumberIssued"] = 0;
}
int nextTokenNumberTobeIssued = (int)Session["LastTokenNumberIssued"] + 1;
Session["LastTokenNumberIssued"] = nextTokenNumberTobeIssued;
tokenQueue.Enqueue(nextTokenNumberTobeIssued);
AddTokensToListBox(tokenQueue);
}
in c# can't read session?
Session["TokenQueue"] = queueTokens;
how to use session in c# winform?
Session normally helps us to maintain information for a user across multiple pages in a web application. When you are converting any web application to windows application you need to know the certain aspects of web application. As session is pretty common in most of web application frameworks. You can achieve same behavior by static variables in any language. In C# you can make a class to hold such information in static variables like this
internal static class SESSIONWINFORM
{
public static string TokenQueue = string.Empty;
public static DateTime LastLogin = DateTime.MinValue;
// more variables as you needed
}
Then you assign these variables values at particular events of your windows application for example in login method to save logged in time like this
protected bool login(string username, string password) {
if (succesfullLogic)
{
SESSIONWINFORM.LastLogin = DateTime.Now;
....
}
}
And to show in a Label1 to user his last login in a WinForm. You can set it text like this
Label1.Text = SESSIONWINFORM.LastLogin;
You don't need sessions since Windows apps run within the user context. There is always a single user.
I would advice to make the variable a static variable, since then it really is shared for the lifetime of the session, as it would in ASP.NET. What if you make a Session class in your Winforms project and mimic the session behavior? That would make it easier to exchange code between your projects.
In my Silverlight application, I put the WCF call in my ViewModel class.
DateTime CurrentDateTime;
internal void GetDateTime()
{
var client = new WcfClient();
client.GetCurrentDateTimeCompleted += GetCurrentDateTimeCompleted;
client.GetCurrentDateTimeAsync();
}
private void GetCurrentDateTimeCompleted(object sender, GetCurrentDateTimeCompletedEventArgs args)
{
try
{
CurrentDateTime = args.Result;
}
Then in my code behind code some.xaml.cs file. I have a checkbox clicked event.
private void CheckBox_Clicked(object sender, RoutedEventArgs e)
{
var msgBoxControl = new MessageBoxControl();
msgBoxControl.Closed -= MessageBoxYesNo_Closed;
msgBoxControl.Closed += MessageBoxYesNo_Closed;
Inside the method MessageBoxYesNo_Closed, I call the method in the ViewModel class.
private void MessageBoxYesNo_Closed(object sender, EventArgs e)
{
try
{
this.ViewModel.GetDateTime();
curDateTime = this.ViewModel.CurrentDateTime;
My question is that sometimes the line curDateTime = this.ViewModel.CurrentDateTime; is executed before wcf call completed method, so I can't get the right value.
I guess that it may be there are two threads, one is in UI, the other one is in service call? Please don't use async/await as I have to use Visual Studio 2010.
Thanks
Get the solution, just add a while loop:
this.ViewModel.GetDateTime();
while (true)
{
this.ViewModel.CurrentDateTime = DateTime.Now;
if (this.ViewModel.CurrentDateTime != DateTime.MinValue)
break;
}
curDateTime = this.ViewModel.CurrentDateTime;
Let's say I have a thread that waits for a user to click a button before advancing:
System.Threading.AutoResetEvent dialoguePause = new System.Threading.AutoResetEvent(false);
public void AskQuestion()
{
/* buttons containing choices created here */
dialoguePause.WaitOne();
/*Code that handles choice here */
}
public void Choice_Clicked(object sender, EventArgs e)
{
dialoguePause.Set();
}
How can I pass data from the thread Choice_Clicked is on to AskQuestion without relying on class variables? The best I can do is this:
System.Threading.AutoResetEvent dialoguePause = new System.Threading.AutoResetEvent(false);
string mostRecentChoice;
public void AskQuestion()
{
/* buttons containing choices created here */
dialoguePause.WaitOne();
MessageBox.Show("You chose " + mostRecentChoice + ".");
}
public void Choice_Clicked(object sender, EventArgs e)
{
mostRecentChoice = (sender as Button).Content.ToString(); //Ugly!
dialoguePause.Set();
}
There are many ways to achieve this:
Use a property in a Singleton or Monostate. There is always one instance of such property, so regardless which thread writes, and which reads, the will share it, as long as they are in one Application Domain.
Use messaging
If you are in same class, use field or property (look out for cross-threads!)
...
What I am trying to say, it depends on the application. I have no clue if this is WinForm, WPF or Web ...
I already made a windows service that should autostart when Windows starts up, but for some reason It does not work. I used the code below:
private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
{
using (ServiceController sc = new ServiceController(serviceInstaller1.ServiceName))
{
sc.Start();
}
}
After install the service using InstallUtil.exe it starts automatically, but if I make a restart it does not start even when the configuration in the Service Manager is "Automatic".
I already tried changing for "Automatic (Delayed Start) " but nothing changed.
I will appreciate some advice.
Sorry for my poor english, I'm not a native.
Thanks
namespace curUsers
{
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
public ProjectInstaller()
{
var processInstaller = new ServiceProcessInstaller();
var serviceInstaller = new ServiceInstaller();
//set the privileges
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.DisplayName = "curUsers";
serviceInstaller.StartType = ServiceStartMode.Automatic;
//must be the same as what was set in Program's constructor
serviceInstaller.ServiceName = "curUsers";
this.Installers.Add(processInstaller);
this.Installers.Add(serviceInstaller);
}
private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
{
}
private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
{
}
}
}
Just try this, all of my windows services are developed in the same way. this one also works well.
I built several windows services a while back. Maybe this will help solve your issue
// serviceInstaller1
//
this.serviceInstaller1.ServiceName = "whoisthere";
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
this.serviceInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceInstaller1_AfterInstall);