Visual Studio: Cannot resolve event / custom event tooltip - angularjs

Odd that I can't find anyone else that has encountered this issue.
In Visual Studio I have a few custom events that I fire and listen to between applications on the same page. The event names aren't important but here they are: 'dd.clear', 'dd.select', 'dd.switch'.
I get a tooltip warning "Cannot resolve event 'dd.clear'". How can I fix this? I can use Resharper's inspection tool to disable it but I'd like a better solution. Can I define my custom events somewhere and if so how?
Thanks.

Visual Studio basic JavaScript Snippets seems not to know custom events. Install vscode-standardjs-snippets and you should be fine.
Note that this tooltip warning is nothing realy important. It does not mean that your codes are broken.

The solution I came through is to use the actual type property of the event object :
class Model extends EventTarget {
static topicChangedEvent = new Event("topicChanged");
constructor() {
super();
this.topic = "";
}
setTopic(topic) {
if (this.topic === topic)
return;
this.topic = topic;
this.dispatchEvent(Model.topicChangedEvent);
}
}
const model = new Model();
/* ... */
model.addEventListener(Model.topicChangedEvent.type, () => ...);

Related

PRISM IEventAggregator.GetEvent<>() deos not return the correct event

I am trying to get EventAggregator to work in my PRISM app. I know there are several tutorials and guides and discussions, but it seems non of them can address the issue I encounter. Here is my current setup.
I have several modules and each module has the functionality to open a new modal window. I need to open the modal window of module B from module A. Seems pretty straight-forward. I am attempting to use an IEventAggregator to fire an event from module B and catch it in module A and this is not working. After several hours of researching I decided to use the Shell to subscribe to all events because this would eliminate the possibility that the subscriber get garbage collected before the event is triggered. If the Shell is the subscriber it cannot be GCed because it is always active, right? Yes, but this is not working as well. Here is some code:
The event itself (note using PRISM 4.1):
public class OpenNewPurchaseWindowEvent : CompositePresentationEvent<Customer>
{
}
Subscribing in the Shell like this:
public ShellView(IEventAggregator eventAggregator)
{
this.eventAggregator = eventAggregator;
InitializeComponent();
var newPurchaseEvent = this.eventAggregator.GetEvent<PRISM.DbApp.Shared.OpenNewPurchaseWindowEvent>();
this.openNewPurchaseWindowEventToken = newPurchaseEvent.Subscribe(OpenNewPurchase);
}
And trying to fire the event from Module B:
var eventt = this.eventAggregator.GetEvent<PRISM.DbApp.Shared.OpenNewPurchaseWindowEvent>();
eventt.Publish(vm.SelectedCustomer);
In the constructor of this module I get the IEventAggregator:
public CustomersView(IEventAggregator eventAggregator)
{
this.eventAggregator = eventAggregator;
InitializeComponent();
this.DataContext = vm = new CustomersViewModel();
}
In theory this should be working, but it is not and I cannot understand why. Here is something interesting as well.
Event subscription goes well but when I try to trigger the event and inspect the IEventAggregator just before publishing the event I get this:
It seems like there are two events and one of them has 1 subscriber the other does not. Interestingly the GetEvent<>() returns the one that has 0 Subscribers thus publishing it has no effect.
Can anyone explain why this is happening? Are there any suggestions regarding the approach I am trying to implement? Is there any better approach?

Loading Application With Different Title on Load

Not sure if this is at all possible, but is there any way that, as soon as I start my application, that the title bar will change? So there is always a different title?
So, say my application title is called: Test Application: Instance 1, then ext time I load the application, the title will change to: Test Application: Instance 2, etc.
I am using Visual Studio Express 2015 for Windows Desktop.
I have just started this project, so has the default form load function:
namespace Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
This doesn't work = Form.load
I don't know what else to try or if it is at all possible.
So, I don't know if it is possible, because how do you know when to stop it counting? Or maybe only stop once it hits 10 application hits?
Basically, I want the same form, but a different title name.
Provide a handler for the Load event on your main form and set the Text property to the title you desire:
string newTitle = MethodWhichGeneratesTitleText();
this.Text = newTitle;
In this method you can check your database, config file or other sources that help you determine the title you need.

ADF Jdeveloper Refresh Parent Form on Popup close

I want to refresh(update few fields) on my parent form when OK button is clicked on Poup Dialog. But it does not refresh the fields. I have also set partialTriggers for the fields with Popup Id.
My Jdeveloper version is 11.1.1.7
Thanks
Umer Farooq
All you need is linking the OK button action (or action listener) property with a call through an EL to a method provided on a managed bean. Then, in it you should refresh either each component or just the form/parent component keeping all of them(by registering it's bind into a partial target of the ADF context). The method should be similar to this example:
public String refresh() {
AdfFacesContext.getCurrentInstance().addPartialTarget(formToRefresh);
return null;
}
private RichPanelFormLayout installDisable; //this should be the binding to the JSF form
public void setInstallDisable(RichPanelFormLayout installDisable) {
this.installDisable = installDisable;
}
public RichPanelFormLayout getInstallDisable() {
return installDisable;
}
I would need to see what you implemented in your code in order to provide you the "best" solution overall - as theres multiple ways to implement a dialog in a popup. However, here's a couple options depending on how your Popup Dialog is programmed:
Dialog Listener - use this if you use the built-in buttons of a dialog box. You'll need a managed bean for your jspx/jsf page. Create a Dialog Listener on your managed bean that is on your Dialog box. See below for a example of a dialog listener.
public void myDialogListener(DialogEvent dialogEvent) {
if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.yes)) {
// do something...
} else if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.no) {
//do something...
}
}
Return Listener - if you're running a task flow as a popup dialog, on your button, then add a ReturnListener to your page's managed bean. This fires whenever a your popup/dialog is closing.
public void myReturnListener(ReturnEvent returnEvent) {
//do something...
}
Otherwise, i'd add a an ActionListener to your manual button as Endrik suggests.
Now for refreshing your components, use this method in your managed bean, i use it all the time in my projects:
public void refreshComponent(UIComponent comp) {
RequestContext rContext = RequestContext.getCurrentInstance();
rContext.addPartialTarget(comp);
}
To use it, you need to bind your Form's UI components to a managed bean. Then feed in the UI Component's bean property into the method.
For example, below will refresh a Rich Output Text that i have bound to a managed bean:
private RichOutputText myOutputText;
public void refreshMyStuff() {
refreshComponent(myOutputText);
}
Have a good one.

WPF issue with updating

I have a strange issue. I wonder whether it's a standard behavior of the .NET components, and how to handle this.
Our app is using galasoft mvvm light. I have a form with a tree view, which is getting the data via an asynchronous call. And why that asynchronous task is running, we're showing a progress bar to the user. I'm using ObservableCollection as a collection for my tree structure. Now the problem:
This piece of code gives us the info:
public Task<ObservableCollection<FillingTreeNode>> GetTreeStructureAsync(SyncSettings settings)
{
SearchRequest request = BuildRequest();
return searchService.SearchRecordsAsync(request).ContinueWithConversion(
records => new ObservableCollection<FillingTreeNode>(records
.Select(cabinet => new FillingTreeNode
{
IsChecked = false,
DisplayName = cabinet.Fields[Fields.CabinetName].Value,
Node = cabinet.AsFillingNode(FillingNodeType.Cabinet),
NumberOfNodes = SendXmlRequest(record),
Children = new ObservableCollection<FillingTreeNode>(GetChildren (record));
}
}
This is the task extension to convert the result to some new type:
public static Task<TNew> ContinueWithConversion<TOld, TNew>(this Task<TOld> task, Func<TOld, TNew> conversionAction)
{
return task.ContinueWith(completedTask => conversionAction(task.Result));
}
Now the issue. The data is loaded from the server, the UI (the progress bar) says that the data is loaded, and only after that SendXmlRequest(record) (which is a bit long to wait) begins to work! But i expect that it's already done. The user sees nothing until those functions are finished working
Do you know what is the cause of the problem? Can that be the behavior of the Observable collection? How can i fix it?
Thank in advance.

Issue intercepting property in Silverlight application

I am using Ninject as DI container in a Silverlight application. Now I am extending the application to support interception and started integrating DynamicProxy2 extension for Ninject. I am trying to intercept call to properties on a ViewModel and ending up getting following exception:
“Attempt to access the method failed: System.Reflection.Emit.DynamicMethod..ctor(System.String, System.Type, System.Type[], System.Reflection.Module, Boolean)”
This exception is thrown when invocation.Proceed() method is called. I tried two implementations of the interceptor and they both fail
public class NotifyPropertyChangedInterceptor: SimpleInterceptor
{
protected override void AfterInvoke(IInvocation invocation)
{
var model = (IAutoNotifyPropertyChanged)invocation.Request.Proxy;
model.OnPropertyChanged(invocation.Request.Method.Name.Substring("set_".Length));
}
}
public class NotifyPropertyChangedInterceptor: IInterceptor
{
public void Intercept(IInvocation invocation)
{
invocation.Proceed();
var model = (IAutoNotifyPropertyChanged)invocation.Request.Proxy;
model.OnPropertyChanged(invocation.Request.Method.Name.Substring("set_".Length));
}
}
I want to call OnPropertyChanged method on the ViewModel when property value is set.
I am using Attribute based interception.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class NotifyPropertyChangedAttribute : InterceptAttribute
{
public override IInterceptor CreateInterceptor(IProxyRequest request)
{
if(request.Method.Name.StartsWith("set_"))
return request.Context.Kernel.Get<NotifyPropertyChangedInterceptor>();
return null;
}
}
I tested the implementation with a Console Application and it works alright.
I also noted in Console Application as long as I had Ninject.Extensions.Interception.DynamicProxy2.dll in same folder as Ninject.dll I did not have to explicitly load DynamicProxy2Module into the Kernel, where as I had to explicitly load it for Silverlight application as follows:
IKernel kernel = new StandardKernel(new DIModules(), new DynamicProxy2Module());
Could someone please help? Thanks
Reflection can be really tricky in silverlight because of security issues.
Check Gabe's answer for this question, it's the same problem.
The good news is that you can achieve the same functionality you want using dynamic instead of proxies. Just extend your ViewModel from DynamicObject and override the TrySetMember method.
I hope it helps :)

Resources