TFS GetService in Outlook add-in run once - c#

I want to attach a message from outlook in TFS workitem, so I created a small add-in in outlook to attach a message to workitem.
every thing is work fine, but it's work just once.
when i want to attach a message to a workitem, i've open a window form and select the workitem and attach the message. even though when the form closed it's wont be open again.
i check every thing and i found the problem : when i use tfsTeamProjectCollection.GetService(); the form wont be open again.
also I tried to put GetService in the startup, the Click event of button wont work.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
TeamConfigurations = new Configuration();
_inspectors = Application.Inspectors;
TeamConfigurations.TempFolder = #"C:\EntekhabTfsOutlook\";
LoadSetting();
CheckTempFolder();
AddMenuBar();
}
and the click event
private void AddMailToAttachment_Click(CommandBarButton ctrl, ref bool cancelDefault)
{
var explorer = Application.ActiveExplorer();
var selection = explorer.Selection;
var frm = new FrmWorkItemSelector(selection);
frm.ShowDialog();
}
and finally
var tfsTeamProjectCollection = new TfsTeamProjectCollection(new Uri(url))
{
ClientCredentials = new TfsClientCredentials(true)
};
var workService = tfsTeamProjectCollection.GetService<WorkItemStore>();
i couldn't find the problem.
p.s: i don't want to use another add-in like http://www.teamsystemsolutions.com/teamlook/features/microsoft-outlook-integration.aspx Or another 3rd party tools.

the problem is not related to tfs
I chnage the Create toolbar method , it's work
http://msdn.microsoft.com/en-us/library/ms268864(v=vs.90).aspx

Related

VSTO Add-In CustomTaskPane opens itself after upgrading to Word 2016/2019

We've developed a Word VSTO Add-In for Word 2010 with CustomTaskPanes and MVVM Support through VSTOContrib.
After upgrading to Word 2016/2019 our CustomTaskPanes show up randomly without any action from the user.
It seems like that Word notices when a CustomTaskPane was used and wants to (re)open it automatically the next time.
For example, a CustomTaskPane opens while opening a new/exisitng document. Wouldn't be that bad, if it wouldn't glitch (open, close, open, close, ...) till it closes or stays open.
If the CustomTaskPane stays open, it is unusable because it has no DataContext that was loaded by our Add-In.
This Code in ThisAddIn creates/removes CustomTaskPanes:
public CustomTaskPane AddTaskPane(UserControl userControl, string title, Window owner)
{
return CustomTaskPanes.Add(userControl, title, owner);
}
public void RemoveTaskPane(CustomTaskPane taskPane)
{
if (taskPane == null)
return;
CustomTaskPanes.Remove(taskPane);
}
The RibbonViewModel (ViewModel per Document/Window) calls the Code like this.
The _addInHelper has events for creating/removing CustomTaskPanes to reach the ThisAddIn Code and returns the CustomTaskPane instance by callback. It also uses the IoC Container to resolve the view "CustomTaskPaneView".
// Gets called when a new Window opens or a new Document is opened
public override void Intialize(Document document)
{
// ...
CreateCustomTaskPane();
// ...
}
private void CreateCustomTaskPane()
{
if (_customTaskPane != null)
return;
_addInHelper.AddTaskPane("CustomTaskPaneView", "Custom headline", CurrentWindow, result =>
{
_customTaskPane = result;
});
if (_customTaskPane == null)
{
_log.Error(...);
return;
}
_customTaskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
_customTaskPane.Width = Settings.Default.TaskPaneWidth;
_customTaskPane.DockPosition = Settings.Default.TaskPanePosition;
// TaskPane height and width are saved seperately for DockPositionFloating
if (_customTaskPane.DockPosition != MsoCTPDockPosition.msoCTPDockPositionFloating)
{
// Set height and width for DockPositionFloating.
// If the user drags the TaskPane to Floating, it will have the correct size.
var oldDockPosition = _customTaskPane.DockPosition;
_customTaskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionFloating;
_customTaskPane.Height = Settings.Default.TaskPaneHeight;
_customTaskPane.Width = Settings.Default.TaskPaneWidth;
_customTaskPane.DockPosition = oldDockPosition;
}
else
{
_customTaskPane.Height = Settings.Default.TaskPaneHeight;
_customTaskPane.Width = Settings.Default.TaskPaneWidth;
}
// Saving/updating settings in these
_customTaskPane.VisibleChanged += ContentControlsTaskPane_OnVisibleChanged;
_customTaskPane.DockPositionChanged += ContentControlsTaskPane_OnDockPositionChanged;
}
When closing the Window/Document, this code is called:
public override void Cleanup()
{
if (_customTaskPane != null)
{
SaveCustomTaskPaneProperties();
_contentControlsTaskPane.VisibleChanged -= ContentControlsTaskPane_OnVisibleChanged;
_contentControlsTaskPane.DockPositionChanged -= ContentControlsTaskPane_OnDockPositionChanged;
// Checks if the COM Object was cleaned up already
if (!_contentControlsTaskPane.IsDisposed())
{
// Tried to manually close the CustomTaskPane, but didn't help either
if (_contentControlsTaskPane.Visible)
_contentControlsTaskPane.Visible = false;
// Cleanup the CustomTaskPane ViewModel instance
var taskPaneViewModel = _contentControlsTaskPane.GetViewModel();
taskPaneViewModel?.Dispose();
_addInHelper.RemoveTaskPane(_contentControlsTaskPane);
}
}
}
This only happens while using Word 2016 and 2019 (we don't use 2013) and didn't happen with Word 2010 at all.
After upgrading the VSTO Project to VSTO Add-In 2013 and 2016 for testing purposes, it doesn't get better.
Example:
I didn't find any Word options that could cause this.
Any idea what this could cause and how to fix this / getting a workaround?
EDIT
Here is the updated code example WordTaskPanesBug
Steps to reproduce:
Start Word / run project
Click "Open" button
Click "New document" button
Click "New document" button, TaskPane gets opened (but won't glitch this time)
Also the CustomTaskPane glitches while closing the document in the example project, but not in our real project.
Old example gif
I added indices to indicate which task pane is being displayed, which showed that the task pane being added when you create a new document the second time is from the first document (the one that closes when you create a new document for the first time, probably because it's empty).
I think the problem you're running into is this one: Creating and managing custom task panes for multiple documents in a VSTO Word addin

ASP.NET How to open a second popup on close() event of first

I want to open a popup window with some parameters inside and then open a new one (or even more than one) with different parameters, after the user closes the first.
It should be like a foreach loop where it waits for the closing event before opening a new window.
I'm using .NET Framework v3.5.
foreach (object o in ObjectsList)
{
// Do some stuff...
// Set query string for popup
string queryString = string.Format("Page.aspx?doc={0}, o.ID);
string urlDownload = Page.ResolveClientUrl(string.Format("~/Path/To/Folder/{0}", queryString));
string script = string.Format("loadDownload('{0}','_blank',600,600);", urlDownload);
// Open popup window
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "DocID" + o.ID, script, true);
// Wait for popup close event before proceeding...
}
These links might be of good use to you.
http://aspdotnetcodebook.blogspot.com.au/2009/03/how-to-open-modalpopup-inside.html
http://www.codeproject.com/Articles/546817/ASP-NET-Popup-Control-Displaying-as-multiple-neste
I would have registered to the Closed/disposed event and handle all there, that means
ObjectsList
will be an instance of your class, where you have an indexer, let say i which tells you in which you are:
int i
void frm_disposed(object sender, EventArgs e)
{
showFrm(ObjectsList[++i];
}

C# .NET Window won't show in front after double clicking on listview row

I have this one problem that I can't get over. I think it will be something really simple but I just was not able to find out.. I am trying to open new window here for editing contact when user double click on one row in listview. Window normally opens but the problem is it won't open in front of current main window but behind it so it is not visible and can easily confuse user. I have tried few methods like BringIntoView() or playing with focus but nothing helped.
Please help me with this. Thanks!
Code:
void ListViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
editContact();
}
private void editContact()
{
Window1 win = new Window1("edit");
DatabaseHandler handler = new DatabaseHandler();
win.Show();
List<Contact> listie = handler.GetContactList();
var selected = listview_contacts.SelectedItem as Contact;
win.textbox_id.Text = selected.cId.ToString();
win.textbox_name.Text = selected.Name.ToString();
win.textbox_address.Text = selected.Address.ToString();
win.textbox_email.Text = selected.Email.ToString();
win.textbox_name.Focus();
win.textbox_name.SelectionStart = win.textbox_name.Text.Length;
}
private void editContact()
{
using(Window1 win = new Window1("edit"))
{
DatabaseHandler handler = new DatabaseHandler();
List<Contact> listie = handler.GetContactList();
var selected = listview_contacts.SelectedItem as Contact;
win.textbox_id.Text = selected.cId.ToString();
win.textbox_name.Text = selected.Name.ToString();
win.textbox_address.Text = selected.Address.ToString();
win.textbox_email.Text = selected.Email.ToString();
win.textbox_name.Focus();
win.textbox_name.SelectionStart = win.textbox_name.Text.Length;
win.ShowDialog();
// do something with whatever win1 did.
// if its say OK Cancrl form
// if (win.ShowDialog() == DialogResult.OK) { // do something }
}
}
Will probably fix your issue. However without seeing the rest of your code, or knowing your intent, I can't tell you exactly how badly you've gone wrong.
For example at least all the code setting up win.textbox, should be in win...
Try
win.ShowDialog();
Which should open the new windows as a modal window.
You could try
win.Show(this);
This will enable the user to interact with the main form when your editing dialog opens.
Or you can try
win.ShowDialog();
This will block the main form when your editing dialog opens.

Webkit.Net wait for page to be fully loaded

I'm trying to make an C# windows form application, with an webbrowser.
I'm using the webkit browser: Link to the browser
The webbrowser did i put in an class file, so i can acces it through all the forms i'm going to use.
The code that's generate the webbrowser:
public static WebKit.WebKitBrowser mainBrowser = new WebKitBrowser();
I'm having this piece of code that give's some problems:
globalVars.mainBrowser.Navigate("http://www.somesite.com/");
while (globalVars.mainBrowser.IsBusy)
{
System.Threading.Thread.Sleep(500);
}
globalVars.mainBrowser.Document.GetElementById("user").TextContent = "User Name";
But it's not working. If i do an message box after the while, it shows up before it's possible to render the page...
So what is the best way to wait until the site is fully loaded?
UPDATE 1
In an standalone class file, am i making the webkit controll like this:
public static WebKit.WebKitBrowser mainBrowser = new WebKitBrowser();
And in an form, i've got now this code (thanks to Tearsdontfalls):
public void loginthen()
{
globalVars.mainBrowser.DocumentCompleted += mainBrowser_DocumentCompleted;
globalVars.mainBrowser.Navigate("http://www.somesite.com/");
}
void mainBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var send = sender as WebKit.WebKitBrowser;
if (send.Url == e.Url)
{
MessageBox.Show("Inloggen");
globalVars.mainBrowser.Document.GetElementById("user").TextContent = "User Name";
}
}
But no messagebox shows up. But if i use an local (on the same form) webkit browser, i'm getting te MessageBox. But then the user field isn't filled in.
Even an breakpoint in the documentCompleted event, isn't triggerd. So it looks like the event listner isn't working...
So why is it not working?
You can simply create an event listener on the Document Completed Event on your Webbrowser, or you can create it dynamically like that:
globalVars.mainbrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(mainbrowser_DocumentCompleted);
Where mainbrowser_DocumentCompleted is the name of the void where you can do sth like this(I used the names of your provided code):
void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
var send = sender as WebKit.WebKitBrowser;
if (send.Url == e.Url) {
globalVars.mainBrowser.Document.GetElementById("user").TextContent = "User Name";
}
}
Adding the following piece of code let the events fire when the browser is in invisible mode.
using (Bitmap bmp = new Bitmap(webKitBrowser.Width, webKitBrowser.Height))
{
webKitBrowser.DrawToBitmap(
bmp,
new Rectangle(
webKitBrowser.Location.X,
webKitBrowser.Location.Y,
webKitBrowser.Width,
webKitBrowser.Height
)
);
}

C# VSTO-Powerpoint-TaskPanes in separate windows.

I'm creating a VSTO for my company, and have ran across a interesting issue that I could use some help with. I will try to explain this to the best of my ability. I have the AddIn set up right now for it to create 2 customTaskPanes upon start up via Application.AfterNewPresentation events. And the ability to hide/show these based on user input from togglebuttons on the Ribbon.
Now when I fire up the first PowerPoint 2010 called "Presentation1" everything works great, I can show/hide the TaskPanes and everything inserts the way it should. Now then I open up a second template called "Presentation2"(to help keep things straight here) Everything works great again, I can show/hide the TaskPanes and everything inserts fine. If I go back to "Presentation1" the inserts and everything functions fine, but when I got to hide/show the TaskPanes it hides/shows them on "Presentation2". And if I create a "Presentation3" the same thing will happen but both "Presentation1" and "Presentation2" control "Presentation3" TaskPanes. And if I close the "Presentation2" and "Presentation3" the "Presentation1" buttons do not show/hide anything at all.
Code in the ThisAddIn
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.AfterNewPresentation += new PowerPoint.EApplication_AfterNewPresentationEventHandler(Application_AfterNewPresentation);
}
private void Application_AfterNewPresentation(PowerPoint.Presentation Pres)
{
PowerPoint.Application app = Pres.Application;
PowerPoint.DocumentWindow docWin = null;
foreach (PowerPoint.DocumentWindow win in Globals.ThisAddIn.Application.Windows)
{
if (win.Presentation.Name == app.ActivePresentation.Name)
{
docWin = win;
}
}
this.myWebForm = new SearchWebForm();
this.myWebFormTaskPane = this.CustomTaskPanes.Add(myWebForm, "Search ",docWin);
this.myWebFormTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
this.myWebFormTaskPane.Width = 345;
this.myWebFormTaskPane.VisibleChanged += new EventHandler(WebFormTaskPane_VisibleChanged);
}
private void WebFormTaskPane_VisibleChanged(object sender, System.EventArgs e)
{
Globals.Ribbons.Ribbon1.searchButton.Checked = myWebFormTaskPane.Visible;
if (Globals.Ribbons.Ribbon1.searchButton.Checked == true)
{
myWebForm.SearchForm_Navigate();
}
}
And then this is in the ribbon
private void searchButton_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.WebFormTaskPane.Visible = ((RibbonToggleButton)sender).Checked;
}
In PowerPoint 2007, custom task panes are shared across all presentation windows. If you want to have separate task panes assigned to each presentation you need to handle the corresponding events (WindowActivate, PresentationClose, etc.). You would also need to manage a list of all the task panes that you've created so you can show/hide the appropriate one. This is actually a well-known Outlook pattern frequently referred to in VSTO-world as InspectorWrappers - or in your case a DocumentWindowWrapper.
This has been changed for Powerpoint 2010 and now each taskpane is associated with a specific window. See this article.
Your error is that Globals.ThisAddIn.WebFormTaskPane does not necessarily correspond to the current presentations task pane - you need to lookup the proper task pane in your managed list (as mentioned above). When you create a new task pane (AfterNewPresentation), add it to your CustomTaskPane collection and provide a means of retrieving it.
public partial class ThisAddIn
{
private Dictionary<PowerPoint.DocumentWindow, DocumentWindowWrapper> pptWrappersValue =
new Dictionary<PowerPoint.DocumentWindow, DocumentWindowWrapper>();
}

Categories