private bool readLync2BcmRules(XmlReader r) { LyncState ls; Lync_to_Bcm_Rule R; string sE, sA; ls = null; R = null; try { while (r.Read()) { if (r.IsStartElement()) { sE = r.Name; if (sE == "state") { R = new Lync_to_Bcm_Rule(); sA = r.GetAttribute("id"); if (m_LyncStates.ContainsKey(sA)) { ls = m_LyncStates[sA]; R.rId = sA; R.LyncSt = ls; R.BcmOnline = null; R.BcmOnline = null; sA = r.GetAttribute("sticky"); if (Util.IsNullOrEmpty(sA)) { R.Sticky = false; } else if (sA == "1") { R.Sticky = true; } sA = r.GetAttribute("bcm_online"); if (Util.IsNullOrEmpty(sA) == false) { R.BcmOnline = m_cfg.GetBCMProfile(sA); } sA = r.GetAttribute("bcm_offline"); if (Util.IsNullOrEmpty(sA) == false) { R.BcmOffline = m_cfg.GetBCMProfile(sA); } if (m_Lync2Bcm.ContainsKey(R.rId) == false) { m_Lync2Bcm.Add(R.rId, R); } else { m_log.Log("Error - rule " + R.rId + " already in lync2bcm states"); } } else { m_log.Log("Error - invalid configuration element in Lync2BcmRules - no LyncState with name " + sA); } } if (sE == "BCM_to_Lync") { readBcm2LyncRules(r); return(true); } if (sE == "Lync_to_BCM") { readLync2BcmRules(r); return(true); } } } } catch (Exception e) { m_log.Log("Exception while reading Lync2BCMRules " + e); return(false); } return(true); }
protected void PSI_presencePoll() { PresenceChangeNotification[] aChanges; m_log.Log("Calling GetPresenceChanges\n"); aChanges = m_PSI.GetPresenceChanges(m_PSI_Session, 5000); if (aChanges != null && aChanges.Length > 0) { foreach (PresenceChangeNotification p in aChanges) { try { ObiUser u; u = m_PL.getUserBCM(p.UserId); if (u != null) { string rname = null; Bcm_to_Lync_Rule Rule = null; BcmState bnew = new BcmState(); m_log.Log("BCM change:" + u.logId + " profile:" + p.PresenceProfile + " login:"******" service:" + p.ServiceState + " call:" + p.CallState); if (m_PL.getSyncDirection() == SyncDirection.Lync_2_BCM) { continue; } if (p.PresenceProfile != null && p.PresenceProfile.Length > 0) { bnew.Profile = m_CFG.GetBCMProfile(p.PresenceProfile); } else { bnew.Profile = u.BS.Profile; } if (bnew.Profile == null) { bnew.Profile = m_CFG.GetBcmUnkown(); } if (p.LoginState != UserLoginState.No_Change) { if (p.LoginState == UserLoginState.Logged_In) { rname = "_Online"; bnew.LoginState = true; } else { rname = "_Offline"; bnew.LoginState = false; } } else { bnew.LoginState = u.BS.LoginState; } if (p.ServiceState != UserServiceState.No_Change) { switch (p.ServiceState) { case UserServiceState.Working: rname = "_Working"; bnew.ServiceState = BcmServiceState.Working; break; case UserServiceState.Paperwork: rname = "_PaperWork"; bnew.ServiceState = BcmServiceState.Paperwork; break; case UserServiceState.Wrapup: rname = "_WrapUp"; bnew.ServiceState = BcmServiceState.WrapUp; break; default: rname = "_Working"; bnew.ServiceState = BcmServiceState.Working; break; } } else { bnew.ServiceState = u.BS.ServiceState; } if (p.CallState != UserCallState.No_Change) { if (p.CallState == UserCallState.Talking) { rname = "_Talking"; bnew.CallState = true; } else { rname = "_EndCall"; bnew.CallState = false; } } else { bnew.CallState = u.BS.CallState; } if (p.EndTime != DateTime.MaxValue && p.EndTime != DateTime.MinValue) { m_log.Log("Endtime in notification now " + p.EndTime); } if (u.bcm_initial == false) { m_log.Log("User " + u.logId + "(" + u.FName + ") presence changed"); if (u.BS.IsDifferent(bnew)) { // find rule first by change indication if (rname != null) { m_log.Log("Change indication rule check " + rname); Rule = u.ProfileGroup.findBcm2LyncRule(bnew.Profile.Name + rname); if (Rule == null) { Rule = u.ProfileGroup.findBcm2LyncRule(rname); } } if (Rule == null) { if (bnew.Profile != u.BS.Profile) { m_log.Log("Profile changed - rule by profile"); Rule = u.ProfileGroup.findBcm2LyncRule(bnew.Profile.Name); } else { m_log.Log("No profile change - no rule"); } } if (bnew.Profile == u.BS.Profile) { if (u.BS.Sticky) { m_log.Log("No profile change - sticky bcm on - keeping it"); bnew.Sticky = true; } } u.BS = bnew; if (Rule != null) { if (Rule.Sticky) { m_log.Log("Setting sticky BCM state "); u.BS.Sticky = true; } m_PL.Bcm_PresenceChanged(u, Rule); } } } else { m_log.Log("User " + u.logId + "(" + u.FName + ") initial presence received"); u.bcm_initial = false; u.BS = bnew; u.prevBS = new BcmState(); u.prevBS.Set(bnew); // check rule for stickiness if (bnew.Profile.Name != null) { Rule = u.ProfileGroup.findBcm2LyncRule(bnew.Profile.Name); if (Rule != null) { if (Rule.Sticky) { m_log.Log("User " + u.logId + " initial bcm availability is sticky"); u.BS.Sticky = true; } } } if (m_Subscribed.ContainsKey(u.UserId) == false) { m_Subscribed.Add(u.UserId, u); } } } else { m_log.Log("Error - unknown user " + p.UserId + " in presencechanges"); } } catch (Exception exp) { m_log.Log("Exceptoin in GetPresenceChanges: " + exp); } } } else { m_log.Log("No presence changes"); } }