How to restart Cordova WP8 app? - c#

I have a WP8 Cordova app that has one page locally and then it redirects to a server for further functionality. Both pages have the cordova JS API's available and things work well.
Except that when I want to go to the local start page again. Any anchors to it (pointing to x-wmapp0:www/index.html) do not work on the HTML side.
In addition, any tricks with plugins and invocations of CordovaBrowser.Navigate() result in UnauthorizedAccessException errors.
The fallback has been for me to try to go back in browser history like this:
window.history.go(-window.history.length + 1);
But this doesn't do anything if I spend any time in the remote pages at all. So this isn't applicable either!
Is there a decent way to get to the starting page? With help from C# or otherwise?

So the UnauthorizedAccessException stuff came from thread issues. (The VS Express for WP can sometimes hide the details of an exception pretty well.)
This is a complete plugin that performs the redirection with neatest elegance available.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
namespace Cordova.Extension.Commands
{
public class Jumper : BaseCommand
{
/** Instruct the browser component to go to beginning. */
public void goHome(string unused)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var webview = WebViewHandler.getInstance().webView;
webview.CordovaBrowser.Navigate(webview.StartPageUri);
});
}
}
}
The WebViewHandler is a singleton for sharing the Cordova WebView to plugins, described in another SO answer (thanks #MikeBryant!).

Related

Cannot navigate to my end point URL on ASP.NET Web App

I'm trying to re-install a legacy ASP.NET Web application. It is old code and I realize that I need to redo it using ASP.NET Core. My machine was automatically rebuilt by Microsoft's December update and I lost all my programs. I'm having trouble re-installing a legacy REST Server. The clients are iPhone Apps, and I don't want to redo them now.
My machine environment is now:
Windows 10 Enterprise
Version: 1903
Installed on: 12/11/2019
OS build: 18362.535
Visual Studio 2019 Version 16.4.2
My end point URL should be: "http://www.cypresspoint.com/TrinREST/TrinService/GetData".
but it no longer works. I am getting a 404 response in my Chrome browser. The screen shows:
My complete server code is:
using System;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
[WebService(Namespace = "http://cypresspoint.com/TrinREST/TrinService")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TrinService : WebService {
[OperationContract]
[WebGet(UriTemplate = "GetData")]
[WebMethod]
public string GetData() {
try {
var nyseTrin = 0.00M;
var msg = string.Format("{0}", nyseTrin);
return msg;
} catch (Exception ex) {
return "GetTrinData Error: " + ex.Message;
}
}
}
I then re-loaded the project as Administrator and did a Publish. The browser appeared with:
and when I click on Invoke, I get:
So far so good. However, when I try my original end point URL:
"http://www.cypresspoint.com/TrinREST/TrinService/GetData"
I still get error 404.0.
Max, I appreciate you sticking with me.
Charles
As you can see the Invoke button trigger a POST request instead of a GET request, consequently you CANNOT use the browser to test the method.
I made the connection using Postman sending a POST request
Same result if I add the service reference on a Visual Studio project
If you want

System.Windows.Forms - RemoteWebDriver -> Access is denied

We have a problem with my team for several weeks.
We currently have a test in MSTest v1 and Selenium 3.11 that is dedicated to upload a photo when filling out a profile.
In local works perfectly (hehehe), but in remote (RemoteWebdriver) the server of Build & Releases (VSTS) throws an error just in the step where I interact with this window, of the Access Denied type.
It is not really Selenium who acts there, but the System.Windows.Forms library and the SendWait method of the SendKeys class that gives the error when it is launched remotely.
Screenshot of the element in question >>> UploadFile
Example code:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Windows.Forms;
using OpenQA.Selenium;
using System.IO;
//...
public class EditarFotoUsuarioAdministrador
{
public static void Execute(IWebDriver driver, string foto)
{
driver.FindElement(By.XPath("//button[#id='upload']")).Click();
System.Threading.Thread.Sleep(2000);
SendKeys.SendWait(Directory.GetCurrentDirectory() + foto);
SendKeys.SendWait(#"{Enter}");
System.Threading.Thread.Sleep(2000);
driver.FindElement(By.XPath("//button[#id='save']")).Click();
System.Threading.Thread.Sleep(500);
}
}
As I said, this in local works perfectly, but when it runs on the remote server, the whole test goes well until it reaches the SendKeys line:
AccessIsDenied
Hopefully someone has an answer, thank you very much !!
The agent need to be running as interactive mode.
I've fixed it using AutoIT3.
Loading the nuget and using its methods to send the path of the file, you can perfectly interact with any pop-up browser window.
And best of all, the remote server does it too.
Thank you very much to all !
AutoIT3 or AutoItX.Dotnet ?
can you please send the code snippet. i used below code
` AutoItX.WinActivate("Open");
AutoItX.ControlGetFocus("Open");
AutoItX.Send(file);
System.Threading.Thread.Sleep(2000);
AutoItX.ControlClick("Open", " ", "Button1");`
It works fine in local but not in remote

Mount Network Drive with WMI

Trying to write a WMI class function to mount a network drive on any computer (remote or local) using the credentials of the logged in computer.
This is a class for a larger project that I wrote for help desk staff to do first line fixes on remote PC's. The tech types in the the machine name or ip address and the app connects to it and allows to tech to click a couple of buttons and fix some basic items without having to remote(VNC) into the PC.
I've read all over the internet that it is much easier ways than WMI, but due to the remote nature of the app I would rather not use local API calls, nor do I want to worry about uploading script and executing it though a process start. Also other functions are already in WMI so I'd like to keep the code base the same.
The basic idea is to mount H: to //fileserver.example.com/$username
NetFixer is already in production use so I'm trying to keep my code nice and neat
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace WMIcontrols
{
public class Remote
{
public string target;
//Some code skipped here for simplicity sake...
public bool MountNetDrive(string DriveLetter, string MountLocation)
{
try
{
//Mount the network drive
return true;
}
catch
{
//Mount Failed
return false;
}
}
}
}
This is not using WMI but will accomplish what you want and is very simple
System.Diagnostics.Process.Start("cmd", "/c net use x: \\fileserver.example.com /user:Username Password");

HTTPWebRequest.GetResponse() throws connection failure exception

I'm trying to create a simple application that does a HTTP
request/response on a button click. Here's the entire code which I got
from a reference book:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace emulator2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
Uri l_Uri = new Uri("http://www.testing.com");
HttpWebRequest l_WebReq = (HttpWebRequest)WebRequest.Create(l_Uri);
HttpWebResponse l_WebResponse =
(HttpWebResponse)l_WebReq.GetResponse();
Stream l_responseStream = l_WebResponse.GetResponseStream();
StreamReader l_SReader = new StreamReader(l_responseStream);
string resultstring = l_SReader.ReadToEnd();
Console.WriteLine(resultstring);
}
}
}
The thing that puzzles me is that when I shift the entire chunk of code
to a Windows Application, it works fine. But when I use it on a Device
Application, it just throws me an error. Here are the details of the
error:
System.Net.WebException was unhandled Message="Could not establish
connection to network." StackTrace: at
System.Net.HttpWebRequest.finishGetResponse() at
System.Net.HttpWebRequest.GetResponse() at
emulator2.Form1.button1_Click() at
System.Windows.Forms.Control.OnClick() at
System.Windows.Forms.Button.OnClick() at
System.Windows.Forms.ButtonBase.WnProc() at
System.Windows.Forms.Control._InternalWnProc() at
Microsoft.AGL.Forms.EVL.EnterMainLoop() at
System.Windows.Forms.Application.Run() at emulator2.Program.Main()
The error points at this line:
HttpWebResponse l_WebResponse = (HttpWebResponse)l_WebReq.GetResponse();
Does anyone have any idea on how to solve this? I need to get this
solved real quick..so any help given is greatly appreciated! Thanks!
My guess is that the emulator doesn't have proper network connectivity. It can be a pain (and hit-and-miss in my experience) getting networking up and running on the old Windows Mobile emulators. (It's easy in Windows Phone 7.)
Load up Internet Explorer and see if that can make a connection to the same URL...
Additionally, you're not disposing of any of your resources (and if this code is really in a reference book exactly as you wrote it, that's a significant black mark against the book). For example, you should be disposing of the web response:
using (HttpWebResponse response = ...)
{
}
Likewise I would personally dispose of the response stream and the stream reader, just on general principle. I suspect that when the response is disposed, the stream will be too - but it makes sense to dispose of all streams etc unless you know you need to leave them undisposed.
If you're running in the emulator you'll ned to "cradle" the emulator and then create a partnership with ActiveSync (Win XP) or Windows Mobile Device Center (Vista or 7).
This will allow the emulator to share the network connection with the PC. You also need to do this even if you want to connect from the emulator to the PC.
As Jon mentions, in WP7 you don't need to make a connection in this way, the WP7 emulator automatically shares the network connection of the host PC.
Use IE Mobile (on the emulator) to check that the device can connect to the site.
Edit
To cradle the emulator, in VS2008 select "Device Emulator Manager" from the Tools menu. Select the emulator that's running, right click and select "Cradle".
Mobile Device Center should start automatically and ask if you want to create a partnership, just as if you'd connected a real device.

Get Windows Service Description ASP .NET

I'm writing a service monitoring ASP .NET app and I'm having issues particularly with getting the service descriptions. My current method (reading from registry) is not going to work due to registry read permissions on the production server.
For example:
Microsoft.Win32.RegistryKey system, currentControlSet, services, service;
system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System");
currentControlSet = system.OpenSubKey("CurrentControlSet");
services = currentControlSet.OpenSubKey("Services");
service = services.OpenSubKey(scTemp.ServiceName, true);
row["service_description"] = service.GetValue("Description");
Produces:
System.Security.SecurityException: Requested registry access is not allowed.
My question is:
Is there a work-around with another .NET class (maybe under System.ServiceProcess namespace?) or will it always end with a security exception error?
I have no issues getting Service names and states with the System.ServiceProcess namespace but I can't find any classes contained to get descriptions which is why I resorted to reading from registry.
I think this should work.
EDIT: I should read questions closer. The code below gets the description for the first service in the array.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
using System.Management;
namespace ServiceNames
{
class Program
{
static void Main(string[] args)
{
ServiceController[] services = ServiceController.GetServices();
string serviceName = services[0].ServiceName;
string objPath = string.Format("Win32_Service.Name='{0}'", serviceName);
using (ManagementObject service = new ManagementObject(new ManagementPath(objPath)))
{
Console.WriteLine(service["Description"]);
}
Console.Read();
}
}
}
The previous answer showing the WMI solution is a good alternative and worth trying first.
--
I am not aware of a .NET Framework class that exposes the service description.
The first thing I would consider is requiring authenticated connections (e.g. NTLM) and impersonate the caller. As long as you don't do a double-hop (i.e. make a remote call with your impersonated credentials) you may find that you are able to successfully make the registery read.
If that is not possible then making a P/Invoke call may work.
If the credentials your web service has the SERVICE_QUERY_CONFIG permission you could do the following:
Find the service you are interested in using the ServiceController class
Using the ServiceHandle property make a P/Invoke call to QueryServiceConfig2 using the SERVICE_CONFIG_DESCRIPTION info level passing in null for the buffer and 0 for the lenght, reading the required buffer length from pcbBytesNeeded.
Allocate the proper buffer length and call QueryServiceConfig2 a second time getting the service description.
Obviously reading from the registery is a little more straight-forward (and in the end the permissions issues may be similar in both cases) - but using a supported API seems like a less fragile solution.
Side question: is there something you are trying to accomplish that PerfMon and logging can't tell you?

Categories

Resources