Missed Chats on Skype using C# - c#

Am trying to display unread chats from skype to my c# application. I used int msgCount=skype.MissedMessages.Count to get number of unread messages and tried given functions skype.MissedChats.ToString() and skype.get_Message(msgCount).ToString(). But they display " System._ComObject". Any suggestions???

The answer is so simple and I got it as follows..
for (int i = 0; i < skype.MissedMessages.Count; i++)
{
if (skype.MissedMessages[i + 1].Type == TChatMessageType.cmeSaid)
{
string unreadMessage = skype.MissedMessages[i + 1].Body;
}
}
It's possible to read other details such as name of sender by skype.MissedMessages[i + 1].Sender

I would guess that it would require you to use an indexer to actually display the content of one particular chat message. Right now you're converting a ChatCollection to a string, and I would guess that they haven't implemented that, so it just returns this.GetType().Name.
I would guess that the indexer would work like this:
List<string> messages = new List<string>();
foreach (Char c in skype.MissedChats)
{
try
{
messages.Add(c.Name);
}
catch (COMException) { } // Invalid chat
}

Related

How can i interate on Fulfillment Messages to return message by message to client

I'm using Dialogflow to integrate on Microsoft Bot Framework, when i use FulfillmentText, my code works fine, but i need to use FulfillmentMessages because i have many messages returning on my code, i tried this code, but "retorno" variable receive json format return, how can i interate to all messages returning line by line to response for my client?
foreach (Intent.Types.Message msg in queryResult.FulfillmentMessages)
{
retorno = msg.Text;
Console.WriteLine($"Fulfillment text: {retorno}");
}
Do you have any sample using Microsoft Bot Framework and Google.Cloud.Dialogflow.V2 API?
I created a array of IActivity and used foreach at each messages adding text by text to "respostas" array.
Finally i used "await turnContext.SendActivitiesAsync(retorno, cancellationToken);" because i can pass array of IActivity:
IActivity[] respostas;
respostas = new IActivity[1];
int cnt = 0;
foreach (Intent.Types.Message msg in queryResult.FulfillmentMessages)
{
foreach (string msgstr in msg.Text.Text_)
{
retorno = retorno + msgstr.ToString() + "\r\n";
respostas[cnt] = MessageFactory.Text(msgstr.ToString(), msgstr.ToString());
cnt++;
}
Console.WriteLine($"Fulfillment text: {retorno}");
}
await turnContext.SendActivitiesAsync(retorno, cancellationToken);
This code works fine for my objectives.

Compare two word document in c#

I have a problem. I need to compare word document. Text and format in c# and i found a third party library to view and process the document and it is Devexpress. So i downloaded the trial to check if the problem can be solved with this
Example i have two word document
1: This is a text example
This is not a text example
In the text above the difference is only the word not
My problem is how can i check the difference including the format?
So far this is my code for iterating the contents of the Document
public void CompareEpub(string word)
{
try
{
using (DevExpress.XtraRichEdit.RichEditDocumentServer srv = new DevExpress.XtraRichEdit.RichEditDocumentServer())
{
srv.LoadDocument(word);
MyIterator visitor = new MyIterator();
DocumentIterator iterator = new DocumentIterator(srv.Document, true);
while (iterator.MoveNext())
{
iterator.Current.Accept(visitor);
}
foreach (var item in visitor.ListOfText)
{
Debug.WriteLine("text: " + item.Text + " b: " + item.IsBold + " u: " + item.IsUnderline + " i: " + item.IsUnderline);
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
throw ex;
}
}
public class MyIterator : DocumentVisitorBase
{
public List<Model.HtmlContent> ListOfText { get; }
public MyIterator()
{
ListOfText= new List<Model.HtmlContent>();
}
public override void Visit(DocumentText text)
{
var m = new Model.HtmlContent
{
Text = text.Text,
IsBold = text.TextProperties.FontBold,
IsItalic = text.TextProperties.FontItalic,
IsUnderline = text.TextProperties.UnderlineWordsOnly
};
ListOfText.Add(m);
}
}
With the code above i can navigate to the text and its format. But how can i use this as a text compare?
If I'm going to create a two list for each document to compare.
How can i compare it?
If i'm going to compare the text in with another list. Compare it in loop.
I will be receiving it as only two words are equal.
Can help me with this. Or just provide an idea how i can make it work.
I didn't post in the devexpress forum because i feel that this is a problem with how i will be able to do it. And not a problem with the trial or the control i've been using. And i also found out that the control doesn't have a functionality to compare text. Like the one with Microsoft word.
Thank you.
Update:
Desired output
This is (not) a text example
The text inside the () means it is not found in the first document
The output i want is like the output of Diff Match Patch
https://github.com/pocketberserker/Diff.Match.Patch
But i can't implement the code for checking the format.

Is it possible to foreach or check if it contains a certain text in HttpFileCollection.FileName? - ASP.Net

So, I am trying to upload a certain files with names like '2018-2-10 10-23-34' // February 10, 2018 10:23:34, this is not a one file only, I have like multiple files with names like these. That's why I use HttpFileCollection.
Now, for example that I selected files with file names like these, I want to check if it has the right file name, else it will just SaveAs as it is.
As you can see below, I added a fake code, its fake since its not working or it has a wrong syntax in it.
I saw a code like this, but I don't know how to apply this on my current code with HttpFileCollection, please help.
bool contains = Directory.EnumerateFiles(path).Any(f => f.Contains("three"));
My Code
protected void UploadButton_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
try
{
string date = DateTime.Now.ToString("yyyy-M-d");
DateTime DateValue;
DateValue = DateTime.Parse(date, CultureInfo.InvariantCulture);
string dayoftheweek = "(" + DateValue.ToString("dddd") + ")";
Response.Write(dayoftheweek);
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
foreach (hfc[i].FileName.Contains(date))// What I am trying to do, but wrong syntax or wrong code
{
hfc[i].SaveAs(#path+"\\" + hfc[i].FileName + dayoftheweek);
}// What I am trying to do, but wrong syntax or wrong code
Response.Write(hfc[i].FileName);
hfc[i].SaveAs(#path+"\\" + hfc[i].FileName);
}
}
catch (Exception) { }
}
Your foreach loop is wrong as you mentioned.
//This will make you iterate trough the file collection
for (int i = 0; i < hfc.Count; i++)
{
if(hfc[i].FileName.Contains(date))
{
hfc[i].SaveAs(#path+"\\" + hfc[i].FileName + dayoftheweek);
}
}
The foreach loop is not needed anymore so you can remove
foreach (hfc[i].FileName.Contains(date))
{
}
The problem is your for each loop doesnt have a declaration
foreach(var variable in Enumerable){
//other code
}
so in your case it would be
foreach( var file in hfc)
{
//other code
}
and it should work just fine

can't get the body/attachments of new mails in outlook

I've developed an Outlook plugin using C# where for each new mail received, i get(and save) the sender/subject/the body of email & the attachments. Well, the last 2 gave me a headache. I can see the sender and the subject of the new mail but for the body&attachments it seems that is a problem. I've used NewMailEx for getting the new mails in Inbox. The function looks like this:
private void Application_NewMailEx(string EntryIDCollection)
{
string[] entryIdArray = EntryIDCollection.Split(',');
foreach (string entryId in entryIdArray)
{
try
{
Outlook.MailItem item = (Outlook.MailItem)Application.Session.GetItemFromID(EntryIDCollection, null);
string subj = item.Subject; //works
string to = item.To; //works
string bec = item.BCC; //does not work but dont care
string body = item.Body; //DOES NOT SAVE THE BODY OF THE NEW MAIL RECEIVED
string final = "Sender: " + item.SenderEmailAddress + "\r\n" + "Subject: " + subj + "\r\n" + "BCC: " + bec + "\r\n" + "TO: " + to + "\r\n\n" + "Body: " + body + "\r\n\n";
System.IO.File.AppendAllText(#"D:\tmp\atr.txt", final);
//the result of item.attachments.count is always 0 , even though I've
//sent mails with a different number of attachments. So the if
//statement is false
if (item.Attachments.Count > 0)
{
for (int i = 1; i <= item.Attachments.Count; i++)
{
item.Attachments[i].SaveAsFile(#"D:\tmp\" + item.Attachments[i].FileName);
}
}
Marshal.ReleaseComObject(item);
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}
}
}
Where does the Item variable come from? You need to initialize it using Application.Session.getItemfromID().
I'm writing in VBA, so I feel like posting my code here would be a faux pas, but I have come to a solution using similar Object Libraries from the Outlook application that I think transfer well to your C++ intentions.
First of all, switching to POP3 certainly fixes this problem, but you're stuck using POP3, which is only ideal from a programming standpoint.
The solution I have found follows this algorithm:
//Generate Outlook MailItem Object, "item"
//If item.DownloadState is not 1,
//item.Display
//item.Close(1)
//Perform end of code operations
//Call Function that is identical to Application_NewMailEx but is not Application_NewMailEx because Application_NewMailEx is a function that is thrown during the incoming mail event.
//Else,
//Perform Intended Code
You see how calling a function identical to Application_NewMailEx creates a kind of loop because if item.DownloadState is not 1, you'll be calling that function again? I get that this isn't the most ideal coding practice, but I have scoured the internet and Outlook Application and Outlook Object Library experts have no idea how to solve this problem any other way (in fact, no one even proposes THIS solution)
For my full VBA Solution Check out:
https://superuser.com/questions/894972/outlook-strange-item-attachments-error/990968#990968

How can I get the outlook contact's avatar image?

I am trying to get the contact's avatar image.
using Microsoft.Office.Interop.Outlook;
public sealed class OutlookAvatarFetcher
{
private static void FetchAvatars()
{
var outlook = new Application();
var folder = outlook.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderContacts);
var items = folder.Items;
for (var i = 0; i < items.Count; ++i)
{
var contact = items[i + 1] as ContactItem;
if (contact == null)
continue;
if (contact.HasPicture)
{
// TODO store the picture somehow.
}
}
}
}
But unfortunately I can't find a picture accessor.
You can use the attachments property of the ContactItem:
contact.Attachments["ContactPicture.jpg"]
If you want to save the file to disk, for example, you could do something like this:
contact.Attachments["ContactPicture.jpg"].SaveAsFile(#"{some_path}\ContactPicture.jpg")
Do you mean the picture that comes from Facebook or LinkedIn?
You cannot access it - MS did not provide any API to do that for legal purposes. Remember, that data comes from a third party service, and quite a few lawyers are involved in cases like this.

Categories