I have a notification system for my Asp.net application that uses sql-server. Currently, when there is an update on certain tables email alert sent. I am wondering, if there is a way to use Lync instead of email so that when tables updated, users will get Lync messages?
You can use Lync client for .Net. Here is the link- https://code.msdn.microsoft.com/lync/Lync-2013-Use-the-Lync-47ded7b4
Below is a sample code.
using Microsoft.Lync.Model;
using Microsoft.Lync.Model.Conversation;
private static void SendMessage()
{
try
{
string[] arrRecepients = { "sip:receiver1#domain.com", "sip:receiver2#domain.com" }; //add your recepients here
LyncClient lyncClient = LyncClient.GetClient();
Conversation conversation = lyncClient.ConversationManager.AddConversation();
foreach (string recepient in arrRecepients)
{
conversation.AddParticipant(lyncClient.ContactManager.GetContactByUri(recepient));
}
InstantMessageModality imModality = conversation.Modalities[ModalityTypes.InstantMessage] as InstantMessageModality;
string message = GetNotification(); //use your existing notification logic here
imModality.BeginSendMessage(message, null, null);
}
catch (Exception ex)
{
}
}
Related
I’m relatively new to c# and working with API’s. I’ve created a simple windows form in VS and I’m trying to connect t a rest service to retrieve information based on a search condition (e.g ID number) and display everything in a data grid. I’ve been looking for examples of what I’m trying to achieve with very little success. The idea is to enable a user to enter an ID number inside a text box and click a “search” button which will then connect to the rest service and retrieve all the information related to that specific ID number and display it all in a data grid with column names. Is this possible? Can anyone advise me on how to establish my connection to the rest service?
Try this. Path1 is your connection:
The Class ApiResult is just a class with a List of ArticleApiModel.
public static List<ArticleApiModel> GetArticles (int id)
{
try
{
var task = Task<List<ArticleApiModel>>.Run(async () =>
{
using (HttpClient client = new HttpClient())
{
var response = await client.GetAsync(path1 + "/api/articles/",id);
if (response != null)
{
var jsonString = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<ApiResult>(jsonString);
return result.Result;
}
}
return null;
});
task.Wait();
return task.Result;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return null;
}
I am writing a program in C# using Windows Forms and I am stuck at this part.
When any user logs in to the program for the first time in any given week, an email should be sent to all users who have a task (the task will be assigned by an admin). If a user has no tasks, he/she should not receive an email. When the second user logs in for that week, emails should not be sent.
I mean when the any first user of the program logging in, the emails will be send for all users who has tasks (to remind them to do the task). The problem is I do not want one user to receive too many duplicate emails.I already have the code for sending the emails, but I need a way to handle the rest of the process. I have researched and I saw that Windows Services might be an option.
Is there another way to do this?
public int OutLook_Send_Email_To_User(string user_Email, string email_Subject, string email_Content)
{
try
{
Outlook.Application outApp = new Outlook.Application();
Outlook.MailItem outMsg = (Outlook.MailItem)outApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Recipient outTo = null;
outApp = new Outlook.Application();
outMsg = (Outlook.MailItem)outApp.CreateItem(Outlook.OlItemType.olMailItem);
outTo = (Outlook.Recipient)outMsg.Recipients.Add(user_Email);
outTo.Type = (int)Outlook.OlMailRecipientType.olTo;
outTo.Resolve();
outMsg.Subject = email_Subject;
outMsg.HTMLBody = email_Content;
outMsg.Save();
outMsg.Send();
outTo = null;
outMsg = null;
outApp = null;
return 0;
}
catch (Exception ex)
{
return -1;
}
}
So I know this API is quite old and very undocumented, exactly the reason that I'm making a SO question, so I wanted to know how I can select a chat in Skype using the C# Skype Desktop API, I've done some looking around but most people seem to be using WinForms to make their app, mine's just a simple console application, code:
Skype Skype = new Skype();
Skype.Attach(5, true);
Skype.Chat.SendMessage("Hello ??");
Parser.Pause();
On runtime, I of course get an exception telling me I need to select a chat, but I'm not sure as to how I can do that, I've looked here but that didn't help me much.
Is there a way to reference a chat easily using a specific code? etc... Thanks!
I have constructed this snippet which should help you...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
using SKYPE4COMLib;
namespace skypeExperiment
{
class Program
{
static void Main(string[] args)
{
Skype s = new Skype();
s.Attach();
if (!s.Client.IsRunning)
{
// start minimized with no splash screen
s.Client.Start(true, true);
}
// wait for the client to be connected and ready
//you have to click in skype on the "Allow application" button which has popped up there
//to allow this application to communicate with skype
s.Attach(6, true);
//this will print out all the chat names to the console
//it will enumerate all the chats you've been in
foreach (Chat ch in s.Chats)
{
Console.WriteLine(ch.Name);
}
//pick one chat name of the enumerated ones and get the chat object
string chatName = "#someskypeuser/someskypeuser;9693a13447736b9";
Chat chat = GetChatByName(s, chatName);
//send a message to the selected chat
if (chat != null)
{
chat.SendMessage("test");
}
else
{
Console.WriteLine("Chat with that name was not found.");
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
private static Chat GetChatByName(Skype client, string chatName)
{
foreach (Chat chat in client.Chats)
{
if (chat.Name == chatName) return chat;
}
return null;
}
}
}
Instead of using an existing chat object, you can create new chat object with method
Chat chat = s.CreateChatWith("name of the user to chat with");
chat.SendMessage("test");
You can create a group chat with:
Group mygroup = s.CreateGroup("mygroup");
mygroup.AddUser("user1");
mygroup.AddUser("user2");
Chat myGroupChat = s.CreateChatMultiple(mygroup.Users);
myGroupChat.SendMessage("test");
or create method to retrieve group by display name
private static Group GetGroupByDisplayName(Skype client, string groupDisplayName)
{
foreach (Group g in client.Groups)
{
if (g.DisplayName == groupDisplayName)
{
return g;
}
}
return null;
}
and use it then like:
Group majesticSubwayGroup = GetGroupByDisplayName("majesticsubway");
Chat majesticSubwayGroupChat = s.CreateChatMultiple(majesticSubwayGroup.Users);
majesticSubwayGroupChat.SendMessage("test");
I have developed a windows application using Lync api. My client want to disable incoming calls to this application. So i have added some thing like this. I am able to cut the call but there are few rings before im able to do that
private void ClientInitialized(IAsyncResult result)
{
try
{
//registers for conversation related events
//these events will occur when new conversations are created (incoming/outgoing) and removed
client.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
client.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;
}
catch (Exception ex)
{
MessageBox.Show("Problem in adding/removing conversation", "Bella IVIS", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e)
{
try
{
var _client = client;
if (e.Conversation.State == ConversationState.Active)
{
for (int intLoop = 0; intLoop < _client.ConversationManager.Conversations.Count; intLoop++)
{
_client.ConversationManager.Conversations[intLoop].End();
}
_client = null;
return;
}
}
}
I do not know if there is a way to capture conversation before Conversation_Added event. However, if the Lync status is not of any relevance to you then you change the Lync Status to "Do not disturb". This way you would never get any incoming request (unless the user Lync setting allow to do so)
var newInformation =new Dictionary<PublishableContactInformationType, object>();
newInformation.Add(PublishableContactInformationType.Availability, ContactAvailability.DoNotDisturb);
try
{
this.lyncClient.Self.BeginPublishContactInformation(newInformation,(result) => this.lyncClient.Self.EndPublishContactInformation(result) , null);
} catch {}
Simply I would like to receive a notification every time someone added a new appointment or made any changes on what he/she has.
The only way I know how to do it , is by using
service.SubscribeToStreamingNotifications
but the problem here that it only listens to the account that the service is bound to like in this way
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
{
Credentials = new WebCredentials(userName, password)
};
service.SubscribeToStreamingNotifications(new FolderId[]
{
WellKnownFolderName.Calendar
}, EventType.FreeBusyChanged, EventType.Deleted);
I have solved this problem by creating a list of services each service is bounded to different user and the application should listen to each of them.
The problem with this way is that I need to have the password of each account I wont to listen to its events, which is not possible in real world.
so is there any way to deal with that ?
I have solved this problem, by creating a list of services, all the services are a clone of the main ExchangeService, with the same credentials for the admin account, but they are impersonated to the other accounts.
NOTE: You need to setup the server so it allows impersonation.
private void ImpersonateUsers(ICollection<string> userSmtps)
{
if (userSmtps != null)
if (userSmtps.Count > 0)
{
foreach (var userSmtp in userSmtps)
{
if (_services.ContainsKey(userSmtp)) continue;
var newService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
try
{
var serviceCred = ((System.Net.NetworkCredential)(((WebCredentials)(_services.First().Value.Credentials)).Credentials));
newService.Credentials = new WebCredentials(serviceCred.UserName, serviceCred.Password, serviceCred.Domain);
newService.AutodiscoverUrl(serviceCred.UserName + "#" + serviceCred.Domain, RedirectionUrlValidationCallback);
newService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, userSmtp);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
_services.Add(userSmtp, newService);
}
}
}
Where userSmtps is a list of the email addresses I want to impersonate and _services is the dictionary of services where the first member is the main service.
you will have to create a service instance per user. There is no way to subscribe to other users folder.
But instead of StreamingNotifications you can use Pull and Push-Subscriptions too.
Something like this:
List<FolderId> folders = new List<FolderId>();
folders.Add(new FolderId(WellKnownFolderName.Calendar));
PullSubscription subscription = = service.SubscribeToPullNotifications(folders, 1440, watermark, EventType.Created, EventType.Deleted, EventType.Modified, EventType.Moved, EventType.NewMail);
Some time later....
GetEventsResults currentevents = m_subscription .GetEvents();