System.Windows.Controls in Mono - mono

I am unable to find System.Windows.Controls in Mono.
Here's a simple program to reproduce the issue ...
using System;
using System.Windows;
using System.Windows.Controls;
public class HelloWorld {
static public void Main() {
Console.WriteLine ("Hello Mono World");
}
}
Any ideas/clues/thoughts?
Thanks

Related

How to get first or guardian actor in akka.net?

Edit : Executive summary: Where the bleep is 'Sys' defined? I see it in Akka.net code all over the internet, but my build is not finding it. Who or what do I have to import, use, link, do, bribe or kill?
Should be screamingly easy. Taking first steps in Akka.net, the sample does not build. This was copied from the [Getting Started example][1]
[1]: https://getakka.net/articles/intro/tutorial-1.html . It does not build, because 'Sys' is not defined. This obviously elementary step is nowhere described on their site, and I've given up on tweak-n-try.
Here is all of the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyAkka
{
class Program
{
public class PrintMyActorRefActor : UntypedActor
{
protected override void OnReceive(object message)
{
switch (message)
{
case "printit":
IActorRef secondRef = Context.ActorOf(Props.Empty, "second-actor");
Console.WriteLine($"Second: {secondRef}");
break;
}
}
}
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var firstRef = Sys.ActorOf(Props.Create<PrintMyActorRefActor>(), "first-actor");
Console.WriteLine($"First: {firstRef}");
firstRef.Tell("printit", ActorRefs.NoSender);
Console.ReadKey();
}
}
}
Here is a working version of your code:
using System;
using Akka.Actor;
namespace SysInAkkaNet
{
class Program
{
public class PrintMyActorRefActor : UntypedActor
{
protected override void OnReceive(object message)
{
switch (message)
{
case "printit":
IActorRef secondRef = Context.ActorOf(Props.Empty, "second-actor");
Console.WriteLine($"Second: {secondRef}");
break;
}
}
}
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
using (var actorSystem = ActorSystem.Create("MyActorSystem"))
{
var firstRef = actorSystem.ActorOf(Props.Create<PrintMyActorRefActor>(), "first-actor");
Console.WriteLine($"First: {firstRef}");
firstRef.Tell("printit", ActorRefs.NoSender);
Console.ReadKey();
}
}
}
}
You need to create an actor system to put your actors in. And you need to add a reference to the Akka NuGet package, and a corresponding using Akka.Actor; statement.
I know that the Akka.TestKit has a property Sys, which gives you a reference to the actor system that is created for a given test.
Apart from that, I am not able to answer why the documentation you are referring to shows these "Sys.ActorOf(...)" examples like that (with a capital S), indicating that it is a (possibly built-in) property, so I kind of understand your confusion there.

Fody MethodDecorator not working

I am trying to create a method decorator using Fody but it gives me the following error:
I have taken specific care to not wrap my IMethodDecorator inside any namespace as has been mentioned in a lot of places online. Following is the sample code I am trying in a console app.
IMethodDecorator
using System;
using System.Reflection;
public interface IMethodDecorator
{
void OnEntry(MethodBase method);
void OnExit(MethodBase method);
void OnException(MethodBase method, Exception exception);
}
MethodDecoratorAttribute
using System;
using System.Diagnostics;
using System.Reflection;
using FODYPOC;
// Atribute should be "registered" by adding as module or assembly custom attribute
[module: MethodDecorator]
namespace FODYPOC
{
// Any attribute which provides OnEntry/OnExit/OnException with proper args
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Assembly | AttributeTargets.Module)]
public class MethodDecoratorAttribute : Attribute, IMethodDecorator
{
// instance, method and args can be captured here and stored in attribute instance fields
// for future usage in OnEntry/OnExit/OnException
public MethodDecoratorAttribute() { }
public void OnEntry(MethodBase method)
{
Console.WriteLine();
}
public void OnExit(MethodBase method)
{
Console.WriteLine();
}
public void OnException(MethodBase method, Exception exception)
{
Console.WriteLine();
}
}
public class Sample
{
[MethodDecorator]
public void Method()
{
Debug.WriteLine("Your Code");
}
}
}
Can someone point me in the right direction. It looks pretty simple to implement and I know I am making a very silly mistake somewhere.
Apparently the latest version of MethodDecorator.Fody (Version 0.9.0.6 currently) was not working. Downgrading the version to version 0.8.1.1 fixed the issue for me.
After a little more investigation, it appears that the interface method signatures were different in the two versions. So when I had the new package, it was not expecting MethodBase as a parameter and due to not finding anything that matches the interface it expects, it was throwing the error.

structuremap configuration asp.net mvc 4

I have a problem with MVC4 StructureMap configuration, when I run the project the compiler fires this error
No Default Instance defined for PluginFamily Mace_CrmSystem.Controllers.HomeController
this is my code
global.aspx code
namespace Mace_CrmSystem
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteTable.Routes.MapRoute("Oqla", "Oqla", new { controller = "Home", action = "index" });
RouteConfig.RegisterRoutes(RouteTable.Routes);
ControllerBuilder.Current.SetControllerFactory(new MyCustomeFactory());
ObjectFactory.Initialize(x => x.For<string>().Use<string>());
}
}
}
MycustomeFactory class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using StructureMap;
namespace Mace_CrmSystem
{
public class MyCustomeFactory : System.Web.Mvc.DefaultControllerFactory
{
protected override System.Web.Mvc.IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
{
return StructureMap.ObjectFactory.GetInstance(controllerType) as System.Web.Mvc.IController;
}
}
}
Controller class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Mace_CrmSystem.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public HomeController(string parameter)
{
TempData["Hi"] = "Hi";
}
public ActionResult Index()
{
return View();
}
}
public class logger
{
public void log()
{
}
}
}
what I noticed that when I add a parameter of type object like
public HomeController(logger parameter)
instead of
public HomeController(string parameter)
and
ObjectFactory.Initialize(x => x.For<logger>().Use<logger>());
instead of
ObjectFactory.Initialize(x => x.For<string>().Use<string>());
it works probably but with the string parameter it does not work .
so please couold anyone explain that for me.
From my understanding of StructureMap (and someone please correct me if I'm wrong) the reason you're seeing the behaviour that you're seeing is because StructureMap will use the longest constructor by default and attempt to fill in the parameters with the default instance registered with StructureMap.
In your instance you're not providing a default instance of string so StructureMap doesn't know how to resolve it.
If you wish to do what you're trying to do then your best bet is to look at creating a custom convention (see this answer for more information), however these do rely on knowing the name of the property your constructor is expecting.
Generally though, when dealing with strings your best bet is to move the string to an intermediate type and inject that instead.

WCF Service Creation

I am trying to build a small WCF service and wanted to utilize it in a test application.
PFB service code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace HelloIndigo
{
[ServiceContract(Namespace="http://www.thatindigoirl.com/samples/2006/06")]
public interface IHelloIndigoService
{
[OperationContract]
string HelloIndigo();
}
public class HelloIndigoService : IHelloIndigoService
{
public string HelloIndigo()
{
return "Hello indigo";
}
}
}
Host Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace Host
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService), new Uri("http://localhost:8000/HelloIndigo")))
{
host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService), new BasicHttpBinding(), #"HelloIndigoService");
host.Open();
Console.WriteLine("Press <ENTER> to terminate the service hosy");
Console.ReadLine();
}
}
}
}
Whenever I am trying to run Host I am getting below mentioned error in host.Open() statement.
HTTP could not register URL
http://+:8000/HelloIndigo/. Your
process does not have access rights to
this namespace (see
http://go.microsoft.com/fwlink/?LinkId=70353
for details).
Can anyone help me with this
You need to run the host app with elevated privileges (i.e., "As Administrator"). Under Vista/Win7, only administrative accounts have the permission to register socket listeners.

WCF Relocation of DataContracts

This is a fully functional WCF Hello World program. I.e. I am able to run this program without any Exception.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace DataContractsNamespace
{
[DataContract]
public class AccountInfo
{
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
namespace Clients
{
public class BankProxy : ServiceContractsNamespace.IBank
{
ServiceContractsNamespace.IBank channel;
public BankProxy()
{
channel = ChannelFactory<ServiceContractsNamespace.IBank>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://localhost:8000/Services/BankService"));
}
public decimal GetAcccountBalance(string AcctNo)
{
return channel.GetAcccountBalance(AcctNo);
}
public DataContractsNamespace.AccountInfo GetAccountInfo(string AcctNo)
{
return channel.GetAccountInfo(AcctNo);
}
}
}
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Text;
namespace ServiceContractsNamespace
{
[ServiceContract]
public interface IBank
{
[OperationContract]
decimal GetAcccountBalance(string AcctNo);
[OperationContract]
DataContractsNamespace.AccountInfo GetAccountInfo(string AcctNo);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Clients
{
class Program
{
static void Main(string[] args)
{
BankProxy prox = new BankProxy();
Console.WriteLine("Hit enter to invoke the service call. Type exit then enter to close");
while (Console.ReadLine() != "exit")
{
string balance = prox.GetAcccountBalance("1234").ToString("c");
DataContractsNamespace.AccountInfo ai = prox.GetAccountInfo("1234");
Console.WriteLine("{0} {1} your account balance is {2}.", ai.FirstName, ai.LastName, balance);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Hosts
{
public class BankService : ServiceContractsNamespace.IBank
{
public decimal GetAcccountBalance(string AcctNo)
{
return 1.37m;
}
public DataContractsNamespace.AccountInfo GetAccountInfo(string AcctNo)
{
DataContractsNamespace.AccountInfo ai = new DataContractsNamespace.AccountInfo();
ai.FirstName = "Paul";
ai.LastName = "Johansen";
return ai;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
namespace Hosts
{
class Program
{
static void Main(string[] args)
{
ServiceHost servHo = new ServiceHost(typeof(BankService), new Uri("http://localhost:8000/Services"));
servHo.AddServiceEndpoint(typeof(ServiceContractsNamespace.IBank), new BasicHttpBinding(), "BankService");
servHo.Open();
Console.WriteLine("This service is open for business. Hit Enter to close.");
Console.ReadLine();
servHo.Close();
}
}
}
As you can see, AccountInfo - Data contract is shared by both Client and Host.
I need to keep data contract only to Host/Service side.
Clients should only see interfaces of DataContracts (like IAccountInfo).
How should I modify my program to introduce IAccountInfo?
It sounds like you want to return an interface instead of a class. I'm not exactly sure why you are not content to return AccountInfo. However, you should be able to do this but you will need to use a KnownType or perhaps ServiceKnownType to make it work.
Alternately, if you are working in a fully .NET environment you can use the NetDataContractSerializer instead of the DataContractSerializer.
For reference and examples you can check out:
http://nirajrules.wordpress.com/2009/08/26/wcf-serializers-xmlserializer-vs-datacontratserializer-vs-netdatacontractserializer/
http://www.pluralsight.com/community/blogs/aaron/archive/2006/04/21/22284.aspx
http://weblogs.asp.net/avnerk/archive/2006/07/31/WCF-Serialization-part-1_3A00_-Interfaces_2C00_-Base-classes-and-the-NetDataContractFormatSerializer.aspx
http://www.thoughtshapes.com/WCF/ExampleTwo.htm
And what should IBank.GetAccountInfo return to client if you don't want to share AccountInfo? create 2 classes make the first datacontract the second not, and where you want to share use the first one, where not, the second one