Why will some modules load and some modules not load in FLEX 3? - flex3

I have an app with several modules. There is only one module loaded at anyone time. 2 out of the 3 modules load without problems but the third a new module will not fire the ModuleEvent.Ready. I have an event handler function that handles the ModuleEvent.PROGRESS and it just traces out the bytes loaded vs bytes total. It seems to load the module completely yet never fires the ready event. Here is how I am loading the modules:
public var moduleInfo:IModuleInfo;
public function loadModule(url:String):void{
if(moduleInfo != null)
moduleInfo.release();
moduleInfo = ModuleManager.getModule(url+"?"+"x="+Math.random().toString());
moduleInfo.addEventListener(ModuleEvent.READY,moduleLoadHandler,false,0,true);
moduleInfo.addEventListener(ModuleEvent.PROGRESS,onModuleProgress,false,0,true);
moduleInfo.load(ApplicationDomain.currentDomain);
}

Ok, turns out it has been a long time since I created a new module. I forgot one critical thing. Since my modules are in separate projects, I need to change the root tag of the main mxml file from Application to Module. :)
Live and learn and never be ashamed to admit when you are wrong.

Related

Prestashop - additional code when deleting a customer

I would like to add the code associated with one of the modules that should be executed when the client is removed by the administrator in the back office. Where should I put this code? I cant find the right file.
Update
I added this code to the module for testing, but it doesn't seem to do anything.
public function hookActionObjectCustomerDeleteAfter($params)
{
$customer_id = (int)$params['object']->id;
PrestaShopLogger::addLog(
sprintf('Customer with id %d was deleted with success', $customer_id)
);
}
I guess the right hook would be hookActionObjectCustomerDeleteAfter in some custom module. Don't forget to register your module to the hook before launching the code. You can do this during a module install process in install method with code $this->registerHook('actionObjectCustomerDeleteAfter')
Use hook hookActionObjectProductDeleteAfter.

How do you Cache-bust individually rendered files while debugging?

Currently it is impossible for devs to easily work together. While debugging our code minification and bundling are turned off and so is the cache buster. This leads to every dev that touches javascript having to open every javascript file and force-refresh to make sure they aren't missing changes.
I found a couple references that I thought might work but none of the implementations have worked out yet.
The first is to apply a transform to the individual Bundles via an IBundleTransform.
Public Class DebugCacheBuster
Implements IBundleTransform
Public Sub Process(context As BundleContext, response As BundleResponse) Implements IBundleTransform.Process
If BundleTable.EnableOptimizations Then
Exit Sub
End If
For Each file As BundleFile In response.Files
file.IncludedVirtualPath &= GetPathHash(HostingEnvironment.MapPath(file.IncludedVirtualPath))
Next
End Sub
End Class
This looked promising but I have not been able to get it to work. I tried adding a new instance of this class to the constructor of each bundle and I also tried looping over all of the bundles after they were created. My break-points are hit and IncludedVirtualPath appears to have been updated. After continuing on with rendering the paths are not updated.
I also tried to create a custom VirtualPathProvider and a custom VirtualFile and overrode VirtualPath to return the correct value but again, when it rendered, the path was bare.
Did I do something wrong with the transform? Is there some other way to implement this?
Apparently this code will not work with version 1.1.0 of System.Web.Optimizations. After upgrading to version 1.1.3 (and adding an assembly binding redirect to solve a compatibility issue with Web Grease) the snippet in the question works flawlessly.

How to get a module instance in PRISM

I have a PRISM desktop app which loads modules from a directory with the help of the DirectoryModuleCatalog.
Everything is fine, except that I cannot find a way to get the instance of a loaded module.
IModuleManager and IModuleCatalog don't have a method like getInstance(ModuleInfo) or similar.
See
moduleManager.LoadModule(moduleInfo.ModuleName);
This line loads the module properly(moduleManager is of type IModuleManager), but what do I have to do next to get the actual instance of this module?
The modules are loaded on demand of the user, so I cannot register all modules at startup within the bootstrapper.
If by Module instance you mean the class that implement IModule, then you must explicitly register the instance into the container to be able to get it.
Although the aforementioned will work, you should not take that approach at all. The idea is that the module classes are specific to a particular module and should only be used for module initialization purposes.
I would place each module's Start method in a separate component (IStartable), register each component in the container with a different Id and resolve/import an IEnumerable to get all instances that have the start method.
Hope this helps

Methods best practice - VB.NET

I have a program that is getting pretty big and it is a pain to find everything through all the functions and classes.
I am trying to break it up into other files based on their method.
Some of these functions have calls to others in the main class. I changed most my functions from private to public to access this. I had problems calling certain code created windows so importing mainwindow helped that.
My last problem is editing the mainwindow ui from one of the module files. I want to make sure im on the right page before i continue breaking it up. My only guess is that anything they updates the ui should be left on the main class.
Thanks
The only code in your form class should be code that talks to other classes and updates the UI based on data from other classes.
Depending on your application, the form class might handle change events from other classes to update the UI or pass user input to other classes in Change or Click events.
A couple options:
Use callbacks into the your main window.
Create events for when you need the form updated. Your program logic raises the events, and your main window class can consume them.

MEF + SL4 question

I'm working on an app in the Silverlight 4 RC and i'm taking the oppertunity to learn MEF for handling plugin controls. I've got it working in a pretty basic manor, but it's not exactly tidy and I know there is a better way of importing multiple xap's.
Essentially, in the App.xaml of my host app, I've got the following telling MEF to load my xap's:
AggregateCatalog catalog = new AggregateCatalog();
DeploymentCatalog c1 = new DeploymentCatalog(new Uri("TestPlugInA.xap", UriKind.Relative));
DeploymentCatalog c2 = new DeploymentCatalog(new Uri("TestPlugInB.xap", UriKind.Relative));
catalog.Catalogs.Add(c1);
catalog.Catalogs.Add(c2);
CompositionHost.Initialize(catalog);
c1.DownloadAsync();
c2.DownloadAsync();
I'm sure I'm not using the AggregateCatalog fully here and I need to be able to load any xap's that might be in the directory, not just hardcoding Uri's obviously....
Also, in the MainPage.xaml.cs in the host I have the following collection which MEF puts the plugin's into:
[ImportMany(AllowRecomposition = true)]
public ObservableCollection<IPlugInApp> PlugIns { get; set; }
Again, this works, but I'm pretty sure I'm using ImportMany incorrectly....
Finally, the MainPage.xaml.cs file implements IPartImportsSatisfiedNotification and I have the following for handling the plugin's once loaded:
public void OnImportsSatisfied()
{
sp.Children.Clear();
foreach (IPlugInApp plugIn in PlugIns)
{
if (plugIn != null)
sp.Children.Add(plugIn.GetUserControl());
}
}
This works, but it seems filthy that it runs n times (n being the number of xap's to load). I'm having to call sp.Children.Clear() as if I don't, when loading the 2 plugin's, my stack panel is populated as follows:
TestPlugIn A
TestPlugIn A
TestPlugIn B
I'm clearly missing something here. Can anyone point out what I should be doing?
Thanks!
I think most of what you are doing is fine. Although ObservableCollections do support notifications of individual elements being added and removed, MEF doesn't take advantage of this. In your case it will simply clear the collection and then add all the plugins. Since you are using OnImportsSatisfied for the change notification, you don't even need an ObservableCollection. You could just use an IEnumerable for your import.
To add flexibility in downloading different xaps, I would expose a service in your container that can be imported and that provides the functionality to download a xap given a url. Then any component in your container can trigger a download, and the url to download can come from whatever source you deem appropriate.