Add custom Header to raw push notification on Windows Phone - windows-phone-7

HttpNotification class that handles raw notifications has Headers property. But unfortunately, it's always empty collection and I don't know how to get X-MessageID or some other custom header when notification is received
static void Channel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
{
string header = e.Notification.Headers["X-CUSTOM-HEADER"];
}

Related

Raw Notification Handling in UI inside my App in Windows Phone 8

Can some one help me out in showing a TextBox in all screens after parsing a Raw Notification data. I'm successfully able to show this data on a MessageBox like the code below but unable to show in TextBox and I want this TextBox to be called from any screen in my app. How can I do this?
public void PushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
{
string message;
using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
{
message = reader.ReadToEnd();
}
Debug.WriteLine("This is a "+message);
var RawNotification = (RawData)serializer.ReadObject(e.Notification.Body);*/
Dispatcher.BeginInvoke(() =>
MessageBox.Show(String.Format("Received Notification {0}:\n{1}",
DateTime.Now.ToShortTimeString(), message))
);
}
I did this for one of my app. I Don't know if this is correct way of doing it or not but it solved my purpose.
1) First Create a UserControl in whatever look and feel you want to have. Make sure you create a Public Variable that will accept String ( In this case your Message )
2) Create a method in App.xaml.cs with String parameter ( To Pass your message string ). Withing the Method, Do a Dispatcher which will call a Messagebox with Content as the usercontrol. When invoking the UserControl, Pass your message as parameter.
Now whenerver or wherever you want to display a message, Use this method from App.xaml.cs and then you can create this textbox update.

C++ builder indy intercept IdHTTPProxyServer to insert header

I want to insert header of external script over https inside browser. For those purpose i use C++ builder with IdHTTPProxyServer component. I read Document from Response event but dont know how to just insert one simple .js. -> cause Document property is read only, on the other side BeforeCommandHandler want append with script (in code under i use just text to insert for simplicity)
How to insert .js external script in C++ builder?
Here is what i done so far.
void __fastcall TForm5::IdHTTPProxyServer1HTTPResponse
(TIdHTTPProxyServerContext *AContext)
{
Memo1->Lines->Append("\nOn Response!!!\n" + AContext->Document);
}
void __fastcall TForm5::IdHTTPProxyServer1BeforeCommandHandler
(TIdCmdTCPServer *ASender, UnicodeString &AData, TIdContext *AContext) {
try {
Memo1->Lines->Add(AData);
UnicodeString sa = AData;
AData = L"<html>Something</html>" + sa;
}
catch (int e) {
MessageBeep(100);
}
}
The TIdHTTPProxyServer::OnBeforeCommandHandler event is triggered before a client's request is processed. The AData parameter is the original request. This event is meant for logging/altering commands before they are parsed.
The TIdHTTPProxyServer::OnHTTPBeforeCommand event is triggered after a client's request headers have been received but before a connection is established to the target server and the client's request body is read and sent to the server.
The TIdHTTPProxyServer::OnHTTPResponse event is triggered after a server's response headers have been received but before the response body is read and sent to the client.
So none of those events will help you.
Neither will the TIdHTTPProxyServerContext::Document property, for that matter. That property does not contain the document data, as you are assuming. It contains the server-relative URL of the document being requested instead.
To do what you are asking for, set the TIdHTTPProxyServer::DefaultTransferMode property to tmFullDocument and use the OnHTTPDocument event. The TIdHTTPProxyServerContext::TransferSource property will tell you if the data is coming from the client or the server.
You will have full access to the headers and body data and you can modify them as needed. Just make sure you update the TIdHTTPProxyServerContext.Headers, in particular the Content-Length header, if you modify the body data. The body data is provided as a TStream object (specifically, a TMemoryStream). So you can either modify the stream's content directly, or you can create a new TStream object with your desired content (the VStream parameter of the event is passed by reference so you can re-assign it).
For example:
void __fastcall TForm5::IdHTTPProxyServer1HTTPDocument(TIdHTTPProxyServerContext* AContext, TStream* &VStream)
{
if (AContext->TransferSource == tsServer)
{
String s = ReadStringAsContentType(VStream, AContext->Headers->Values[L"Content-Type"], QuoteHTTP);
// this is NOT thread-safe! TIdHTTPProxyServer is multi-threaded,
// you must synchronize with the main thread in order to safely
// update UI controls...
//
// Memo1->Text = s;
s = L"<html>Something</html>" + s;
delete VStream;
VStream = new TStringStream(s, Sysutils::TEncoding::UTF8);
AContext->Headers->Values[L"Content-Length"] = VStream->Size;
AContext->Headers->Params[L"Content-Type"][L"charset"] = L"utf-8";
}
}

Issue with SentOnBehalfOfName

i'm stack with Outlook issue where i want to change Email Sender. I want to send all emails from Outlook with one sender. When i change sender from Outlook it works fine but when i change it from Outlook plugin it's not work. I'm using following code:
private void adxOutlookEvents_ItemSend(object sender, ADXOlItemSendEventArgs e)
{
if (e.Item is MailItem)
{
MailItem mail = e.Item as MailItem;
mail.SentOnBehalfOfName = "UserName";
mail.Save();
return;
}
}
But nothing happens. I don't see any error or exception but email come to Outlook with old sender. Can you please help me with that?
UPDATED: The way how i fix it. We cant use property "SentOnBehalfOfName" Outlook handle it incorect. Except it you should use "Sender" property:
mail.Recipients.Add(mail.SentOnBehalfOfName);
mail.Recipients.ResolveAll();
var adressEntry = mail.Recipients[mail.Recipients.Count].AddressEntry;
mail.Recipients.Remove(mail.Recipients.Count);
mail.Sender = adressEntry;
Are you sending through Exchange and want to send on behalf of another user (do you have the permission?) or trying to send through a particular POP3/SMTP account (use MailItem.SendUsingAccount property)?

Logging errors when sending ASync email with MvcMailer

I'm using the excellent MvcMailer package to send email from within my application.
I'm using the SendAsync() method to send email, and would like to log errors + dispose of attachments i.e.
MailMessage message = UserMailer.SendSomeEmail(emailViewModel);
var client = new SmtpClientWrapper();
client.SendCompleted += (sender, e) =>
{
if (e.Error != null || e.Cancelled)
{
Logger.LogError(e.Error);
}
if (message != null)
{
message.Attachments.Dispose();
message.Dispose();
}
client.Dispose();
};
message.SendAsync("this means nothing afaik", client);
This works great, but it would get too painful to repeat the same snippet all over wherver I need to send email.
How should I set this up so that I can log any errors + dispose of message attachments when the async call is completed? There has to be a better way!
If what you're trying to do is to avoid having to write that logging and cleanup code every time you send an async email, the answer is simple -- stop using anonymous methods. Just take your current code and put it in a regular method like this:
public void AsyncSendCompleted(object sender, EventArgs e)
{
// Use an appropriate type instead of EventArgs so you can get
// stuff like e.Cancelled and e.Error
// The rest of your code goes here
}
Now use this method as the event handler for your SendCompleted event:
client.SendCompleted += AsyncSendCompleted;

Hooking to Send/Receive Sync event of Outlook Contacts

How can I attach an event handler for SendAndReceive event of Contact folders/Contact Items in Outlook 2007 using VSTO AddIn? I tried using:
Application.ActiveExplorer().SyncObjects.ForEach
{
SyncObject.SyncEnd += \\Do something
}
But it is not working.
I tried
Application.ActiveExplorer().SyncObjects.AppFolders.SyncEnd += \\EventHandler
This hooks on to send/receive of all default folders..
Actually my need was a bit different but may be the same:
I wanted to be notified of the changes of a folder (appointments in my case) after a send/receive.
My first thought (and I think you are on the same track) was to check for a send/receive event and maybe get some collection of items out of it or something similar, but no such thing is available. (as is also explained in this forum post)
My second path came from the following article: I can register to the Item_Add and Item_Change (and even Item_Removed) event of a folder (whom are also triggered by the changes done by a send receive):
Some code:
// Get the folder calendar folder and subscribe to the events.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Items.ItemAdd += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Items.ItemChange += new Microsoft.Office.Interop.Outlook.ItemsEvents_ItemChangeEventHandler(Items_ItemChange);
}
// Do something with it.
void Items_ItemAdd(object Item)
{
logItem(Item, "Add");
}
void logItem(object Item, string Action)
{
Outlook.AppointmentItem item = Item as Outlook.AppointmentItem;
File.AppendAllText(#"e:\log.txt", string.Format("Item {0}: {1}", Action, Item));
if (item != null)
{
File.AppendAllText(#"e:\log.txt", " - Appointment: " + item.Subject);
}
}
You can hook up the mail send/receive event and then check that the mail type is a ContactItem. Here is an example of the Send event.
// hook up the event
this.Application.ItemSend += ThisApplication_SentMail;
then in your event handler you check the mail item type;
internal void ThisApplication_SentMail(object item, ref bool cancel)
{
Outlook.ContactItem contactItem = item as Outlook.ContactItem;
// mail message is not a ContactItem, so exit.
if (contactItem == null) return;
// do whatever you need to here
}
In my case, I need to trigger an event after a new email is received & after email sync so that I get a new email, or else I will not receive a new email attachment.
Below my solution may help you.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.NewMail += Application_NewMail;
}
private void Application_NewMail()
{
_currentExplorer = Application.ActiveExplorer();
_currentExplorer.Session.SyncObjects[1].SyncEnd += AppFolders_SyncEnd;
_currentExplorer.Session.SyncObjects[1].Start();
}
private void AppFolders_SyncEnd()
{
//Your enter code here
}

Resources