Beispiel #1
0
        /// <summary>
        ///     Gets the binary data.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        IEnumerable <BinaryDataEntry> IDataSource.GetBinaryData(IProcessingContext context)
        {
            if (_binaryCache == null)
            {
                var data = new List <BinaryDataEntry>( );
                Func <string, byte[]> loadBinaryData = token => FileRepositoryUtils.LoadFileData(Factory.BinaryFileRepository, token, context);

                using (IDbCommand command = CreateCommand( ))
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = CommandText.TenantSourceGetBinaryDataCommandText;
                    command.AddParameterWithValue("@tenant", TenantId);

                    using (IDataReader reader = command.ExecuteReader( ))
                    {
                        while (reader.Read( ))
                        {
                            var binaryDataEntry = new BinaryDataEntry
                            {
                                DataHash         = reader.GetString(0),
                                LoadDataCallback = loadBinaryData
                            };

                            data.Add(binaryDataEntry);
                        }
                    }
                }

                _binaryCache = data;
            }

            return(_binaryCache);
        }
        public IEnumerable <DocumentDataEntry> GetDocumentData(IProcessingContext context)
        {
            if (_documentCache == null)
            {
                var data = new List <DocumentDataEntry>( );
                Func <string, byte[]> loadDocumentData = token => FileRepositoryUtils.LoadFileData(Factory.DocumentFileRepository, token, context);

                using (IDbCommand command = CreateCommand( ))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "spGetTenantAppDocumentFileData";
                    command.AddParameterWithValue("@solutionId", SolutionId);
                    command.AddParameterWithValue("@tenant", TenantId);

                    using (IDataReader reader = command.ExecuteReader( ))
                    {
                        while (reader.Read( ))
                        {
                            var binaryDataEntry = new DocumentDataEntry
                            {
                                DataHash         = reader.GetString(0),
                                LoadDataCallback = loadDocumentData
                            };

                            data.Add(binaryDataEntry);
                        }
                    }
                }

                _documentCache = data;
            }

            return(_documentCache);
        }
Beispiel #3
0
        public IEnumerable <DocumentDataEntry> GetDocumentData(IProcessingContext context)
        {
            Func <string, byte[]> loadDocumentData = token => FileRepositoryUtils.LoadFileData(Factory.AppLibraryFileRepository, token, context);

            using (IDbCommand command = CreateCommand( ))
            {
                command.CommandType = CommandType.Text;
                command.CommandText = CommandText.AppLibraryGetDocumentData;

                command.AddParameterWithValue("@appVer", AppVerId);
                command.AddParameterWithValue("@isOfTypeId", Helpers.IsOfTypeRelationshipUpgradeId);
                command.AddParameterWithValue("@inheritsId", Helpers.InheritsRelationshipUpgradeId);
                command.AddParameterWithValue("@fileDataHashFieldId", Helpers.FileDataHashFieldUpgradeId);
                command.AddParameterWithValue("@imageFileTypeId", Helpers.ImageFileTypeUpgradeId);
                command.AddParameterWithValue("@fileTypeId", Helpers.FileTypeUpgradeId);

                using (IDataReader reader = command.ExecuteReader( ))
                {
                    while (reader.Read( ))
                    {
                        var documentDataEntry = new DocumentDataEntry
                        {
                            DataHash         = reader.GetString(0),
                            LoadDataCallback = loadDocumentData
                        };

                        yield return(documentDataEntry);
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        ///     Scan for document token fields.
        /// </summary>
        private void LoadDocumentCaches(IProcessingContext context)
        {
            _binaryCache   = new List <BinaryDataEntry>( );
            _documentCache = new List <DocumentDataEntry>( );

            HashSet <string> tokensDone = new HashSet <string>( );

            // GUID for fileDataHash field.
            long fileDataHash = new EntityRef("fileDataHash").Id;
            long isOfType     = WellKnownAliases.CurrentTenant.IsOfType;

            // Determine types that are 'binary'. Others are 'document'.
            ISet <long> fileTypes     = PerTenantEntityTypeCache.Instance.GetDescendantsAndSelf(new EntityRef("fileType").Id);
            ISet <long> binaryTypes   = PerTenantEntityTypeCache.Instance.GetDescendantsAndSelf(new EntityRef("imageFileType").Id);
            ISet <long> documentTypes = new HashSet <long>(fileTypes.Except(binaryTypes));

            // Callbacks to load data
            Func <string, byte[]> loadDocumentData = token => FileRepositoryUtils.LoadFileData(Factory.DocumentFileRepository, token, context);
            Func <string, byte[]> loadBinaryData   = token => FileRepositoryUtils.LoadFileData(Factory.BinaryFileRepository, token, context);

            foreach (KeyValuePair <FieldKey, FieldValue> field in _bulkResult.FieldValues)
            {
                if (field.Key.FieldId != fileDataHash)
                {
                    continue;
                }

                // Get token
                string token = field.Value?.RawValue as string;
                if (string.IsNullOrEmpty(token))
                {
                    continue;
                }

                if (tokensDone.Contains(token))
                {
                    continue;
                }
                tokensDone.Add(token);

                // Get entity type
                long            entityId   = field.Key.EntityId;
                RelationshipKey typeRelKey = new RelationshipKey(entityId, isOfType);
                List <long>     types;
                _bulkResult.Relationships.TryGetValue(typeRelKey, out types);
                long?singleType = types?.FirstOrDefault( );
                if (singleType == null)
                {
                    continue;
                }
                long typeId = singleType.Value;

                // Determine type
                bool isBinary = binaryTypes.Contains(typeId);
                bool isDoc    = documentTypes.Contains(typeId);

                // Create entry
                if (isBinary)
                {
                    var binaryDataEntry = new BinaryDataEntry
                    {
                        DataHash         = token,
                        LoadDataCallback = loadBinaryData
                    };

                    _binaryCache.Add(binaryDataEntry);
                }
                else if (isDoc)
                {
                    var docDataEntry = new DocumentDataEntry
                    {
                        DataHash         = token,
                        LoadDataCallback = loadDocumentData
                    };

                    _documentCache.Add(docDataEntry);
                }
            }
        }