Esempio n. 1
0
    /// <summary>
    /// Method creates a file handler and returns to the caller.
    /// IFileHandler implements all labeling and protection operations in the File API.
    /// </summary>
    /// <param name="options">Struct provided to set various options for the handler.</param>
    /// <returns></returns>
    private IFileHandler CreateFileHandler(FileOptions options)
    {
        // Create the handler using options from FileOptions. Assumes that the engine was previously created and stored in private engine object.
        // There's probably a better way to pass/store the engine, but this is a sample ;)
        var handler = Task.Run(async() => await engine.CreateFileHandlerAsync(options.FileName, options.FileName, options.IsAuditDiscoveryEnabled)).Result;

        return(handler);
    }
        /// <summary>
        /// Creates an IFileHandler for the specified file or stream.
        /// </summary>
        /// <param name="stream">Can be null. If null, fileName must be the full path to the file.</param>
        /// <param name="fileName">File name or full path. Should be full path is stream is null</param>
        /// <returns>IFileHandler</returns>
        private IFileHandler CreateFileHandler(Stream stream, string fileName)
        {
            IFileHandler handler;

            try
            {
                if (stream != null)
                {
                    handler = Task.Run(async() => await fileEngine.CreateFileHandlerAsync(stream, fileName, true)).Result;
                }
                else
                {
                    handler = Task.Run(async() => await fileEngine.CreateFileHandlerAsync(fileName, fileName, true)).Result;
                }

                return(handler);
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }