Visual Studio 2010 Extensions - visual-studio-2010

I'm writing my own abstract extension for Visual Studio 2010, it makes similary functionality as Ook Language Integration. I have a question, is it possibly to mix my own AutoCompletion with standart C++ autocompletion of VS? How to do it? Is in need to use libraries of VS and call some methods?

This is a very good example about adding features to C# intellisense.
First of all you should capture the completionSession and use it.
Like this snippet, but in C++
[Export(typeof(IIntellisensePresenterProvider))]
[ContentType("text")]
[Order(Before = "Default Completion Presenter")]
[Name("Object Intellisense Presenter")]
internal class IntellisensePresenterProvider : IIntellisensePresenterProvider
{
[Import(typeof(SVsServiceProvider))]
IServiceProvider ServiceProvider { get; set; }
#region Try Create Intellisense Presenter
#region Documentation
/// <summary>
/// Inject the IntelliSense presenter
/// </summary>
/// <param name="session"></param>
/// <returns></returns>
#endregion // Documentation
public IIntellisensePresenter TryCreateIntellisensePresenter(IIntellisenseSession session)
{
#region Validation (is C#)
const string CSHARP_CONTENT = "CSharp";
if (session.TextView.TextBuffer.ContentType.TypeName != CSHARP_CONTENT)
{
return null;
}
#endregion // Validation
ICompletionSession completionSession = session as ICompletionSession;
if (completionSession != null)
{
var presenter = new IntelliSenseViewModel(ServiceProvider, completionSession);
return presenter;
}
return null;
}
#endregion // Try Create Intellisense Presenter
}
Hope helps!

Related

Net Core NLog.Web "aspnet-request:header" property usage?

Is there any way to log all headers using "aspnet-request:header" property with one parameter? Or should I get headers one by one like "aspnet-request:header=MyHeader" and combine them into one parameter before insert? I have lots of headers and don't want to add them seperately, I need a quick way to log them if its possible.
Currently only one at once header is supported, as it calls
string header = httpRequest.Headers[this.Header]; see source
edit: you could plug it in NLog like this:
using System;
using System.Text;
using Microsoft.AspNetCore.Http;
using NLog.Config;
using NLog.LayoutRenderers;
using NLog.Web.Internal;
namespace NLog.Web.LayoutRenderers
{
/// <summary>
/// Render all headers for ASP.NET Core
/// </summary>
/// <example>
/// <code lang="NLog Layout Renderer">
/// ${aspnet-request-all-headers}
/// </code>
/// </example>
[LayoutRenderer("aspnet-request-all-headers")]
public class AspNetRequestAllHeadersLayoutRenderer : AspNetLayoutRendererBase
{
protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
{
var httpRequest = HttpContextAccessor.HttpContext.TryGetRequest();
if (httpRequest == null || httpRequest.Headers == null)
{
return;
}
foreach(var kpv in httpRequest.Headers)
{
if (header != null)
{
builder.Append(kpv.Key);
builder.Append(=);
builder.Append(kpv.Value);
}
}
}
}
}
Register it (startup.cs)
ConfigurationItemFactory.Default.LayoutRenderers
.RegisterDefinition("aspnet-request-all-headers", typeof(AspNetRequestAllHeadersLayoutRenderer ));
See also Extending NLog
usage
${aspnet-request-all-headers}

Extending Umbraco ProfileModel with custom member model

I have the following code while updating the member account detail information:
/// <summary>
/// Verifies and edits the member fields.
/// </summary>
/// <param name="model"></param>
/// <returns>MemberDetailsFormViewModel containing all the editable information.</returns>
[Authorize]
public ActionResult HandleUpdateMemberDetails(MemberDetailsFormViewModel model)
{
if (ModelState.IsValid == false)
{
return CurrentUmbracoPage();
}
var memberService = Services.MemberService;
var member = memberService.GetById(Members.GetCurrentMemberId());
member.Properties[Constant.PropertyAlias.Authentication.FirstName].Value = model.FirstName;
member.Properties[Constant.PropertyAlias.Authentication.LastName].Value = model.LastName;
member.Properties[Constant.PropertyAlias.Authentication.AddressLine1].Value = model.AddressLine1;
member.Properties[Constant.PropertyAlias.Authentication.AddressLine2].Value = model.AddressLine2;
member.Properties[Constant.PropertyAlias.Authentication.TownCity].Value = model.TownCity;
member.Properties[Constant.PropertyAlias.Authentication.PostCode].Value = model.PostCode;
member.Properties[Constant.PropertyAlias.Authentication.County].Value = model.County;
member.Properties[Constant.PropertyAlias.Authentication.Country].Value = model.Country;
member.Properties[Constant.PropertyAlias.Authentication.PhoneNumber].Value = model.PhoneNumber;
memberService.Save(member);
if (Members.IsLoggedIn())
{
ViewBag.DetailSuccessfullyChanged = 1;
return CurrentUmbracoPage();
}
return View("/");
}
Although this solution works, I would like to do more elegant updating of the member.Properties["propertyName"].Value through extended ProfileModel with the following method of MembershipHelper: UpdateMemberProfile(ProfileModel model).
Useful links:
MembershipHelper documentation link.
Similar issue on OUR Umbraco
Has anyone managed to do something like this?
EDIT:
I see that Warren did something similiar on his GitHub.

Instantly Update Property in MVVM Light?

I have a property in my View Model
public const string WelcomeTitlePropertyName = "WelcomeTitle";
private string _welcomeTitle = string.Empty;
/// <summary>
/// Gets the WelcomeTitle property.
/// Changes to that property's value raise the PropertyChanged event.
/// </summary>
public string WelcomeTitle
{
get
{
return _welcomeTitle;
}
set
{
RaisePropertyChanging(WelcomeTitlePropertyName);
_welcomeTitle = value;
RaisePropertyChanged(WelcomeTitlePropertyName);
}
}
This is hooked up to a textbox and has 2 way binding.
Now I have a KeyDown event that I need to get the current length of the "WelcomeTitle" property
public ICommand AutoComplete
{
get
{
return new RelayCommand<KeyEventArgs>(e =>
{
var length = WelcomeTitle.Length;
});
}
}
Yep what I am finding is that WelcomeTitle property does not get updated till the user leaves the textbox. This does not work for me as I need to know the length(and later the current value in WelcomeTitle) and keydown.
How can I get around this? In codebehind this is no problem.
In WPF it would be easily achieved by setting UpdateSourceTrigger="PropertyChanged" in the binding; unfortunately, this is not possible with Windows Phone, so you need a workaround. A few options are described in this question.

Where do I add a behavior to a single Region?

My problem is very simple, but all the options confuse me...
In my MEF/Prism-application, I want to attach a specific behavior to one specific region. The doumentation says, that you can do it that way:
IRegion region = regionManager.Region["Region1"];
region.Behaviors.Add("MyBehavior", new MyRegion());
But where should I put this? Is there some place, this is supposed to be done in a bootstrapper method? Currently, I am adding the behavior like this in the Loaded-event of the shell:
/// <summary>
/// Interaction logic for Shell.xaml
/// </summary>
[Export(typeof(Shell))]
public partial class Shell
{
[ImportingConstructor]
public Shell(IRegionManager regionManager, ElementViewInjectionBehavior elementViewInjectionBehavior)
{
InitializeComponent();
Loaded += (sender, args) =>
{
IRegion region = regionManager.Regions[RegionNames.ElementViewRegion];
region.Behaviors.Add("ElementViewInjection", elementViewInjectionBehavior);
};
}
}
Is this a good solution. I'd rather do it in the bootstrapper, so that it is done in the same place as the other region behavior registrations (ConfigureDefaultRegionBehaviors()).
So, the question: Where is the best place to add the behavior to one single region?
I just came up with a slightly improved solution, using a static string collection in the behavior to add the regions to attach the behavior to.
public class ViewModelInjectionBehavior : RegionBehavior, IDisposable
{
private static List<string> _regionNames;
public static List<string> Regions
{
get { return _regionNames ?? (_regionNames = new List<string>()); }
}
protected override void OnAttach()
{
if (Regions.Contains(Region.Name)) {...}
}
}
Then in my bootstrapper, I can define the regions:
protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
{
var behaviorFactory = base.ConfigureDefaultRegionBehaviors();
ViewModelInjectionBehavior.Regions.Add(RegionNames.ElementViewRegion);
behaviorFactory.AddIfMissing("ElementViewInjectionBehavior", typeof(ViewModelInjectionBehavior));
return behaviorFactory;
}
At least, the behavior is universally usable now...
We had the same issue - in the end we just checked the region name in the region behaviour and acted only if it was that region that we wanted, kind of sucks because you are attaching the behaviour to all regions - but for us it was better than the suggested solution..
An example looks like :
public class TrackViewOpenerBehaviour : IRegionBehavior
{
public IRegion Region { get; set; }
public void Attach()
{
if (this.Region.Name == ApplicationRegions.WorkspaceRegion
|| this.Region.Name == ApplicationRegions.DialogRegion)
{
this.Region.Views.CollectionChanged += (sender, e) =>
{
//Code Here.
};
}
}
}
I always thought maybe we could create a behaviour that was responsible for attaching other behaviours to specfiic regions for us, then we could register that in the bootstrapper - but never got round to it.

VS2008 Windows Form Designer does not like my control

I have a control that is created like so:
public partial class MYControl : MyControlBase
{
public string InnerText {
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
public MYControl()
{
InitializeComponent();
}
}
partial class MYControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(28, 61);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0;
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(7, 106);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 95);
this.listBox1.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(91, 42);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 2;
this.label1.Text = "label1";
//
// MYControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label1);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.textBox1);
this.Name = "MYControl";
this.Size = new System.Drawing.Size(135, 214);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
}
MyControlBase contains the definition for the ListBox and TextBox. Now when I try to view this control in the Form Designer it gives me these errors:
The variable 'listBox1' is either
undeclared or was never assigned.
The variable 'textBox1' is either
undeclared or was never assigned.
This is obviously wrong as they are defined in MyControlBase with public access. Is there any way to massage Form Designer into allowing me to visually edit my control?
I think you'll have to use base.listBox1 and base.textBox1. They are defined in MyControlBase which is the base class, not the child class where you need to use the this keyword.
Dunno if this is your problem, but the designer has trouble when multiple types are defined in the same .cs file. If this is the case, try using a .cs file for each class.
Sometimes (always?) VS needs you to recompile your project before it can successfully display your usercontrol in the designer.
Also take into account that the VS designer actually loads up and instantiates your control to show it on the form. Your code is actually running in the background. However it will not have all the things it might expect to be there - like some global application variables or even other things on the same form. Your control has to be prepared for the "design mode". Otherwise if it generates an exception the designer will not show it. There was a property on every control (don't remember the name, but you should find it easily) that allowed you to determine if the control is in "design mode" or actually running.
The compiler is right (as it tends to be).
Neither textbox1 nor listbox1 are defined in the source code. They don't appear in either the derived class or the base class.
You should add the following to your base class:
protected System.Windows.Forms.TextBox textbox1;
protected System.Windows.Forms.ListBox listbox1;
You'll also need to do the changes outlined by Nazgulled if you decide to use private instead of protected for textbox1 and listbox1.

Resources