Exemplo n.º 1
0
        private void SetAvailability(ContactAvailability NewAvailability)
        {
            Trace.WriteLine("SetAvailability(" + NewAvailability.ToString() + ")");
            //Add the availability to the contact information items to be published
            Dictionary <PublishableContactInformationType, object> newInformation =
                new Dictionary <PublishableContactInformationType, object>();

            newInformation.Add(PublishableContactInformationType.Availability, NewAvailability);

            //Publish the new availability value
            try
            {
                lyncClient.Self.BeginPublishContactInformation(newInformation, PublishContactInformationCallback, null);
            }
            catch (LyncClientException lyncClientException)
            {
                Trace.WriteLine(lyncClientException);
            }
            catch (SystemException systemException)
            {
                if (IsLyncException(systemException))
                {
                    // Log the exception thrown by the Lync Model API.
                    Trace.WriteLine("Lync Exception: " + systemException);
                }
                else
                {
                    // Rethrow the SystemException which did not come from the Lync Model API.
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        void Contact_ContactInformationChanged(object sender, ContactInformationChangedEventArgs e)
        {
            string        returnValue = string.Empty;
            StringBuilder sb          = new StringBuilder();
            Boolean       raiseUpdate = false;

            if (e.ChangedContactInformation.Contains(ContactInformationType.Availability))
            {
                //get actual contactModel availability (Will be int value within OCOM availaiblity ranges)
                ContactAvailability availEnum = (ContactAvailability)((Contact)sender).GetContactInformation(ContactInformationType.Availability);
                string activityString         = (string)((Contact)sender).GetContactInformation(ContactInformationType.Activity);
                sb.Append(availEnum.ToString() + " " + activityString);
                raiseUpdate = true;
            }

            if (raiseUpdate)
            {
                returnValue = "Updated availability for "
                              + ((Contact)sender).GetContactInformation(ContactInformationType.DisplayName).ToString()
                              + System.Environment.NewLine
                              + sb.ToString();
            }

            Dictionary <PublishableContactInformationType, object> publishState = new Dictionary <PublishableContactInformationType, object>();

            publishState.Add(PublishableContactInformationType.Availability, ContactAvailability.Free);

            writeMessage("simulate mouse click" + DateTime.Now.ToString());
            DoMouseClick();

            //_lyncClient.Self.BeginPublishContactInformation(publishState, publishState_callback, null);
        }
Exemplo n.º 3
0
        private void Contact_ContactInformationChanged(object sender, ContactInformationChangedEventArgs e)
        {
            //Set LED matching Lync/SfB state
            Console.WriteLine("Lync/SfB state changed!");
            ContactAvailability myAvailability = (ContactAvailability)lyncClient.Self.Contact.GetContactInformation(ContactInformationType.Availability);

            controlBusylight(string.Format("kSetLed,{0};", myAvailability.ToString()));
        }
        /// <summary>
        /// Read the current Availability Information from Lync/Skype for Business and set the color
        /// </summary>
        void SetCurrentContactState()
        {
            Rgb blinkColor = blinkColorOff;

            byte[] arduinoLeds = arduinoColorOff;

            if (lyncClient.State == ClientState.SignedIn)
            {
                ContactAvailability currentAvailability = (ContactAvailability)lyncClient.Self.Contact.GetContactInformation(ContactInformationType.Availability);
                switch (currentAvailability)
                {
                case ContactAvailability.Busy:                  // Busy
                    blinkColor  = blinkColorBusy;
                    arduinoLeds = arduinoColorBusy;
                    break;

                case ContactAvailability.BusyIdle:              // Busy and idle
                    blinkColor  = blinkColorBusyIdle;
                    arduinoLeds = arduinoColorBusyIdle;
                    break;

                case ContactAvailability.Free:                  // Available
                    blinkColor  = blinkColorAvailable;
                    arduinoLeds = arduinoColorAvailable;
                    break;

                case ContactAvailability.FreeIdle:              // Available and idle
                    blinkColor  = blinkColorAvailableIdle;
                    arduinoLeds = arduinoColorAvailableIdle;
                    break;

                case ContactAvailability.Away:                  // Inactive/away, off work, appear away
                case ContactAvailability.TemporarilyAway:       // Be right back
                    blinkColor  = blinkColorAway;
                    arduinoLeds = arduinoColorAway;
                    break;

                case ContactAvailability.DoNotDisturb:          // Do not disturb
                    blinkColor  = blinkColorBusy;
                    arduinoLeds = arduinoColorBusy;
                    break;

                case ContactAvailability.Offline:               // Offline
                    blinkColor  = blinkColorOff;
                    arduinoLeds = arduinoColorOff;
                    break;

                default:
                    break;
                }

                SetBlink1State(blinkColor);
                arduino.SetLEDs(arduinoLeds);

                Debug.WriteLine(currentAvailability.ToString());
            }
        }
        /// <summary>
        /// lync search callback to parse the results of the query
        /// </summary>
        /// <param name="r"></param>
        private void BeginSearchCallback(IAsyncResult r)
        {
            //Console.WriteLine("callback here");
            object[]       asyncState = (object[])r.AsyncState;
            ContactManager cm         = (ContactManager)asyncState[0];

            try
            {
                SearchResults results = cm.EndSearch(r);
                if (results.AllResults.Count == 0)
                {
                    Console.WriteLine(Resources.NoResults);
                    _done = true;
                }
                else if (results.AllResults.Count == 1)
                {
                    Contact contact = results.Contacts[0];

                    ContactAvailability availability = (ContactAvailability)contact.GetContactInformation(ContactInformationType.Availability);

                    //todo: check idle time without hanging
                    string timeElapsed        = GetElapsedIdleTime(contact);
                    string userStatus         = availability.ToString();
                    string statusCode         = contact.GetContactInformation(ContactInformationType.Availability).ToString();
                    string isOutOfOfficeCheck = contact.GetContactInformation(ContactInformationType.IsOutOfOffice).ToString();
                    Console.WriteLine(String.Format("Status: {0}, Code: {1}, Last seen: {2}, Is Out Of Office: {3}", userStatus, statusCode, timeElapsed, isOutOfOfficeCheck));

                    //http://rcosic.wordpress.com/2011/11/17/availability-presence-in-lync-client/
                    //Invalid (-1),
                    //None (0) – Do not use this enumerator. This flag indicates that the cotact state is unspecified.,
                    //Free (3500) – A flag indicating that the contact is available,
                    //FreeIdle (5000) – Contact is free but inactive,
                    //Busy (6500) – A flag indicating that the contact is busy and inactive,
                    //BusyIdle (7500) – Contact is busy but inactive,
                    //DoNotDisturb (9500) – A flag indicating that the contact does not want to be disturbed,
                    //TemporarilyAway (12500) – A flag indicating that the contact is temporarily away,
                    //Away (15500) – A flag indicating that the contact is away,
                    //Offline (18500) – A flag indicating that the contact is signed out.

                    _done = true;
                }
                else
                {
                    Console.WriteLine(Resources.MultipleResults);
                    _done = true;
                }
            }
            catch (SearchException se)
            {
                Console.WriteLine(Resources.SearchFailed + se.Reason.ToString());
                _done = true;
            }
            _client.ContactManager.EndSearch(r);
        }
        internal LedPanelMapper Create(ContactAvailability ca)
        {
            var type = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(f => typeof(LedPanelMapper).IsAssignableFrom(f) && f.Name == ca.ToString());

            if (type == null)
            {
                throw new NotImplementedException(ca.ToString());
            }

            var result = (LedPanelMapper)Activator.CreateInstance(type);

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Send state to callback
        /// </summary>
        private void SendState()
        {
            if (callback == null)
            {
                return;
            }

            if (!sendEvent)
            {
                return;
            }


            if (lyncClient == null)
            {
                callback.WriteState("not-running", "");
                return;
            }

            if (lyncClient.State != ClientState.SignedIn)
            {
                callback.WriteState("signed-out", "");
                return;
            }

            foreach (var conv in lyncClient.ConversationManager.Conversations)
            {
                ModalityState state = conv.Modalities[ModalityTypes.AudioVideo].State;

                if (state == ModalityState.Notified)
                {
                    callback.WriteState("call-calling", "");
                    return;
                }
                if (state == ModalityState.Connecting ||
                    state == ModalityState.Connected ||
                    state == ModalityState.Joining ||
                    state == ModalityState.ConnectingToCaller)
                {
                    callback.WriteState("call-connected", "");
                    return;
                }
            }

            ContactAvailability currentAvailability = (ContactAvailability)lyncClient.Self.Contact.GetContactInformation(ContactInformationType.Availability);

            // Busy, BusyIdle, Free, FreeIdle, Away, TemporarilyAway, DoNotDisturb, Offline
            callback.WriteState(currentAvailability.ToString(), "");
        }
 public static void SetSelfAvailability(ContactAvailability availability, string activityId = null)
 {
     if (string.IsNullOrEmpty(activityId))
     {
         activityId = availability.ToString().ToLower();
     }
     try
     {
         var info = new Dictionary <PublishableContactInformationType, object> {
             { PublishableContactInformationType.Availability, availability },
             { PublishableContactInformationType.ActivityId, activityId }
         };
         LyncClient.GetClient().Self.BeginPublishContactInformation(info, null, null);
     }
     catch { }
 }
Exemplo n.º 9
0
        internal static me.ContactAvailability ToContactAvaliability(this ContactAvailability ca)
        {
            var nativeIndex = (int)ca;

            var modelEnumType = typeof(me.ContactAvailability);

            foreach (Enum val in Enum.GetValues(modelEnumType))
            {
                var fi       = modelEnumType.GetField(val.ToString());
                var custAttr = (NativeContactAvailabilityIdAttribute)fi.GetCustomAttributes(typeof(NativeContactAvailabilityIdAttribute), false).FirstOrDefault();
                if (custAttr != null && custAttr.NativeIndex == nativeIndex)
                {
                    return((me.ContactAvailability)val);
                }
            }

            throw new NotImplementedException(ca.ToString());
        }
        /// <summary>
        /// Gets the contact details.
        /// </summary>
        /// <param name="contact">The contact whose details needs to be retrieved.</param>
        public string GetContactInfo(Contact contact)
        {
            string returnValue         = string.Empty;
            string activityDescription = null;

            List <object> collaborationPhones = null;

            // Get the Availability information for the contact.
            ContactAvailability availEnum = (ContactAvailability)(contact)
                                            .GetContactInformation(ContactInformationType.Availability);

            // Get the Activity information for the contact.
            activityDescription = (string)contact
                                  .GetContactInformation(ContactInformationType.Activity);

            // Get the ContactEndpoints information for the contact.
            collaborationPhones = (List <object>)contact
                                  .GetContactInformation(ContactInformationType.ContactEndpoints);

            // Generate a string for the information retrieved and return it.
            if (collaborationPhones != null)
            {
                returnValue += "\r\nPhones:";
                foreach (object phone in collaborationPhones)
                {
                    ContactEndpoint anEndpoint = (ContactEndpoint)phone;
                    returnValue += "\r\nType: "
                                   + anEndpoint.Type.ToString()
                                   + "\r\n DisplayName: "
                                   + anEndpoint.DisplayName
                                   + "\r\n Uri: "
                                   + anEndpoint.Uri;
                }
            }

            returnValue += "\r\n Activity:" + activityDescription;
            returnValue += "\r\nPersonal note: " + contact
                           .GetContactInformation(ContactInformationType.PersonalNote);
            returnValue += "\r\nOOF note: " + contact
                           .GetContactInformation(ContactInformationType.OutOfficeNote);
            returnValue += "\r\nAvailable:" + availEnum.ToString();

            return(returnValue);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Read the current Availability Information from Lync/Skype for Business and set the color
        /// </summary>
        void SetCurrentContactState()
        {
            if (lyncClient.State == ClientState.SignedIn)
            {
                ContactAvailability currentAvailability = (ContactAvailability)lyncClient.Self.Contact.GetContactInformation(ContactInformationType.Availability);
                switch (currentAvailability)
                {
                case ContactAvailability.Busy:                  // Busy
                    SetStateColor(STATE_COLOR_BUSY);
                    break;

                case ContactAvailability.BusyIdle:              // Busy and idle
                    SetStateColor(STATE_COLOR_BUSY_IDLE);
                    break;

                case ContactAvailability.Free:                  // Available
                    SetStateColor(STATE_COLOR_AVAILABLE);
                    break;

                case ContactAvailability.FreeIdle:              // Available and idle
                    SetStateColor(STATE_COLOR_AVAILABLE_IDLE);
                    break;

                case ContactAvailability.Away:                  // Inactive/away, off work, appear away
                case ContactAvailability.TemporarilyAway:       // Be right back
                    SetStateColor(STATE_COLOR_AWAY);
                    break;

                case ContactAvailability.DoNotDisturb:          // Do not disturb
                    SetStateColor(STATE_COLOR_DO_NOT_DISTURB);
                    break;

                case ContactAvailability.Offline:               // Offline
                    SetStateColor(STATE_COLOR_OFF);
                    break;

                default:
                    break;
                }

                Debug.WriteLine(currentAvailability.ToString());
            }
        }
Exemplo n.º 12
0
 public void Set(ContactAvailability avail)
 {
     _cmdMessenger.SendCommand(new SendCommand((int)Command.SetLed, avail.ToString()));
 }
Exemplo n.º 13
0
 public Presence(ContactAvailability presence)
 {
     this.status = presence.ToString();
 }
Exemplo n.º 14
0
        private void NotifyAvailability(ContactAvailability presence)
        {
            // yay cross-thread!
            var renderUpdatedPresence = new Action(() =>
            {
                this.lblCurrentStatus.Text = presence.ToString();

                switch (presence)
                {
                case ContactAvailability.Offline:
                    this.lblCurrentStatus.ForeColor = System.Drawing.Color.DarkGray;
                    break;

                case ContactAvailability.Free:
                    this.lblCurrentStatus.ForeColor = System.Drawing.Color.Green;
                    break;

                case ContactAvailability.Away:
                    this.lblCurrentStatus.ForeColor = System.Drawing.Color.Orange;
                    break;

                case ContactAvailability.DoNotDisturb:
                case ContactAvailability.Busy:
                    this.lblCurrentStatus.ForeColor = System.Drawing.Color.Red;
                    break;

                default:
                    this.lblCurrentStatus.ForeColor = System.Drawing.Color.Black;
                    break;
                }
            });

            if (this.InvokeRequired)
            {
                this.Invoke(renderUpdatedPresence);
            }
            else
            {
                renderUpdatedPresence();
            }


            // do the notification
            using (var httpClient = new HttpClient())
            {
                var payload = JsonConvert.SerializeObject(new Presence(presence));
                var content = new StringContent(payload, System.Text.Encoding.UTF8, "application/json");

                // notify the endpoint
                Task.Run(async() =>
                {
                    var result = await httpClient.PostAsync(_endpoint, content);

                    if (!result.IsSuccessStatusCode)
                    {
                        notifyIcon.ShowBalloonTip(2000, Application.ProductName,
                                                  "There was a problem communicating with the endpoint you specified.", ToolTipIcon.Error);
                    }
                }).Wait();
            }
        }
Exemplo n.º 15
0
        private void alertInventory()
        {
            //Scans the inventory and alerts
            if (failHosts.Count + failServices.Count > Properties.Settings.Default.spam_thres)
            {
                //The shit just hit the fan, gross!
                showTip(rm.GetString("balloon_chaos_title"),
                        rm.GetString("balloon_chaos_msg").Replace("X", failHosts.Count.ToString())
                        .Replace("Y", failServices.Count.ToString()),
                        ToolTipIcon.Warning);
            }
            else
            {
                //Hosts
                try
                {
                    foreach (string host in failHosts.Keys)
                    {
                        if (Properties.Settings.Default.balloon_enable == true)
                        {
                            //Show tooltip if enabled
                            showTip(string.Format("Host {0}", dictStatesHost[failHosts[host]].ToUpper()), string.Format("Host '{0}' {1}", host, dictStatesHost[failHosts[host]]), ToolTipIcon.Error);
                        }

                        SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode,
                                               string.Format("Alarm: Host '{0}' is '{1}'", host, dictStatesHost[failHosts[host]]),
                                               Properties.Settings.Default.log_level, 2);

                        annoyUser(dictColorHost[failHosts[host]]);
                    }

                    //Services
                    foreach (string host in failServices.Keys)
                    {
                        //Only report if host not generally down
                        if (failHosts.ContainsKey(host) == false)
                        {
                            SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode,
                                                   string.Format("Host '{0}' not blacklisted!", host),
                                                   Properties.Settings.Default.log_level, 2);

                            //Report service
                            foreach (string service in failServices[host])
                            {
                                try
                                {
                                    //Extract state and service
                                    int    thisState   = Convert.ToInt32(service.Substring(service.IndexOf(';') + 1));
                                    string thisService = service.Substring(service.IndexOf('!') + 1);
                                    thisService = thisService.Substring(0, thisService.IndexOf(';'));

                                    SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode,
                                                           string.Format("Alarm: '{0}' on '{1}' is '{2}'", thisService, host, dictStates[thisState]),
                                                           Properties.Settings.Default.log_level, 2);

                                    //Show tooltip if enabled
                                    if (Properties.Settings.Default.balloon_enable == true)
                                    {
                                        showTip(string.Format("Service {0}", dictStates[thisState].ToUpper()),
                                                string.Format("Service '{0}' {1} '{2}' {3}", thisService, rm.GetString("state_on"), host, dictStates[thisState]), dictIcons[thisState]);
                                    }

                                    annoyUser(dictColor[thisState]);
                                }
                                catch (FormatException e)
                                {
                                    //Format error
                                    SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode, string.Format("Format error: '{0}'", e.Message), Properties.Settings.Default.log_level, 2);
                                }
                            }
                        }
                        else
                        {
                            //Ignoring host
                            SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode, string.Format("Ignoring host '{0}' as it's down", host), Properties.Settings.Default.log_level, 2);
                        }
                    }
                }
                catch (InvalidOperationException e)
                {
                    SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode, string.Format("Invalid operation: '{0}'", e.Message), Properties.Settings.Default.log_level, 2);
                }

                //Reset Lync/SfB state if enabled
                if (Properties.Settings.Default.lync_enable == true)
                {
                    SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode, "Resetting Lync/SfB state...", Properties.Settings.Default.log_level, 2);
                    try
                    {
                        lyncClient = LyncClient.GetClient();
                        if (lyncClient.State == ClientState.SignedIn)
                        {
                            //Read state
                            ContactAvailability myAvailability = (ContactAvailability)lyncClient.Self.Contact.GetContactInformation(ContactInformationType.Availability);
                            SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode, string.Format("Lync/SfB state is '{0}'", myAvailability.ToString()), Properties.Settings.Default.log_level, 2);
                            //Set color
                            var controller = new Busylight.SDK();
                            controller.Light(dictSkypeColor[myAvailability]);
                        }
                    }
                    catch (System.Runtime.InteropServices.MarshalDirectiveException e)
                    {
                        SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode, string.Format("Unable to read Lync/SfB state: '{0}'", e.Message), Properties.Settings.Default.log_level, 0);
                    }
                    catch (Exception e)
                    {
                        SimpleLoggerHelper.Log(Properties.Settings.Default.log_mode, string.Format("Unable to read Lync/SfB state: '{0}'", e.Message), Properties.Settings.Default.log_level, 0);
                    }
                }
            }
        }
Exemplo n.º 16
0
 public void Set(ContactAvailability avail)
 {
     _cmdMessenger.SendCommand(new SendCommand((int)Command.SetLed, avail.ToString()));
 }
        /// <summary>
        /// Handles the event raised when contact information is updated for a contact
        /// </summary>
        /// <param name="sender">object. The Contact whose information has changed.</param>
        /// <param name="e">ContactInformationChangedEventArgs. The event state. Provides collection of change contact information types.</param>
        void _remoteContact_ContactInformationChanged(object sender, ContactInformationChangedEventArgs e)
        {
            //**************************************
            //This event handler performs any of 4 actions based on contact availability:
            // 1: Sets the background color of the form based on contact availability
            // 2: Sets the conversation window title to current conversation state and contact availability
            // 3: Enables or disables the SendMessage_Button
            // 4: Adds the _remoteContact to the conversation if it is available to join the conversation.
            //
            //Note: An conversation state
            //**************************************

            //**************************************
            //Has the contact availability changed?
            //**************************************
            if (e.ChangedContactInformation.Contains(ContactInformationType.Availability))
            {
                ContactAvailability currentAvailability = (ContactAvailability)((Contact)sender).GetContactInformation(ContactInformationType.Availability);
                switch (currentAvailability)
                {
                case ContactAvailability.DoNotDisturb:
                    //**************************************
                    //Contact is not available.
                    //**************************************

                    //**************************************
                    //Update the window title text with the current conversation state and contact availability.
                    //**************************************
                    this.Dispatcher.Invoke(FormActor, new object[] { FormActions.UpdateWindowTitle, this, "Conversation is " + _Conversation.State.ToString() + ". Contact is " + currentAvailability.ToString() });
                    this.Dispatcher.Invoke(FormActor, new object[] { FormActions.SetFormBackColor, this, Brushes.AntiqueWhite });

                    //**************************************
                    //Disable the send message button on conversation form.
                    //**************************************
                    this.Dispatcher.Invoke(FormActor, new object[] { FormActions.DisableButton, Send_Button, null });
                    break;

                case ContactAvailability.Offline:
                    //**************************************
                    //Contact is not available.
                    //**************************************

                    //**************************************
                    //Change form color to white, indicating the remote participant cannot accept Im text.
                    //**************************************
                    this.Dispatcher.Invoke(FormActor, new object[] { FormActions.SetFormBackColor, this, Brushes.AntiqueWhite });
                    this.Dispatcher.Invoke(FormActor, new object[] { FormActions.UpdateWindowTitle, this, "Conversation is " + _Conversation.State.ToString() + ". Contact is " + currentAvailability.ToString() });

                    //**************************************
                    //Disable the send message button on conversation form.
                    //**************************************
                    this.Dispatcher.Invoke(FormActor, new object[] { FormActions.DisableButton, Send_Button, null });
                    break;

                default:
                    //**************************************
                    //If the contact is now available to join a conversation...
                    //**************************************

                    //**************************************
                    //Call helper method to add the contact to the conversation.
                    //**************************************
                    AddContactToConversation(_Conversation, (Contact)sender);

                    //**************************************
                    //Change the conversation form color to blue if
                    //conversation state is active and contact is available.
                    //**************************************
                    if (_Conversation.State == ConversationState.Active)
                    {
                        this.Dispatcher.Invoke(FormActor, new object[] { FormActions.SetFormBackColor, this, Brushes.CadetBlue });
                    }
                    this.Dispatcher.Invoke(FormActor, new object[] { FormActions.UpdateWindowTitle, this, "Conversation is " + _Conversation.State.ToString() + ". Contact is " + currentAvailability.ToString() });

                    //**************************************
                    //enable send message button on conversation form
                    //**************************************
                    this.Dispatcher.Invoke(FormActor, new object[] { FormActions.EnableButton, Send_Button, null });
                    break;
                }
            }
        }