|
the format is consistent in the database but I can't get a place double.tryparse in my code.
|
|
|
|
|
it's work it was necessary to add the line for format :
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
|
|
|
|
|
Hi,
I am having a problem in putting a marker for every location in my bing map, this is my code:
private async void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
await
this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(
async () =>
{
UriString4 = "my URL";
var http = new HttpClient();
http.MaxResponseContentBufferSize = Int32.MaxValue;
var response = await http.GetStringAsync(UriString4);
var rootObject = JsonConvert.DeserializeObject<NvBarberry.Models.RootObject>(response);
Location[] location = new Location[int.Parse(rootObject.total)];
for (int i = 0; i < int.Parse(rootObject.total); i++)
{
location[i] = new Location(rootObject.locals[i].local_latit,rootObject.locals[i].local_longi);
MapLayer.SetPosition(GpsIcon, location[i]);
GpsIcon.SetRadius(args.Position.Coordinate.Accuracy);
GpsIcon.Visibility = Windows.UI.Xaml.Visibility.Visible;
MyMap.SetView(location[i], 17);
}
}));}
This is the JSON data from where I want to get the local_longi and local_latit of every Location:
{
success : 1,
total : 2,
locals : [{
id_local : "59",
local_longi : "20",
local_latit : "25894"
}, {
id_local : "60",
local_longi : "10.33699",
local_latit : "25.997745"
}
]
}
The problem is that I get only one marker on the map,
from the Debugger,I get all results in "location" variable,I don't know why I get only one marker in the Map
Please How can I correct my code to have multiple Locations set in the Map
thanks for help
|
|
|
|
|
Hi Friends
I am creating a PoC in windows MDM. I gone through the below link and understand the flow of the MDM.
I create a sample OMA Client Provisioning File(WAP format) and i need to update this Provisioning data(XML) into CSP to support OMA Device Management Command(SyncML).
I try to create C# code(ConfigurationManager.ProcessConfiguration Method (Microsoft.WindowsMobile.Configuration)[^]). Not able to find this library( microsoft.windowsmobile.configuration.dll). As an alternate I create VC++ based on below link()[Device_Management DMProcessConfigXMLFiltered">^]
I am getting Error like (
HRESULT - 0x80010106 - Cannot change thread mode after it is set.
).
I need help on reading the WAP provisioning XML and set it to registry or CSP in windows 10.
Your help is appreciated. Thanks
|
|
|
|
|
The is a continuation from the last question I had in implementing WeakEvents. I am able to add a handler to INotifyPropertyChange property using reflection, and also check if it exists within the class:
MethodInfo addHandlerMethod = SendOrListenType.GetMethod("AddHandler");
if (typeof(INotifyPropertyChanged).IsAssignableFrom(_WeakBoundObject.Target.GetType()))
addHandlerMethod.Invoke(null, new object[] { _WeakBoundObject.Target, "PropertyChanged", handler });
My problem arises when I wanted to add WeakHandlers to an ObservableCollection. I am able to find the event CollectionChanged:
EventInfo er = _WeakBoundObject.Target.GetType().GetProperty(PropertyName).PropertyType.GetEvent("CollectionChanged");
And Im also able to check if it exists:
if (typeof(INotifyCollectionChanged).IsAssignableFrom(_WeakBoundObject.Target.GetType().GetProperty(PropertyName).PropertyType))
but this refuses to compile:
addHandlerMethod.Invoke(null, new object[] {_WeakBoundObject.Target.GetType().GetProperty(PropertyName).PropertyType, "CollectionChanged", handler });
I have tried loads of different alternatives, but I can find the right one, can anyone spot my mistake here?
[Edit]
I have also changed the code to initialize the WeakEventMAnager:
Type unboundWEMType = typeof(WeakEventManager<,>);
Type[] typeArgs = { typeof(ObservableCollection<string>) , typeof(EventArgs) };
Type TempSendOrListenType = unboundWEMType.MakeGenericType(typeArgs);
MethodInfo addHandlerMethod2 = TempSendOrListenType.GetMethod("AddHandler");
if (typeof(INotifyCollectionChanged).IsAssignableFrom(_WeakBoundObject.Target.GetType().GetProperty(PropertyName).PropertyType))
addHandlerMethod2.Invoke(null, new object[] {_WeakBoundObject.Target.GetType().GetProperty(PropertyName), "CollectionChanged", handler });
Stack trace:
An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code
Additional information: Object of type 'System.Reflection.RuntimePropertyInfo' cannot be converted to type 'System.Collections.ObjectModel.ObservableCollection`1[System.String]'.
modified 27-Jan-16 13:12pm.
|
|
|
|
|
It looks like you need to pass the property value to the AddHandler method, rather than the property type or the PropertyInfo .
Try:
addHandlerMethod2.Invoke(null, new object[] {_WeakBoundObject.Target.GetType().GetProperty(PropertyName).GetValue(_WeakBoundObject.Target), "CollectionChanged", handler });
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you, it works. It's very useful , but I hate reflection
|
|
|
|
|
Kenneth Haugland wrote: but I hate reflection Why, I know it may be a funny for you but I'm curious to the background to the attitude.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I might not have been very precise here. I hate the way that it is set up. They seem to work like pointers that doesn't point in the direction I think they are. I think I have the right values, but then I don't, it turns my hairs grey.
|
|
|
|
|
I can't claim to deeply understand these two posts, but their "depth," and the fascinating responses, get my up-votes
If you have time/inclination to say something about the context in this scenario that leads you to need to compose executable code, and modify objects, that would be very interesting.
thanks, Bill
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
|
I'm following this example[^]
Here's my code:
using System.Collections.Generic;
using EnvDTE;
namespace MyApp
{
public class IISDebugAttach
{
public void AttachToIIS()
{
bool attached = false;
List<string> listProcess = new List<string>();
listProcess.Add("aspnet_wp.exe");
listProcess.Add("w3wp.exe");
listProcess.Add("webdev.webserver.exe");
foreach (Process process in DTE.Debugger.LocalProcesses)
{
foreach (var processName in listProcess)
{
if (process.Name.ToLower().IndexOf(processName) != -1)
{
process.Attach();
}
}
}
}
}
}
I get a compilation error on the first FOREACh saying "An object reference is required for the non-static field, method, or property '_DTE.Debugger'"
What am I doing wrong here???
If it's not broken, fix it until it is
|
|
|
|
|
DTE is a class, but Debugger is not a static property - you want the instance that is passed in as the method parameter in the example:
public static void LocalProcesses(DTE dte)
{
...
EnvDTE.Processes processes = dte.Debugger.LocalProcesses;
I've not tried any of this - never had the need - but does this help: HOWTO: Get an EnvDTE.DTE instance from a Visual Studio package[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: you want the instance that is passed in as the method parameter in the example:
What parameter? What example are you referring to? The example I quoted has no param being passed in. Where do you see ...void LocalProcesses(DTE dte)?
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: What parameter? What example are you referring to?
The example you linked to...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I think I figured it out. I needed:
DTE dte = (DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.14.0");
If it's not broken, fix it until it is
|
|
|
|
|
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks man
If it's not broken, fix it until it is
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Works great! Here's the entire class. I'm going to add to it to accept a list of processes to attach, then make it a VS addin that I can launch from a toolbar.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using EnvDTE;
namespace MyApp
{
public static class IISDebugAttach
{
public static void AttachToIIS()
{
MessageFilter.Register();
DTE dte = (DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.14.0");
var listProcess = new List<string>();
listProcess.Add("iisexpress");
var processes = dte.Debugger.LocalProcesses;
try
{
foreach (Process process in processes)
{
foreach (var processName in listProcess)
{
if (!string.IsNullOrEmpty(process.Name))
{
string procName = process.Name;
if (procName.ToLower().IndexOf(processName, StringComparison.Ordinal) != -1)
{
process.Attach();
}
}
}
}
}
catch (Exception e)
{
int x = 1;
}
MessageFilter.Revoke();
}
public class MessageFilter : IOleMessageFilter
{
public static void Register()
{
IOleMessageFilter newFilter = new MessageFilter();
IOleMessageFilter oldFilter = null;
CoRegisterMessageFilter(newFilter, out oldFilter);
}
public static void Revoke()
{
IOleMessageFilter oldFilter = null;
CoRegisterMessageFilter(null, out oldFilter);
}
int IOleMessageFilter.HandleInComingCall(int dwCallType,
System.IntPtr hTaskCaller, int dwTickCount, System.IntPtr
lpInterfaceInfo)
{
return 0;
}
int IOleMessageFilter.RetryRejectedCall(System.IntPtr
hTaskCallee, int dwTickCount, int dwRejectType)
{
if (dwRejectType == 2)
{
return 99;
}
return -1;
}
int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee,
int dwTickCount, int dwPendingType)
{
return 2;
}
[DllImport("Ole32.dll")]
private static extern int
CoRegisterMessageFilter(IOleMessageFilter newFilter, out
IOleMessageFilter oldFilter);
}
[ComImport(), Guid("00000016-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
interface IOleMessageFilter
{
[PreserveSig]
int HandleInComingCall(
int dwCallType,
IntPtr hTaskCaller,
int dwTickCount,
IntPtr lpInterfaceInfo);
[PreserveSig]
int RetryRejectedCall(
IntPtr hTaskCallee,
int dwTickCount,
int dwRejectType);
[PreserveSig]
int MessagePending(
IntPtr hTaskCallee,
int dwTickCount,
int dwPendingType);
}
}
}
If it's not broken, fix it until it is
|
|
|
|
|
Post it up as a tip, so it doesn't scroll off the page and into oblivion!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'm going to create a VSIX then post it here.
Many thanks
If it's not broken, fix it until it is
|
|
|
|
|
Yeah, was gonna suggest that as well! It's very useful indeed.
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
Hi Please can you help. I have been asked to see if I can integrate our systems with a 3rd party tool.
I've had the details from the 3rd party and it turns out I need to upload some data to a JSON Web service, then obviously manipulate the results
Example php has been supplied, but I always work in c# or VB and Ive made a start but starting to feel lost, can you help ?
''
public function runJsonRequestTest() {
$client = new \SoapClient(
"https://website.wsdl",
array(
'trace' => 1,
'exception' => 0
)
);
try {
$response = json_decode(
$client->json_request(
‘username’,
‘password’,
json_encode( //The request array
[
‘category’ => ‘api’,
‘type’ => ‘getMethods’,
‘data’ => [ ]
]
)
),
true
);
}
catch(\Exception $e) {
return "Soap request failed: {$e->getMessage()}
" . $client->__getLastResponse();
}
$string = print_r($response, true);
return $String;
'''
I've also got
'''
Example request array:
[
‘category’ => ‘api’,
‘type’ => ‘getMethods’,
]
Example return output:
Array (
[status] => COMPLETE
[data] => Array (
[0] => methodA
[1] => methodB
[2] => methodC
[3] => methodD) )
'''
so far I've got the below - but I get many errors and starting to get a bit lost - the below does not compile !
'''
public class ResultsTest
{
public string status { get; set; }
public List data { get; set; }
}
public class ResultsTestList
{
public int option { get; set; }
}
public static async Task RunAsync(String Url, String Username, String Password, InstructionMessageModel instruction, String log)
{
_log = log;
_url = Url;
_username = Username;
_password = Password;
var baseAddress = new Uri(_url);
using (var client = new HttpClient())
{
client.BaseAddress = baseAddress;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var auth = string.Format("{0}:{1}", _username, _password);
var encoded = Convert.ToBase64String(Encoding.ASCII.GetBytes(auth));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encoded);
try
{
HttpResponseMessage response = await client.PostAsJsonAsync(_url, instruction);
if (!response.IsSuccessStatusCode)
{
var errors = await response.Content.ReadAsAsync();
}
else
{
var jsonAsString = await response.Content.ReadAsAsync();
var output = JsonConvert.DeserializeObject(jsonAsString);
}
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
}
'''
|
|
|
|
|
I guess it depends if you want to transliterate the php => c# or 'do over' ie from scratch in c#.. Personally, I would
a) request the full JSON API details from the third party - this should be language independant
b) start from scratch in c#, using RestSharp, NewtonSoft JSON [tools], ...
c) I'm not sure about your POCO's for deserialising the JSON result - you have
public class ResultsTest
{
public string status { get; set; }
public List data { get; set; }
}
public class ResultsTestList
{
public int option { get; set; }
}
I dont get why ResultsTestList has 'option' in it - wouldnt it be
public class ResultsTestList
{
public List<ResultsTest> ResultsItems { get; set; }
}
ie a list of ResultsTest Objects, and I think ResultsTest should be
public class ResultsTest
{
public string status { get; set; }
public List<string> data { get; set; }
}
ie 'data' is a list of 'strings' - if you have an example of proper JSON, you can always use http://json2csharp.com/ to see what it says about the POCO's - I usually use this to start with and 'optimise' the output if I need to
looking at my point a, I dont have enough knowledge of PHP to see how it puts the call to the JSON Service together - thats why you'd be better off seeing a language independent version of the api docs - it might be as simple as {baseurl}/api/getmethods or it may not
|
|
|
|
|