Ready event in Microsoft Outlook 2010? - outlook

Is there an event in Microsoft Outlook 2010 which one can subscribe on, in order to known when Outlook has finished initializing and all components, folders etc. have been loaded?

Not sure about VSTO but good ol' COM addins get the StartupComplete "event" (via IDTExtensibility2) for exactly that purpose.

Ok, I found out what I needed to do...
...
private void ThisAddInStartup(object sender, EventArgs e)
{
this.Application.Startup += ApplicationStartup;
this.Application.ItemLoad += ApplicationItemLoad;
}
void ApplicationItemLoad(object Item)
{
//Do something
}
private void ApplicationStartup()
{
//Do something
}
...
http://msdn.microsoft.com/en-us/library/ff869298.aspx

Not that I'm aware of. Usually, addins don't do anything that requires talking with many outlook objects till some triggering event happens (like opening a mail, or creating a new inspector) so THAT'S when you'd typically see some custom code hooked in.
In my addins, the code connected to startup does things like load up some config, and maybe connect to a DB (although even that I tend to do on demand vs once at startup).

Related

Error while leaving my application xamarin forms android in the background

My solution when I leave the application or leave it in the background gives an error 'The test application stopped', I can not find out where this queue comes from. Does anyone know where this trigger comes from the moment it leaves in the background
Is it something in this part of the code?
protected override void OnStart()
{
Debug.WriteLine("OnStart");
}
protected override void OnResume()
{
Debug.WriteLine("OnResume");
}
protected override void OnSleep()
{
Debug.WriteLine("OnSleep");
}
This type of errors came along with a specific part of your code, like #apineda mentioned maybe you are using an Android service that is updating some data on your application or it may be there to show a local notification who knows? but the thing I want to imply is that you need to take a look at your code and investigate further which is the part that is making the crash. Here are some tips:
1.- If you are using push notifications that may lead to something!
2.- Check you MainActivity.cs class since this is the one responsible of the Xamarin.Forms activity life cycle.
3.- If you have any timers on your shared code or even a background Task created with Task.Run or a Task.Factory.StartNew() check those too, deadlocks on Xamarin.Forms applications between the UI thread and background threads are a common thing on Xamarin.Forms.
I hope this helps!

Can you intercept or overwrite an IPreviewHandler of docx files?

In my previous investigation I discovered that even though windows file explorer launches word.exe in an embedded state the Documents collection remains empty.
Excel and word opened in Windows Explorer preview panel have Workbooks.Count and Documents.Count equal to 0
A bit further research when I made the embedded applications visible they would load with out a document inside of it:
public static class WordAppExt
{
public static Word.Document GetActiveDoc(this Word.Application App)
{
try
{
App.Visible = true;
if (App.Documents.Count > 0)
{
return App.ActiveDocument;
}
else
{
return null;
}
}
catch (Exception)
{
return null;
}
}
}
SO I came to the conclusion that explorer only needs to launch word, but it does not have the documents hosted inside of word. which means windows explorer is likely a IOleContainer. If true this means any object embedded in the preview pane can be accessed via EnumObjects.
Unfortunately my code runs in a VSTO addin, I don't have access to the explorer com objects so I can't do a QI for IOleContainer. But I have a theory that there maybe another way of accessing the Document COM object, through the PreviewHandler. I think that the reason Word, Powerpoint, and Excel get launched is either to register or initialization of the previewHandler?
So HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PreviewHandlers has a list of guids associated with IPreviewHandler for different file types.
There are plenty of articles about how to create your own previewHandler for new file types:
Building Preview Handlers
How to Register a Preview Handler
PreviewHandler.cs
Hosting Preview Handlers in Windows Forms Applications
Preview Handlers Revisited
http://www.codeproject.com/Articles/19744/Using-Preview-Handlers-in-Windows-Vista
https://code.msdn.microsoft.com/CppShellExtPreviewHandler-58db53b8
But I want to replace Words Preview Handler with my own. If I can't replace it I'd be more than happy to intercept the existing Preview Handler.

Background service confusion

I'm trying to find out how to keep an Android service running after the starting app is closed. I've tried looking at samples for background services (e.g this one, and some on the Xamarin site) but in every case the service stops running if the minimised app is 'swiped' off the screen. I don't want the service to accidently stop like this, it should run continually until a confirmed stop is requested. The service does not consume much in the way of resources, just gets a GPS location and posts it to a website every 2 minutes.
By way of background, I am a newbie to Xamarin/Android, but have in the past created several successful services in Windows with C#
(Later)
One sample I tried did leave an item in the Settings list of running apps, but didn't actually perform any service tasks once swiped off the screen. Additionally there was no icon in the status bar. After doing some reading it seems that my androidmanifest file is missing a 'service' attribute (although none of the samples I tried have this); what I have now tried is this
<service
android:name=".LocationService"
android:icon="#drawable/icon"
android:label="#string/service_name"
>
<intent-filter>
<action android:name="android.service.LocationService" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
...but still no luck.
Have you had a look at the Xamarin sample here the source is here
They create a service like so:
[Service]
public class SimpleService : Service
{
System.Threading.Timer _timer;
public override StartCommandResult OnStartCommand (Android.Content.Intent intent, StartCommandFlags flags, int startId)
{
Log.Debug ("SimpleService", "SimpleService started");
DoStuff ();
return StartCommandResult.Sticky;
}
public override void OnDestroy ()
{
base.OnDestroy ();
_timer.Dispose ();
Log.Debug ("SimpleService", "SimpleService stopped");
}
public void DoStuff ()
{
_timer = new System.Threading.Timer ((o) => {
Log.Debug ("SimpleService", "hello from simple service");}
, null, 0, 4000);
}
public override Android.OS.IBinder OnBind (Android.Content.Intent intent)
{
throw new NotImplementedException ();
}
}
And start and stop it with this:
StartService (new Intent (this, typeof(SimpleService)));
StopService (new Intent (this, typeof(SimpleService)));
Also it sounds like you want a Sticky service Docs
When the system is under memory pressure, Android may stop any running services. The exceptions to this rule are services explicitly started in the foreground, which are discussed later in this article.
When a service is stopped by the system, Android will use the value returned from OnStartCommand to determine how or if the service should be restarted. This value is of type StartCommandResult, which can be any of the following:
Sticky – A sticky service will be restarted, and a null intent will be delivered to OnStartCommand at restart. Used when the service is continuously performing a long-running operation, such as updating a stock feed.
RedeliverIntent – The service is restarted, and the last intent that was delivered to OnStartCommand before the service was stopped by the system is redelivered. Used to continue a long-running command, such as the completion of a large file upload.
NotSticky – The service is not automatically restarted.
StickyCompatibility – Restart will behave like Sticky on API level 5 or greater, but will downgrade to pre-level 5 behavior on earlier versions.
Hope this helps.
Solved it now. The confusion was mainly due to many samples being out-of-date (using deprecated methods) and different suggestions for 'pure' Android projects and Xamarin ones. Certainly don't need to modify the androidmanifest file as I suggested above.
If anyone is trying to find something similar, my project is here.
Solving the initial issue has now raised some new questions, of course, but I will post separately about that if needed.

Starting a WCF service in Windows Service when initialization takes a long time

I have a WCF project that I host in a windows Service (actually I use topshelf) and it runs fine. I have to make changes however that will cause the initialization to take substantially longer. This causes problems when the service starts as it times out while executing the WCF Service constructor.
I wanted to reduce the amount of code in the constructor and then when the service was opened I would do my longer running initializations. I put register the open event in the WCF ctor but it does not seem to be called.
public WCFService()
{
this.Faulted += WCF_Faulted;
this.Opened += WCF_Opened;
...
and event handlers
void WCF_Opened(object sender, EventArgs e)
{
}
void WCF_Faulted(object sender, EventArgs e)
{
}
I am guessing that I am not implementing this correctly.
I was able to trap the opened event in the servicehost but then I dont know how to access the instance (it is a singleton) to call a method on it.
Ideas?

Checkin Notification with StarTeam

Does someone know how we can have Starteam send email notifications when a check in occurs? We are using Starteam 2006 R2.
Unfortunately StarTeam doesn't offer the ability to execute post-checkin actions. You may be able to use an application like Cruise Control to monitor your repository for changes and then take action upon seeing them.
I had a similar need a few months ago, this is what I discovered:
Starteam does not have commit hooks but it does have Starteam MPX (borland.com). From that link,
StarTeamMPX is a framework for publish/subscribe messaging. The StarTeamMPX Server uses an advanced caching and communication technology that both improves the performance of StarTeam clients and extends the scalability of the StarTeam Server.
Ok, so, we can subscribe to events. It's looking promising.
There is a Java API (borland.com) for Starteam, create an app using this API with your own emailing implemention of the CheckinListener interface. The app will then have to connect to Starteam, find any views that you're interested in and register listeners against them. And then wait.
Your listener will receive CheckinEvents and can interrogate these. Unfortunately, it appears to be on a file by file basis. I couldn't see anything in the API to say "commit finished", only "file finished". You are able to discover if a commit was cancelled. I don't know how easy it is to combine file checkin events back into a complete check in event.
*StarteamMPX is an extension (paid) to Starteam, it is available for 2006 R2. All of this is clearly only applicable if it is enabled.
My Experience:
My company didn't have that extension enabled, and to enable it required upgrading i.e. more money. So it didn't happen (I think it's painful enough paying for Starteam to begin with). At this point I abandoned my research and none of the above was ever implemented this. I hope this is some use to someone.
I've been doing some homework into this topic too, so will share what I've learnt.
MicroFocus now offer a Notification Agent tool for this sort of thing:
http://www.youtube.com/watch?v=QTKAT-ufkIs
It's an extra you pay for though.
I've been also pondering how to "roll-your-own" via advice given in Dan's post above. Yes, MPX does seem to be the way to go, although after studying the CheckinListener, this isn't the class you're after. To clarify, CheckinListener is used by the client performing the check-in, so that it can monitor progress of the check-in (perhaps to display a progress bar, that sort of thing).
Here's some sample-code of what listening to MPX events looks like:
Server s = new Server(strAddress, nPort);
s.connect();
s.enableMPX(); // must do this for MPX support
s.logOn(strUsername, strPassword);
Project p = s.findProject("mylovelyproject");
View v = p.s.findView("mylovelyview");
ItemListener listener = new ItemListener()
{
public void itemAdded(ItemEvent e)
{
System.out.println("itemAdd() - " + e.getNewItem().getComment());
}
public void itemMoved(ItemEvent e)
{
System.out.println("itemMoved() - from: " + e.getOldItem().getParentFolderHierarchy() + ", to: " + e.getNewItem().getParentFolderHierarchy());
}
public void itemChanged(ItemEvent e)
{
System.out.println("itemChanged() - " + e.getNewItem().getComment());
System.out.println(" - from: v" + e.getOldItem().getDotNotation().toString());
System.out.println(" - to: v" + e.getNewItem().getDotNotation().toString());
User locker = e.getNewItem().getLocker();
if (locker != null)
System.out.println(" - locked by:" + locker.getDisplayName());
else
System.out.println(" - not locked");
}
public void itemRemoved(ItemEvent e)
{
System.out.println("itemRemoved() - " + e.toString());
}
};
v.addItemListener(listener, s.getTypes().FILE);
The MPX-related items to focus on here are new ItemListener() (what to do about the events you listen to) and v.addItemListener() (which starteam view you want to listen to).
The sample code will spit out various print output to the console as files in your view are added/modified/moved/deleted.
Apart from ItemListener, you also have ViewListener and ProjectListener. Each interface provides a different scope of events to listen for, more info on this in the sdk docs, also a nice article here:
http://conferences.embarcadero.com/article/32231#MPXEventHandling
So if you want to roll-your-own notification emails, these MPX events provide part of your answer (a way to listen to these change-events).
Other aspects you'll need to look into after this are:
How to allow users to subscribe to various servers/projects/views, to decide what they want to listen to.
How to email to the user what they want (StarTeam's Server class offers a .SendMail() method, which can help here).
Once all these bases are covered, you should have something that does the trick. I'll be working on something like this myself over the coming days, I'll share what I can.

Resources