예제 #1
0
        private static string GetLogFilePath(InstantMessageModality messageInfo)
        {
            string path = ConfigurationManager.AppSettings["LOG_PATH"];

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string username;

            if (messageInfo.Conversation.Participants.Count > 2)
            {
                username = "******";
            }
            else
            {
                Participant participant = LyncHelper.GetConversationParticipant(messageInfo.Conversation);
                username = LyncHelper.GetContactUsername(participant.Contact);
            }

            path += "/" + username;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string conversationId = (string)messageInfo.Conversation.Properties[ConversationProperty.Id];
            string filename       = GetConversationFilename(conversationId);

            path += "/" + filename;

            return(path);
        }
예제 #2
0
 private void CheckLyncProcessStatus(object state)
 {
     if (LyncHelper.GetLyncProcess() == null)
     {
         DebugLog.Write("Lync is no longer running, exiting LyncChatLogger");
         DebugLog.Write("SHUTDOWN{0}", Environment.NewLine);
         Environment.Exit(0);
     }
 }
예제 #3
0
        public static void Open(Conversation conversation)
        {
            Participant participant = LyncHelper.GetConversationParticipant(conversation);

            if (participant != null)
            {
                string username = LyncHelper.GetContactUsername(participant.Contact);

                DebugLog.Write("Conversation with {0} started at {1} {2}", username, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());
            }
        }
예제 #4
0
        public static void ShutdownLync()
        {
            DebugLog.Write("LyncChatLogger closing, shutting down Lync");

            Process p = LyncHelper.GetLyncProcess();

            if (p != null)
            {
                p.Kill();
            }

            DebugLog.Write("SHUTDOWN{0}", Environment.NewLine);
        }
예제 #5
0
        public static void Write(InstantMessageModality messageInfo, string text)
        {
            string username = LyncHelper.GetContactUsername(messageInfo.Participant.Contact);
            string path     = GetLogFilePath(messageInfo);

            using (var writer = new StreamWriter(path, true))
            {
                if (!text.EndsWith(Environment.NewLine))
                {
                    text += Environment.NewLine;
                }

                writer.Write("[{0} {1}] {2}: {3}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), username, text);
            }
        }
예제 #6
0
        private void MainForm_Load(object sender, EventArgs args)
        {
            try
            {
                DebugLog.Write("STARTUP");

                LyncClient client = LyncHelper.GetLyncClient();

                if (client == null)
                {
                    Application.Exit();
                    return;
                }

                // subscribe to conversation added/removed events
                client.ConversationManager.ConversationAdded   += ConversationAdded;
                client.ConversationManager.ConversationRemoved += ConversationRemoved;

                //// subscribe to contact availibility changes
                //foreach (var group in client.ContactManager.Groups)
                //{
                //	//Debug.WriteLine("{0}: {1}", group.Name, group.Count);

                //	foreach (var contact in group)
                //	{
                //		contact.ContactInformationChanged += ContactInformationChanged;

                //		ContactStatus status = GetContactStatus(contact);

                //		if (status != null)
                //		{
                //			Debug.WriteLine("{0} initial status: {1} {2}", status.Username, status.Availability, status.Activity);
                //		}
                //	}
                //}

                DebugLog.Write("Waiting for incoming messages...");

                // check for shutdown of lync client
                _lyncStatusTimer = new System.Threading.Timer(CheckLyncProcessStatus, null, 1000, 1000);
            }
            catch (Exception ex)
            {
                LogException("InitializeLogger", ex);
                LyncHelper.ShutdownLync();
                Environment.Exit(0);
            }
        }
예제 #7
0
        public static void Close(Conversation conversation)
        {
            string conversationId = (string)conversation.Properties[ConversationProperty.Id];

            if (_logs.ContainsKey(conversationId))
            {
                _logs.Remove(conversationId);
            }

            Participant participant = LyncHelper.GetConversationParticipant(conversation);

            if (participant != null)
            {
                string username = LyncHelper.GetContactUsername(participant.Contact);

                DebugLog.Write("Conversation with {0} ended at {1} {2}", username, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());
            }
        }
예제 #8
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs args)
 {
     LyncHelper.ShutdownLync();
 }