GetPath() public method

Gets the path.
public GetPath ( BinaryFile file ) : string
file BinaryFile The file.
return string
Beispiel #1
0
        /// <summary>
        /// Saves the files.
        /// </summary>
        /// <param name="newFileList">The new file list.</param>
        private static void SaveFiles( Dictionary<int, Rock.Model.BinaryFile> newFileList, ProviderComponent storageProvider )
        {
            if ( storageProvider == null )
            {
                LogException( "Binary File Import", string.Format( "Could not load provider {0}.", storageProvider.ToString() ) );
                return;
            }

            var rockContext = new RockContext();
            rockContext.WrapTransaction( () =>
            {
                foreach ( var file in newFileList )
                {
                    storageProvider.SaveContent( file.Value );
                    file.Value.Path = storageProvider.GetPath( file.Value );
                }

                rockContext.BinaryFiles.AddRange( newFileList.Values );
                rockContext.SaveChanges( DisableAuditing );

                foreach ( var file in newFileList )
                {
                    rockContext.People.FirstOrDefault( p => p.Id == file.Key ).PhotoId = file.Value.Id;
                }

                rockContext.SaveChanges( DisableAuditing );
            } );
        }
        /// <summary>
        /// Saves the files.
        /// </summary>
        /// <param name="newFileList">The new file list.</param>
        private static void SaveFiles( List<DocumentKeys> newFileList, ProviderComponent storageProvider )
        {
            if ( storageProvider == null )
            {
                LogException( "Binary File Import", string.Format( "Could not load provider {0}.", storageProvider.ToString() ) );
                return;
            }

            if ( newFileList.Any( f => f.File == null ) )
            {
                LogException( "Binary File Import", string.Format( "Could not load {0} files because they were null.", newFileList.Count( f => f.File == null ) ) );
            }

            var rockContext = new RockContext();
            rockContext.WrapTransaction( () =>
            {
                foreach ( var entry in newFileList )
                {
                    storageProvider.SaveContent( entry.File );
                    entry.File.Path = storageProvider.GetPath( entry.File );
                }

                var list = newFileList.Select( f => f.File ).ToList();

                rockContext.BinaryFiles.AddRange( newFileList.Select( f => f.File ) );
                rockContext.SaveChanges();

                var currentPersonAttributes = new Dictionary<int, List<int>>();

                foreach ( var entry in newFileList.OrderByDescending( f => f.File.CreatedDateTime ) )
                {
                    List<int> attributeList = null;

                    if ( currentPersonAttributes.ContainsKey( entry.PersonId ) && currentPersonAttributes[entry.PersonId] != null )
                    {
                        attributeList = currentPersonAttributes[entry.PersonId];
                    }
                    else
                    {
                        // first document for this person in the current zip file, start a list
                        attributeList = new List<int>();
                        currentPersonAttributes.Add( entry.PersonId, attributeList );
                    }

                    if ( !attributeList.Contains( entry.AttributeId ) )
                    {
                        var attributeValue = rockContext.AttributeValues.FirstOrDefault( p => p.AttributeId == entry.AttributeId && p.EntityId == entry.PersonId );

                        // set person attribute value to this binary file guid
                        if ( attributeValue == null )
                        {
                            attributeValue = new AttributeValue();
                            attributeValue.IsSystem = false;
                            attributeValue.EntityId = entry.PersonId;
                            attributeValue.AttributeId = entry.AttributeId;
                            attributeValue.Value = entry.File.Guid.ToString();
                            rockContext.AttributeValues.Add( attributeValue );
                        }
                        else if ( attributeValue.CreatedDateTime < entry.File.CreatedDateTime )
                        {
                            attributeValue.Value = entry.File.Guid.ToString();
                            rockContext.Entry( attributeValue ).State = EntityState.Modified;
                        }

                        attributeList.Add( entry.AttributeId );
                    }
                }

                rockContext.SaveChanges( DisableAuditing );
            } );
        }
        /// <summary>
        /// Saves the files.
        /// </summary>
        /// <param name="newFileList">The new file list.</param>
        private static void SaveFiles( Dictionary<int, Rock.Model.BinaryFile> newFileList, ProviderComponent storageProvider )
        {
            if ( storageProvider == null )
            {
                LogException( "Binary File Import", string.Format( "Could not load provider {0}.", storageProvider.ToString() ) );
                return;
            }

            var rockContext = new RockContext();
            rockContext.WrapTransaction( () =>
            {
                foreach ( var entry in newFileList )
                {
                    if ( entry.Value != null )
                    {
                        storageProvider.SaveContent( entry.Value );
                        entry.Value.Path = storageProvider.GetPath( entry.Value );
                    }
                }

                rockContext.BinaryFiles.AddRange( newFileList.Values );
                rockContext.SaveChanges();

                foreach ( var entry in newFileList )
                {
                    // associate the image with the right transaction
                    var transactionImage = new FinancialTransactionImage();
                    transactionImage.TransactionId = entry.Key;
                    transactionImage.BinaryFileId = entry.Value.Id;
                    transactionImage.Order = 0;
                    rockContext.FinancialTransactions.FirstOrDefault( t => t.Id == entry.Key )
                        .Images.Add( transactionImage );
                }

                rockContext.SaveChanges( DisableAuditing );
            } );
        }