Exemple #1
0
        /// <summary>
        /// Create an array of FileItem objects based on a data object that contains
        /// FileContents
        /// </summary>
        /// <param name="dataObject">data object containing FileContents</param>
        /// <returns>Array of FileItem objects. Returns null if the FileContents
        /// could not be extracted from the passed dataObject</returns>
        public static FileItem[] CreateArrayFromDataObject(IDataObject dataObject)
        {
            try
            {
                // get the ole data object
                OleDataObject oleDataObject = OleDataObject.CreateFrom(dataObject);
                if (oleDataObject == null)
                {
                    Debug.Fail("Unable to access OleDataObject!");
                    return(null);
                }

                // get an array of file descriptors specifying the file contents
                FileDescriptor[] fileDescriptors =
                    FileContentsHelper.GetFileDescriptors(dataObject);

                // allocate a FileItem object for each descriptor
                FileItem[] fileItems = new FileItem[fileDescriptors.Length];

                // initialize the file items
                for (int i = 0; i < fileDescriptors.Length; i++)
                {
                    fileItems[i] = new FileItemFromFileContents(
                        fileDescriptors[i], oleDataObject, i);
                }

                // return the file items
                return(fileItems);
            }
            // this is a sketchy operation involving all kinds of interop voodoo,
            // if we fail in release mode it is likely due to a drop source giving
            // us invalid or unexpected data -- handle this gracefully while
            // logging the error
            catch (Exception e)
            {
                Debug.Fail("Unexpected error accessing FileContents", e.Message);
                return(null);
            }
        }
Exemple #2
0
 /// <summary>
 /// Create an array of file items based on the specified data object
 /// </summary>
 /// <param name="dataObject">data object</param>
 /// <returns>array of file items</returns>
 public FileItem[] CreateFileItems(IDataObject dataObject)
 {
     return(FileItemFromFileContents.CreateArrayFromDataObject(dataObject));
 }
        /// <summary>
        /// Create an array of FileItem objects based on a data object that contains
        /// FileContents
        /// </summary>
        /// <param name="dataObject">data object containing FileContents</param>
        /// <returns>Array of FileItem objects. Returns null if the FileContents
        /// could not be extracted from the passed dataObject</returns>
        public static FileItem[] CreateArrayFromDataObject(IDataObject dataObject)
        {
            try
            {
                // get the ole data object
                OleDataObject oleDataObject = OleDataObject.CreateFrom(dataObject);
                if (oleDataObject == null)
                {
                    Debug.Fail("Unable to access OleDataObject!");
                    return null;
                }

                // get an array of file descriptors specifying the file contents
                FileDescriptor[] fileDescriptors =
                    FileContentsHelper.GetFileDescriptors(dataObject);

                // allocate a FileItem object for each descriptor
                FileItem[] fileItems = new FileItem[fileDescriptors.Length];

                // initialize the file items
                for (int i = 0; i < fileDescriptors.Length; i++)
                {
                    fileItems[i] = new FileItemFromFileContents(
                        fileDescriptors[i], oleDataObject, i);
                }

                // return the file items
                return fileItems;
            }
            // this is a sketchy operation involving all kinds of interop voodoo,
            // if we fail in release mode it is likely due to a drop source giving
            // us invalid or unexpected data -- handle this gracefully while
            // logging the error
            catch (Exception e)
            {
                Debug.Fail("Unexpected error accessing FileContents", e.Message);
                return null;
            }
        }