Example #1
0
        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);
        }
Example #2
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);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        ///     Deserializes the document.
        /// </summary>
        /// <param name="xmlReader">The XML text reader.</param>
        /// <param name="xmlStack">The XML stack.</param>
        private void DeserializeDocument(XmlReader xmlReader, Stack <string> xmlStack)
        {
            string hashAttribute = xmlReader.GetAttribute(XmlConstants.DocumentConstants.Hash);

            if (string.IsNullOrEmpty(hashAttribute))
            {
                ThrowXmlException("Document hash attribute is invalid.", xmlReader);
            }

            string extensionAttribute = xmlReader.GetAttribute(XmlConstants.DocumentConstants.Extension);

            string data = xmlReader.ReadString( );

            DocumentDataEntry entry = new DocumentDataEntry
            {
                DataHash         = hashAttribute,
                FileExtension    = extensionAttribute,
                LoadDataCallback = s => LoadBinaryData(data)
            };

            _documents.Add(entry);
        }
Example #4
0
        public IEnumerable <DocumentDataEntry> GetDocumentData(IProcessingContext context)
        {
            if (!StorageProvider.DoesTableExist("_Filestream_Document"))
            {
                yield break;
            }

            using (IDbCommand command = CreateCommand( ))
            {
                const string sql = @"SELECT DISTINCT fb.FileExtension, 
                                                     fb.DataHash
                                     FROM _Filestream_Document fb
                                     JOIN _Data_NVarChar dn ON dn.Data = fb.DataHash                                
                                     WHERE dn.FieldUid = @fileDataHashFieldId";

                command.CommandType = CommandType.Text;
                command.CommandText = sql;
                command.Parameters.Add(new SQLiteParameter("@fileDataHashFieldId", DbType.String));
                (( SQLiteParameter )command.Parameters[0]).Value = Helpers.FileDataHashFieldUpgradeId.ToString( ).ToLower( );

                using (IDataReader reader = command.ExecuteReader( ))
                {
                    while (reader.Read( ))
                    {
                        var documentDataEntry = new DocumentDataEntry
                        {
                            DataHash         = reader.GetString(1),
                            FileExtension    = !reader.IsDBNull(0) ? reader.GetString(0) : null,
                            LoadDataCallback = LoadDocumentData
                        };

                        yield return(documentDataEntry);
                    }
                }
            }
        }
Example #5
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);
                }
            }
        }