Send data changing page Windows Phone - windows-phone-8

I'm trying to change page and send some data to the new page just create. Basicaly, I have a page where the user could log, I'm gonna save the informations and then I'm going to open a new page by sendind the information to my "profil" page, where the user will have the information about his account. I'm using the MVVM patern, I don't know if it's going to change something but I ad this precision ;).
Edit: The only solution i have found is to pass the string of my object (gladly it is just strings). Because we can pass strings to another page. But I would prefer to give my object directly, or change my architecture if needed. Like don't create a page but replace my Usercontroles by others :(.
Thanks for the help.

For temp data:
If it is WP silverlight app, we can directly assign object to public property of destination page in OnNavigateFrom event of source page. For example, we can declare a public property A on Dest page, and implement the following in Source page to pass the user object:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
Dest destPage = e.Content as Dest;
if(destPage != null)
{
User a = new User();
a.UserName = "aa";
a.ID = 1;
destPage.A = a;
}
}
For WP runtime app on WP 8.1, you can directly use Frame.Navigate(TypeName, Object) to pass the parameter.
For persist data:
I will suggest storing the data to local storage on source page and read it from destination page.

If I understand right you should use parameters in navigate URI
For example to send name you can use:
NavigationService.Navigate(new Uri("/View/Page.xaml?name=UserName", UriKind.Relative));
and then in OnNavigatedTo() check name parameter:
string name;
NavigationContext.QueryString.TryGetValue("name", out name);

You can use IsolatedStorageSettings.ApplicationSettings["keyname"]=yourobject;
And whenever you want to use this value just unbox this value as below,
if(IsolatedStorageSettings.ApplicationSettings.Contains("keyname"))
{
var obj=(yourobject)IsolatedStorageSettings.ApplicationSettings["keyname"];
}

Related

EWS - FileAttachment Content is empty / byte[0]

I have written a WebAPI controller method that finds a mail by its unique ID from ExchangeOnline. I wrote a small model class in order to store some attributes of a mail like the subject, the sender, the date received and so on.
Now I also want to access file attachments if the mail has such attachments. Therefore, I wrote this code (just the relevant part):
List<AttachmentItem> attDataContainer = new List<AttachmentItem>();
EmailMessage originalMail = EmailMessage.Bind(service, new ItemId(uniqueID), new PropertySet(ItemSchema.Attachments));
foreach (Attachment att in originalMail.Attachments)
{
if (att is FileAttachment && !att.IsInline)
{
FileAttachment fa = att as FileAttachment;
fa.Load();
attDataContainer.Add(
new AttachmentItem
{
ID = fa.Id,
Name = fa.Name,
ContentID = fa.ContentId,
ContentType = fa.ContentType,
ContentLocation = fa.ContentLocation,
Content = Convert.ToBase64String(fa.Content),
Size = fa.Size
});
}
}
The method indeed finds the attachments and displays all of the attributes you can see in the "AttachmentItem" object - BUT NOT the fa.Content attribute.
I have crwaled almost any document I could find on this (especially the *.Load() part as well as much examples. But in my case I get "byte[0]" when debugging the output.
Do you have any idea for me what could be the reason for this?
PS: By the way, I have version v2.0.50727 of Microsoft.Exchange.WebServices referenced.
Best regards and thanks in advance,
Marco
When you call the load method on the Attachment that should make a GetAttachment request to the server which will return the data for that Attachment. If you enable tracing https://msdn.microsoft.com/en-us/library/office/dn495632(v=exchg.150).aspx that should allow you to follow the underlying SOAP requests which should help with troubleshooting (eg you can see what the server is returning which is important).
The other thing to check is that is this is a real attachment vs a One Drive attachment which could be the case on ExchangeOnline.

Get HTML from Frame using WebBrowser control - unauthorizedaccessexception

I'm looking for a free tool or dlls that I can use to write my own code in .NET to process some web requests.
Let's say I have a URL with some query string parameters similar to http://www.example.com?param=1 and when I use it in a browser several redirects occur and eventually HTML is rendered that has a frameset and a frame's inner html contains a table with data that I need. I want to store this data in the external file in a CSV format. Obviously the data is different depending on the querystring parameter param. Let's say I want to run the application and generate 1000 CSV files for param values from 1 to 1000.
I have good knowledge in .NET, javascript, HTML, but the main problem is how to get the final HTML in the server code.
What I tried is I created a new Form Application, added a webbrowser control and used code like this:
private void FormMain_Shown(object sender, EventArgs e)
{
var param = 1; //test
var url = string.Format(Constants.URL_PATTERN, param);
WebBrowserMain.Navigated += WebBrowserMain_Navigated;
WebBrowserMain.Navigate(url);
}
void WebBrowserMain_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
if (e.Url.OriginalString == Constants.FINAL_URL)
{
var document = WebBrowserMain.Document.Window.Frames[0].Document;
}
}
But unfortunately I receieve unauthorizedaccessexception because probably frame and the document are in different domains. Does anybody has an idea of how to work around this and maybe another brand new approach to implement functionality like this?
Thanks to the Noseratio's comments I managed to do that with the WebBrowser control. Here are some major points that might help others who have similar questions:
1) DocumentCompleted event should be used. For Navigated event body of the document is NULL.
2) Following answer helped a lot: WebBrowserControl: UnauthorizedAccessException when accessing property of a Frame
3) I was not aware about IHTMLWindow2 similar interfaces, for them to work correctly I added references to following COM libs: Microsoft Internet Controls (SHDocVw), Microsoft HTML Object Library (MSHTML).
4) I grabbed the html of the frame with the following code:
void WebBrowserMain_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.OriginalString == Constants.FINAL_URL)
{
try
{
var doc = (IHTMLDocument2) WebBrowserMain.Document.DomDocument;
var frame = (IHTMLWindow2) doc.frames.item(0);
var document = CrossFrameIE.GetDocumentFromWindow(frame);
var html = document.body.outerHTML;
var dataParser = new DataParser(html);
//my logic here
}
5) For the work with Html, I used the fine HTML Agility Pack that has some pretty good XPath search.

SSRS streamIDs and chart images render with same id for different requests

Does anyone know if there is a way in the report definition to force a unique streamid for report images per request. I have a situation where I am rendering a report as a byte[] via the ReportExecutionsService web api. Whenever a report has images SSRS will give each image a streamid and I am required to save the parts to a temp web folder the client can access.
When I put a chart on a report the streamID never changes and this is causing a cache issue in browsers. The same chart displayed regardless of parameters, however, I can view the temp file on the server and see that the chart has been updated.
Posting a workable solution in case anyone is interested.
A. Calculate the physical and virtual mapping to a temp folder in your controller methods.
a. NOTE : For reports with charts you should create a folder per request for the report. I used:
private string GetVirtualTempFolder()
{
if (Url != null)
return Url.Content("~/Temp/");
else
return VirtualPathUtility.ToAbsolute("~/Temp/");
}
private string GetPhysicalTempFolder()
{
return AppDomain.CurrentDomain.BaseDirectory + #"Temp\";
}
...
string virtualTempFolder = "";
string physicalTempFolder = "";
if (makeUniqueTempFolder)
{
virtualTempFolder = this.GetVirtualTempFolder();
physicalTempFolder = this.GetPhysicalTempFolder();
string unique = Guid.NewGuid().ToString();
virtualTempFolder = virtualTempFolder + unique + "/";
physicalTempFolder = physicalTempFolder + unique + "/";
System.IO.Directory.CreateDirectory(physicalTempFolder);
}
B. Pass the directory names into your reporting services wrapper layer. I am using a DI so the signatures needed to be modified.
C. In the ReportingServices Rendering api you can pass the chosen virtual directory to pull temp files associated with streams via the DeviceInfo interface.
D. The streamIDs are returned in the Render method. Iterate and save them to the calculated physical location.
While I already had the temp folder functionality working, I had to add the ability to optionally create a temp location per request.

Best Way to keep Settings for a WinRT App?

I'm working on a WinRT app that's actually also a game. I need to keep different information such as audio settings or player statistics somewhere in sort of a file or somehow. If it's a file, just write settings in or... ? I have an idea but I think is way too rudimentary... What is the best approach to obtain this?
Any help or suggestions are greatly appreciated!
Here are some ways to save Data in a WinRT app, the method with Settings in the name is probably what you are looking for!- just added the other ones as well,- you also can serialize data if you want to. This is working code- but don't forget to add error handling etc. It's a simple demo code :)
As for settings, you can save simple settings as key and values, and for more complex settings you can use a container. I've provided both examples here =)
public class StorageExamples
{
public async Task<string> ReadTextFileAsync(string path)
{
var folder = ApplicationData.Current.LocalFolder;
var file = await folder.GetFileAsync(path);
return await FileIO.ReadTextAsync(file);
}
public async void WriteTotextFileAsync(string fileName, string contents)
{
var folder = ApplicationData.Current.LocalFolder;
var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(file, contents);
}
public void SaveSettings(string key, string contents)
{
ApplicationData.Current.LocalSettings.Values[key] = contents;
}
public string LoadSettings(string key)
{
var settings = ApplicationData.Current.LocalSettings;
return settings.Values[key].ToString();
}
public void SaveSettingsInContainer(string user, string key, string contents)
{
var localSetting = ApplicationData.Current.LocalSettings;
localSetting.CreateContainer(user, ApplicationDataCreateDisposition.Always);
if (localSetting.Containers.ContainsKey(user))
{
localSetting.Containers[user].Values[key] = contents;
}
}
}
The MSDN has an article on using app settings in Windows Store apps.
The Windows.UI.ApplicationSettings namespace contains all the classes you need.
Provides classes that allow developers to define the app settings that appear in the settings pane of the Windows shell. The settings pane provides a consistent place for users to access app settings.
Basically these classes let you store application settings and hook them into the standard place for all application settings. Your users don't have to learn anything new, the settings will be in the expected place.

Flex: Export Excel via Servlet

I want a user to press an excel button and get prompted to download an excel file. I normally do it like this:
var dest:String = excelEndpoint;
var request:URLRequest = new URLRequest();
request.url = dest;
fr.download( request,'Locates.xls' );
fr.addEventListener(HTTPStatusEvent.HTTP_STATUS, handleStatus);
fr.addEventListener(IOErrorEvent.IO_ERROR, handleErr);
However, now I need to pass an object to the servlet. Seeing that you can't do that with URLRequest I tried using HTTPService:
var service:HTTPService = new HTTPService();
service.url = excelEndpoint;
service.method = "POST";
service.showBusyCursor = true;
service.addEventListener("result", httpResult);
service.addEventListener("fault", httpFault);
service.send( myObject);
Now I can get my data (myObject) to the servlet successfully, but I don't get prompted for a download.
How can I do that? Is it even possible with HTTPService?
Thanks for any helpful tips.
I don't think there is anything you can do w/ a remote request from the Flash Player to prompt the user to download something. The way I have done this in the past is two fold:
Remote request pings server that generates the excel file and saves it to a temporary directory. The request returns a URL to the Flex app as the result of the call.
When Flex app gets the result--a URL--it creates a URL request and pops it open in a new window, prompting the user to download the generated excel sheet.
I don't see a way to do this in one shot; because the return value from the Flex HTTPService call goes to the Flash Player, not the browser.
SOLVED:
I wanted to accomplish this with 1 remote call and the way I found to do this while passing an object that contained collections is this:
var uv:URLVariables = new URLVariables();
uv.typesColl = myObj.types.toString();
uv.partiesColl = myObj.parties.toString();
uv.statuses = myObj.statuses.toString();
Basically, create a property on the URLVariables object for each collection and then set all collections toString();
Hope that helps someone.