public void CopyFrom(BinaryData data) { //Id = data.Id; FileName = data.FileName; ContentType = data.ContentType; Size = data.Size; this.SetStream(data.GetStream()); }
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()); }
/// <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 }
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; }
private string GetStringFromBinaryData(BinaryData binary) { Stream stream = binary.GetStream(); StreamReader sr = new StreamReader(stream, Encoding.UTF8); string value = sr.ReadToEnd(); return value; }
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()); } }
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."); }
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; }