Sending location with get - windows-phone-7

I am making a simple app that sends location data to a server using http get request.
The problem is that the request is made only on the first time despite the fact that it is inside the positionchanged event handler.
Here is my code. I can't find what is wrong with it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Device.Location;
namespace kechap
{
public partial class MainPage : PhoneApplicationPage
{
GeoCoordinateWatcher gw = new GeoCoordinateWatcher();
Uri url = new Uri("http://127.0.0.1:5000/upload/1e3fae069dd62fa1641183cd77092ed2053a0e75/1/2");
// Constructor
public MainPage()
{
InitializeComponent();
gw.MovementThreshold = 10;
gw.PositionChanged += (s, e) =>
{
MyMap.Center = e.Position.Location;
MyPushpin.Location = e.Position.Location;
WebClient wc = new WebClient();
wc.OpenReadAsync(url);
wc.OpenReadCompleted += (ss, ee) =>
{
};
};
gw.Start();
}
}
}

At a guess I would say the URI, which in the code you have posted does not change between calls, is resolved from cache after the first time. I suggest you use the age old hack of appending a parameter and giving it a value that changes with each invocation (eg the position you seem to want to report).

Related

How to use BotAuthentication botframework v3

I'm trying to make a proactive message according to this.
I can understand the way to it. I'm worried about security. So I'm trying to use BotAuthentication. But I don't know how to use it. I tried to add a token according to this.
But it seems useless. How to use BotAuthentication? By the way, do I need to worry about security?
using Bot.Dialogs.FAQ.Liquidation;
using Bot.Dialogs.Menu;
using Bot.Resources;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Resources;
using System.Threading.Tasks;
using System.Web.Http;
namespace Bot
{
[BotAuthentication]
public class CustomWebAPIController : ApiController
{
[HttpGet]
[Route("api/CustomWebAPI")]
public async Task<HttpResponseMessage> SendMessage()
{
try
{
if (!string.IsNullOrEmpty(ConversationStarter.conversationReference))
{
await ConversationStarter.Resume(); //We don't need to wait for this, just want to start the interruption here
var resp = new HttpResponseMessage(HttpStatusCode.OK);
resp.Content = new StringContent($"<html><body>Message sent, thanks.</body></html>", System.Text.Encoding.UTF8, #"text/html");
return resp;
}
else
{
var resp = new HttpResponseMessage(HttpStatusCode.OK);
resp.Content = new StringContent($"<html><body>You need to talk to the bot first so it can capture your details.</body></html>", System.Text.Encoding.UTF8, #"text/html");
return resp;
}
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
}
}
}
}
You don't need to handle bot authentication. That is done by the SDK.
You should not be using v3 as it is deprecated and no longer being developed. V4 is the current version.
Here is the documentation on V4 proactive messages.
And here is a sample that shows how to use proactive messages.

Getting the specified username of windows credentials (Windows Vault)

The following problem is happening. Our company is changing all the passwords of the users.
They asked me to write a program so that the user can enter his or her's username and new password so this will be replaced in the windows credentials manager. (Windows Vault).
What I am trying to do is to get all the stored credentials in the credential manager with a specified username. When I find the username I will edit the password.
I do not know the Target name so I cannot find the credentials with a Target name.
I made the following script with https://www.nuget.org/packages/CredentialManagement/:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CredentialManagement;
using System.Diagnostics;
using System.Security;
using Microsoft.Win32.SafeHandles;
namespace RU_PWReplacer
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetCredentials();
}
public void GetCredentials()
{
List<Credential> Credentials = new List<Credential>();
List<string> TargetPath = new List<string>();
TargetPath.Add("test1.nl");
TargetPath.Add("test2.nl");
TargetPath.Add("test3.nl");
for (int i = 0; i < TargetPath.Count; i++)
{
Credential Try_ToFind_Credential = new Credential { Target = TargetPath[i], Type = CredentialType.DomainPassword };
Credentials.Add(Try_ToFind_Credential);
}
foreach (Credential c in Credentials)
{
if (!c.Exists())
{
Console.Write("Not Found\n");
}
else
{
Console.Write("Found\n");
}
}
}
}
}
The problem is that this way I am searching with a Target name and that is not a possibility, because there can be a lot of target names. So searching for a Username is more efficient.
If have found this post: How do I store and retrieve credentials from the Windows Vault credential manager?
The problem with this is that it still uses a Target name to find the credential.
I hope you guys can point me in the right direction.
With kind regards,
Dennis.

unable to connect the remote server with very simple httpWebRequest class app

I used visual2010 to write a simple app with httpWebRequest class. The very first time of running the app, it'd work but after some successes, it was stuck with warning
"unable to connect the remote server".
I have read a lot in net but not much clues could done, almost said because the anti virus soft or firewall cause the problem, but when i'd turn off both, it still does not work. I also reinstall visual2010 but the problem still
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace new_httpWebRequest
{
class Program
{
static void Main(string[] args)
{
string result ="";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://my-favor.net");
// line code problem below:
`HttpWebResponse response = (HttpWebResponse)request.GetResponse();`
var sr = new StreamReader(response.GetResponseStream() ?? System.IO.Stream.Null, Encoding.UTF8);
result = sr.ReadToEnd();
sr.Close();
Console.Write(result);
Console.ReadLine();
}
}
}
finally, i find the solution just by adding this line:
request.Proxy = null;
I don't know why it work, just do it by god bless.

Remote Server returned an error : Not Found

I wrote one program which sends request for particular site and gets response. It properly runs with localhost. but, if i put www.google.com then it prompts error as "The remore sever returned an error: Not Found"
****Code*****
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
namespace WindowsPhoneApplication2
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
var request = (HttpWebRequest)WebRequest.Create(new Uri(#"http://www.google.com"));
request.BeginGetResponse(r =>
{
var httpRequest = (HttpWebRequest)r.AsyncState;
var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r);
using (var reader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = reader.ReadToEnd();
Deployment.Current.Dispatcher.BeginInvoke(new Action(() => { textBox1.Text = response; }));
}
}, request);
}
}
}
please tell me soultion
thanx in advance
Your code works for me.
Can you access Google from IE on the device/emulator?
I suspect that this is a networking issue local to you and not related to the device.

Visual C# - InvalidActiveXStateException

I am getting an error when trying to embed a flash (.swf) file into my Visual C' form - I have notice this is a fairly common error, though the solutions don't mean much to me.
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.Windows.Forms;
using AxShockwaveFlashObjects;
using ShockwaveFlashObjects;
namespace WindowsFormsApplication1
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
frm1.ShowDialog();
}
private void axShockwaveFlash2_Enter(object sender, EventArgs e)
{
**//this.axShockwaveFlash1.LoadMovie(0, "C:\\Documents and Settings\\Gary\\My Documents\\Flash File\\CalmBay1.swf");**
}
private void Form6_Load(object sender, EventArgs e)
{
AxShockwaveFlash axShockwaveFlash = new AxShockwaveFlash();
axShockwaveFlash.Location = new System.Drawing.Point(50, 50);
this.Controls.Add(axShockwaveFlash);
**axShockwaveFlash.Movie = ("C:\\Documents and Settings\\Gary\\My Documents\\Flash File\\CalmBay1.swf");**
//ShockwaveFlash.Size = new System.Drawing.Size(150, 150);// set size as required
axShockwaveFlash.Play();
}
}
}
The line with the asterix is where the error is, but as i say, i've no idea on how to resolve it!
Even though it's been months since this question was asked, I just had the same problem. When creating AxShockwaveFlash objects programmatically, you have to initialize:
var flashObj = new AxShockwaveFlash();
((ISupportInitialize) (flashObj)).BeginInit(); // <--
flashObj.Dock = DockStyle.Fill;
flashObj.Enabled = true;
((ISupportInitialize) (flashObj)).EndInit(); // <--
Controls.Add(flashObj);
flashObj.AutoSize = true; // All of these properties won't work unless the component has been initialized
flashObj.ScaleMode = 1;
flashObj.AlignMode = 0;
flashObj.LoadMovie(0, #"movie.swf");
flashObj.Stop();
flashObj.Play();
Hopefully this will save future readers some time.
I had the same problem I tried the proposed solutions of calling CreateControl without any success.
It turned out that the interops were generated targeting the .net 2.0 framework and the problem occurred when being called from 4.0 code. The solution was to generate interops using .NET Framework Tools 4.0.

Resources