Outlook add-in : programmatically perform an “advanced Find” on the “SelectNamesDialog” - c#

In my Outlook Add-In I’m bringing up the SelectNamesDialog to select a contact set on GAL. I would like to perform an Advance Find in order to look for Example for contact of a particular Company (See Screenshot).
Do you know if this is something that is actually doable? Is there an interface I’m Missing? You can look at my code with some unsuccessful ties out.
Outlook.SelectNamesDialog snd = Globals.ThisAddIn.Application.Session.GetSelectNamesDialog();
Outlook.AddressList contactsAddrList = null;
Outlook.AddressList gal = Globals.ThisAddIn.Application.Session.GetGlobalAddressList();
String company = "My Company";
// Try to look > Dead code not working
//Outlook.MAPIFolder galFolder = Globals.ThisAddIn.Application.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.);
//String sScope = "SCOPE ('shallow traversal of " + (char)34 + + (char)34 + "')";
//String sFilter = (char)34 + "urn:content-classes:person" + (char)34 + " LIKE 'RE:%'";
//Outlook.Search search = Globals.ThisAddIn.Application.AdvancedSearch(sScope, sFilter, false, company);
//contactsAddrList = search.Save(company).;
// Set InitialAddressList to Contacts folder AddressList.
snd.SetDefaultDisplayMode(Outlook.OlDefaultSelectNamesDisplayMode.olDefaultSingleName);
snd.InitialAddressList = contactsAddrList;
snd.AllowMultipleSelection = false;
snd.ForceResolution = true;
snd.ShowOnlyInitialAddressList = true;
snd.Display();

There is no way to invoke this the Outlook Object Model or even Redemption.
You can do this on the Extended MAPI level (C++ or Delphi) - open the PR_SEARCH property as IMAPIContainer, set various properties (PR_DISPLAY_NAME, PR_ACCOUNT, etc.), then call IMAPIContainer::GetContentsTable.

Related

Process.GetCurrentProcess().MainWindowTitle of Revit retrieves empty string ""

I am creating a plugin for Revit that registers several events within its application.
For every time an event happens, a line is writen on a txt file telling me about the event such as:
The user opened a document on Autodesk Revit 2019 (...)
I am obtaining the "Autodesk Revit 2019" (name of application) by getting the name of the MainWindowTitle of the application like so: Process.GetCurrentProcess().MainWindowTitle
public static string originalString = Process.GetCurrentProcess().MainWindowTitle;
(...)
Trace.WriteLine("O utilizador " + Environment.UserName + " abriu o " + originalString + " a " + DateTime.Now + " (ApplicationInitializedEventArgs)");
Which writes in the txt file:
O utilizador rita.aguiar abriu o a 20/09/2018 10:36:42 (ApplicationInitializedEventArgs)
As you can read, it did not write on the txt file "Autodesk Revit 2019 - [Home]" between the words "o" and "a" as I hoped for.
If I had writen Process.GetCurrentProcess().MainWindowTitle directly on the Trace.WriteLine I would have obtained "Autodesk Revit 2019 - [Home]", but I wish to write an assigned name instead.
How to successfully write "Autodesk Revit 2019 - [Home]" by assigning a name to Process.GetCurrentProcess().MainWindowTitle?
Later I would like to obtain this name by instead getting just Autodesk Revit 2019 like so:
public static string originalString = Process.GetCurrentProcess().MainWindowTitle;
public static string[] splittedString = originalString.Split("-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
public static string AppName = splittedString[0];
Any help would be appretiated!
As I suggested answering your similar question on assigning a name to a string C# in the Revit API discussion forum, I would look at the code executing step by step in the debugger.
Then you can see for yourself exactly what is going on.
You could also add some more intermediate lines and variables for absolute clarity:
string originalString = Process
.GetCurrentProcess()
.MainWindowTitle;
string s2 = "O utilizador "
+ Environment.UserName
+ " abriu um documento no "
+ originalString + " a " + DateTime.Now;
//or use string interpolation:
//https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated
string s3 = $"O utilizador {Environment.UserName} abriu um documento no {originalString} a {DateTime.Now}";
Trace.WriteLine( s2 );
Trace.WriteLine( s3 );
The debugger is good!
Invaluable, in fact.
Some of the comments on the discussion how to determine Revit demo mode show how you can access the Revit main window title.
To be able to store the Main Window Title in a name of type string I had to first declare each string outsite of the methods I am using:
string originalString;
string[] splittedString;
string AppName;
After declaring each string name I obtained the Application Name "Autodesk Revit 2019" by including each definition inside the first private method, which was created to register when the Revit application is opened. This had to be done inside a method because it is only after the application is launched that we can access the MainWindowTitle. This is the reason why I was getting an empty string "" when trying to obtain the MainWindowTitle the moment the application is starting to launch, but before it has completely launched and thus opened a Window with such Title.
private void DumpEventArgs(ApplicationInitializedEventArgs args_initialized)
{
originalString = Process.GetCurrentProcess().MainWindowTitle;
splittedString = originalString.Split(new[] { " -" }, StringSplitOptions.RemoveEmptyEntries);
AppName = splittedString[0];
//StreamWriter file = new StreamWriter("C://Users//" + Environment.UserName + "//AppData//Roaming//Autodesk//" + Environment.UserName + ".txt", append: true);
//MessageBox.Show($"O utilizador {Environment.UserName} iniciou o {AppName} a {DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}");
file.WriteLine($"{Environment.UserName},{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")},{AppName},iniciar");
}
And I could use this same string later when required because it has been declared outside the method, for example here I needed to write AppName again:
private void DumpEventArgs(DocumentSavedEventArgs args_saved)
{
//StreamWriter file = new StreamWriter("C://Users//" + Environment.UserName + "//AppData//Roaming//Autodesk//" + Environment.UserName + ".txt", append: true);
//MessageBox.Show($"O utilizador {Environment.UserName} guardou um documento no {AppName} a {DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}");
file.WriteLine($"{Environment.UserName},{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")},{AppName},guardar");
}
Finally AppName retrieves what I wanted: "Autodesk Revit 2019".

Is there a way to add custom work item type programmatically in TFS c#?

I am able to add Custom Work Item Type in Visual studio with Power Tools.
I need to automate this.
Able to interact which TFS API by the below code.
Uri collectionUri = new Uri(txtPreview.Text);
NetworkCredential credential = new NetworkCredential(txtUserName.Text.Trim(), txtPassword.Text.Trim());
teamProjectCollection = new TfsTeamProjectCollection(collectionUri, credential);
teamProjectCollection.EnsureAuthenticated();
WorkItemStore workItemStore = teamProjectCollection.GetService<WorkItemStore>();
Query query = new Query(this.workItemStore,
" SELECT [System.Id], [System.WorkItemType]," +
" [System.State], [System.AssignedTo], [System.Title] " +
" FROM WorkItems Where [System.WorkItemType]='" + cmbTFSTypes.SelectedItem.ToString() + "'" +
"AND [System.TeamProject]='" + cmbProjects.SelectedItem.ToString() + "'" +
" ORDER BY [System.WorkItemType], [System.Id]"
);
WorkItemCollection workItemCollection = query.RunQuery();
Able to add get fields from TFS work item like User story
if(workItemStore.Projects[projectIndex].WorkItemTypes[cmbTFSTypes.SelectedIndex] != null)
{
foreach (FieldDefinition Fd in workItemStore.Projects[projectIndex].WorkItemTypes[cmbTFSTypes.SelectedIndex].FieldDefinitions)
{
}
}
From above code allow us to access list of fields. If some custom field says "XId" is not available , need to add to TFS then make enter to "User story"
Kindly Help.
You can automatically add an work item type by using the witadmin command line tools. Command sample:
cd %programfiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE\
witadmin importwitd /collection:http://mytfs:8080/tfs/MyCollection /p:MyTFSProject /f:c:\foo\mycustomworkitemtype.xml
You need to:
Export work item type template via API: https://msdn.microsoft.com/en-gb/library/microsoft.teamfoundation.workitemtracking.client.workitemtype.export.aspx This method returns a XmlDocument document.
Analyze and edit content in XmlDocument document.
Import work item type template via API: https://msdn.microsoft.com/en-gb/library/microsoft.teamfoundation.workitemtracking.client.workitemtypecollection.import.aspx

Facebook feed story not posting when user input's nothing

The title pretty much says it all. A few days ago the FB.Feed was working normally. The user could hit the share button and simply post the pre made feed story to his timeline. Now there has to be some sort of user input involved in order for the story to get posted. Even if its just a white space. Has facebook changed something or what ?
here is the feed method :
if (FB.IsLoggedIn)
{
int shareScore = m_score.globalScore;
string shareMsg1 = "SAmple msg";
string shareMsg2 = "Sample msg2";
if (gameOverFlag)
{
shareScore = m_score.scoreForPost;
shareMsg1 = "game overmsg1";
shareMsg2 = "gameover msg2 ";
}
FB.Feed(
link: "test.com",
linkName: shareMsg1 + (DataHolder.holder.levelIndex + 1).ToString() + " FuBar",
linkDescription: "Some text",
linkCaption: shareMsg2 + shareScore + " and " + score.ToString() + " Stars",
picture: "test.com/test.jpg",
callback: LogCallback
);
}
else
{
FB.Login("public_profile,user_friends,email,publish_actions", LoginCallback);
}
I replaced the proper links with the fictional test.com in the given example.

SharpSVN Repo-Browser

Viewing the repository data of TortoiseSVN is done by right click on a file -> TortiseSVN -> Repo-Browser.
I would like to get this data using SharpSVN, in order to retrieve the name of lock owner.
Is it possible? How? Where does this data being saved?
I've tried to get a lock owner name using the following code, however, I get the lock infirmation just in case I'm on the machine where the lock was done from. If I'm another user, I cannot get the lock information.
using (SvnClient client = new SvnClient())
{
client.GetInfo(#"path\to\working\copy\file.xml", out info);
SvnLockInfo lc = info.Lock;
if (lc != null)
{
MessageBox.Show("Owner: " + lc.Owner + "\n" +
"Creation time: " + lc.CreationTime + "\n" +
"Comment: " + lc.Comment + "\n" +
"Expiration time: " + lc.ExpirationTime);
}
}
Even when I set the target as the repository URI- instead of path to the local working copy I get the same result:
Uri target = client.GetUriFromWorkingCopy(#"path\to\working\copy\file.xml");
client.GetInfo(target, out info);
The way I can see the lock owner name from another working copy is, as mentioned, by right click on file -> repo-browser.
Any ideas how to perform it programmatically?

C# / Webservice app on server throwing strange exception

We use ADP for employee information. I had to create a small app that called some web services that ADP has to pull employee information. The app is fairly procedural..not really object orientated in a sense. Basically I go through some web services to pull general information, work information, employee status, etc.
I have most of this data writing out to a text file as a log so I can ensure that everything is working correctly. Finally got it all done, and it works perfect on my local machine. Thought I'd just copy the entire structure onto a server and use windows scheduler to schedule the exe to run nightly (once a day). When it tries to run the app it looks like it is dying when it calls the first web service. The task scheduler log says:
""ADP.job" (ADP.exe)
Started 2/11/2010 2:14:34 PM
"ADP.job" (ADP.exe)
Finished 2/11/2010 2:14:38 PM
Result: The task completed with an exit code of (e0434f4d)."
So I checked the event viewer and it says this:
EventType clr20r3, P1 adp.exe, P2 1.0.0.0, P3 4b745bb9, P4 adp, P5 1.0.0.0, P6 4b745bb9, P7 289, P8 2d, P9 system.io.filenotfoundexception, P10 NIL.
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
I put in some console.writelines to see where it is failing...
Here is a simple example of main:
static void Main(string[] args)
{
OpenTextFile();
Console.WriteLine("About to process employee work information...");
tw.WriteLine("About to process employee work information...");
//work info service
EmpWorkInfo();
}
And inside of opentextfile:
public static void OpenTextFile()
{
//used to log data
String sLogName;
Console.WriteLine("Inside of opentextfile");
if (Directory.Exists(logPath))
{
//directory exists
}
else
{
Directory.CreateDirectory(logPath);
}
Console.WriteLine("Inside of opentextfile2");
sLogName = "log_" + DateTime.Today.ToString("MM_dd_yyyy") + ".txt";
tw = new StreamWriter(logPath + sLogName);
}
I see all the console.writelines on the server but as soon as it hits this line from main:
EmpWorkInfo();
Thats when all hell breaks lose (basically it doesn't work). The EmpWorkInfo() is simply a function to get work related information from a web service (as I said this works locally).
static void EmpWorkInfo()
{
Console.Writeline("THIS NEVER PRINTS!!!");
SQLClass s=null;
// Create the web service proxy client.
GetEmployeeWorkInfoService oService = new GetEmployeeWorkInfoService();
oService.Timeout = Int32.MaxValue;
// Serialize the UsernameToken into XML.
// Create the UsernameToken as defined in the WS-I secure profile.
UsernameToken oUsernameToken = new UsernameToken(USERNAME, SECRET);
System.Xml.XmlElement oSecurityHeaderXml =
oUsernameToken.GetXml(new System.Xml.XmlDocument());
ADP.GetEmployeeWorkInfoWebService.SecurityHeaderType oSecurityHeader = new ADP.GetEmployeeWorkInfoWebService.SecurityHeaderType();
oSecurityHeader.Any = new System.Xml.XmlElement[] { oSecurityHeaderXml };
oService.Security = oSecurityHeader;
GetEmployeeWorkInfoRequestFilter oFilter = new GetEmployeeWorkInfoRequestFilter();
//filter by thyssenkrupp company
oFilter.Companies = new String[] { COMPANY_IDENTIFIER };
GetEmployeeWorkInfoRequest oRequest = new GetEmployeeWorkInfoRequest();
oRequest.Filter = oFilter;
try
{
EmployeeWorkInfoType[] arPersonalInfo = oService.GetEmployeeWorkInfo(oRequest);
try
{
s = new SQLClass();
}
catch (Exception e)
{
throw new System.Exception(e.Message.ToString());
}
for (int i = 0; i < arPersonalInfo.Length; i++)
{
String stID = arPersonalInfo[i].EmployeeKey.Identifier.EmployeeId; //employee number
String stEmailAddress = arPersonalInfo[i].WorkInfo.EmailAddress; //employee email address (work)
String stFax = arPersonalInfo[i].WorkInfo.Fax; //employee fax number
DateTime dtHireDate = arPersonalInfo[i].WorkInfo.OriginalHireDate;
String stPhone = arPersonalInfo[i].WorkInfo.Phone; //employee phone number
String stWireless = arPersonalInfo[i].WorkInfo.Wireless; //employee wireless number
tw.WriteLine("Processing ID:" + stID + " Email Work: " + stEmailAddress + " Fax Work: " + stFax + " Hire Date: " + dtHireDate + " Phone Work: " + stPhone + " Wireless Work: " + stWireless + ".");
Console.WriteLine("Processing ID:" + stID + " Email Work: " + stEmailAddress + " Fax Work: " + stFax + " Hire Date: " + dtHireDate + " Phone Work: " + stPhone + " Wireless Work: " + stWireless + ".");
s.SetSQLCommand("dbo.ADP_uiEmployeeWorkInfo");
s.AddSQLCmdParameter("#EmployeeNumber", System.Data.SqlDbType.VarChar, stID);
s.AddSQLCmdParameter("#EmailAddress", System.Data.SqlDbType.VarChar, stEmailAddress);
s.AddSQLCmdParameter("#Fax", System.Data.SqlDbType.VarChar, stFax);
s.AddSQLCmdParameter("#HireDate", System.Data.SqlDbType.DateTime, dtHireDate);
s.AddSQLCmdParameter("#Telephone", System.Data.SqlDbType.VarChar, stPhone);
s.AddSQLCmdParameter("#Mobile", System.Data.SqlDbType.VarChar, stWireless);
s.SQLExecuteNonQuery();
Console.WriteLine("Processed ID:" + stID + " Email Work: " + stEmailAddress + " Fax Work: " + stFax + " Hire Date: " + dtHireDate + " Phone Work: " + stPhone + " Wireless Work: " + stWireless + ".");
Console.WriteLine(Environment.NewLine);
}
s.CloseSQLDB();
s.Dispose();
}
//catch any exception from adp side.
catch (Exception e)
{
throw new System.Exception(e.Message.ToString());
}
}
This functions code is irrelevant (its ugly but do not let that bother you, the code works...). My issue is I cannot even get to the first console.writeline of that function. Is there anything special I need to do when it comes to working with webservices?
Edit
Logpath is defined as simply a static string outside of main:
private static string logPath = Environment.CurrentDirectory + "\\log\\";
I suspect that your application is not able to load the types referenced in that function - EmpWorkInfo.
1) Can you run this application on the target server in a commannd window (cmd.exe) ?
2) Are you using any assemblies from ADP that are installed in the global assembly cache (GAC)? Run "gacutil -l" on your localmachine to see if you are using any assemblies from ADP that are installed in thr gac. If they are, you will need to install these into the machine on which you are running the app.
Does logPath have a trailing backslash? Either way, you ought to use Path.Combine, rather than the string catenation operator (+).
What happens if you comment out all the code in EmpWorkInfo() apart from the first Console.Writeline? Does it still not get written out?
Found out I need the Microsoft.Web.Services3 dll installed on the server.
Continuation on "feroze" answer;
If you want to figure out if the 'loading of dependencies' is causing you grief here, i suggest using the "FUSLOGVW.EXE" tool *(part of .Net). When you run this it will give you a little dialog window with a few options. Create a directory somewhere (like "c:\temp\fusion_logs"), set the mode of FUSLOGVW to "log bind failures only", "custom location->c:\temp\fusion_logs".
Now restart your application and check that it failed. Now look into your fusion_logs directory. This should give you sub directories with different (maybe only 1 for now) application names. Inside each directory you will find the log files. These log files contain the "failed assembly loads" and who (which calling assembly) caused them.
They might help your hunt for a working application,
Hope this helps,
Edit: Posted this after you found the cause. The fuslogvw.exe would have shown you the missing assembly.

Categories

Resources