GetStream() 공개 메소드

public GetStream ( ) : Stream
리턴 Stream
예제 #1
0
 public void CopyFrom(BinaryData data)
 {
     //Id = data.Id;
     FileName    = data.FileName;
     ContentType = data.ContentType;
     Size        = data.Size;
     this.SetStream(data.GetStream());
 }
예제 #2
0
 public void CopyFrom(BinaryData data)
 {
     FileId           = data.FileId;
     FileName         = data.FileName;
     ContentType      = data.ContentType;
     Size             = data.Size;
     BlobProvider     = data.BlobProvider;
     BlobProviderData = data.BlobProviderData;
     this.SetStream(data.GetStream());
 }
예제 #3
0
파일: Binary.cs 프로젝트: maxpavlov/FlexNet
        /// <summary>
        /// Sets data within the FieldControl
        /// </summary>
        /// <param name="data">Data of the <see cref="SenseNet.ContentRepository.Field">Field</see> wrapped</param>
        public override void SetData(object data)
        {
            _data = data as BinaryData;
            var stream = _data == null ? null : _data.GetStream();
            var streamString = string.Empty;

            try
            {
                if (IsTextInternal && stream != null)
                    streamString = Tools.GetStreamString(stream);
            }
            catch (Exception ex)
            {
                // failed to load stream
                // streamString will be string.Empty, no need for special actions
                Logger.WriteException(ex);
            }

            if (_textBox != null)
                _textBox.Text = streamString;

            #region template

            if ((!UseBrowseTemplate && !UseEditTemplate) && !UseInlineEditTemplate)
                return;

            var title = GetLabelForTitleControl() as Label;
            var desc = GetLabelForDescription() as Label;
            var innerControl = GetInnerControl() as TextBox;
            if (title != null)
                title.Text = this.Field.DisplayName;
            if (desc != null)
                desc.Text = this.Field.Description;
            if (innerControl != null)
                innerControl.Text = streamString;

            #endregion
        }
예제 #4
0
        private PageState GetPageState(BinaryData binaryData)
        {
            if (binaryData == null)
                throw new ArgumentNullException("binaryData");

            PageState resultPageState = null;
            Stream sharedDataBlobStream = binaryData.GetStream();
            int streamLength = Convert.ToInt32(sharedDataBlobStream.Length);
            var byteContent = new byte[streamLength];

            //try
            //{
            sharedDataBlobStream.Read(byteContent, 0, streamLength);
            resultPageState = new PageState(byteContent, PersonalizationScope.Shared);
            //}
            //catch (Exception exc)
            //{
            //    WriteException(exc);
            //}

            return resultPageState;
        }
예제 #5
0
		public void CopyFrom(BinaryData data)
		{
			//Id = data.Id;
			FileName = data.FileName;
			ContentType = data.ContentType;
			Size = data.Size;
			this.SetStream(data.GetStream());
		}
예제 #6
0
        private string GetStringFromBinaryData(BinaryData binary)
        {

            Stream stream = binary.GetStream();
            StreamReader sr = new StreamReader(stream, Encoding.UTF8);

            string value = sr.ReadToEnd();

            return value;
        }
예제 #7
0
 private static void WriteDatas(HttpContext context, BinaryData cacheBinary)
 {
     if (cacheBinary.GetStream() != null)
     {
         MemoryStream result = new MemoryStream();
         result = (MemoryStream)cacheBinary.GetStream();
         context.Response.BinaryWrite(result.ToArray());
     }
 }
예제 #8
0
 public void BinaryData_DefaultValues()
 {
     BinaryData target = new BinaryData();
     Assert.AreEqual(0, target.Id, "SenseNet.ContentRepository.Storage.BinaryData.Id default value is incorrect.");
     Assert.AreEqual(string.Empty, target.ContentType, "SenseNet.ContentRepository.Storage.BinaryData.ContentType default value is incorrect.");
     Assert.AreEqual(string.Empty, target.FileName.Extension, "SenseNet.ContentRepository.Storage.BinaryData.FileName.Extension default value is incorrect.");
     Assert.AreEqual(string.Empty, target.FileName.FileNameWithoutExtension, "SenseNet.ContentRepository.Storage.BinaryData.FileName.FileNameWithoutExtension default value is incorrect.");
     Assert.AreEqual(Convert.ToInt64(-1), target.Size, "SenseNet.ContentRepository.Storage.BinaryData.Size default value is incorrect.");
     Assert.AreEqual(null, target.GetStream(), "SenseNet.ContentRepository.Storage.BinaryData.Stream default value is incorrect.");
 }
예제 #9
0
        public static string GetExtract(BinaryData binaryData, Node node)
        {
            if (binaryData == null)
                return string.Empty;
            var fname = binaryData.FileName;
            if (fname == null)
                return string.Empty;
            var ext = fname.Extension;
            if (String.IsNullOrEmpty(ext))
                return string.Empty;

            ITextExtractor extractor = null;
            var result = string.Empty;
            switch (ext.ToLower())
            {
                case "contenttype":
                case "xml": extractor = new XmlTextExtractor(); break;
                case "doc": extractor = new DocTextExtractor(); break;
                case "xls": extractor = new XlsTextExtractor(); break;
                case "pdf": extractor = new PdfTextExtractor(); break;
                case "docx": extractor = new DocxTextExtractor(); break;
                case "xlsx": extractor = new XlsxTextExtractor(); break;
                case "pptx": extractor = new PptxTextExtractor(); break;
                case "txt": extractor = new PlainTextExtractor(); break;
                default:
                    return String.Empty;
            }

            var stream = binaryData.GetStream();
            if (stream == null)
                return String.Empty;
            if (stream.Length == 0)
                return String.Empty;

            try
            {
                ////-- sync
                //result = extractor.Extract(stream);

                //-- async
                Action<TimeboxedActivity> timeboxedFunctionCall = activity =>
                {
                    var x = (Stream)activity.InArgument;
                    var extract = extractor.Extract(x);
                    activity.OutArgument = extract;
                };

                var act = new TimeboxedActivity();
                act.InArgument = stream;
                act.Activity = timeboxedFunctionCall;
                act.Context = HttpContext.Current;

                var finishedWithinTime = act.ExecuteAndWait(Repository.TextExtractTimeout * 1000);
                if (!finishedWithinTime)
                {
                    act.Abort();
                    var msg = String.Format("Text extracting timeout. Version: {0}, path: {1}", node.Version, node.Path);
                    Logger.WriteWarning(msg);
                    return String.Empty;
                }
                else if (act.ExecutionException != null)
                {
                    WriteError(act.ExecutionException, node);
                }
                else
                {
                    result = (string)act.OutArgument;
                }
            }
            catch (Exception e)
            {
                WriteError(e, node);
            }

            if (String.IsNullOrEmpty(result))
            {
                var format = @"Couldn't extract text. VersionId: {0}, path: '{1}' ";
                var inf = String.Format(CultureInfo.InvariantCulture, format, node.VersionId, node.Path);
                Logger.WriteWarning(inf);
            }

            result = result.Replace('\0', '.');
            return result;
        }