Is it possible to initialize a castle container (windsor) by passing a stream to
the XmlInterpreter somehow? It appears that the current implementation only supports
files.
thanx,
-tzurs
Inherit from AbstractStreamResource, then you can do:
var c = new WindsorContainer(new XmlInterpreter(new MyStreamResource(...)));
See FileResource for guidance.
Related
How can I patch actionscript without constantly rebuilding sfw?
There is a fairly large actionscript project that I need to modify and resulting swf is used on a live site. The problem I have is that I need to make quick small updates to the swf and it's not acceptable to update the swf on live site ten time a day (I don't control that part, I need to ask another person to put the result on live site).
What options do I have to workaround that issue? I'm a complete noob when it comes to actionscript and all flash related stuff and I'm not even sure what is possible and what isn't. I'm thinking about the following approaches, which ones are possible/acceptable?
Imagine that live site is on www.livesite.com/game.html and this page loads www.livesite.com/flashgame.swf. In that flashgame.swf among many others there is a class com/livesite/Magic.as that gets instantiated and instance of that class has a member variable xxx123 of class com/livesite/MagicWork.as. I only need to modify this MagicWork class. Now, I simply modify it, build and ask to put updated flashgame.swf live. So, I want to avoid that manual step.
All my ideas can be split in two basic approaches: 1) keep flashgame.swf totally unmodified and then load flashgame.mod.swf that contains alternative implementation of that MagicWork class, then using javascript access internals of instance of that Magic class and update its xxx123 member to be an instance of MagicWork class from flashgame.mode.swf. I'd need to modify game.html to load my javascript so that my js file would load flashgame.mod.swf and patch code inside flashgame.swf. By patching I mean javascript-style overwriting of Magic.xxx123 to a new value. flashgame.mode.swf would ideally reside on my own host that I control. Is that kind of stuff possible, if not what's not possible?
2) I could make one-time change in flashgame.swf so that it would effectively load itself my own code at runtime and patch it's xxx123 member. Is that possible?
I had already written a note about loading runtime shared libraries previously. I'll put the most essential parts of the process here, and add a link to the full article at the end.
You need to tag your main application entry point in the following manner.
[Frame(factoryClass="Preloader")]
public class Main extends Sprite
{
}
Then create a class called Preloader.
public class Preloader
{
public function Preloader()
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.loader_completeHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.loader_ioErrorHandler);
var request:URLRequest = new URLRequest("math.swf");
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loader.load(request, context);
}
private function loader_completeHandler(event:Event):void
{
var mainClass:Class = getDefinitionByName("Main") as Class;
var mainInstance:Main = new mainClass();
this.addChild(mainInstance);
}
}
The full implementation of the Main class is like this.
[Frame(factoryClass="Preloader")]
public function Main()
{
var integer:IntegerArithmetic = new IntegerArithmetic(); // Type declared in math.swf
var operand1:int = 10;
var operand2:int = 10;
var result:int = integer.add(operand1, operand2);
}
Deploying Runtime Shared Libraries
The confusing bit about using a runtime shared library is realizing that the SWF has to be extracted from the SWC at the time of deploying the application. This was not immediately obvious and I ended up spending days placing a compiled SWC file in various locations and wondering why the application was unable to load it at runtime. An obscure article on the Adobe website made explicit this particular step and set things straight.
The full article along with the same example is available at http://www.notadesigner.com/runtime-shared-libraries-with-plain-actionscript/.
Frameworks like Spring, Struts facilitates for property file reading. For instance MessageResources in Struts. I want to know whether there are such property files which are in built supported by Restlet framework itself. If there is one, then I will not need to re invent the wheel and be able to use it straight.My application configuration values will be included in that file. I am new to Restlet, I couldn't find any soulution. Any way to do this?
There is no support like this in Restlet. That said you can leverage client protocols to load these properties files from difference locations:
Protocol.FILE - from filesystem directly
Protocol.CLAP - from classpath
Protocol.OBAP - from OSGi bundle
Here is a sample:
ClientResource cr = new ClientResource("clap://someproperties.properties");
Properties props = new Properties();
props.load(cr.get().getStream());
You need to specify this protocol when defining your component:
Component component = new Component();
(...)
component.getServers().add(Protocol.HTTP, 8182);
component.getClients().add(Protocol.CLAP);
I am registering a bunch of ITask implementations with Windsor using Named to separate them. Is there a way a class can request all instances of ITask?
Windsor can do what you request via the CollectionResolver subdependency resolver:
var container = new WindsorContainer();
var kernel = container.Kernel;
kernel.Resolver.AddSubResolver(new CollectionResolver(kernel));
Now, if you register multiple implementations of ITask, your task runner can have a ctor like this:
public TaskRunner(IEnumerable<ITask> tasks)
{
// ...
}
which is what you want, right?
Yes,
container.ResolveAll<ITask>()
This blog post explains in detail how to do it in a container ignorant way:
10 Advanced Windsor Tricks – 3. How to resolve arrays
Similar to the other answer given.
I would like to register some components in my Windsor container before my Facilities load - (so that I can use some the components in the facilities)
I was thinking there should be some way to initialize windsor without a configuration file, register some components, and only then load the configuration? - this would result in that my configured facilities would load only after I registered my components.
For example:
var container = new WindsorContainer();
//Register a custom component, which will be used in some of the facilities
container.Register(Component.For<IMyService>().ImplementedBy<MyService>());
//Now load via the configuration - unfortunately the method "Configure" doesn't exist
container.Configure(new XmlInterpreter(new ConfigResource("castle")));
Appreciate any help on this,
Thanks!
container.Install(Configuration.FromAppConfig());
See the documentation.
I'm using Castle Windsor with a configuration from my App.config file.
In the code I use :
IWindsorContainer container = new WindsorContainer(new XmlInterpreter());
to get the container.
But for some configurations of my application I don't want to use CastleWindsor (for some migration issues...) and therefore, I don't want to add any Castle section in my App.config.
And the problem is that if there is no castle config, then
IWindsorContainer container = new WindsorContainer(new XmlInterpreter());
throws an exception "Could not find section 'castle' in the configuration file associated with this domain."
So basically in my code I want to do something like:
if (IsCastleWindsorInitialized()) {/* do something */ } else { /* do something else */ }
where 'IsCastleWindsorInitialized()' returns true when the App.config contains a castle section.
In order to implement that function I can certainly use the ConfigurationManager but I'm wondering if I can use Castle Windsor API to do that.
I would probe the app.config with a ConfigurationManager.GetSection("castle") (that is, if you use XML-only configuration)