/// <summary>
 /// Sets a document stream and its content type to be opened
 /// </summary>
 /// <param name="stream">The file stream</param>
 /// <param name="fileType">The stream content type</param>
 /// <returns>An instance of the widget object</returns>
 public AnnotationWidget Stream(Stream stream, FileType fileType)
 {
     _stream = new InputStream {
         Stream = stream, FileType = fileType, FileName = Guid.NewGuid().ToString()
     };
     return(this);
 }
Example #2
0
 public InvokeOutgoingAsyncT(IObjectPrx prx,
                             IOutgoingAsyncCompletionCallback completionCallback,
                             OutputStream?os = null,
                             InputStream?iss = null) : base(prx, completionCallback, os, iss)
 {
 }
        /// <summary>
        /// Sets a document stream and its name to be opened
        /// </summary>
        /// <param name="stream">The file stream</param>
        /// <param name="fileName">The file name</param>
        /// <returns>An instance of the widget object</returns>
        public AnnotationWidget Stream(Stream stream, string fileName)
        {
            //Filename validation
            if (string.IsNullOrWhiteSpace(fileName) == true)
            {
                throw new ArgumentException("Filename cannot be NULL or empty string");
            }
            string tempFilename = fileName.Trim().ToLowerInvariant();

            if (tempFilename.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                throw new ArgumentException("Filename contains invalid characters");
            }
            string[] illegalFilenames =
            { "CON",  "PRN",  "AUX",  "NUL",
              "COM1", "COM2", "COM3", "COM4","COM5",  "COM6", "COM7", "COM8", "COM9",
              "LPT1", "LPT2", "LPT3", "LPT4","LPT5",  "LPT6", "LPT7", "LPT8", "LPT9" };

            if (illegalFilenames.Contains(tempFilename, StringComparer.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException("Filename is invalid");
            }
            if (tempFilename.Length > 200)
            {
                throw new ArgumentException("Filename is too long");
            }
            //Extension validation
            string extension = Path.GetExtension(tempFilename);

            if (extension == "")
            {
                throw new ArgumentException("Specified filename should contain extension");
            }
            extension = extension.Trim().TrimStart(new char[1] {
                '.'
            });

            //Defining a FileType
            string[] supportedExtensions = Enum.GetNames(typeof(FileType));
            string[] cleared             = Array.FindAll(supportedExtensions, s => s.Equals("Undefined", StringComparison.OrdinalIgnoreCase) == false).ToArray();

            var definedFileType = FileType.Undefined;

            for (int i = 0; i < cleared.Length; i++)
            {
                string current = cleared[i];
                if (current.Equals(extension, StringComparison.OrdinalIgnoreCase) == true)
                {
                    definedFileType = (FileType)Enum.Parse(typeof(FileType), current, true);
                    break;
                }
            }

            if (definedFileType == FileType.Undefined)
            {
                throw new ArgumentException("Extension '" + extension + "' is unknown or not supported");
            }

            _stream = new InputStream {
                Stream = stream, FileName = fileName, FileType = definedFileType
            };
            return(this);
        }
 /// <summary>
 /// Sets a document stream and its content type to be opened
 /// </summary>
 /// <param name="stream">The file stream</param>
 /// <param name="fileType">The stream content type</param>
 /// <returns>An instance of the widget object</returns>
 public AnnotationWidget Stream(Stream stream, FileType fileType)
 {
     _stream = new InputStream { Stream = stream, FileType = fileType, FileName = Guid.NewGuid().ToString() };
     return this;
 }
        /// <summary>
        /// Sets a document stream and its name to be opened
        /// </summary>
        /// <param name="stream">The file stream</param>
        /// <param name="fileName">The file name</param>
        /// <returns>An instance of the widget object</returns>
        public AnnotationWidget Stream(Stream stream, string fileName)
        {
            //Filename validation
            if(string.IsNullOrWhiteSpace(fileName) == true)
            {
                throw new ArgumentException("Filename cannot be NULL or empty string");
            }
            string tempFilename = fileName.Trim().ToLowerInvariant();
            if(tempFilename.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                throw new ArgumentException("Filename contains invalid characters");
            }
            string[] illegalFilenames =
            { "CON", "PRN", "AUX", "NUL",
                "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
                "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };

            if(illegalFilenames.Contains(tempFilename, StringComparer.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException("Filename is invalid");
            }
            if(tempFilename.Length > 200)
            {
                throw new ArgumentException("Filename is too long");
            }
            //Extension validation
            string extension = Path.GetExtension(tempFilename);
            if(extension == "")
            {
                throw new ArgumentException("Specified filename should contain extension");
            }
            extension = extension.Trim().TrimStart(new char[1] { '.' });

            //Defining a FileType
            string[] supportedExtensions = Enum.GetNames(typeof(FileType));
            string[] cleared = Array.FindAll(supportedExtensions, s => s.Equals("Undefined", StringComparison.OrdinalIgnoreCase) == false).ToArray();

            var definedFileType = FileType.Undefined;

            for(int i = 0; i < cleared.Length; i++)
            {
                string current = cleared[i];
                if(current.Equals(extension, StringComparison.OrdinalIgnoreCase) == true)
                {
                    definedFileType = (FileType) Enum.Parse(typeof(FileType), current, true);
                    break;
                }
            }

            if(definedFileType == FileType.Undefined)
            {
                throw new ArgumentException("Extension '" + extension + "' is unknown or not supported");
            }

            _stream = new InputStream { Stream = stream, FileName = fileName, FileType = definedFileType };
            return this;
        }