I like to interact with some of my wordpress blogs through xmlrpc interface. During my research I found xml-rpc.net-Library (www.xml-rpc.net) which works really fine except for one thing.
I build my xmlrpc.net instance like this:
[XmlRpcUrlAttribute("http://my-example-blog.com/xmlrpc.php")]
public class WP : XmlRpcClientProtocol
{
public WP()
{
}
...
}
But I want to set the xmlrpc-Url dynamically during runtime. So I like to add more blogs during the UI at runtime and don't want to implement each blog "hard-coded".
Does anybody had a same problem and can help me? Is there another possibility within xmlrpc.net-library or do you know another good xmlrpc library?
Greets,
Raffi
You can specify the URL at runtime:
proxy.Url = "http://my-example-blog.com/xmlrpc.php";
Related
Here is the situation that I have:
I have set up a route like this:
Routing.RegisterRoute("Cars/CarMgmtPage", typeof(CarMgmtPage));
When a button is clicked it calls the following:
await Shell.Current.GoToAsync("Cars/CarMgmtPage", true);
However CarMgmtPage takes constructors in the argument like this;
public CarMgmtPage(IAddCar addCar1,
IAddCar addCar2)
What I need to do is to use the Microsoft.Extensions.DependencyInjection that is used in my application to create this page something like this:
var abc = Startup.ServiceProvider.GetRequiredService<CarMgmtPage>();
But I have no idea how to go about this as it seems the Xamarin Shell handles the creation of the page and I don't see how I can fit DI into that.
I hope someone has some ideas on how to do this.
It would seem that at this time this is not possible. There are a couple of issues in the Xamarin Github talking about this:
[Enhancement] Dependency Injection support for creating ContentPage in Shell. #8359
Current status of this is:
Under consideration-High Interest in Enhancements on Jun 2, 2020
Also
[WiP] .NET MAUI Shell Improvements #10804
So the answer to this is that it we can hopefully expect this in the near future but right now it's still at the planning stage.
I've been trying to open a file in asp.net 5 and have not been having a lot of success.
In the past you used Server.MapPath or HostingEnvironment.ApplicationPhysicalPath. They are both gone in the OWIN based framework.
There is a HostingEnvironment class but it's in the System.Aspnet but it needs to be initialized by the hosting environment (it no longer has a static member for ApplicationPhysicalPath but I'm guessing the WebRoot member does that now. The problem is I can't find a reference to it anywhere.
I've also looked at Context.GetFeature<> but it doesn't seem to have any feature that would show the application path, just request and response related info. The code listing the features can be found here.
<snark>Is the ability to work with files a discontinued feature in ASP.NET?</snark>
There is also the possibility that I can't brain very well right now and missed something.
You can get it from the ApplicationBasePath property of Microsoft.Framework.Runtime.IApplicationEnvironment serivce.
Example: https://github.com/aspnet/Mvc/blob/9f1cb655f6bb1fa0ce1c1e3782c43a2d45ca4e37/test/WebSites/FilesWebSite/Controllers/DownloadFilesController.cs#L28
There are two approaches now:
using Microsoft.Extensions.PlatformAbstractions;
public Startup(IApplicationEnvironment appEnv)
{
// approach 1
var path01 = PlatformServices.Default.Application.ApplicationBasePath;
// approach 2
var path02 = appEnv.ApplicationBasePath;
}
I want to show some XHTML documents that reference some resources (style sheets, scripts, images, etc). These resources are local, but they do not exist on the file system - instead, they are generated by my application.
Using Android.Webkit.WebView and Android.Webkit.WebViewClient, I can intercept requests and provide these resources flawlessly, using something like this:
internal class MyWebViewClient : WebViewClient
{
public override WebResourceResponse ShouldInterceptRequest (WebView view, string url)
{
/* logic to create a resource stream for the requested url */
return new WebResourceResponse (mimeType, encoding, generatedStream);
}
}
Can I achieve something similar using Xamarin.Forms.WebView and its related classes? If so, how? I haven't noticed in the API documentation any methods that look like they provide equivalent behavior.
The Xamarin.Forms WebView control is very basic at present. The class members show that you wouldn't be able achieve what you are wanting to do.
You can load a HTML resource etc here that is quite useful in determining how to reference local files, if you do decide and go down that route.
Do note, however, that in Xamarin.Forms v1.2.2.6243 on Android the Source property is incorrectly set for URLs. For instance, if you navigate to www.yahoo.com and do a few clicks on that site, you will see some query string parameters etc. However, on Android this always comes back as Source property being www.yahoo.com. Xamarin have created a temporary fix for this, however you have to include and implement your own custom renderer at present to overcome this.
I am taking over an application developed with MvvmCross.vNext.
While trying to update it with MvvmCross.V3, I found the following breaking change: in the constructor of the MainViewModel, we show the LoginViewModel (ShowViewModel()).
It worked fine in vNext.
But with V3, the LoginView doesn't show.
After a long search, I found out that the following code, added in MvxStoreMainThreadDispatcher.RequestMainThreadAction :
if (_uiDispatcher.HasThreadAccess)
{
action();
return true;
}
was responsible for my troubles.
If I comment it out, my application works as previously, but I guess this code is there for some reasons...
Do you have any suggestions ?
Can I force the previous behavior without changing MvvmCross source code?
Should I refactor the code to handle the LoginView differently ?
Thanks in advance for your comments.
Philippe
While trying to update it with MvvmCross.V3, I found the following breaking change: in the constructor of the MainViewModel, we show the LoginViewModel (ShowViewModel()). It worked fine in vNext.
I think your constructor navigation would have broken on several platforms in any MvvmCross version. To be honest, I think you were lucky it worked before.
The problem is that ViewModels are constructed (or located) during View events such as ViewDidLoad, OnNavigatedTo, and OnCreate - and these events are normally
called during 'page transitions'
To work around this you will need to move your login navigation out of the constructor.
How you do this depends on your app
if you do need the Home->Login backstack, then you can trigger off some async or time delay or you can trigger off some other View event such as something like ViewDidAppear
if you don't need that backstack then the way I normally implement this sort of thing is to use a custom IMvxAppStart - something like:
public class AppStart
: MvxNavigatingObject
, IMvxAppStart
{
public void Start(object hint = null)
{
var authService = Mvx.Resolve<IMySerice>();
if (authService.IsLoggedIn)
{
ShowViewModel<HomeViewModel>();
}
else
{
ShowViewModel<LoginViewModel>();
}
}
}
(you can see another example in https://github.com/slodge/MvvmCross/blob/v3/Sample%20-%20CirriousConference/Cirrious.Conference.Core/ApplicationObjects/AppStart.cs)
This can be registered in App.cs startup using:
RegisterAppStart(new AppStart());
I'm trying to inject specific class into my WCF service but it doesn't work and I can't understand why. I'm VERY NEW to MEF and patterns, just trying to make it work. Watched series of videos to understand what it is about but bootstraping won't work in my case since it is not Silverlight
http://channel9.msdn.com/blogs/mtaulty/mef--silverlight-4-beta-part-1-introduction
Here is my Web application's Global.asax code. This is non MVC, just regular ASP.NET app:
private void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
var catalog = new WebScopedCatalog(new DirectoryCatalog(Server.MapPath("~\\bin")));
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
FIRST, I'm not sure I even bootrstrap it properly.. SECOND, I'm using http://www.timjroberts.com/2011/02/web-scoped-mef-parts/ as a guidance for web-scoped parts. I need that because some injected objects supposed to live during request only.
Now, I have following class:
[Export(typeof(ITest))]
[WebPartCreationPolicy(WebCreationPolicy.Session)]
public class Test : ITest
{
public string TestMe()
{
return "Hello!";
}
}
And my service looks like:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class MobileService
{
[Import]
public ITest MyTestClass { get; set; }
public MobileService()
{
int i = 10;
}
When breakpoint hits at i=10 - I have NULL inside MyTestClass. Clearly, MEF does not initialize this class for me. Am I missing something?
EDIT:
When I examine catalog - I see my class Exported but I don't see it imported anywhere...
EDIT 2:
Daniel, Thank you. It makes sense. It still feels litle like a magic for me at this point. Yes, WCF creates this service. Than I have MembershipProvider and various Utility classes that ALL need the same import. And I'm not creating neither of those classes so I can't have Mef creating them. (Service created by WCF, MembershipProvider created by who-knows-what, Utility classes have static methods..) I wanted to use Mef instead of storing my stuff in HttpContext.Current. My container object doesn't have SatisfyImports. It has SatisfyImportsOnce. What if I do it in many different constructors? Will Mef share same singleton or it will be creating new instance every time?
At this point I wonder if I should even use Mef in this particular scenario..
MEF won't satisfy imports for objects it doesn't create. What is it that creates MobileService? If it's not MEF, then the import won't be satisfied by default. Even if it is MEF, the import wouldn't be satisfied in the constructor- you can't set properties on an object you create until it is done being created (ie the constructor has finished).
You can call container.SatisfyImportsOnce(mobileService) to satisfy the imports of a part. You should try to avoid doing this everywhere you need a MEF import. If you can, you should export a part and import it from another part so that MEF handles the creation for you. However, it looks like this part may be created by WCF so you can't have MEF create it, and in that case it would be OK to use SatisfyImportsOnce.
Response to EDIT2: If you use the same container each time, MEF will by default only create one instance of the part with the export. You can set the CreationPolicy to NonShared (in either the export or import attribute) to change this.
As for whether it makes sense to use MEF the way you are trying to, I don't know enough about writing web services to give you any advice on that.
The web-scoped part creation policy that I wrote won't help with WCF services.
I've posted a new blog post that documents an approach to composeable WCF services:
http://www.timjroberts.com/2011/08/wcf-services-with-mef/
Basically, you need to implement a custom Instance Provider that is MEF-aware and can compose the WCF service object when it is created.
I wrote about how to compose your WCF in a generic way that its configuration based here:
Unit Testing, WCF and MEF
I actually built my solution on the code samples Tim Robert's provided in his post. only that I took it a bit further and instead of using code in the global asax i moved the configuration into the web.config so its easier to maintain.