Пример #1
0
        public bool Evaluate(UserConnection userConnection, AdElement element, Entity relatedEntity, Entity handler)
        {
            _logger.Info(handler.GetColumnDisplayValue(handler.Schema.Columns.GetByName("NavHandler")));
            // проверяем, что из AD мы получили значение нужного атрибута
            var    existsInAD   = element.Attributes.ContainsKey(handler.GetTypedColumnValue <string>("NavAdAttributeName"));
            var    hasValueInAD = false;
            var    adValue      = string.Empty;
            object setValue     = null;

            if (existsInAD)
            {
                adValue = element.Attributes[handler.GetTypedColumnValue <string>("NavAdAttributeName")].Value;

                _logger.Info("Приводим значение атрибута к типу, записываемому в БД");
                // определяем тип к которому нужно привести и приводим
                string typeName = AdAttributesHelper.GetXmlElement("type", handler.GetTypedColumnValue <string>("NavHandlerParameterXML"));
                if (typeName.IsEmpty())
                {
                    _logger.Warn("Не удалось прочитать значение xml-элемента <type>");
                }
                switch (typeName.Trim().ToLower())
                {
                case "bool":
                    string revertParam = AdAttributesHelper.GetXmlElement("revert", handler.GetTypedColumnValue <string>("NavHandlerParameterXML"));
                    bool   revert      = revertParam == "true";
                    setValue = getBoolValue(adValue);
                    if (revert)
                    {
                        setValue = !(bool)setValue;
                    }
                    break;

                case "date":
                    setValue = getDateValue(adValue);
                    break;

                default:
                    setValue = adValue;
                    break;
                }
                hasValueInAD = (setValue != null);
            }
            if (hasValueInAD)
            {
                // Если атрибут существует в AD и у него есть значение
                _logger.Info("Значение атрибута LDAP [" + handler.GetTypedColumnValue <string>("NavAdAttributeName") + "] = \"" + adValue + "\"");
            }
            else
            {
                // Если атрибут отсутствует в AD или пустует, удаляем соотвутствующие данные из системы
                _logger.Info("Значение атрибута в LDAP отсутствует или пустое. Очищаем поле " + handler.GetTypedColumnValue <string>("NavAdAttributeName"));
            }
            relatedEntity.SetColumnValue(handler.GetTypedColumnValue <string>("NavEntityFieldName"), setValue);
            _logger.Info("Сохраняем запись");
            relatedEntity.Save(false);
            return(true);
        }
Пример #2
0
        public bool Evaluate(UserConnection userConnection, AdElement element, Entity relatedEntity, Entity handler)
        {
            _logger.Info("Добавляем средство связи " + handler.GetTypedColumnValue <string>("NavAdAttributeName"));

            string adValue = AdAttributesHelper.GetAdValue(element, (NavAdAttributesHandlers)handler);

            var  contact             = (Contact)relatedEntity;
            Guid communicationTypeId = GetCommunicationType(userConnection, handler.GetTypedColumnValue <string>("NavAdAttributeName"));

            ContactCommunication[] contactCommunications = GetContactCommunications(userConnection, contact, communicationTypeId);

            if (adValue != null)
            {
                char[] separator           = Core.Configuration.SysSettings.GetValue(userConnection.AppConnection.SystemUserConnection, "ContactCommunicationSeparator").ToString().ToArray();
                var    communicationValues = adValue.Split(separator).Select(s => s.Trim()).ToList();

                // обрабатываем уже существующие в bpm средства связи
                foreach (var cm in contactCommunications)
                {
                    if (!communicationValues.Contains(cm.Number))
                    {
                        cm.Delete();
                    }
                    else
                    {
                        communicationValues.Remove(cm.Number);
                    }
                }

                // создаем отсутствующие записи
                foreach (var cv in communicationValues)
                {
                    var contactCommunication = new ContactCommunication(userConnection);
                    contactCommunication.UseAdminRights = false;

                    contactCommunication.SetDefColumnValues();
                    contactCommunication.ContactId               = contact.Id;
                    contactCommunication.CommunicationTypeId     = communicationTypeId;
                    contactCommunication.NavSynchronizedWithLDAP = true;

                    contactCommunication.Number = cv;
                    contactCommunication.Save(false);
                }
            }
            else
            {
                foreach (var cm in contactCommunications)
                {
                    cm.Delete();
                }
            }

            return(true);
        }
Пример #3
0
        public bool Evaluate(UserConnection userConnection, AdElement element, Entity relatedEntity, Entity handler)
        {
            string adValue = AdAttributesHelper.GetAdValue(element, (NavAdAttributesHandlers)handler);

            if (adValue != null)
            {
                // получаем данные о справочнике, на который смотрит колонка в основном объекте
                var NavEntityFieldName = handler.GetTypedColumnValue <string>("NavEntityFieldName");
                if (NavEntityFieldName.IsEmpty())
                {
                    throw new Exception("Не заполнено поле NavEntityFieldName");
                }

                var    lookupColumn = relatedEntity.Schema.Columns.GetByName(NavEntityFieldName);
                var    entitySchema = lookupColumn.ReferenceSchema;
                string schemaName   = entitySchema.Name;

                var searchColumn = AdAttributesHelper.GetXmlElement("searchcolumn", handler.GetTypedColumnValue <string>("NavHandlerParameterXML"));
                if (searchColumn.IsEmpty())
                {
                    searchColumn = entitySchema.GetPrimaryDisplayColumnName();
                }

                Entity lookupValue = AdAttributesHelper.GetLookupValue(userConnection, adValue, schemaName, searchColumn);
                if (lookupValue == null)
                {
                    lookupValue = AdAttributesHelper.CreateLookupValue(userConnection, adValue, schemaName, searchColumn);
                }

                // Если атрибут существует в AD и у него есть значение
                _logger.Info("Записываем в поле " + relatedEntity.Schema.Caption + "." + handler.GetTypedColumnValue <string>("NavEntityFieldName") + " = \"" + lookupValue.PrimaryDisplayColumnValue + "\"(" + lookupValue.PrimaryColumnValue + ")");
                relatedEntity.SetColumnValue(handler.GetTypedColumnValue <string>("NavEntityFieldName") + "Id", lookupValue.PrimaryColumnValue);
            }
            else
            {
                // Если атрибут отсутствует в AD, удаляем соотвутствующие данные из системы
                _logger.Info("Очищаем поле (отсутствует в AD) " + relatedEntity.Schema.Caption + "." + handler.GetTypedColumnValue <string>("NavEntityFieldName"));
                relatedEntity.SetColumnValue(handler.GetTypedColumnValue <string>("NavEntityFieldName") + "Id", null);
            }
            _logger.Info("Сохраняем запись");
            relatedEntity.Save(false);
            return(true);
        }
Пример #4
0
        public bool Evaluate(UserConnection userConnection, AdElement element, Entity relatedEntity, Entity handler)
        {
            _logger.Info("Читаем адрес контакта");
            var    contact   = (Contact)relatedEntity;
            Guid?  countryId = null;
            Guid?  cityId    = null;
            string addr      = null;
            string room      = null;
            string zip       = null;

            // Страна
            string countryAttr = AdAttributesHelper.GetXmlElement("country", handler.GetTypedColumnValue <string>("NavHandlerParameterXML"));

            if (countryAttr.IsNotEmpty() && element.Attributes.ContainsKey(countryAttr))
            {
                string countryName = element.Attributes[countryAttr].Value;
                var    country     = (Country)AdAttributesHelper.GetOrCreateEntityByDisplayValue(userConnection, "Country", countryName);

                countryId = country.Id;

                _logger.Info("Страна = " + countryName);
            }

            // Город
            string cityAttr = AdAttributesHelper.GetXmlElement("city", handler.GetTypedColumnValue <string>("NavHandlerParameterXML"));

            if (cityAttr.IsNotEmpty() && element.Attributes.ContainsKey(cityAttr))
            {
                string cityName = element.Attributes[cityAttr].Value;
                var    city     = (City)AdAttributesHelper.GetOrCreateEntityByDisplayValue(userConnection, "City", cityName);

                cityId = city.Id;

                _logger.Info("Город = " + cityName);
            }

            // Улица, дом
            string addrAttr = AdAttributesHelper.GetXmlElement("address", handler.GetTypedColumnValue <string>("NavHandlerParameterXML"));

            if (addrAttr.IsNotEmpty() && element.Attributes.ContainsKey(addrAttr))
            {
                addr = element.Attributes[addrAttr].Value;

                _logger.Info("Адрес = " + addr);
            }

            // postalCode
            string zipAttr = AdAttributesHelper.GetXmlElement("postalCode", handler.GetTypedColumnValue <string>("NavHandlerParameterXML"));

            if (zipAttr.IsNotEmpty() && element.Attributes.ContainsKey(zipAttr))
            {
                zip = element.Attributes[zipAttr].Value;

                _logger.Info("zip = " + zip);
            }

            ContactAddress address = GetContactAddress(userConnection, contact);

            if (countryId != null || cityId != null || addr != null || zip != null)
            {
                _logger.Info("Сохраняем адрес контакта");

                address.SetColumnValue("CountryId", countryId);
                address.SetColumnValue("CityId", cityId);
                address.Address = addr;
                address.Zip     = zip;

                try
                {
                    address.Save(false);
                }
                catch (Exception ex)
                {
                    _logger.Error("Ошибка при сохранении адреса " + ex.ToString());
                }
            }
            else
            {
                _logger.Info("Удаляем адрес контакта");
                try
                {
                    address.Delete();
                }
                catch (Exception ex)
                {
                    _logger.Error("Ошибка при удалении адреса " + ex.ToString());
                }
            }

            return(true);
        }