Emulators Providing Different Results - windows-phone-7

I am developing an application on windows phone with version 7.1 set as my target build. The problem i am having is that one of the listviews in on of my pages refus to display.
I have debugged to ensure the list gets parsed with contents inside of it . Also the application runs fine when i use a windows 8 emulator. But the same technique used in populating other listviews in other pages of the application work fine on all emulators aprt from this single page that does not display.
I even tried to set the colour of the binding stack panel to see if it will show up and it does but without any content.
I am really confused and my code is very perfect. I wonder if any one has seem this issue before with windows phone emulators?
private void countdownClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
HtmlDocument doc = new HtmlDocument();
if (e.Error != null)
{
//MessageBox.Show(e.Error.InnerException.Message + "\n Ensure You Have A Working Internet Connection");
return;
}
doc.LoadHtml(e.Result);
String noCountdown = "<div><span>Sorry no buses are expected within 30 minutes of this stop. Please try again later or go to www.tfl.gov.uk</span></div>";
if (e.Result.Contains(noCountdown))
{
//No Buses Expected;
return;
}
else
{
HtmlNode stopCountdownNode;
try
{
stopCountdownNode = doc.DocumentNode.SelectSingleNode("//*[contains(#id, 'stopBoard')]").SelectSingleNode("tbody");
}
catch (Exception)
{
MessageBox.Show("Error Responce From Server");
return;
}
if (stopCountdownNode != null)
{
HtmlNodeCollection countdownNodeList = stopCountdownNode.SelectNodes("tr");
CountDownListBox.ItemsSource = GetCountdownList(countdownNodeList);
}
}
}
private ObservableCollection<BusCountdown> GetCountdownList(HtmlNodeCollection countdownNodeList)
{
ObservableCollection<BusCountdown> countdownList = new ObservableCollection<BusCountdown>();
foreach (HtmlNode countDown in countdownNodeList)
{
String busName = HttpUtility.HtmlDecode(countDown.SelectSingleNode("*[contains(#class, 'resRoute')]").InnerHtml);
String busDestination = HttpUtility.HtmlDecode(countDown.SelectSingleNode("*[contains(#class, 'resDir')]").InnerHtml);
String countDownTime = HttpUtility.HtmlDecode(countDown.SelectSingleNode("*[contains(#class, 'resDue')]").InnerHtml);
countdownList.Add(new BusCountdown(busName, busDestination, countDownTime));
}
return countdownList;
}
public string GetRandomSlash()
{
Random r = new Random();
String slash = "";
int rand = r.Next(1, 20);
for (int i = 0; i < rand; i++)
{
slash += "/";
}
return slash;
}

Try setting your class access specifier which you use to bind to public and give it a try. Let me know if it works.
For ex:
public class Bindingclass
{
public string Name{get;set;}
}

Try using Expression Blend and also delete your previous solution file and build a new solution.
Also set the build action property properly for all pages.
Update your SDK to 7.8 version. You will get multiple choices for Emulators - Emulator 7.1 (256 MB), Emulator 7.1 (512 MB), Emulator 7.8 (256 MB), Emulator 7.8 (512 MB). Test it on all these versions and check output on each Emulator type.
I hope at least one of these helps you get things get working. Let us know.

Related

Silverlight app freezes on Mac when file saved

Pretty simple code to launch SaveFileDialog and then save data.
Opens prompt, I can select where I save, it saves file and then whole tab/app freezes. Obviously works fine on Windows/IE. Any suggestions?
private void SavePDFFile()
{
var saveFileDialog = new SaveFileDialog
{
DefaultExt = "pdf",
Filter = string.Format("Document(.{0})|*.{0}", "pdf"),
FilterIndex = 1,
DefaultFileName = DateTime.Now.ToString("HHmmMMddyyyy")
};
var saveClicked = saveFileDialog.ShowDialog();
if (!saveClicked.HasValue || !saveClicked.Value) return;
var fileStream = saveFileDialog.OpenFile();
try
{
this.IsBusy = true;
fileStream.Write(this.PDFData, 0, this.PDFData.Length);
fileStream.Close();
}
catch (Exception ex)
{
this.DisplayErrorMessage("Error saving PDF file", ex);
}
finally
{
this.IsBusy = false;
}
}
Answering my own question. This is nothing to do with code itself. It is security issue. In order to allow this code to execute on Mac (and it seems new versions of IE as well) you need to give it more permissions.
On IE you need to add website to list of Trusted sites.
On Mac - you need to set Silverlight to run in "Unsafe" mode. This is in Preferences/Security/Silverlight and need to select website, hold "Option" key and then open dropdown to see that option. Took a while to find it..
#katit I also faced this issue while working on a Silverlight OOB application.. my app was working fine in Windows but in Mac it got freezed and I have to force quit to use it again.
I was actually reading a PDF (stored in field type - 'varbinary') from server and storing it to user's local machine.
The solution worked for me is to download file chunks in parts (I used buffer size - 1 MB).
Not sure what file size you are using when your application gets freeze.. but I think, writing 'PDFData' to filestream in small parts may help you.
Also, add filestream.Flush(); (see highlighted in below code) in your code and see if this helps:
private void SavePDFFile()
{
var saveFileDialog = new SaveFileDialog
{
DefaultExt = "pdf",
Filter = string.Format("Document(.{0})|*.{0}", "pdf"),
FilterIndex = 1,
DefaultFileName = DateTime.Now.ToString("HHmmMMddyyyy")
};
var saveClicked = saveFileDialog.ShowDialog();
if (!saveClicked.HasValue || !saveClicked.Value) return;
var fileStream = saveFileDialog.OpenFile();
try
{
this.IsBusy = true;
fileStream.Write(this.PDFData, 0, this.PDFData.Length);
**filestream.Flush();**
fileStream.Close();
}
catch (Exception ex)
{
this.DisplayErrorMessage("Error saving PDF file", ex);
}
finally
{
this.IsBusy = false;
}
}

Developing iTunes like application in c#

I need to develop an application in c# that could automatically detect an iPhone when it is connected to the system and read a particular file for the iPhone file system. I basically want this file to be downloaded automatically from device to the PC. I used USBpcap tool that suggests that iTunes connects to phone using some XML format. Any help or insight greatly appreciated. Is there any documentation of Third party APIs that can get me started? There are some applications that can replicate iTunes functionality e.g Copytrans
Is there any protocol or APIs provided by Apple?
I have been digging the internet and found this link Layered communication for iPhone.
Also I am using the LibUsbDotNet libraries for communicating to the usb device(Example). Can any one suggest which EndPoints should be used.
It seems to me that I have to implement usbmuxd in windows application. It is a multilayer protocol. There must be some libraries that implement usbmuxd(I dont think I have to implement the protocol all by my self)
I dont have much idea about iTunes communication as well as USB communication. I am adding as much information as I can(of course with the things I come up with in my R&D). Any help is highly appreciated.
public static DateTime LastDataEventDate = DateTime.Now;
public static UsbDevice MyUsbDevice;
#region SET YOUR USB Vendor and Product ID!
public static UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(1452, 4768);
#endregion
private void LibUSB()
{
ErrorCode ec = ErrorCode.None;
try
{
// Find and open the usb device.
MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
// If the device is open and ready
if (MyUsbDevice == null)
throw new Exception("Device Not Found.");
// If this is a "whole" usb device (libusb-win32, linux libusb)
// it will have an IUsbDevice interface. If not (WinUSB) the
// variable will be null indicating this is an interface of a
// device.
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
// This is a "whole" USB device. Before it can be used,
// the desired configuration and interface must be selected.
// Select config #1
wholeUsbDevice.SetConfiguration(1);
// Claim interface #0.
wholeUsbDevice.ClaimInterface(0);
}
// open read endpoint 1.
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep03);
// open write endpoint 1.
UsbEndpointWriter writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep02);
int bytesWritten;
ec = writer.Write(usbmux_header.GetBytes(), 2000, out bytesWritten);
if (ec != ErrorCode.None)
throw new Exception(UsbDevice.LastErrorString);
byte[] readBuffer = new byte[1024];
while (ec == ErrorCode.None)
{
int bytesRead;
// If the device hasn't sent data in the last 100 milliseconds,
// a timeout error (ec = IoTimedOut) will occur.
ec = reader.Read(readBuffer, 10000, out bytesRead);
if (ec == ErrorCode.Win32Error)
throw new Exception("port not open");
if (bytesRead == 0)
throw new Exception("No more bytes!");
// Write that output to the console.
Console.Write(Encoding.Default.GetString(readBuffer, 0, bytesRead));
}
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
}
finally
{
if (MyUsbDevice != null)
{
if (MyUsbDevice.IsOpen)
{
// If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
// it exposes an IUsbDevice interface. If not (WinUSB) the
// 'wholeUsbDevice' variable will be null indicating this is
// an interface of a device; it does not require or support
// configuration and interface selection.
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
// Release interface #0.
wholeUsbDevice.ReleaseInterface(0);
}
MyUsbDevice.Close();
}
MyUsbDevice = null;
// Free usb resources
UsbDevice.Exit();
}
}
}
class usbmux_header
{
public static UInt32 length = 10; // length of message, including header
public static UInt32 reserved = 0; // always zero
public static UInt32 type = 3; // message type
public static UInt32 tag = 2; // responses to this query will echo back this tag
public static byte[] GetBytes()
{
byte[] lgth = BitConverter.GetBytes(length);
byte[] res = BitConverter.GetBytes(reserved);
byte[] tpe = BitConverter.GetBytes(type);
byte[] tg = BitConverter.GetBytes(tag);
byte[] retArray = new byte[16];
lgth.CopyTo(retArray, 0);
res.CopyTo(retArray, 4);
tpe.CopyTo(retArray, 8);
tg.CopyTo(retArray, 12);
return retArray;
}
};
I have been trying to send hello packet bytes to iPhone but I am not able to read any response from phone.
To play with ipod you can use SharePodLib
As I understand it, only one client can use the USB connection to iOS at one time. On both macOS and Windows, that one client is usbmux. That library multiplexes TCP connections with higher-level clients, including iTunes, Photos, and (on macOS) the open-source peertalk library.
So on Windows, you wouldn't want to implement your own usbmux, but rather a client that sits on top of that, analogous to peertalk. I haven't seen anything open-source that does this, but a number of developers have accomplished it with their own proprietary software.
If anybody else has pointers about using usbmux on Windows, I'd love to hear about it.
—Dave
You can use imobiledevice-net. It provides a C# API to connect to iOS devices using your PC.
For example, to list all iOS devices connected to your PC, you would run something like this:
ReadOnlyCollection<string> udids;
int count = 0;
var idevice = LibiMobileDevice.Instance.iDevice;
var lockdown = LibiMobileDevice.Instance.Lockdown;
var ret = idevice.idevice_get_device_list(out udids, ref count);
if (ret == iDeviceError.NoDevice)
{
// Not actually an error in our case
return;
}
ret.ThrowOnError();
// Get the device name
foreach (var udid in udids)
{
iDeviceHandle deviceHandle;
idevice.idevice_new(out deviceHandle, udid).ThrowOnError();
LockdownClientHandle lockdownHandle;
lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();
string deviceName;
lockdown.lockdownd_get_device_name(lockdownHandle, out deviceName).ThrowOnError();
deviceHandle.Dispose();
lockdownHandle.Dispose();
}

How to get the Device Resolution in Wp7

I want to set some icons in my app according to device screen resolution like wxga or wvga. I saw in many links like App.Current.Host.Content.ScaleFactor or Application.Current.RootVisual.RenderSize. But I can only access App.Current.Host.Content.ActualWidth or Height. These always say as 480x800 even though I am running the app in wxga Device. How do i know the resolution correctly ?
Windows Phone 7 only supports one resolution(800*480). Are you asking about Windows Phone 8? Please a look at Multi-resolution apps for Windows Phone 8 . Here is the ResolutionHelper class you can use.
public enum Resolutions { WVGA, WXGA, HD720p };
public static class ResolutionHelper
{
private static bool IsWvga
{
get
{
return App.Current.Host.Content.ScaleFactor == 100;
}
}
private static bool IsWxga
{
get
{
return App.Current.Host.Content.ScaleFactor == 160;
}
}
private static bool Is720p
{
get
{
return App.Current.Host.Content.ScaleFactor == 150;
}
}
public static Resolutions CurrentResolution
{
get
{
if (IsWvga) return Resolutions.WVGA;
else if (IsWxga) return Resolutions.WXGA;
else if (Is720p) return Resolutions.HD720p;
else throw new InvalidOperationException("Unknown resolution");
}
}
}
You Target your app for Windows Phone 7.1 , so you should update your app to target windows phone 8.0 OS by clicking right on your project and Upgrade to Windows Phone 8.0

Memory usage in IE for gwt application

For the last couple of days I've been trying to find out why my gwt application is leaking on IE 9.
I want to share one of my findings with you and maybe someone can give me a clue about what is going one here...
I wrote this small test:
public class Memory implements EntryPoint
{
FlowPanel mainPanel = new FlowPanel();
FlowPanel buttonsPanel = new FlowPanel();
FlowPanel contentPanel = new FlowPanel();
Timer timer;
Date startDate;
public void onModuleLoad()
{
mainPanel.setWidth("100%");
mainPanel.setHeight("100%");
RootPanel.get().add(mainPanel);
Button startBtn = new Button("start test");
startBtn.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event)
{
startDate = new Date();
System.out.println("Started at " + startDate);
timer = new Timer()
{
public void run()
{
Date now = new Date();
if(isWithin5Minutes(startDate, now))
{
manageContent();
}
else
{
System.out.println("Complete at " + new Date());
timer.cancel();
contentPanel.clear();
}
}
};
timer.scheduleRepeating(50);
}
});
buttonsPanel.add(startBtn);
mainPanel.add(buttonsPanel);
mainPanel.add(contentPanel);
}
private void manageContent()
{
if(contentPanel.getWidgetCount() > 0)
{
contentPanel.clear();
}
else
{
for(int i =0; i < 20; i++)
{
Image image = new Image();
image.setUrl("/images/test.png");
contentPanel.add(image);
}
}
}
private boolean isWithin5Minutes(Date start, Date now)
{
//true if 'now' is within 5 minutes of 'start' date
}
}
So, I have this Timer that runs every 50 ms (during around 5 minutes) and executes the following:
- if the panel has content, clear it;
- if the panel has no content add 20 png images (30x30 with transparency) to it.
Using the Process Explorer from sysInternals I got the following results:
IE 9:
Firefox 21.0:
I ran the same program with some changes (.jpg images instead of .png, create the images only once and use them as member variables, create the images using a ClientBundle) but the result was the same. Also, I ran the application in production mode.
Is there something wrong with my code that could cause this behavior in IE?
Shouldn't the Garbage Collector (GC) free some of the used memory at least when the timer ends?
Any of you came across this problem before?
Garbage collector in IE is quite strange thing. E.g. you can force it to run by simply minimizing browser window. I guess leaks in your case are images that weren't removed properly by browser when you clear container. Try to remove them by using JS "delete" operation, like that:
private native void utilizeElement(Element element) /*-{
delete element;
}-*/;
Then change your manageContent a little:
if(contentPanel.getWidgetCount() > 0)
{
for (Iterator<Widget> it = contentPanel.iterator(); it.hasNext();)
utilizeElement(it.next().getElement());
contentPanel.clear();
}
Hope this helps.

Windows Phone 7.1 -Saving path of photo taken by cameraCaputreTask

I'm building an app that should- among other things, let the user capture a picture and then save the picture and other info (like location of where this picture was taken -using GPS of the phone and etc...) on a DataBase.
Im using a string to save the pictures to the DataBase. So far so good. My problem is that after the user has captured a picture I can not find the path of the picture anyWhere (in order to display it later to the user )
I know I can display the picture if I use a image and not a string but then I am not able to save it to the DB.
Also I used the picture string (which should be the path of the picture ) to be the primaryKey column in my table and if the string is null this will be a problem for sure.
After checking on the internet I found out that you cannot use the GeoCoordinateWatcher (for GPS) on the emulator so I had to use a random place.
This led me into thinking that a picture taken by the emulator may not have a path??
Part of my code: (the Event of the camera and the bottun that saves everyting to DB)
void c_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
MessageBox.Show(e.ChosenPhoto.Length.ToString());
//Code to display the photo on the page in an image control named myImage.
BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
myImage.Source = bmp;//display the picture right after taking it. before saving to DB
p.UrlImage = bmp.UriSource.AbsolutePath;//Do not Work!
}
}
private void saveToDB_Click(object sender, RoutedEventArgs e)
{
p.Description = DesriptionList.SelectedValue.ToString();//description of the pic
p.Date = DateTime.Today;//date picture taken
GeoCoordinateWatcher myWatcher = new GeoCoordinateWatcher();
var myPosition = myWatcher.Position;
p.Location = myPosition.Location.Altitude+" "+myPosition.Location.Latitude;//do not work with emulator
p.Location = "Some Where Over The Rainbow";
MainPage.m._bl.addPic(p);//add pic to DB
MessageBox.Show("Added Successfully! :)");
NavigationService.Navigate(new Uri(#"/Intro.xaml", UriKind.Relative));//go to another page
}
}
my class:
[Table]
public class Picture
{
public Picture()
{
}
public Picture(string l, string d, string url, DateTime da)
{
Location = l;
Description = d;
UrlImage = url;
Date = da;
}
string location;
[Column]
public string Location
{
get { return location; }
set { location = value; }
}
string urlImage;
[Column (IsPrimaryKey=true)]
public string UrlImage
{
get { return urlImage; }
set { urlImage = value; }
}
DateTime date;
[Column]
public DateTime Date
{
get { return date; }
set { date = value; }
}
string description;
[Column]
public string Description
{
get { return description; }
set { description = value; }
}
}
}
Anyway- I would like to know if I can get the path in some way...
And also- if I cant get the path- does Windows have a "Better" emulator?
this emulator cant do much and this is quite annoying giving the fact I dont have a WP to check my apps on..
Thanks!
You already get the stream of the taken image in e.ChosenPhoto. You just need to save that.
var imageBytes = new byte[e.ChosenPhoto.Length];
e.ChosenPhoto.Read(imageBytes, 0, imageBytes.Length);
using (var isoFile = IsolatedStorageFile.GetUserStoreForApplication()) {
using (var stream = isoFile.CreateFile("myImage.jpg")) {
stream.Write(imageBytes, 0, imageBytes.Length);
}
}
edit:
Regarding emulator, there is nothing wrong or limited about it.
The taken image is stored in a temp file that may vanish later on that's why you need to save it locally in your isolated storage if you want to display that image again.
Regarding GPS, you can use the additional tools (just click on the '>>' button on the right side of the emulator to set various settings that you find on an actual device such as accelerometer, location, network, etc.. For GeoWatcher you can define a set of points on the map that will be played back as if the device's actual GPS location was changing.

Resources