Why can't I see my ocean plugin - ocean

I am stuck trying to figure why my module is not loading but I don't see any obvious error message.
It is a very basic setup (nothing fancy yet)
Here is my module definition :
public class MyModule : IModule
{
public void Disintegrate()
{
}
public void Initialize()
{
CoreLogger.Info("Starting my module ");
}
public void Integrate()
{
// Register MyModuleProcess
MyModuleProcess mymoduleprocessInstance = new MyModuleProcess();
PetrelSystem.ProcessDiagram.Add(mymoduleprocessInstance , "Plug-ins");
}
public void IntegratePresentation()
{
}
public void Dispose()
{
}
}
And my process is also very simple :
class MyModuleProcess: Process
{
/// <summary>
/// Constructor.
/// </summary>
public MyModuleProcess() : base("MyModuleProcess")
{
}
#region Process overrides
/// <summary>
/// Creates the UI of the process.
/// </summary>
/// <returns>the UI contol</returns>
protected override System.Windows.Forms.Control CreateUICore()
{
return new MyModuleProcessUI(this);
}
/// <summary>
/// Runs when the process is activated in Petrel.
/// </summary>
protected override sealed void OnActivateCore()
{
base.OnActivateCore();
}
/// <summary>
/// Runs when the process is deactivated in Petrel.
/// </summary>
protected override sealed void OnDeactivateCore()
{
base.OnDeactivateCore();
}
#endregion
}
and my config file entry is :
<add moduleType="MyModulePlugin.MyModule, MyModulePlugin,Version=1.0.0.0,Culture=neutral, PublicKeyToken=xxxxxxxxxxx"/>
Petrel loads ok, I don't get any error message, but I don't see my process under the plug-ins folder, any ideas?
Thanks

Are you sure you modified the correct petrel.exe.config
Did you add your folder to the probing path? You would get an error however if this was true, but an idea.

My solution might help people who have signed the assembly. I was neither able to see my plug-in in Petrel nor able to debug my VS project.
After lot of head scratching for the past two days, I was able to resolve the same issue by doing the following simple steps:
Go to your Visual Studio project properties.
Go to the "Signing" tab.
Uncheck "Delay sign only" option if it is checked.
Now run your project and it should work. I worked for me.

Related

Ninject not working in Web API contructor in ASP.NET MVC 4

I am new to ASP.NET Web API.
I have upgraded my ASP.NET MVC 3 project to ASP.NET MVC 4 by using this tutorial.
Now I am trying to use Web Api here, as you can see I am trying to use ninject here, but when I declare ProductsController constructor in such a way, this does not work.
public class ProductsController : ApiController
{
private readonly IProductService _productService;
public ProductsController(IProductService productService)
{
this._productService = productService;
}
public List<Product> GetProducts()
{
return _productService.GetAllProducts();
}
}
Please help me on this.
If I add this constructor there is no call made to Web Api methods, I confirmed this by using breakpoints and it makes call otherwise.
Browser shows an xml error which reads
<Error><Message>An error has occurred.</Message></Error>
My NinjectWebCommon.cs class code is
[assembly: WebActivator.PreApplicationStartMethod(typeof(Web.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(Web.App_Start.NinjectWebCommon), "Stop")]
namespace Web.App_Start
{
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IProductService>().To<ProductService>();
}
}
}
You can follow these steps to get WebApi and Ninject up and running:
1 Create a new WebApi project
2 Add the following code for a field and a constructor to the default ValuesController:
private IFooService _foo;
public ValuesController(IFooService foo)
{
_foo = foo;
}
3 Create an interface IFooService and a class FooService
public interface IFooService
{
}
public class FooService : IFooService
{
}
4 Run the following command in your Nuget Packag Manager Console to install Ninject
Install-Package Ninject.MVC3
5 Add the following binding to App_Start\NinjectWebCommon.cs in method RegisterServices(IKernel kernel)
kernel.Bind<IFooService>().To<FooService>().InRequestScope();
In your code, you are probably not calling the NInject configuration at the right moment. When you use the Nuget package you get the following lines at the top of your Ninject file:
[assembly: WebActivator.PreApplicationStartMethod(typeof(WebApiNinjectTest.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(WebApiNinjectTest.App_Start.NinjectWebCommon), "Stop")]
These lines will make sure your code is executed at the right time.
Update : A super awesome explanation at : http://www.strathweb.com/2012/05/using-ninject-with-the-latest-asp-net-web-api-source/, Now I no longer have to use ProductsController(): this(new ProductService()).
Ah alas got this working now :)
Here is what I did...
I have two constructor of each of my WebApiController. For example for my ProductsController now the constructor I needed to define were as follows...
public class ProductsController : ApiController
{
private readonly IProductService _productService;
public ProductsController(): this(new ProductService())
{
}
public ProductsController(IFolderService productService)
{
this._polderService = productService;
}
public List<Product> GetProducts()
{
return _productService.GetAllProducts();
}
}
:)

SignalR dependency injection via Spring.Net

I'm trying to inject dependencies via Spring.NET.
First I created a custom DependencyResolver:
public class SignalRSpringNetDependencyResolver : DefaultDependencyResolver
{
private IApplicationContext _context;
public SignalRSpringNetDependencyResolver(IApplicationContext context)
{
_context = context;
}
/// <summary>
/// Gets the application context.
/// </summary>
/// <value>The application context.</value>
public IApplicationContext ApplicationContext
{
get
{
if (_context == null || _context.Name != ApplicationContextName)
{
if (string.IsNullOrEmpty(ApplicationContextName))
{
_context = ContextRegistry.GetContext();
}
else
{
_context = ContextRegistry.GetContext(ApplicationContextName);
}
}
return _context;
}
}
/// <summary>
/// Gets or sets the name of the application context.
/// </summary>
/// <remarks>
/// Defaults to using the root (default) Application Context.
/// </remarks>
/// <value>The name of the application context.</value>
public static string ApplicationContextName { get; set; }
/// <summary>
/// Resolves singly registered services that support arbitrary object creation.
/// </summary>
/// <param name="serviceType">The type of the requested service or object.</param>
/// <returns>The requested service or object.</returns>
public override object GetService(Type serviceType)
{
System.Diagnostics.Debug.WriteLine(serviceType.FullName);
if (serviceType != null && !serviceType.IsAbstract && !serviceType.IsInterface && serviceType.IsClass)
{
var services = ApplicationContext.GetObjectsOfType(serviceType).GetEnumerator();
services.MoveNext();
try
{
return services.Value;
}
catch (InvalidOperationException)
{
return null;
}
}
else
{
return base.GetService(serviceType);
}
}
/// <summary>
/// Resolves multiply registered services.
/// </summary>
/// <param name="serviceType">The type of the requested services.</param>
/// <returns>The requested services.</returns>
public override IEnumerable<object> GetServices(Type serviceType)
{
var services = ApplicationContext.GetObjectsOfType(serviceType).Cast<object>();
services.Concat(base.GetServices(serviceType));
return services;
}
Note that i escape interfaces and abstract classes so that I will get the default implementations of SignalR from the base DefaultDependencyResolver
and here I assigned the resolver using WebActivator:
public static void PostStart()
{
// Inject Dependencies to SignalR, should be always come before ASP.NET MVC configuration
var dependecyResolver = new SignalRSpringNetDependencyResolver(ContextRegistry.GetContext());
GlobalHost.DependencyResolver = dependecyResolver;
RouteTable.Routes.MapHubs();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
However, SignalR is always trying to resolve it's own dependencies using the Resolver i assigned and i get the following error:
'myhub' hub could not be resolved.
I only need the resolver to be aware of other dependencies(my Repository for example) and keep the default implementation of SignalR services.
I think it's hard to get Spring.Net working with SignalR
for the current version (Spring.Net 1.3.2) it's difficult to support asynchronous programming. Spring.Net session management doesn't play well with Task<T> types.
I ended up injecting my dependencies in 2 steps:
1- registering the required type on WebActivator PostStart:
GlobalHost.DependencyResolver.Register(
typeof(IUserService),
() => (UserService)ctx.GetObject("UserService"))
2- picking them up in my Hub constructor:
public MyHub()
{
_userService =
DependencyResolver.Current.GetService<IUserService>();
}

NinjectWebCommon Bindings in RegisterServices not working for me in WebApi

I create a new ASP.NET Web API project. I then use nuget to pull Ninject.Web.Common, then I download and build Ninject.Web.WebApi from here. Included it in the project. I added a service and the injection via constructor, setup binding (the debugger shows that the code actually hits the bind) but still throws this error:
Error activating IValueService
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency IValueService into parameter valueService of constructor of type ValuesController
1) Request for ValuesController
Suggestions:
1) Ensure that you have defined a binding for IValueService.
2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
3) Ensure you have not accidentally created more than one kernel.
4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
5) If you are using automatic module loading, ensure the search path and filters are correct.
Libraries in my project:
Ninject.dll
Ninject.Web.Common
Ninject.Web.Webapi
WebActivator
All ninject libraries are marked as version 3.
Here is the Code:
[assembly: WebActivator.PreApplicationStartMethod(typeof(MvcApplication3.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(MvcApplication3.App_Start.NinjectWebCommon), "Stop")]
namespace MvcApplication3.App_Start
{
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IValueService>().To<ValueService>();
}
}
}
service:
public interface IValueService
{
List<string> GetStrings();
}
public class ValueService : IValueService
{
public List<string> GetStrings()
{
return new List<string>{"test", "test"};
}
}
controller:
public class ValuesController : ApiController
{
private readonly IValueService valueService;
// GET /api/values
public ValuesController(IValueService valueService)
{
this.valueService = valueService;
}
}
The downloaded project sample from github works but not when I create a new project. Am I missing a step?
I just checked that there is no issue with this extension (at least not with the lastest MVC4 preview):
Create a new MVC4 WEB Api project
Nuget Install-Package Ninject.Web.WebAPI
Change controller + add bindings
Your code looks good. There must be a problem somewhere else.
Do not bind directly in RegisterServices but first create a class from
IDependencyResolver en add your bindings in AddBindings
example
See in book Pro ASP.NET MVC5 from Adam Freeman

WCF Data Service Partial class property on the client causes SaveContext exceptions

I have a WCF Data Service running that is exposing an EDM. There are several properties I needed on the client side, that the database doesn't need to know about. After setting all that up I got to testing the SaveContext method and get this error on the server "Error processing request stream. The property name 'CanDelete' specified for type 'DataModels.Customer' is not valid."
Is there a way to tell WCF Data Services on the client side to ignore this property? Or should I move to RIA Serivces? I've read that setting the property to internal will do this, but I need the property for binding and I have the client UI code in a different project (de-coupling my SL applications from my data service).
on the client I have:
public partial class Customer
{
private bool canDelete;
/// <summary>
/// Gets or sets a value indicating whether this instance can be deleted.
/// </summary>
/// <value>
/// <c>true</c> if this instance can delete; otherwise, <c>false</c>.
private bool canDelete;
/// <summary>
/// Gets or sets a value indicating whether this instance can be deleted.
/// </summary>
/// <value>
/// <c>true</c> if this instance can delete; otherwise, <c>false</c>.
/// </value>
public bool CanDelete
{
get
{
return this.canDelete;
}
set
{
if (this.canDelete != value)
{
this.canDelete = value;
this.OnPropertyChanged("CanDelete");
}
}
}
}
I had the exact same problem and adapted some code below from
extending partial designer classes
It simply involves hooking the WritingEntity Event inside a partial class of the Context.
I added my own attribute (IgnorePropertyAttribute) so I could attach it to other properties.
Would of course be nice if the attribute wasnt inserted in the first place but this worked for me
public sealed class IgnorePropertyAttribute : Attribute
{
}
...
partial void OnContextCreated()
{
this.WritingEntity += MyDataContext_WritingEntity;
}
private void MyDataContext_WritingEntity(object sender, System.Data.Services.Client.ReadingWritingEntityEventArgs e)
{
//
foreach (XElement node in e.Data.Elements())
{
if (node != null && node.Name.LocalName == "content")
{
foreach (XElement el in node.Elements())
{
if (el.Name.LocalName == "properties")
{
foreach (XElement prop in el.Elements())
{
if(e.Entity.GetType().GetProperty(prop.Name.LocalName).GetCustomAttributes(typeof(IgnorePropertyAttribute), true).Length > 0)
{
prop.Remove();
}
}
}
}
}
}
}

Designing an webtesting DSL to be implemented by different Web testing drivers - should we mix primitive and non-primitive operations?

We are implementing a web test automation project for some intranet applications.
To easy the writing of each test, we are designing a Java DSL that can be implemented using different adapters (we've chosen Sahi and Selenium/WebDriver so far, as we want to measure them side by side in terms of performance, readability, maintainability, etc.).
We've identified two types of operations in the DSL:
1) Primitive: its implementation will surely have to deal with HTML/Selenium/Sahi/etc specifics. Example: (using Sahi web driver)
public void insertProjectRecord(String projectName) {
b.link("Create new project").click();
b.textbox("ctl00$ProjectForm$Name").setValue(projectName);
b.span("Insert").click();
}
2) Non-Primitive: an operation worth including in our DSL for reusability purposes, although that can be built using primitives. Example:
public void createFormulation(String projectName, String rteDummyText) {
goToAddProjectPage();
insertProjectRecord(projectName);
switchToEditModeForFirstAvailableRecord();
editBeneficiaryCountries();
editAcronyms(rteDummyText);
saveSectionChanges();
}
Question: we initially started with an interface with only primitive operations, but later we changed it to an abstract class in order to include the non-primitive methods (which a specific implementations are allowed to override, if needed).
However, it doesn't feel "OK" to mix primitives and non-primitives, and the list of methods will certainly became very long.
What other approach would you suggest and/or explore?
I would highly recommend using the Page Object Model. In this you create a class for each page and then abstract items away.
I wrote a blog post on writing maintainable tests here.
You can see my blog post on the Page object model here
So your object could be like below.
public class Home
{
private readonly ISelenium _selenium;
/// <summary>
/// Instantiates a new Home Page object. Pass in the Selenium object created in the test SetUp().
/// When the object in instantiated it will navigate to the root
/// </summary>
/// <param name="selenium">Selenium Object created in the tests
public Home(ISelenium selenium)
{
this._selenium = selenium;
if (!selenium.GetTitle().Contains("home"))
{
selenium.Open("/");
}
}
/// <summary>
/// Navigates to Selenium Tutorials Page. Selenium object wll be passed through
/// </summary>
/// <returns>SeleniumTutorials representing the selenium_training.htm</returns>
public SeleniumTutorials ClickSelenium()
{
_selenium.Click("link=selenium");
_selenium.WaitForPageToLoad("30000");
return new SeleniumTutorials(_selenium);
}
/// <summary>
/// Click on the blog or blog year and then wait for the page to load
/// </summary>
/// <param name="year">blog or blog year
/// <returns>Object representing /blog.* pages</returns>
public Blog ClickBlogYear(string year)
{
_selenium.Click("link=" + year);
_selenium.WaitForPageToLoad("30000");
return new Blog(_selenium);
}
// Add more methods as you need them
}
public class SeleniumXPathTutorial
{
private readonly ISelenium _selenium;
public const string FirstInput = "number1";
public const string SecondInput = "number2";
public const string Total = "total";
public SeleniumXPathTutorial(ISelenium selenium)
{
this._selenium = selenium;
}
public bool IsInputOnScreen(string locator)
{
return _selenium.IsElementPresent(locator);
}
}
and then the test class would be like
[TestFixture]
public class SiteTests
{
private ISelenium selenium;
[SetUp]
public void Setup()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.theautomatedtester.co.uk");
selenium.Start();
}
[TearDown]
public void Teardown()
{
selenium.Stop();
}
[Test]
public void ShouldLoadHomeThenGoToXpathTutorial()
{
Home home = new Home(selenium);
SeleniumTutorials seleniumTutorials = home.ClickSelenium();
SeleniumXPathTutorial seleniumXPathTutorial = seleniumTutorials.ClickXpathTutorial();
Assert.True(seleniumXPathTutorial.
IsInputOnScreen(SeleniumXPathTutorial.FirstInput));
Assert.True(seleniumXPathTutorial
.IsInputOnScreen(SeleniumXPathTutorial.SecondInput));
Assert.True(seleniumXPathTutorial
.IsInputOnScreen(SeleniumXPathTutorial.Total));
}
}