Configure Interception with Unity AutoConfig in VB.NET - c#-to-vb.net

I'm trying to get interception working in vb.net since my work only allows that. The way I would use it is to configure say some logger so that every business logic function that gets run is intercepted and logged to the database (bad idea, but its just an example). This is an example that I found:
container
.ConfigureAutoRegistration()
.Include(If.Implements<IBusinessService>, (x, y) =>
{
if (x.IsClass)
y.Configure<Interception>().
SetDefaultInterceptorFor(x,new VirtualMethodInterceptor());
})
This is what I tried to get working in vb.net, but it keeps throwing an error.
container.
ConfigureAutoRegistration().
Include([if].ImplementsITypeName, Function(x, y)
if x.IsClass
y.Configure(of Interception)()
.SetDefaultInterceptorFor(x,new VirtualMethodInterceptor())
End Function)
The error is:
Argument not specified for parameter 'type' of 'Public Shared Function ImplementsITypeName(type as System.Type) As Boolean.
Now obviously I need to specify some type, but the point is that I need to autoregister, so why do I need to provide a type? Also, the C# code doesn't require it, and neither does the code sample (see below).
var container = new UnityContainer();
container
.ConfigureAutoRegistration()
.ExcludeAssemblies(a => a.GetName().FullName.Contains("Test"))
.Include(If.Implements<ILogger>, Then.Register().UsingPerCallMode())
.Include(If.ImplementsITypeName, Then.Register().WithTypeName())
.Include(If.Implements<ICustomerRepository>, Then.Register().WithName("Sample"))
.Include(If.Implements<IOrderRepository>,
Then.Register().AsSingleInterfaceOfType().UsingPerCallMode())
.Include(If.DecoratedWith<LoggerAttribute>,
Then.Register()
.As<IDisposable>()
.WithTypeName()
.UsingLifetime<MyLifetimeManager>())
.Exclude(t => t.Name.Contains("Trace"))
.ApplyAutoRegistration();
http://autoregistration.codeplex.com/

I ended up using structure map.

Related

Calling push() on array, TypeError: Attempted to assign to readonly property

Working in React Native. I'm trying to declare an array and then push things to said array, but I'm getting the error TypeError: Attempted to assign to readonly property
CONTEXT:
The app prints via a thermal printer.
The print method receives an array of commands
Example:
print([{appendText: "blah"}, {
appendCutPaper: StarPRNT.CutPaperAction.PartialCutWithFeed,
}]
The print method is asynchronous and if you attempt to call the method again before the last call has finished, it errors.
Because of #2, we created a queue system that accepts a job (array of commands) and then works through the jobs synchronously.
In a React component, I'm attempting to create a job by declaring an empty array named printJob
and then pushing various commands to it. In this case, we take a snapshot of a View and then push the commands returned by the printImage method to the printJob array.
onClick={() => {
const printJob = []
viewShot.current
.capture()
.then((uri) => {
printJob.push(...printImage(uri))
})
.catch((err) => alert(err))
newPrintJob(printJob)
}
printImage returns the array of commands to print an image and cut the paper:
const CUT_PAPER = {
appendCutPaper: StarPRNT.CutPaperAction.PartialCutWithFeed,
}
export function printImage(uri) {
return [{ appendBitmap: uri }, CUT_PAPER]
}
So the goal is to generate the array of commands and pass that to the queue as a job. Now, I could just do newPrintJob(printImage(uri)) in the above case, which works completely fine. However, there is a particular setting the user can configure where it will need to print multiple images, one per ticket (in other words, multiple printImages). I want to consider all of that one job, hence the need to create the printJob array.
THE PROBLEM:
I'm getting an error TypeError: Attempted to assign to readonly property which seems to be triggered by printJob.push(...printImage(uri)). If I comment that line out, the error doesn't get thrown.
I don't understand why this would happen because you can call push on an array, even if it's declared as a constant. I also tried declaring it with var and let and still received the same error.
I hope I've provided enough context here. LMK if I need to add more.
Additional info:
"react": "16.13.1"
"react-native": "~0.63.3"
Turns out the issue was not pushing to the array. The issue was was trying to add the job to the queue:
newPrintJob(printJob)
...outside of the async's callback. Solution was to move the newPrintJob line into the .then block.

How do I create a Flow with a different input and output types for use inside of a graph?

I am making a custom sink by building a graph on the inside. Here is a broad simplification of my code to demonstrate my question:
def mySink: Sink[Int, Unit] = Sink() { implicit builder =>
val entrance = builder.add(Flow[Int].buffer(500, OverflowStrategy.backpressure))
val toString = builder.add(Flow[Int, String, Unit].map(_.toString))
val printSink = builder.add(Sink.foreach(elem => println(elem)))
builder.addEdge(entrance.out, toString.in)
builder.addEdge(toString.out, printSink.in)
entrance.in
}
The problem I am having is that while it is valid to create a Flow with the same input/output types with only a single type argument and no value argument like: Flow[Int] (which is all over the documentation) it is not valid to only supply two type parameters and zero value parameters.
According to the reference documentation for the Flow object the apply method I am looking for is defined as
def apply[I, O]()(block: (Builder[Unit]) ⇒ (Inlet[I], Outlet[O])): Flow[I, O, Unit]
and says
Creates a Flow by passing a FlowGraph.Builder to the given create function.
The create function is expected to return a pair of Inlet and Outlet which correspond to the created Flows input and output ports.
It seems like I need to deal with another level of graph builders when I am trying to make what I think is a very simple flow. Is there an easier and more concise way to create a Flow that changes the type of it's input and output that doesn't require messing with it's inside ports? If this is the right way to approach this problem, what would a solution look like?
BONUS: Why is it easy to make a Flow that doesn't change the type of its input from it's output?
If you want to specify both the input and the output type of a flow, you indeed need to use the apply method you found in the documentation. Using it, though, is done pretty much exactly the same as you already did.
Flow[String, Message]() { implicit b =>
import FlowGraph.Implicits._
val reverseString = b.add(Flow[String].map[String] { msg => msg.reverse })
val mapStringToMsg = b.add(Flow[String].map[Message]( x => TextMessage.Strict(x)))
// connect the graph
reverseString ~> mapStringToMsg
// expose ports
(reverseString.inlet, mapStringToMsg.outlet)
}
Instead of just returning the inlet, you return a tuple, with the inlet and the outlet. This flow can now we used (for instance inside another builder, or directly with runWith) with a specific Source or Sink.

Transfer file to webworker: DataCloneError: The object could not be cloned

I want to transfer a file from a form to a webworker. In chrome i simple can use this code to transfer a FileList-Object:
worker.postMessage(files: array_files);
But with Firefox i get this error:
Transfer file to webworker: DataCloneError: The object could not be cloned.
So i tried to use the Syntax for transferable objects. Something like this?
var post = {files: array_files, file_ids: response.file_ids};
worker.postMessage(post, [post]);
But with that i get this in Chrome
Uncaught DataCloneError: Failed to execute 'postMessage' on 'Worker': Value at index 0 does not have a transferable type.
And still
DataCloneError: The object could not be cloned.
in Firefox.
What is the right way to pass a FileList to a worker?
I don't know how to pass File objects with postMessage, but at the least I can advise that transferable objects do not work in this way. The optional second parameter is an array of the backing ArrayBuffer instances of any typed arrays you wish to pass. So for instance, suppose the message you would like to post is a structured object:
var message = {foo: 'abc', bar: new Uint8Array(...)};
worker.postMessage(message, [message.bar.buffer])
Also notice that passing a typed array to another worker/window as a transferable object makes the transferred array inaccessible from the sending worker/window.

How can i achieve dictionary type data access in Chromium embedded CEF1

I would like to achieve dictionary like data pattern that can be accessed from the
java script. Something like this:
pseudo Code:
for all records:
{
rec = //Get the Record
rec["Name"]
rec["Address"]
}
I am trying to achieve with CefV8Accessor, but i am not getting near to the solution.
Kindly provide few links for the reference, as i see the documentation is very less from chromium embedded.
If I understand correctly, you're trying to create a JS "dictionary" object for CEF using C++. If so, here's a code snippet that does that:
CefRefPtr<CefV8Value> GetDictionary(__in const wstring& sName, __in const wstring& sAddress)
{
CefRefPtr<CefV8Value> objectJS = CefV8Value::CreateObject(NULL);
objectJS->SetValue(L"Name", sName, V8_PROPERTY_ATTRIBUTE_NONE);
objectJS->SetValue(L"Address", sAddress, V8_PROPERTY_ATTRIBUTE_NONE);
return objectJS;
}
The CefV8Accessor can also be used for that matter, but that's only if you want specific control over the set & get methods, to create a new type of object.
In that case you should create a class that inherits CefV8Accessor, implement the Set and Get methods (in a similar way to what appears in the code above), and pass it to the CreateObject method. The return value would be an instance of that new type of object.
I strongly suggest to browse through this link, if you haven't already.

Using Linq to filter parents by their children

Having some problems with my Silverlight app (with RIA services) filtering my results. The idea is on the client I set up the EntityQuery and its filters and call load. However this isn't working for me.
Heres my code.
public void FireQuery(string filterValue)
{
EntityQuery<Parent> query = m_ParentDomainContext.GetParentQuery();
query = query.Where(p => p.Children.Any(c => c.Name.Contains(filterValue)));
m_ParentDomainContext.Load(query, Query_Completed, null);
}
Compiles just fine, however, runtime I get "Query operator 'Any' is not supported." Exception.
Does anyone know of a good way to filter like this? Again, I'm looking for a way to set this up on the client.
EDIT: I should note, I've tried a few other queries as well, with similar results:
query = query.Where(p => p.Children.Where(c => c.Name.Contains(filterValue)).Count() != 0);
query = query.Where(p => p.Children.Where(c => c.Name.Contains(filterValue)).FirstOrDefault != null);
query = query.Where(p => p.Children.Where(c => c.Name.Contains(filterValue)).Any());
Query Operator 'Count/FirstOrDefault/Any' is not supported. I'm clearly missing something here...
As I tried to play around a little with this, I figured out that methods like First, Any and Count can't be used with LINQ to Entities (and, I believe, even NHibernate) over WCF RIA Services because they're not defined on the IQueryable itself, but, instread, are extention methods defined in the System.Linqnamespace. That is precisely why this shows as a run-time exception and not a compile-time error. The only extension methods that can be used here are those found in System.ServiceModel.DomainServices.Client (such as Where, Skip, Take, OrderBy, etc.).
This has to do with the "EntityQuery" objects, because those need to be composed and sent back to the server, whereas for the collections (such as m_ParentDomainContext.Parents in your case), you can use the System.Linq extension methods freely.
In order to implement this functionality, I suggest, as Thomas Levesque said, to expose it from the server in order to only get the data you want, or, alternatively, you can compose a query using the available constructs (the ones in System.ServiceModel.DomainServices.Client) and then apply the other filters on the resulting data (where you can use extension methods from the System.Linq namespace).
PS: I tried this with both classic Entity Framework and Entity Framework CodeFirst, and had the same results.
I hope this helps

Resources