SharePoint webpart connections - sharepoint

Is it possible to have a bi-directional web part connection? I am aware that a web part can be both a provider and a consumer but it seems only one connection is allowed between two web parts.
What I am trying to accomplish is a bi-directional connection where a field in web part A can update web Part B and a field in B can update web part A.

You can do this in several ways.
The main things to understand are:
You're in complete control of the interface the web parts share
By default only the consumer knows anything about the other web part
Here is then a couple of ways to implement what you describe:
Option 1: Pull/Push:
You can make your interface such that the consumer can pull the information it needs by either calling function or getting property values
And the consumer also pushes the information the other webpart might need by calling functions or setting property values.
Option 2: Consumer announcing
Here you define your interface (and way of using it) such that when a consumer get's a connection it make a call back through the interface to give the producer a reference to the consumer. This reference can then implement the same or another interface any way out want.
Now both the consumer and the producer has a reference to another web part where they can get the information they need.

Related

why should I not use MVC Jsonresult instead of apicontroller get method

I have developed an application which was MVC application. It has a requirement that the application will return json data for one get request.
So I have added apicontroller and created a get method to return json data.
So far so good. but then I thought, is it really needed to add apicontroller to create just one get method.
I started exploring and googling what is the difference other than content negotiation. Got lots of answers and articles but non of them were satisfactory.
So here is the actual confusion, why can't I just create a method in the MVC controller with JsonResponse and return the json data(Which I know only is need for my requirement, but other application on different domain will consume it).
Can anyone convince me why should I use apicontroller instead of MVC JsonResponse for my requirement or should I not be using apicontroller at all.
apology if there is any mistake.
If I get it right the question is Can we use MVC action to serve json content answer is yes! Is it okay to use Json Result? answer is It depends where do you want to consume it
Say I am an in a Web Environment where I have no need for the APIs (that means I am not going to serve my data to multiple clients) If that's the scenario where only your View is going to consume data returned from your Action Method you are good to go. An Action returning a Json Result is basically an Action Result and that's what it is made for.
but If you are in a REST scenario and you need your backend to serve your data to the client de facto standard is to use an independent Web API for that.
Controllers' main responsibility should be to work as an intermediary between your View and Model and whatever service layer you want to bring inside it. on the other hand, Web APIs are data-driven there only purpose is to serve data (use them if you need them)
Web APIs are good cause they give you the flexibility of serving the data to possibly any client that might need it. That's what I would pick if I am starting from scratch but if I only need to serve data to one client Controller Action methods will be way to go.
Hope this helps.

spring integration multiple stored procedure enricher pattern

I am new to spring integration. I have very specific requirement.
I have two Database to fetch.
Created two SP.
I have to get the data calling their respective stored procedure and create a JAXB object to make webservice call.
I am able to call one SP but not able to call 2nd SP. I think I can use enricher pattern but dont know how to configure.
Please help.
Well, trying to answer to your so broad question I only may suggest:
Configure <int-jdbc:stored-proc-outbound-gateway> to call first SP
Configure <int:enricher> with a request-channel for sub-flow to call the second SP similar way like a previous one
with this <int:enricher> you will be able to store additional info in some your Customer model property (which is payload) or headers
And so on until WS call.
Everything rest you can find in the Spring Integration Reference Manual and samples project.
UPDATE
I still need help.
Since it looks like you still don't understand Spring Integration principles properly, I'd suggest you to have one <service-activator> and call both stored procedures in custom code using Spring JDBC directly.
Eventually with an experience you will be able to refactor it really to separate components with the <enricher> on board.
OTOH your scenario recalls me Scatter-Gather pattern.

Chromecast discover with multiple Activities and CCL

I'm developing an Android app for Chromecast which makes use of the Chromecast Companion Library (CCL) together with a MediaRouterButton. When the first activity is created, onCastDeviceDetected is called and MediaRouterButton is set to visible. The second activity is created from within the first activity, but no onCastDeviceDetected is called in the second activity!
What is best practice for keeping state of discovered Chromecast devices with the combination of multiple activities, MediaRouterButton and CCL?
In CCL version 1.8 onCastDeviceDetected was always called when starting a new activity, so this issue seems to be introduced (with purpose) in version 1.9 ?
I am not sure if what you are asking was ever working differently; I looked at the code and there hasn't been any changes in the behavior around that but I could be wrong.
Right now CCL doesn't provide an API for you to do that. From CCL's point of view, availability of routes hasn't changed when you move from one activity to another so it doesn't fire that callback (and the intention was not to do that either). The problem you are facing can be addressed by either of these:
Keep track of the route availability in, say, your Application instance; register a VideoCastConsumer in your Application class and listen to onCastAvailabilityChanged(). Keep the result in your Application instance and then when you start a new activity, ask your application instance if there is any cast device or not (based on the preserved value that I talked about); that would give the initial state. Have your activity register a consumer with the same callback so from that point on, the activity is self-contained as long as it is alive.
File a feature request for CCL so I add an API to get you around the need to add that piece in your own application instance.

Is there a way to link a specific method to a Route in ServiceStack?

The Problem
I'm aware of the basic way to create a route/endpoint in ServiceStack using methods with names like "Get", "Post", "Any", etc inside a service but in the particular case that I'm trying to work with I have an existing service (which I can make an IService via inheritance) that can not be retrofitted w/ServiceStack attributes and currently uses DTOs for the requests and responses.
This service contains many functions that I do not want to manually mask (as this is a pass-through layer) but otherwise already conform to ServiceStack's requirements. What I'm wondering is if there's a way to manually create these routes in a way that would work like I've mocked up here. My existing functions and DTOs already contain the information I would need to define the routes so if this approach is possible it would only require me to enumerate them at initialization time as opposed to generating the services layer manually.
I noticed there is an extension method on Routes.Add that takes an Expression of type Expression> but I was not able to get that working because I believe the underlying code makes assumptions about the type of Expression generated (LambdaExpression vs MemberExpression or something like that). I also may be barking up the wrong tree if that's not the intended purpose of that function but I can not find documentation anywhere on how that variant is supposed to work.
Why?
I'm not sure this is necessary but to shed some light on why I want to do this as opposed to retrofitting my existing layers: The current code is also used outside of a web service context and is consumed by other code internally. Retrofitting ServiceStack in to this layer would make every place that consumes it require ServiceStack's assemblies and be aware of the web service which is a concern I want separated from the lower code. We were previously using MVC/WCF to accomplish this goal but we want some of the features available from ServiceStack.
the current architecture looks like this:
data -> DAL -> discrete business logic -> composition -> web service
Hopefully that makes enough sense and I'm not being obtuse. If you would like any more details about what I want to do or why I'll try to update this post as soon as possible.
Thanks!
You might use the fallback route in order to provide your own routing mechanism.
Then you get the request.Path property and route using your own mapping of path:Function which can be stored in a simple dictionary.
Anyway, if you go this path I don't see much benefit in using servicestack. It seems you just need an http handler that routes requests to existing services.

re-using ServiceStack validation in Winforms offline client

We have a working website using ServiceStack as the back end that amounts to a complex data-entry form.
My users have requested an "offline editor" for the forms. To use the offline program, the user will have to connect to the ServiceStack service, create empty instances of the forms, and then I will save the POCOs from the service to disk using ServiceStack's JSON serializer. From there the user can log off the service and edit the POCOs. When they're done, they reconnect to the service, and post/put the edited POCO object.
This all works great. My question involves validation. The validation logic is built into my Service.Interface library, which isn't available offline. The winforms program references only the POCO library and the ServiceStack "common" libraries, which do not look like they include the ServiceStack.Validation namespace.
Is there a way I can rearrange my project so that both the service and the Winforms client can run Validation against the POCOs, so that they can have data validation while offline?
UPDATE:
getting closer, I think - I moved all of the Validation classes into their own project. From my Winforms project, I can now manually set up a validator for a POCO class like this:
ServiceStack.FluentValidation.IValidator<SomePOCO> IValidator;
IValidator = new Tonto.Svc.Validation.SomePOCOValidator();
ServiceStack.FluentValidation.Results.ValidationResult vr =
IValidator.Validate(_rpt);
I can see the validator constructor being set up and the rules being initialized, but the .Validate method doesn't seem to do anything. (object comes back as valid, and breakpoints into custom validator code never get there).
UPDATE #2
I discovered my validator code wasn't running from Winforms because my validators all specify a servicestack ApplyTo Put/Post only (see sample code below). When I remove the entire Ruleset clause, though, then validation happens in my service on GETs - something I never want.
Can anyone think of a way to configure the validator rules to run for POST/PUT only when called from ServiceStack, but to also always run when NOT in servicestack? So close!
public class SomePOCOValidator : AbstractValidator<SomePOCO>
{
public SomePOCO()
{
RuleSet(ApplyTo.Put | ApplyTo.Post, () =>
{
(rules)
});
}
}
If your validation is doing anything interesting, then it probably HAS to be done "online".
Maybe just allow your client to save the POCOs locally until they go back online, at which point you send them up to your server. Any transactions that are okay, get processed normally, and any that fail, get returned for the user to edit (so your client will need some smarts to have a working set of POCOs for editing)...
If you don't want ANY extra stuff on the client, just have the transactions that fail to validate get stuffed into a "needs_corrections" table on the server, and then code up a supervisor-sort of screen to manage that table.
The validation framework that ServiceStack uses is named FluentValidation. There is no WinForms support in it. Jeremy Skinner the creator of FluentValidation answerd a question about this back in 2010 on his forum here.
Personally I don't use FV with WinForms - the vast majority of my projects are web-based with the occasional WPF project.
However, if I was going to do this then I probably wouldn't validate the controls directly, but instead use a ViewModel which is bound to the controls. I'd use a fairly strict convention where the names of the controls would match the names of the properties that they're bound to. Then, after validation completes I'd walk the control hierarchy to find the control with the name that matches the property that failed validation (I'm not sure how you'd do this in WinForms, but in WPF I'd use LogicalTreeHelper.FindLogicalNode) and then use the ErrorProvider to set the appropriate error.
Jeremy
I was able to work out a solution that allowed me to use ServiceStack validation libraries on both a ServiceStack client and an offline client. Here are the details.
Move all AbstractValidators to their own project: Proj.Svc.Validation.
get rid of all RuleSets in your AbstractValidators.
Reference Proj.Svc.Validation from Proj.Svc.Interface and Proj.OfflineWinformsClient projects.
Turn OFF the ValidationFeature() plugin in your service. All validation will have to be done manually. This means no iOC injected validators in your service classes.
When it's time to validate, either from your service or the offline client, manually declare the validator and use it like this.
IValidator validator = new
Tonto.Svc.Validation.SomePOCOValidator();
ServiceStack.FluentValidation.Results.ValidationResult vr =
validator.Validate(poco);
if (!vr.IsValid)
(throw exception or notify user somehow);

Resources