/// <summary>
        /// Returns <see cref="SyncErrorMessage"/> instance filtered by <paramref name="errorCode"/>.z
        /// </summary>
        /// <param name="errorCode"><see cref="SyncErrorMessage.Code"/> column value.</param>
        /// <returns><see cref="SyncErrorMessage"/> instance.</returns>
        protected Entity GetSyncErrorMessageByCode(Guid errorCodeId)
        {
            EntitySchema syncErrorMessageSchema = _schemaManager.GetInstanceByName("SyncErrorMessage");
            Entity       syncErrorMessage       = syncErrorMessageSchema.CreateEntity(UserConnection);

            if (syncErrorMessage.FetchFromDB(errorCodeId, false))
            {
                return(syncErrorMessage);
            }
            return(null);
        }
Ejemplo n.º 2
0
        private void AddLczColumn(Guid cultureId, string cultureName, Select select, string schemaName,
                                  string schemaAlias, string referencePath, string columnName,
                                  bool useInnerJoin = true, string columnAlias = null, string tableAlias = null)
        {
            EntitySchema schema            = EntitySchemaManager.GetInstanceByName(schemaName);
            string       lczTableName      = schema.LocalizationSchemaName;
            string       lczTableAliasName = string.IsNullOrEmpty(tableAlias)
                                ? GetLczAliasName(schemaName, cultureName)
                                : tableAlias;
            string lczColumnAliasName = string.IsNullOrEmpty(columnAlias)
                                ? GetLczAliasName(string.Concat(schemaName, columnName), cultureName)
                                : columnAlias;
            string lczColumnName = columnName;
            IsNullQueryFunction lczColumnQueryFunction = GetLczColumnQueryFunction(lczTableAliasName, lczColumnName,
                                                                                   schemaAlias, columnName);

            select.Column(lczColumnQueryFunction).As(lczColumnAliasName);
            if (useInnerJoin)
            {
                select.InnerJoin(lczTableName).As(lczTableAliasName)
                .On(lczTableAliasName, "RecordId").IsEqual(schemaAlias, referencePath)
                .And(lczTableAliasName, "SysCultureId").IsEqual(new QueryParameter(cultureId));
            }
            else
            {
                select.LeftOuterJoin(lczTableName).As(lczTableAliasName)
                .On(lczTableAliasName, "RecordId").IsEqual(schemaAlias, referencePath)
                .And(lczTableAliasName, "SysCultureId").IsEqual(new QueryParameter(cultureId));
            }
        }
Ejemplo n.º 3
0
        private void AddContactsDynamicGroupFilters(
            IDictionary <string, Guid> localFolderUIds, UserConnection userConnection,
            EntitySchemaQueryFilterCollection filters)
        {
            if (!localFolderUIds.Any())
            {
                return;
            }
            EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager;
            var    foldersEsq           = new EntitySchemaQuery(entitySchemaManager, "ContactFolder");
            string searchDataColumnName = foldersEsq.AddColumn("SearchData").Name;

            string[] folderIdsStrArray =
                (from folderId in localFolderUIds.Values
                 select folderId.ToString()).ToArray();
            foldersEsq.Filters.Add(foldersEsq.CreateFilterWithParameters(FilterComparisonType.Equal, false,
                                                                         "Id", folderIdsStrArray));
            EntityCollection folderEntities = foldersEsq.GetEntityCollection(userConnection);

            foreach (Entity folderEntity in folderEntities)
            {
                byte[]       data = folderEntity.GetBytesValue(searchDataColumnName);
                string       serializedFilters = Encoding.UTF8.GetString(data, 0, data.Length);
                EntitySchema entitySchema      = entitySchemaManager.GetInstanceByName("Contact");
                var          dataSourceFilters =
                    Json.Deserialize <Terrasoft.Nui.ServiceModel.DataContract.Filters>(serializedFilters);
                IEntitySchemaQueryFilterItem esqFilters =
                    dataSourceFilters.BuildEsqFilter(entitySchema.UId, userConnection);
                if (esqFilters != null)
                {
                    filters.Add(esqFilters);
                }
            }
        }
        /// <summary>
        /// Convert client filters to Select object.
        /// </summary>
        /// <param name="userConnection">A <see cref="instance"/> of the current user connection.</param>
        /// <param name="ruleId">Unique identifier of the scoring rule.</param>
        /// <param name="entitySchemaName">Rule entity schema name.</param>
        /// <returns>Select object</returns>
        public Select GetRuleSelectQuery(UserConnection userConnection, Guid ruleId, string entitySchemaName)
        {
            EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager;
            EntitySchemaQuery   formESQ             = new EntitySchemaQuery(entitySchemaManager, entitySchemaName);

            formESQ.PrimaryQueryColumn.IsAlwaysSelect = true;
            formESQ.AddColumn("SearchData");
            formESQ.Filters.Add(formESQ.CreateFilterWithParameters(
                                    FilterComparisonType.Equal,
                                    "Id",
                                    new object[] { ruleId }
                                    ));
            EntityCollection formEntityCollection = formESQ.GetEntityCollection(userConnection);
            Entity           entity = formEntityCollection.First();

            byte[] searchData        = entity.GetColumnValue("SearchData") as byte[];
            string serializedFilters = UTF8Encoding.UTF8.GetString(searchData, 0, searchData.Length);

            DataContract.Filters jsonFilters = Json.Deserialize <DataContract.Filters>(serializedFilters);
            var leadSchema = entitySchemaManager.GetInstanceByName("Lead");
            var esqFilters = jsonFilters.BuildEsqFilter(leadSchema.UId, userConnection);
            var leadEsq    = new EntitySchemaQuery(userConnection.EntitySchemaManager, leadSchema.Name);

            leadEsq.UseAdminRights = false;
            leadEsq.PrimaryQueryColumn.IsVisible = true;
            leadEsq.Filters.Add(esqFilters);
            return(leadEsq.GetSelectQuery(userConnection));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns allowed activity results.
        /// </summary>
        /// <param name="userConnection">User connection.</param>
        /// <param name="activityId">ID of the activity.</param>
        /// <returns>Allowed values of the activity result.</returns>
        public static string GetAllowedActivityResults(UserConnection userConnection, Guid activityId)
        {
            var select = (Select) new Select(userConnection)
                         .Column("AllowedResult")
                         .From("Activity")
                         .Where("Id").IsEqual(Column.Parameter(activityId));
            var allowedResult = select.ExecuteScalar <string>();

            if (string.IsNullOrEmpty(allowedResult))
            {
                return("[]");
            }
            EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager;
            EntitySchema        entitySchema        = entitySchemaManager.GetInstanceByName("ActivityResult");
            var esq = new EntitySchemaQuery(entitySchemaManager, entitySchema.Name)
            {
                UseAdminRights = false
            };

            esq.PrimaryQueryColumn.IsAlwaysSelect = true;
            string columnName = entitySchema.GetPrimaryDisplayColumnName();

            esq.AddColumn(columnName);
            esq.AddColumn("Category");
            EntitySchemaQueryFilterCollection filters = esq.Filters;
            var allowedResultIds = ServiceStackTextHelper.Deserialize <string[]>(allowedResult);
            var columnParameters = new object[allowedResultIds.Length];

            for (int i = 0; i < allowedResultIds.Length; i++)
            {
                var resultId = new Guid(allowedResultIds[i]);
                columnParameters[i] = resultId;
            }
            filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Id", columnParameters));
            EntityCollection entityCollection = esq.GetEntityCollection(userConnection);
            bool             isFirstItem      = true;
            var sb = new StringBuilder("[");

            foreach (Entity entity in entityCollection)
            {
                if (!isFirstItem)
                {
                    sb.Append(",");
                }
                else
                {
                    isFirstItem = false;
                }
                sb.AppendFormat("{{\"resultId\":\"{0}\",\"caption\":\"{1}\",\"categoryId\":\"{2}\"}}",
                                entity.GetTypedColumnValue <Guid>("Id"), entity.GetTypedColumnValue <string>(columnName),
                                entity.GetTypedColumnValue <Guid>("CategoryId"));
            }
            sb.Append("]");
            return(sb.ToString());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates section in workplace registration for <paramref name="workplace"/>.
        /// Existing items skipped.
        /// </summary>
        /// <param name="workplace"><see cref="Workplace"/> instance.</param>
        private void RegisterNewSections(Workplace workplace)
        {
            var schema = _entitySchemaManager.GetInstanceByName("SysModuleInWorkplace");

            foreach (var sectionId in workplace.GetSectionIds())
            {
                var entity = schema.CreateEntity(_userConnection);
                entity.SetDefColumnValues();
                if (entity.FetchFromDB(new Dictionary <string, object> {
                    { "SysModule", sectionId },
                    { "SysWorkplace", workplace.Id }
                }))
                {
                    continue;
                }
                entity.PrimaryColumnValue = Guid.NewGuid();
                entity.SetColumnValue("SysModuleId", sectionId);
                entity.SetColumnValue("SysWorkplaceId", workplace.Id);
                entity.Save();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns information of dependent entity.
        /// </summary>
        /// <param name="dependentEntity">Information of dependent entity.</param>
        /// <returns>Information of dependent entity.</returns>
        private DependentInfo GetDependenInfo(KeyValuePair <string, List <Guid> > dependentEntity)
        {
            var           count           = 0;
            var           recordIds       = new List <Guid>();
            string        schemaName      = dependentEntity.Key;
            EntitySchema  entitySchema    = EntitySchemaManager.GetInstanceByName(schemaName);
            string        caption         = entitySchema.Caption;
            Guid          entitySchemaUId = entitySchema.UId;
            List <string> columnsName     = GetColumnsNameByUIds(entitySchema, dependentEntity.Value);

            if (columnsName.Count == 0)
            {
                return(null);
            }
            var dependentInfo = new DependentInfo {
                EntitySchemaUId     = entitySchemaUId,
                EntitySchemaName    = schemaName,
                EntitySchemaCaption = caption,
                ColumnsName         = columnsName
            };

            try {
                if (_isLoadRecordId)
                {
                    recordIds = GetRecordIds(schemaName, columnsName);
                    if (recordIds != null)
                    {
                        count = recordIds.Count;
                    }
                }
                else
                {
                    count = CountRecords(schemaName, columnsName);
                }
            } catch (SecurityException) {
                dependentInfo.CanRead = false;
                return(dependentInfo);
            }
            if (count > 0)
            {
                dependentInfo.CanRead      = true;
                dependentInfo.RecordsCount = count;
                if (_isLoadRecordId)
                {
                    dependentInfo.RecordIds = recordIds;
                }
                return(dependentInfo);
            }
            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns collection of dependent entites.
        /// </summary>
        /// <returns>Collection of dependent entites.</returns>
        protected virtual Dictionary <string, List <Guid> > GetDependentEntities()
        {
            EntitySchema entity = EntitySchemaManager.GetInstanceByName(EntitySchemaName);
            EntitySchemaOppositeReferenceInfoCollection dependentEntites =
                EntitySchemaManager.GetSchemaOppositeReferences(entity.UId, EntitySchemaColumnUsageType.General,
                                                                UserConnection, true);
            var result = new Dictionary <string, List <Guid> >();

            foreach (EntitySchemaOppositeReferenceInfo dependentEntity in dependentEntites)
            {
                EntitySchema depEntity = EntitySchemaManager.GetInstanceByName(dependentEntity.SchemaName);
                if (!depEntity.IsDBView)
                {
                    AddDependentEntity(dependentEntity, result);
                }
            }
            return(result);
        }
        public List <EntitySchemaInfo> GetIsolatedSchemasInfo(Guid externalAccessId)
        {
            EntitySchemaManager entitySchemaManager = UserConnection.EntitySchemaManager;

            var select = (Select) new Select(UserConnection)
                         .Distinct()
                         .Cols("EntitySchemaName")
                         .From("SysIsolatedRecord")
                         .Where("ExternalAccessId").IsEqual(Column.Parameter(externalAccessId));
            IEnumerable <EntitySchemaInfo> entitySchemaInfos = select.ExecuteEnumerable(reader => {
                string schemaName               = reader.GetColumnValue <string>("EntitySchemaName");
                EntitySchema entitySchema       = entitySchemaManager.GetInstanceByName(schemaName);
                string primaryDisplayColumnName = entitySchema.PrimaryDisplayColumn?.Name;
                return(new EntitySchemaInfo(schemaName, primaryDisplayColumnName));
            });

            return(entitySchemaInfos.ToList());
        }
Ejemplo n.º 10
0
        public Dictionary <string, Guid> GetColumnReferenceSchemaUIds(Dictionary <string, List <string> > columnMetaSchema)
        {
            var response = new Dictionary <string, Guid>();

            EntitySchemaManager entitySchemaManager = UserConnection.EntitySchemaManager;

            foreach (KeyValuePair <string, List <string> > keyValuePair in columnMetaSchema)
            {
                string        entitySchemaName = keyValuePair.Key;
                EntitySchema  entitySchema     = entitySchemaManager.GetInstanceByName(entitySchemaName);
                List <string> metaPaths        = keyValuePair.Value;
                foreach (string metaPath in metaPaths)
                {
                    EntitySchemaColumn columnPath = entitySchema.GetSchemaColumnByMetaPath(metaPath);
                    response[metaPath] = columnPath.ReferenceSchemaUId;
                }
            }
            return(response);
        }
Ejemplo n.º 11
0
        public Dictionary <string, string> GetMetaPathsAndEntityNames(Dictionary <string, List <string> > columnMetaPaths)
        {
            var response = new Dictionary <string, string>();

            EntitySchemaManager entitySchemaManager = UserConnection.EntitySchemaManager;

            foreach (KeyValuePair <string, List <string> > keyValuePair in columnMetaPaths)
            {
                string       entitySchemaName = keyValuePair.Key;
                EntitySchema entitySchema     = entitySchemaManager.GetInstanceByName(entitySchemaName);
                response[entitySchemaName] = entitySchema.UId.ToString();
                List <string> columnPaths = keyValuePair.Value;
                foreach (string columnPath in columnPaths)
                {
                    response[columnPath] = entitySchema.GetSchemaColumnMetaPathByPath(columnPath);
                }
            }
            return(response);
        }
Ejemplo n.º 12
0
        public static LocalizableString GetLocalizableValue(UserConnection userConnection, string schemaName,
                                                            string columnName, Guid recordId)
        {
            EntitySchemaQuery       esq;
            EntitySchemaQueryColumn column;
            var result = new LocalizableString();
            EntitySchemaManager entitySchemaManager = userConnection.EntitySchemaManager;
            SysUserInfo         currentUser         = userConnection.CurrentUser;
            CultureInfo         currentUserCulture  = currentUser.Culture;
            EntitySchema        schema = entitySchemaManager.GetInstanceByName(schemaName);

            if (UseMultilanguageData)
            {
                esq    = new EntitySchemaQuery(entitySchemaManager, schemaName);
                column = esq.AddColumn(columnName);
                esq.Filters.Add(esq.CreateFilterWithParameters(
                                    FilterComparisonType.Equal, schema.GetPrimaryColumnName(), recordId));
            }
            else
            {
                Guid   columnUId     = schema.Columns.GetByName(columnName).UId;
                string lczSchemaName = schema.GetLocalizableStringsSchemaName();
                esq    = new EntitySchemaQuery(entitySchemaManager, lczSchemaName);
                column = esq.AddColumn("Value");
                esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "ColumnUId", columnUId));
                esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal, "Record", recordId));
                esq.Filters.Add(
                    esq.CreateFilterWithParameters(FilterComparisonType.Equal, "SysCulture", currentUser.SysCultureId));
            }
            EntityCollection entities = esq.GetEntityCollection(userConnection);

            if (entities.Count > 0)
            {
                Entity entity   = entities.First();
                string lczValue = entity.GetTypedColumnValue <string>(column.Name);
                result.SetCultureValue(currentUserCulture, lczValue);
            }
            return(result);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates activity connection dynamic column parameter if it doesn't exist.
        /// </summary>
        /// <param name="userConnection">User connection.</param>
        /// <param name="target">Target user task schema.</param>
        public static void SynchronizeActivityConnectionParameters(UserConnection userConnection,
                                                                   ProcessUserTaskSchema target)
        {
            EntitySchemaManager manager  = userConnection.EntitySchemaManager;
            EntitySchema        activity = manager.GetInstanceByName("Activity");

            activity.LoadLocalizableValues();
            EntitySchemaQuery esq = CreateActivityConnectionEsq(manager, activity.UId);
            EntityCollection  activityConnections = esq.GetEntityCollection(userConnection);

            foreach (Entity connection in activityConnections)
            {
                Guid columnUId            = connection.GetTypedColumnValue <Guid>("ColumnUId");
                EntitySchemaColumn column = activity.Columns.FindByUId(columnUId);
                if (column == null)
                {
                    _log.InfoFormat("Activity connection column with identifier \"{0}\" not found", columnUId);
                }
                else
                {
                    CreateDynamicProcessSchemaParameterIfNotExist(target, column);
                }
            }
        }
Ejemplo n.º 14
0
        private EntitySchema GetEntitySchema(string schemaName)
        {
            EntitySchemaManager manager = _userConnection.AppConnection.SystemUserConnection.EntitySchemaManager;

            return(manager.GetInstanceByName(schemaName));
        }
        protected virtual EntitySchema GetEntitySchema()
        {
            EntitySchemaManager manager = UserConnection.AppConnection.SystemUserConnection.EntitySchemaManager;

            return(manager.GetInstanceByName(SchemaName));
        }