WordPress database error: [INSERT, UPDATE command denied to user '51213-2'@'10.10.20.81' for table 'wp_options']
INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('_transient_doing_cron', '1715181024.8790750503540039062500', 'yes') ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)


Warning: Cannot modify header information - headers already sent by (output started at /home/lexiqued/www/WordPress/wp-includes/wp-db.php:1502) in /home/lexiqued/www/WordPress/wp-includes/feed-rss2.php on line 8
Windows – Jonathan ANTOINE's thoughts http://www.jonathanantoine.com Yet another blog about... Wed, 12 Oct 2016 17:05:56 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.3 .NET : execute some non-thread-safe code without issue in parallel with AppDomains http://www.jonathanantoine.com/2016/10/12/net-execute-some-non-thread-safe-code-without-issue-in-parallel-with-appdomains/ Wed, 12 Oct 2016 17:00:58 +0000 http://www.jonathanantoine.com/?p=1588 Today I faced a specific need withing a WPF application: I have a well-tested and already in production code which works well for a given user and I need to create an application to execute the same “one-thread/context” code for a lot of users at the same time. The code uses a lot of static fields, properties and can’t be run as it is in different threads.

The solution I ended up with is to create an AppDomain by “worker” and to execute the already existing code in each one. The context will be unique in each AppDomain and I will be able to reuse my existing code.

To have this working I have to perform these steps:

  • Create a new class project “MaDllAPart” on which I add a reference to my existing code assembly.
  • Create a new class “StartPoint” in it which inherits from MarshalByRefObject. This will let it be called from another AppDomain (my new WPF application in this case).
  • Add an “Execute” Method to my StartPoint class which calls my legacy code.
  • Create an AppDomain by thread, instanciate a StartPoint in this AppDomain.
  • Instanciate a StartPoint in this AppDomain and call it’s Execute method.

structure

The code for the StartPoint class is very easy :

public class MonPointDentree : MarshalByRefObject
{
    public static string Context;

    public void Execute(string input)
    {
        // Task can't be marshalled : let's wait
        ExecuteAsync(input).Wait();
    }

    private async Task ExecuteAsync(string input)
    {
        Debug.WriteLine("[BEFORE] " + Context);
        Context = input;
        Debug.WriteLine("[AFTER] " + Context);

        // call my legacy code here
    }
}

The “MaDllAPart” is added as a reference to the WPF project : this let’s me create an instance of StartPoint without special configuration from my side. Be sure to use the full name (with the namespace) of the instanciated type.

private static void LaunchProcess()
{
    for (int i = 0; i < 10; i++)
    {
        var domain = AppDomain.CreateDomain("MonAppDomain_" + i);

        var startPoint = (MonPointDentree)domain
            .CreateInstanceAndUnwrap("MaDllAPart", "MaDllAPart.StartPoint");

        startPoint.Execute("module " + i);
    }
}

Happy coding !

]]>
#HoloLens : launch a 3D (Holograms) app from a 2D #XAML app and going back to it #UWP http://www.jonathanantoine.com/2016/06/29/hololens-launch-a-3d-holograms-app-from-a-2d-xaml-app-and-going-back-to-it-uwp/ http://www.jonathanantoine.com/2016/06/29/hololens-launch-a-3d-holograms-app-from-a-2d-xaml-app-and-going-back-to-it-uwp/#comments Wed, 29 Jun 2016 06:47:02 +0000 http://www.jonathanantoine.com/?p=1573 In this blog post I will show you how to create a 2D #XAML app which will be able to display a 3D view (holograms) and then how to go back to the 2D view from the 3D view.

We wil do this using DirectX and Unity.

As you can see in this video, the “context” of the leaved Windows is kept : the scroll position does not change.

Opening another Windows from a n UWP app

Since a long time now, you can open a new Windows from a Windows Store app (UWP or Universal). For instance, the Mail app does this to let you edit an email in another dedicated window.

To perform this, you have to ask the SDK to create a new View (CoreApplicationView) which maps to a Window (CoreWindow) and an associated Dispatcher. This last point is interesting because you have to be very careful, when you share your ViewModels between windows, to be on the good Dispatcher when raising INotifyPropertyChanged event or doing some UI-related work.

Here is the code to create a Window :

// récupération de l'id courant pour usage ultérieur
var appViewId = ApplicationView.GetForCurrentView().Id;

//Create a new view \o/
CoreApplicationView newCoreAppView = CoreApplication.CreateNewView();

await newCoreAppView.Dispatcher.RunAsync(
    Windows.UI.Core.CoreDispatcherPriority.Low,
     () =>
     {
         //Get the created Windows
         Window window = Window.Current;
         ApplicationView newAppView = ApplicationView.GetForCurrentView();

         // create a new frame and navigate to the page
         var secondFrame = new Frame();
         window.Content = secondFrame;
         secondFrame.Navigate(typeof(MainPage));

         // activate the new Window
         window.Activate();

         // make the new window standalone
         ApplicationViewSwitcher.TryShowAsStandaloneAsync(newAppView.Id,
             ViewSizePreference.UseMore, appViewId, ViewSizePreference.Default);
     });

By providing no argument to the CreateNewView method, we ask the XAML framework to create and manage a XAML UI.

We could also provide an argument of type IFrameworkViewSource to be able to have our own Window managed by our code. This is what DirectX does and it will let us create holograms !

Displaying a 3D DirectX view from the 2D view

By using the “HolographicDirectXApp” Visual Studio sample, I have all I need to create and display a 3D rotating cube by. The generated code creates an instance of IFrameworkView using DirectX. The sample use SharpDX, some C# classes and shaders that I can simply copy/Paste directly in a new XAML UWP project.

Capture

I then only have to use the previous snippet and ask it to use the DirectX AppView.

I have to carefully :

  • keep an instance of my AppViewSource : if it’s garbage collected, my 3D view will disappear.
  • Activate the created Window for the DirectX view.

Of course, as all 3D holographic view, my start screen and the 2D View will disappear to let only the 3D objects in my space.

Capture2

Displaying a 3D Unity view from the 2D view

An Unity app being an UWP app the code to write will be very similar. We will only have to customize the generated Unity code to stay in a 2D World instead of going directly to the 3D exclusive View.

To be in the right configuration, I generate a XAML project instead of a Direct3D player in Unity. I then have this :

  • Unity initialization is done in the App class.
  • A MainPage XAML app which finish the initialisation and is the first page navigated to.

To have a “standard” Xaml project, I then perform these modifications :

  • I create a XAML “BlankPage” named StartupPage.
  • I navigate to this page instead of MainPAge. I then stay in a 2D classic XAML context and I can build my application around it.
  • I move the use of the AppCallbacks class from the App.cs class to the existing MainPage.

 

The next steps are easy : I create a new Window, add a frame in it and navigate to the MainPage. I use exactly the same snippet as before and I only have to register an event handler to the activation of the created Window to be able to initialize Unity then. I also store the main view’s Id for further use.

private async Task CreateNewHoloWindowAsync()
{
    var appViewId = MainAppViewId = ApplicationView.GetForCurrentView().Id;
 
    var _newCoreAppView = CoreApplication.CreateNewView();
 
    await _newCoreAppView.Dispatcher
        .RunAsync(CoreDispatcherPriority.Low,
      async () =>
      {
          var frame = new Frame();
          Window.Current.Content = frame;
          frame.Navigate(typeof(MainPage));
 
          var res = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
              ApplicationView.GetForCurrentView().Id,
              ViewSizePreference.Default, appViewId,
              ViewSizePreference.Default);
 
          _newCoreAppView.CoreWindow.Activated += WindowActivated;
 
          _newCoreAppView.CoreWindow.Activate();
      });
}
 
private void WindowActivated(object sender, WindowActivatedEventArgs e)
{
    if (e.WindowActivationState == CoreWindowActivationState.CodeActivated
        || e.WindowActivationState == CoreWindowActivationState.PointerActivated)
    {
        AppCallbacks.Instance.SetInitialViewActive();
        // Only need to mark initial activation once so unregister ourself
        CoreWindow coreWindowSender = sender as CoreWindow;
        coreWindowSender.Activated -= WindowActivated;
    }
}

Going back to the 2D View

To go back to the 2D XAML view, you have to use the ApplicationViewSwitcher class and ask it to go switch back to the main Window.

I provide my Unity’s code an Action (GoBackToEarth.CloseThisHolographicView) it can call when needed.

// let's capture the dispatcher of the current view
var dispatcher = Dispatcher;
 
GoBackToEarth.CloseThisHolographicView = () =>
{
    // be sure to be on the Window's Dispatcher
    dispatcher.RunIdleAsync(async _ =>
    {
        // go back to the main Window
        await ApplicationViewSwitcher.SwitchAsync(StartupPage.MainAppViewId);
 
        // we close the 3D holographic Window
        Window.Current.Close();
    });
};

Happy coding !

]]>
http://www.jonathanantoine.com/2016/06/29/hololens-launch-a-3d-holograms-app-from-a-2d-xaml-app-and-going-back-to-it-uwp/feed/ 13
#Windows app bundles and the ‘Subsequent submissions must continue to contain a Windows Phone 8.1 appxbundle’ error message http://www.jonathanantoine.com/2016/04/12/windows-app-bundles-and-the-subsequent-submissions-must-continue-to-contain-a-windows-phone-8-1-appxbundle-error-message/ Tue, 12 Apr 2016 08:28:39 +0000 http://www.jonathanantoine.com/?p=1555 Some days ago when uploading my Windows app to the Store, I’ve got a strange error message : “A previous submission for this app was released with a Windows Phone 8.1 appxbundle. Subsequent submissions must continue to contain a Windows Phone 8.1 appxbundle.”. Here’s how I fixed it !

About appxbundle

When you build an app, you can choose to translate it and add ressource dedicated to a special environments. Images/Logo specific to each pixel density plateau is one example of it. If you create bundles, your final package uploaded on the Store will be one “main” package and satellite package for each “specific target”.

It also means that the user will download only what is necessary to their devices : less bandwith used, smaller apps : happy users !

Creating app’s bundle is easy, in the last step of the Visual Studio package wizard, you choose either “If Necessary” or “Always”.
appbundle

Choosing to use app bundles has some consequences. The one which I was not happy with was that you won’t be able to let the user choose the language of your app since only the languages installed on it’s device will be available.

In my last update of TV Show Tracker, I wanted to let this freedom to my users so I used the wizard and choose to never create a bundle. I uploaded my package to the Store and I then get the previously mentionned error 🙁
error

Creating my own appbundle

The solution is then to create my own app bundle with the SDK tools and upload it to the Store.

Here are the steps :

  1. Create a package using Visual Studio without app’s bundle.
  2. Go to the created package folder and find the appx file (it can be in a subfolder).
  3. Copy this file in a separate folder, all alone.
  4. Use the MakeAppx tool to create a bundle aiming this directory.
  5. Upload the created bundle to the Store.
makeappx bundle /p NameOfTheCreatedBundle.appxbundle /d FolderWithTheAppxInside

The name of the bundle can be anything as the name of the folder with the appx inside.

What did I lost in the process ?

The whole app with all ressources will now be downloaded by my users. This can be frightening : how much more will they have to download ? Let’s take a look inside the app bundle…

zip

So an user on a standard density pixels, english phone will now download the not used “scale-140” assets, the “scale-180” assets and french language : 300 more kb –> 2,85 %. So for 2,85% more package size, my user will be able to choose the language of their app. That’s ok for me 🙂

Happy coding !

]]>
WinRT exceptions : how to know what the hexadecimal error code means http://www.jonathanantoine.com/2015/07/25/winrt-exceptions-how-to-know-what-the-hexadecimal-error-code-means/ http://www.jonathanantoine.com/2015/07/25/winrt-exceptions-how-to-know-what-the-hexadecimal-error-code-means/#comments Sat, 25 Jul 2015 10:11:08 +0000 http://www.jonathanantoine.com/?p=1542 When working with the WinRT SDK you somethimes get exceptions from it with only an hexadecimal code to help you understand what the error is. Often, when you look for it on Google/Bing, you end with no help and no way to fix the error. There is a way to know the associated error message !

I am talking about this kind of error messages : “Exception thrown at 0x77694598 (KernelBase.dll) in MonAppli.Windows.exe: 0x40080201: WinRT originate error (parameters: 0x80072F19, 0x00000067, 0x0519EE60).” I looked for every hexadecomal code without success.
Excception

To get the message associated with this error, follow this procedure :

  • Activat the native debugger : in the properties of your project, is at the end of the debug tab.
  • Launch your app with the debugger attached and produced the exception.
  • Copy the third hexadecimal code in the exception Windows (0x0519EE60 here).
  • Click on Break.
  • Open the “Memory 1” Windows. It’s only available in Debug mode in this menu : “Debug > Windows > Memory > Memory 1”
  • Paste the value in the adress text box and press the enter key
  • The description is available at the right 🙂

exception2

]]>
http://www.jonathanantoine.com/2015/07/25/winrt-exceptions-how-to-know-what-the-hexadecimal-error-code-means/feed/ 1