WP7 to WP8.1 app update. Will WP8.1 ApplicationData access same data that was stored using WP7 IsolatedStorageFile? - windows-phone-7

I have a Windows Phone 7 app that has been in the store for many years now. It is installed on WP 7.x, 8.0, and 8.1 devices. I am converting the app to target WP8.1, so I can use the newer Microsoft AdControl (The old one will stop serving ads at the end of the year). This means I will need to start using ApplicationData.Current.LocalFolder to read/write data, instead of using the old IsolatedStorageFile.GetUserStoreForApplication().
My users have lots of data that has been stored using IsolatedStorageFile.GetUserStoreForApplication(). If they upgrade the app to the WP8.1 version, I want to be sure that they will not lose any of this data and that the data will still be accessible using ApplicationData.Current.LocalFolder.
Can anyone confirm that this is the case?
This is how I wrote data in WP7:
using (IsolatedStorageFile applicationStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream file = applicationStorage.OpenFile(filename, FileMode.Create, FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(file))
{
sw.WriteLine("some data goes here");
}
}
}
This is how I will be reading data in WP8.1:
using (Stream stream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(filename))
{
using (StreamReader sr = new StreamReader(stream))
{
String line = sr.ReadLine();
// Do something with line
}
}

Windows Phone 7 app, using Isolated Storage:
var store = IsolatedStorageFile.GetUserStoreForApplication();
Windows 8.1/UWP app:
var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
both will result in the same folder. Absolute path is different:
WP7 IS: "C:\Data\Users\DefApps\AppData\{YOUR_APP_ID}\local"
WP 8.1 / UWP: "C:\Data\Users\DefApps\AppData\Local\Packages\YOURCOMPANY.YOURAPP_SOMEHASH\LocalState"
but both paths will share the same folder / files inside. The most important thing is to edit Package.appxmanifest XML. In Visual Studio click by right mouse button on"View Code" (do not open by "View Designer"). In this XML you have to edit this row:
<mp:PhoneIdentity PhoneProductId="NEW_APP_ID" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
Replace PhoneProductId by Id of your old WP7 App and PhonePublisherId by your old PublisherId (from old WP7 App too). If you do not do this, that codes will give you different folders (WP 8.1 / UWP code gives you empty folder). However, with this changed Ids you will receive the same folder with all old data.
New app will replace your old app after installation.

Related

.NET MAUI app + MediaPicker is crashing with Android.Content.Res.Resources+NotFoundException

In my .NET MAUI app, I use the built-in MediaPicker to access user's photos. The app works fine until I tap the icon to access the photos. It then crashes with the following error message:
Android.Content.Res.Resources+NotFoundException Message=Drawable
com.mycompany.myapp:mipmap/appicon with resource ID #0x7f0d0000
I did replace the app icon recently and I also noticed that the app is not using it when I run the app on an actual device. I simply put a new svg file in the Resources/AppIcon folder with the same name as the original i.e. appicon.svg.
In the properties for this file, I set it as MAUIICON.
This is what's in the project file:
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" />
In case, it's helpful, this is how I'm using the MediaPicker:
try
{
var result = await MediaPicker.PickPhotoAsync(new MediaPickerOptions
{
Title = "Pick Image"
});
if (result == null)
return;
}
catch(Exception e)
{
// Log error
}
I never hit the catch block. It just crashes with the error message I mentioned above.
Any idea how to address this issue?
The issue is definitely the AppIcon. Looks like .NET MAUI is not generating correct size icons from the svg that I had under Resources\AppIcon.
The workaround is to manually create the necessary icons -- in my case, I only created one 72x72 -- and placed them in Platforms\Android\Resources\mipmap folder. In my case, the Resources folder was there under Platforms\Android so I just had to create the mipmap folder.
I then had to go into AndroidManifest.xml file and correctly link them:
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:roundIcon="#mipmap/ic_launcher_round" android:supportsRtl="true"></application>
So, in my case the file name for the app icon I manually generated is ic_launcher.png. I did have to have a second image named ic_launcher_round.png.
Looks like .NET MAUI is supposed to do this work but it's not doing it.
The second bonus -- which it shouldn't be -- is that when I now install the app on a device, I see the correct app icon for my app.
Here's a link to the issue I reported. Anyone experiencing this issue should up vote it so that it'll get the team's attention.
https://developercommunity.visualstudio.com/t/Changing-app-icon-of-NET-MAUI-app-then/10090581

How can I move a png from tmp PCLStorage to local non-temporary PCLStorage in Xamarin.Forms?

I'm using an older version of Xamarin.Forms (3.6) and I'm trying to save a WebView as a PNG so I can view it offline. I found a way to save the image using Forms9Patch (1.3.3).
public void saveWebLicense()
{
var htmlLicenseSource = LicenseSource;
var fileName = $"{CurrentLicense.customerId}WebViewPNG";
Forms9Patch.HtmlStringExtensions.ToPng(htmlLicenseSource.Html, fileName, async (string path) =>
{
if (path != null)
{
System.Diagnostics.Debug.WriteLine("A PNG of your HTML is here: " + path);
}
});
}
Which does fine in saving the png to a filename that looks like this.
/Users/firstname.lastname/Library/Developer/CoreSimulator/Devices/8C7D30F5-F30E-48F6-9584-357193BD5CBB/data/Containers/Data/Application/BE627F14-1EC2-46C8-B015-8F57929111C3/tmp/12345WebViewPNG.png
I can navigate to this folder and see the PNG just fine. The issue is it's stored in a tmp folder and as soon as I exit the app it's gone, so I'm unable to load it. I can't change the save location that Forms9Patch gives me, so my thought was to try and move the image to a different local non-temporary folder or copy it. I need something that works for iOS and Android, and I won't be able to upgrade Xamarin.Forms or Forms9Patch at this time, so I can't use any of their new features. I've tried using File.Move but that function isn't even recognized even when adding System and SystemIO.
I'm also open to other suggestions if they work with older versions of Xamarin Forms.

Creating excel in windows mobile 5.5devices using vb.net

Currently I am working in windows mobile 5.5 devices. I want to create and write excel files. I tried in web they told to add some dll(object library). But no luck. I can't get in vs2008. If any one know how to create excel in windows mobile 5.5 devices using vb.net. Please give any references.
See Create Spreadsheet in .NET Compact Framework 3.5
"Ok, after trying a lot of free librery i found a solution.
Excellibrary works! link to google code
I have tried it with Visual Studio 2008 in combination with a Windows
CE 5 device and it created an xls file easily. I must test it to check
the performance but at least it works and it's free. Also the sintax
is very simple
Dim file As String = "\HardDisk\newdoc.xls" Dim workbook As New
Workbook() Dim worksheet As New SpreadSheet.Worksheet("First Sheet")
worksheet.Cells(3, 3) = New Cell(3.45)
workbook.Worksheets.Add(worksheet) workbook.Save(file)"

How can I create a new Windows Phone 7 assembly from scratch using CCI or Mono.Cecil

I am working on a tool to generate assemblies for WP7. I am doing this from the full framework. Since Reflection.Emit doesn't work with WP7 but either CCI or Mono.Cecil do I am wondering if there is a way to create new assemblies from scratch. I already know that I can modify existing assemblies, but being able to create one would be pretty useful.
I guess a workaround would be to generate an empty assembly in visual studio and keep it as a template, but I think that there should be a better way.
It's pretty easy to do with Mono.Cecil:
using Mono.Cecil;
using Mono.Cecil.Cil;
class Demo
{
static void Main()
{
var winphoneAssemblies = #"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone";
var assemblyResolver = new DefaultAssemblyResolver();
assemblyResolver.AddSearchDirectory(winphoneAssemblies);
var winphoneCorlib = assemblyResolver.Resolve("mscorlib");
var module = ModuleDefinition.CreateModule("Test", new ModuleParameters
{
AssemblyResolver = assemblyResolver,
Runtime = TargetRuntime.Net_2_0,
Kind = ModuleKind.Dll,
});
// trick to force the module to pick the winphone corlib
module.Import(winphoneCorlib.MainModule.GetType("System.Object"));
var type = new TypeDefinition("Test", "Type", TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract, module.TypeSystem.Object);
module.Types.Add(type);
var method = new MethodDefinition("Identity", MethodAttributes.Public | MethodAttributes.Static, module.TypeSystem.Int32);
method.Parameters.Add(new ParameterDefinition("i", ParameterAttributes.None, module.TypeSystem.Int32));
type.Methods.Add(method);
var il = method.Body.GetILProcessor();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ret);
module.Write("Test.dll");
}
}
A few things to note:
The need to create the module with an assembly resolver targeting the winphone assemblies.
A little trick to make sure the module picks up the proper winphone mscorlib (will be fixed in the next version of Cecil).
Silverlight assemblies have the metadata version of the .net 2.0 framework.
It's worth pointing out that while you may be able to generate dynamic assemblies from within the phone's runtime using alternate framework's, you're not goint to be able to load / execute them. Those APIs will throw an exception if executed by application code.

VS add-in: Add context button on web applications

I'm messing around with Visual Studio (2008) add-ins. I want to be able to add a button to all web application context menus (that will setup IIS for the website based on a shared archive from the web deployment tool).
I've got as far as being able to add the context item on the project context menu:
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
applicationObject = (DTE2)application;
addInInstance = (AddIn)addInInst;
if (connectMode == ext_ConnectMode.ext_cm_UISetup) {
var contextGuids = new Object[] {};
var iisSetupCommand = applicationObject.Commands.AddNamedCommand(
addInInstance,
CommandNameSetupIis,
"Setup IIS",
"Create the bindings in IIS for the website. Requires an IIS folder in the project root with the archive xml files for the website.",
true,
52,
ref contextGuids,
(int) vsCommandStatus.vsCommandStatusSupported + (int) vsCommandStatus.vsCommandStatusEnabled
);
var commandBars = (CommandBars) applicationObject.CommandBars;
var projectMenu = commandBars["Project"];
iisSetupCommand.AddControl(projectMenu, projectMenu.Controls.Count + 1);
}
}
This works, but I'm having trouble getting further.
Problem 1 is the button disappears when clicked.
Problem 2 is I have no idea how to only show the button for web application projects.
Problem 3 is I then need to write the code to grab the iis archive, the current project directory path and the project name to create the IIS bindings and then run the web deployment tool with these settings.
This add-in stuff is very obtuse. I've googled as much as I can and read most of the (terrible) msdn documentation. The best info I found was: http://dotnetslackers.com/articles/vs_addin/Lessons_learned_from_Copy_to_Html_Add_in.aspx
Can anyone help?
Problem 1: Override the QueryStatus and set the status to vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled
Problem 2: I don't think this is possible. It is possible to get the project type, but only once the button has been clicked (QueryStatus only seems to fire once the button has been clicked once).
Problem 3: Project path was available via connect.ApplicationObject.ActiveSolutionProjects.

Resources