예제 #1
0
        private string GetText()
        {
            TxtFormatProvider provider = new TxtFormatProvider();

            Telerik.WinForms.Documents.Model.RadDocument document = this.txtSourceSQL.Document;
            return(provider.Export(document));
        }
예제 #2
0
        private void RadRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
        {
            if (e.Command is SaveCommand)
            {
                e.Cancel = true;
                SaveDocument(); // A custom logic for saving document so you can change the properties of the Save File dialog.
            }

            if (e.Command is PasteCommand)
            {
                // Altering the PasteCommand to ensure only plain text is pasted in RadRichTextBox.
                // Obtain the content from the clipboard.
                RadDocument documentFromClipboard = ClipboardEx.GetDocument().ToDocument();

                TxtFormatProvider provider = new TxtFormatProvider();
                // Convert it to plain text.
                string plainText = provider.Export(documentFromClipboard);

                // Create a RadDocument instance from the plain text.
                RadDocument documentToInsert = provider.Import(plainText);
                // Set this document as a content to the clipboard.
                ClipboardEx.SetDocument(new DocumentFragment(documentToInsert));
            }

            if (e.Command is InsertTableCommand)
            {
                // Disable the possibility to insert tables into the document.
                MessageBox.Show("Inserting tables is not allowed.");
                e.Cancel = true;
            }
        }
예제 #3
0
        public static void SaveDocument(RadFlowDocument document, string selectedFromat)
        {
            IFormatProvider<RadFlowDocument> formatProvider = null;
            switch (selectedFromat)
            {
                case "Docx":
                    formatProvider = new DocxFormatProvider();
                    break;
                case "Rtf":
                    formatProvider = new RtfFormatProvider();
                    break;
                case "Txt":
                    formatProvider = new TxtFormatProvider();
                    break;
            }
            if (formatProvider == null)
            {
                return;
            }

            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = String.Format("{0} files|*{1}|All files (*.*)|*.*",
                selectedFromat,
                formatProvider.SupportedExtensions.First());
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    formatProvider.Export(document, stream);
                }
            }
        }
예제 #4
0
 private void ExportToArray()
 {
     #region radwordsprocessing-formats-and-conversion-txt-txtformatprovider_3
     TxtFormatProvider provider = new TxtFormatProvider();
     RadFlowDocument   document = CreateRadFlowDocument();
     string            output   = provider.Export(document);
     #endregion
 }
예제 #5
0
 public override void Close()
 {
     if (ValidateNote()) {
         TxtFormatProvider txtProvider = new TxtFormatProvider();
         this.Note.Note = txtProvider.Export(this.ThisView.Note.Document);
         txtProvider = null;
     }
     this.TryClose();
 }
예제 #6
0
 private void ExportToFile()
 {
     #region radwordsprocessing-formats-and-conversion-txt-txtformatprovider_2
     TxtFormatProvider provider = new TxtFormatProvider();
     using (Stream output = File.OpenWrite("sample.txt"))
     {
         RadFlowDocument document = CreateRadFlowDocument();
         provider.Export(document, output);
     }
     #endregion
 }
예제 #7
0
        public static string GetTextFromRadDocText(string RadDoc)
        {
            if (RadDoc == null || RadDoc.Trim() == "")
            {
                return("");
            }
            var d  = new XamlFormatProvider().Import(RadDoc);
            var pr = new TxtFormatProvider();

            return(pr.Export(d));
        }
예제 #8
0
        private void ExportTxt()
        {
            #region radspreadsheet-model-import-export-txtformatprovider-wpf_1
            Workbook workbook = new Workbook();
            workbook.Worksheets.Add();

            string fileName = "SampleFile.txt";
            IWorkbookFormatProvider formatProvider = new TxtFormatProvider();

            using (FileStream output = new FileStream(fileName, FileMode.Create))
            {
                formatProvider.Export(workbook, output);
            }
            #endregion
        }
예제 #9
0
        private void ExportTxt()
        {
            #region radspreadprocessing-formats-and-conversion-txt-txtformatprovider_1
            Workbook workbook = new Workbook();
            workbook.Worksheets.Add();

            string fileName = "SampleFile.txt";
            IWorkbookFormatProvider formatProvider = new TxtFormatProvider();

            using (FileStream output = new FileStream(fileName, FileMode.Create))
            {
                formatProvider.Export(workbook, output);
            }
            #endregion
        }
예제 #10
0
        public void ExportWorkbookToTxt()
        {
            #region radspreadsheet-model-import-export-txtformatprovider-silverlight_2
            Workbook workbook = new Workbook();
            workbook.Worksheets.Add();

            SaveFileDialog    saveFileDialog = new SaveFileDialog();
            TxtFormatProvider formatProvider = new TxtFormatProvider();
            saveFileDialog.Filter = "TXT (tab delimited) (*.txt)|*.txt|All Files (*.*)|*.*";

            if (saveFileDialog.ShowDialog() == true)
            {
                using (Stream output = saveFileDialog.OpenFile())
                {
                    formatProvider.Export(workbook, output);
                }
            }
            #endregion
        }
예제 #11
0
        public void PasteNewText()
        {
            DocumentFragment clipboardDocument     = null;
            string           clipboardText         = null;
            bool             clipboardContainsData = false;

            if (ClipboardEx.ContainsDocument(null))
            {
                clipboardDocument     = ClipboardEx.GetDocument();
                clipboardContainsData = true;
            }
            else if (ClipboardEx.ContainsText(null))
            {
                clipboardText         = ClipboardEx.GetText(null);
                clipboardContainsData = true;
            }

            if (!clipboardContainsData)
            {
                return;
            }

            this.radRichTextEditor1.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Consolas"));

            if (clipboardDocument != null)
            {
                RadDocument       doc    = new RadDocument();
                RadDocumentEditor editor = new RadDocumentEditor(doc);
                editor.InsertFragment(clipboardDocument);

                string text = provider.Export(doc);

                this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.Insert(text);
            }
            else if (!string.IsNullOrEmpty(clipboardText))
            {
                this.radRichTextEditor1.RichTextBoxElement.ActiveDocumentEditor.Insert(clipboardText);
            }
        }
예제 #12
0
        public static void SaveDocument(RadFlowDocument document, string selectedFromat)
        {
            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (selectedFromat)
            {
            case "Docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "Rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "Txt":
                formatProvider = new TxtFormatProvider();
                break;
            }
            if (formatProvider == null)
            {
                return;
            }

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter = String.Format("{0} files|*{1}|All files (*.*)|*.*",
                                          selectedFromat,
                                          formatProvider.SupportedExtensions.First());
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    formatProvider.Export(document, stream);
                }
            }
        }
        private async Task Generate()
        {
            RadFlowDocument document = this.CreateDocument();
            IFormatProvider <RadFlowDocument> formatProvider = null;
            string exampleName = null;

            switch (selectedExportFormat)
            {
            case "Docx":
                formatProvider = new DocxFormatProvider();
                exampleName    = "example.docx";
                break;

            case "Rtf":
                formatProvider = new RtfFormatProvider();
                exampleName    = "example.rtf";
                break;

            case "Html":
                formatProvider = new HtmlFormatProvider();
                exampleName    = "example.html";
                break;

            case "Txt":
                formatProvider = new TxtFormatProvider();
                exampleName    = "example.txt";
                break;
            }

            using (MemoryStream stream = new MemoryStream())
            {
                formatProvider.Export(document, stream);

                stream.Seek(0, SeekOrigin.Begin);

                await this.fileViewerService.View(stream, exampleName);
            }
        }
예제 #14
0
        private async void ExportCommandExecute()
        {
            this.OpenSample();

            IFormatProvider <RadFlowDocument> formatProvider = null;
            string exampleName = null;

            switch (this.selectedExportFormat)
            {
            case "PDF files(*.pdf)":
                formatProvider = new PdfFormatProvider();
                exampleName    = "example.pdf";
                break;

            case "RTF files(*.rtf)":
                formatProvider = new RtfFormatProvider();
                exampleName    = "example.rtf";
                break;

            case "HTML files(*.html)":
                formatProvider = new HtmlFormatProvider();
                exampleName    = "example.html";
                break;

            case "TXT files(*.txt)":
                formatProvider = new TxtFormatProvider();
                exampleName    = "example.txt";
                break;
            }

            using (MemoryStream stream = new MemoryStream())
            {
                formatProvider.Export(this.flowDocument, stream);
                stream.Seek(0, SeekOrigin.Begin);
                await this.fileViewerService.View(stream, exampleName);
            }
        }
예제 #15
0
        private Field GetField(string processSystemName, PropertyInfo property, IDynamicObject self, bool isGsUpdate, CultureInfo culture = null)
        {
            var containsNumbers = false;
            var temp = property.GetValue(self, null);

            if (typeof(DateTime?).IsAssignableFrom(property.PropertyType))
            {
                containsNumbers = true;
                var attrib = (DateTimeFormatAttribute[])property.GetCustomAttributes(typeof(DateTimeFormatAttribute), false);
                var displayType = attrib.Select(x => x.Value).FirstOrDefault();
                var propValue = (DateTime?)property.GetValue(self, null);
                if (propValue != null)
                {
                    switch (displayType)
                    {
                        case "Date":
                            temp = propValue.Value.ToString(Constants.DefaultShortDateFormat, CultureInfo.InvariantCulture);
                            break;
                        case "Time":
                            temp = propValue.Value.ToString(Constants.DefaultShortTimeFormat, CultureInfo.InvariantCulture);
                            break;
                        case "DateTime":
                            temp = propValue.Value.ToString(Constants.DefaultShortDateTimeFormat, CultureInfo.InvariantCulture);
                            break;
                        default:
                            throw new VeyronException("Not definited time : " + displayType);
                    }
                }
            }

            var crossRefAtrib = (CrossRefFieldAttribute[])property.GetCustomAttributes(typeof(CrossRefFieldAttribute), false);
            if (crossRefAtrib.Count() != 0)
            {
                var enumerable = temp as IEnumerable<object>;
                if (enumerable != null)
                {
                    var items = enumerable.ToArray();

                    var fieldName = crossRefAtrib.Select(x => x.RefFieldName).FirstOrDefault();
                    if (items.Any())
                    {
                        var firstItemType = items[0].GetType();
                        var fieldProperty = firstItemType.GetPropertyByName(fieldName);
                        if (fieldProperty != null)
                        {
                            var list = items.Select(item => (fieldProperty.GetValue(item, null) ?? string.Empty).ToString()).ToList();
                            temp = list.Any() ? list.Aggregate((a, b) => a + ", " + b) : null;
                        }
                    }
                    else
                    {
                        temp = string.Empty;
                    }
                }
                else
                {
                    if (!isGsUpdate)
                    {
                        var crossRefId = temp as int?;
                        if (crossRefId != null)
                        {
                            var crossRefValue = TheDynamicTypeManager.GetCrossReferenceItem(processSystemName, property.Name, (int)crossRefId);
                            if (crossRefValue != null)
                            {
                                temp = crossRefValue.__DisplayName;
                            }
                        }
                    }
                }
            }

            var fieldEditorAtribute = (FieldEditorAttribute[])property.GetCustomAttributes(typeof(FieldEditorAttribute), false);
            if (fieldEditorAtribute.Count() != 0)
            {
                var atribute = fieldEditorAtribute.FirstOrDefault();
                if (atribute.DataType == "Checkbox")
                {
                    var checkBoxValue = temp as bool?;

                    var isSwithTogle = (IsSwitchToggleAttribute[])property.GetCustomAttributes(typeof(IsSwitchToggleAttribute), false);
                    if (isSwithTogle.Count() != 0)
                    {
                        var switchTogleValue = (isSwithTogle.FirstOrDefault().Value as bool?).Value;
                        if (switchTogleValue)
                        {
                            if (!checkBoxValue.HasValue)
                            {
                                temp =
                                    ((UndefinedLabelAttribute[])property.GetCustomAttributes(typeof(UndefinedLabelAttribute), false))
                                        .FirstOrDefault().Value.ToString();
                            }
                            else if (checkBoxValue.Value)
                            {
                                temp =
                                    ((TrueLabelAttribute[])property.GetCustomAttributes(typeof(TrueLabelAttribute), false)).FirstOrDefault()
                                                                                                                           .Value.ToString();
                            }
                            else
                            {
                                temp =
                                    ((FalseLabelAttribute[])property.GetCustomAttributes(typeof(FalseLabelAttribute), false)).FirstOrDefault()
                                                                                                                             .Value.ToString();
                            }
                        }
                        else
                        {
                            if (!checkBoxValue.HasValue)
                            {
                                temp = null;
                            }
                            else if (checkBoxValue.Value)
                            {
                                temp = "True";
                            }
                            else
                            {
                                temp = "False";
                            }
                        }
                    }
                }

                if (atribute.DataType == "Approval")
                {
                    var result = temp as string;
                    var approval = temp as IApprovalEdit;
                    if (approval != null)
                    {
                        result = approval.ApprovalState;
                    }

                    temp = result.ToApprovalState().GetDisplayName();
                }

                if (atribute.DataType == "RichText")
                {
                    var richText = temp as string;

                    if (!string.IsNullOrEmpty(richText))
                    {
                        var htmlProvider = new HtmlFormatProvider();
                        var document = htmlProvider.Import(richText);

                        var textProvider = new TxtFormatProvider();
                        temp = textProvider.Export(document);
                    }
                }

                if (atribute.DataType == "FileProcess")
                {
                    var file = temp as IFileProcess;
                    if (file != null)
                    {
                        temp = file.OriginalFileName;
                    }
                }
            }

            string value = temp == null ? null : temp.ToString();
            if (!containsNumbers && IsNumber(value))
            {
                containsNumbers = true;
            }

            if (value == null || string.IsNullOrWhiteSpace(value))
            {
                return null;
            }

            var field = culture != null ? GetLocalizedFieldName(property.Name, culture) : property.Name;

            return new Field(field, value, Field.Store.YES, containsNumbers ? Field.Index.NOT_ANALYZED : Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS);
        }
 public void NoteSave()
 {
     if (ValidateNote())
     {
         TxtFormatProvider txtProvider = new TxtFormatProvider();
         this.Note.Note = txtProvider.Export(this.NotesView.CurrentNote.Document);
         txtProvider = null;
         NotesView.NoteGrid.Enable(defaultFocusDelegate);
         NotesView.NoteData.Disable();
         this.Notes.AddOrReplace(this.Note.Clone());
         AssistantNoteMode = (int)AssistantViewMode.ReadOnly;
         NotifyOfPropertyChange(() => NotesCount);
         NotifyOfPropertyChange(() => Notes);
         UpdateSummaryNotes();
     }
     NotifyOfPropertyChange(() => CanNoteAdd);
     NotifyOfPropertyChange(() => CanNoteEdit);
     NotifyOfPropertyChange(() => CanNoteRemove);
 }
        private void ReceiveNewEmail()
        {
            var newEmail = EmailService.GetEmails(1).First();
            newEmail.Status = EmailStatus.Unread;

            var provider = new TxtFormatProvider();
            string emailContentText = provider.Export(newEmail.Content);

            this.desktopAlertManager.ShowAlert(new DesktopAlertParameters
            {
                Header = newEmail.Sender,
                Content = newEmail.Subject + emailContentText,
                Icon = new Image { Source = Application.Current.FindResource("DesktopAlertIcon") as ImageSource, Width = 48, Height = 48 },
                IconColumnWidth = 48,
                IconMargin = new Thickness(10, 0, 20, 0),
                Command = new DelegateCommand(this.OnAlertCommandExecuted),
                CommandParameter = newEmail
            });

            this.ReceivedEmails.Add(newEmail);
        }