Dynamically create class that mocks another class (like remotingProxy) in haxe - haxe

I want to be able to dynamically create a new class that has all of the methods of another class. In particular, I want to make my own kind of remoting proxy.
class ApiProxy extends haxe.remoting.Proxy { }
The new class ApiProxy would have all of the same method names and signatures as Api, and would be compile time checked. Only every invocation is done over the wire, instead of handled locally.
I think that remoting.Proxy is a magic internal class - is this true? Do regular users have the ability to define a class that is as powerfully static as this? I've never seen this done in Java and I'm impressed with it's capabilities in Haxe.
How would I implement my own class like remoting.Proxy?

you can achieve this with macros
take a look at this post to get the idea:
http://haxe.1354130.n2.nabble.com/Macros-Are-Awesome-tc5945711.html
You can write, save to filesystem and register a new Class inside of a Macro, based on type information that was passed to the function.

haxe.remoting.Proxy is indeed "magic", it is described that way in the source comments:
http://code.google.com/p/haxe/source/browse/trunk/std/haxe/remoting/Proxy.hx?r=3592
You can't replicate with "normal" haxe code. Adding/modifying functionality to haxe.remoting.Proxy for your own class will be difficult, but maybe not impossible.
Check the tutorial for the "equivalent" api implementing code:
http://haxe.org/doc/remoting/proxy
However, something like this is probably possible with macros:
http://haxe.org/manual/macros
Working with macros is challenging right now. There is little in the way of documentation or examples, and the macro feature is still under development. However, it lets you have a some control over the compiler during the compilation process, which can be amazingly useful at times.
good luck!

Related

How to change the Apache POI SXSSFWorkbook default temporary file name

I am using POI's SXSSFWorkbench class to create extremely large workbooks. Multiple processes may be running of my application concurrently, so I thought it prudent to append the processId to the default temporary filename. I don't know how to do that, and could not find any recent coding examples.
Can anyone point me to an example, or outline to me what has to be done? I see there is a static TempFile.createTempFile method. Should I be executing that using a class override before instantiating the SXSSFWorkbook class? Or after?
I also saw there was a DefaultTempFileCreationStrategy class. Could not find examples of how to use this either.
The main class that Apache POI uses for this is TempFile
The method you'll want to call is TempFile.setTempFileCreationStrategy
What you'll need to do is create your own class implementing the interface TempFileCreationStrategy. This is nice and simple, with just two methods, createTempDirectory and createTempFile.
To get an idea of what's involved, you can look at the source code for DefaultTempFileCreationStrategy online here. It's pretty easy, just put in the logic for your own needs in terms of threading and naming.

How to create custom abstract objects with attributes in Typo3?

I am now familiar with "basic" Typo3 - Usage and templating. Right now, I am stuck though, because I am not familiar with custom extensions etc.
I am looking for a way to represent Objects, that I get via methods of my own php-class from an XML-DB-Interface, in Typo3.
To be more precise :
I have a really complex XML-Interface and a php-class which is complete already, to interact with that interface, making methods available, that are meant to interact with different object-types in the underlying DB.
I now want to create abstract objects with the corresponding attributes in Typo3 to be able to work with them in typo3 (display/create/modify).
Furthermore, it would be helpful to find a way to "link" the functions of my php class to typo3-functions, so I can (perhaps?!) build up some kind of simple report-generator that generates conditional reports of those objects.
Could anybody lead me into the right direction and link (a) HowTo(s) or perhaps even examples that I could modify?
Thanks in advance, Oliver
Check how DBAL extension is coded.
https://docs.typo3.org/typo3cms/extensions/dbal/
You might want to implement this XML system as your own abstraction system to store your objects and use TYPO3 backend forms to manipulate those.

How to create custom extension point in ReSharper plugin

We are working on plugin for ReSharper and we want to make our plugin extensible. Seems, we should use ShellComponent attribute to do it but we can not find any examples. Could anybody enplane how to define custom extension point and how to manage extension. Example of code of extension point and extension implementation would be very helpful.
Thanks.
If you're looking to write a plugin that can extend ReSharper, you need to tell ReSharper about the classes in your plugin, by marking them with the [ShellComponent] or [SoutionComponent] attributes. These attributes have different lifetimes - a shell component lasts the lifetime of ReSharper itself, and a solution component is created when a solution is opened and disposed when the solution is closed.
To make ReSharper do something useful with your components, they typically have to implement an interface, such as ICodeCompletionItemsProvider, and sometimes have to use a different attribute, such as [CodeCleanupModule] (which itself derives from ShellComponentAttribute). There are many extension points in ReSharper, and the one that's appropriate for you depends on what you're trying to do - refactoring, unit test provider, code cleanup, code completion items, etc. The devguide provides a good introduction to the more common extension points.
But if you want to make your own plugin extensible, then your component needs to work with a kind of provider pattern, by deferring work to multiple provider instances. For example, code cleanup works by deferring to multiple code cleanup modules, each responsible for cleaning up a different aspect of your code (whitespace, ordering, etc). To do this, your component should take in a collection of providers in the constructor. ReSharper's component model will automatically create a collection of these types and pass them to. More specifically, you should have a constructor that takes an IEnumerable<T> or IViewable<T>, where T is the interface of the provider you're going to define and call. The IEnumerable<T> will give you a simple collection of providers, but IViewable<T> represents an observable collection, and allows you to subscribe to notifications of new providers being made available from the component model.

How to display timeline information for routines used by controllers in glimpse/Asp.NET MVC

I am currently using Asp.Net MVC 4 and I would like to include the time of some routines used by my controllers in the glimpse's timeline tab.
I know that I have to create an ITimeLineMessage Implementation and send the timing information with a message broker. But how to create the ITimeLineMessage ?
Here is an implementation using anthonyv's suggestion:
https://gist.github.com/droyad/8292852
Here is a way but its not very nice and not supported:
Retrieve the MessageBroker for the following static method:
Glimpse.Core.Framework.GlimpseConfiguration.GetConfiguredMessageBroker()
Then publish an ITimelineMessage to the MessageBroker:
messageBroker.Publish(timelineMessage)
Note, you could create a generic message type that you use over again that implements ITimelineMessage
To populate the properties of your ITimelineMessage implementation you might also need IExecutionTimer. You can get this via the following static method:
Glimpse.Core.Framework.GlimpseConfiguration.GetConfiguredTimerStrategy()
The above will have the knowledge of when the request started for offsets etc.
As #nikmd23 said, we know this is about as bad as what you could ever want to do but v2 will see a much much more simple way of doing this.
You can create any custom class you want, that class just has to implement ITimelineMessage.
As a general heads up, we are currently working through a way to make this WAY easier. If the approach described there interests you, please do provide your feedback.

Encapsulating Logic in Pages using GEB and Cucumber

Using GEB I was using the Page Object Pattern to encapsulate information about the different pages statically.
I then refactored my GEB code to be used from a separate class so I could encapsulate common commands using method calls.
For example I would have a method login() which will call the appropriate GEB code to login to the website that I am testing. I would then have other common functions using method calls on a TestHelper class.
I wanted to move these common functions to the Pages that they act upon. For example a search page would have a search method, the login page would have the login method. This way I can build a library of pages which have all the common functionality on them for use across multiple GEB projects. Now to do this each page must have a handle on the geb.Browser therefore I would now have to instantiate each page in the test setup. By doing so I am no longer able to use the standard page object pattern.
to ReviewQueuePage
assert at(ReviewQueuePage)
The code above will throw a null pointer as the object is no longer able to be accessed in a static manner meaning I had to change the code to
go ReviewQueuePage.url
This removes all the functionality of using the class as a Page.
Does anyone have any solutions for encapsulating the data for each of the pages in way that it doesn't cause the pages to act differently.
This resource maybe of interest to you. http://adhockery.blogspot.com/2010/11/encapsulating-page-state-and-actions-in.html. It also has examples in git.
This also might be useful Passing state between pages when using geb & spock
I'm a bit confused. Are you looking for a way to share common code among multiple pages? This is the impression I get after reading your question several times, but I'm not quite sure. You mentioned "common functions". Well, common components can be encapsulated using Module objects. In each page that uses a common component, simply reference the module object in the page object.

Resources