private void thr_load(object obj)
 {
     Dispatcher.BeginInvoke(new Action(delegate
     {
         string date = cmbHistoryList.SelectedValue.ToString();
         string[] files = Directory.GetFiles(Constants.HISTORYDIR, "*" +windowName+"_"+date + ".hist");
         string file = files[0];
         TextRange tr = new TextRange(usrRTB.richChat.Document.ContentStart, usrRTB.richChat.Document.ContentEnd);
         using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, bufferSize: 4096, useAsync: true))
         {
             if (tr.CanLoad(DataFormats.XamlPackage))
             {
                 tr.Load(fs, DataFormats.XamlPackage);
             }
         }
         foreach (Block b in usrRTB.richChat.Document.Blocks) {
             b.TextAlignment = TextAlignment.Left;
         }
     }));  
 }
Beispiel #2
0
        private string SetRangeContent(TextRange selection, string content)
        {
            string loadType = DataFormats.Rtf;
            IsFormatted = true;
            content = content == "" ? " " : content;
            try
            {
                using (MemoryStream ms = new MemoryStream(ASCIIEncoding.Default.GetBytes(content)))
                {
                    if (content.StartsWith("<Section"))
                    {
                        if (selection.CanLoad(DataFormats.Xaml))
                        {
                            selection.Load(ms, DataFormats.Xaml);
                            loadType = DataFormats.Xaml;
                        }
                    }
                    else if (content.StartsWith("PK"))
                    {
                        if (selection.CanLoad(DataFormats.XamlPackage))
                        {
                            selection.Load(ms, DataFormats.XamlPackage);
                            loadType = DataFormats.XamlPackage;
                        }
                    }
                    else if (content.StartsWith("{\\rtf"))
                    {
                        if (selection.CanLoad(DataFormats.Rtf))
                        {
                            selection.Load(ms, DataFormats.Rtf);
                            loadType = DataFormats.Rtf;
                        }
                    }
                    else
                    {
                        if (selection.CanLoad(DataFormats.Text))
                        {
                            selection.Load(ms, DataFormats.Text);
                            loadType = DataFormats.Text;
                            IsFormatted = false;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return loadType;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            TextPointer start = this._rtb.Document.ContentStart,
                        end = this._rtb.Document.ContentEnd;
            TextRange tr = new TextRange(start, end);
            FileInfo fi = new FileInfo("proba.xaml");

            if (tr.CanLoad(DataFormats.Xaml) && fi.Exists)
            {
                using (Stream s = fi.Open(FileMode.Open))
                {
                    SetDefaultColorOfTextInXmlStream(s);

                    tr.Load(s, DataFormats.Xaml);
                }
            }
        }
        static TextRange SetDocumentContent(FlowDocument document, string text, string dataFormat)
        {
            var content = new TextRange(document.ContentStart, document.ContentEnd);

            if (content.CanLoad(dataFormat))
            {
                if (string.IsNullOrEmpty(text))
                {
                    content.Text = text;
                }
                else
                {
                    using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(text)))
                    {
                        content.Load(stream, dataFormat);
                    }
                }
            }

            return content;
        }
Beispiel #5
0
        public void Load(TextRange storyText)
        {
            // Data format for the person's story file.
            string dataFormat = DataFormats.Rtf;

            if (File.Exists(this.AbsolutePath))
            {
                try
                {
                    // Open the file for reading
                    using (FileStream stream = File.OpenRead(this.AbsolutePath))
                    {
                        if (storyText.CanLoad(dataFormat))
                            storyText.Load(stream, dataFormat);
                    }
                }
                catch
                {
                    // Could not load the story. Handle all exceptions
                    // the same, ignore and continue.
                }
            }
        }
Beispiel #6
0
        // Paste text data on RichTextBox as UTF8 encoding
        private bool PasteTextDataToRichTextBox(string dataFormat, string textData)
        {
            var pasted = false;

            var document = richTextBox.Document;
            var textRange = new TextRange(document.ContentStart, document.ContentEnd);

            Stream stream = new MemoryStream();

            var bytesUnicode = Encoding.Unicode.GetBytes(textData);
            var bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, bytesUnicode);

            if (bytes.Length > 0 && textRange.CanLoad(dataFormat))
            {
                stream.Write(bytes, 0, bytes.Length);
                textRange.Load(stream, dataFormat);
                pasted = true;
            }

            return pasted;
        }
Beispiel #7
0
 private void MenuItemLaden_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         OpenFileDialog open = new OpenFileDialog();
         open.Filter = "Earthdawncharakterarchiv (*.edz)|*.edz";
         if (open.ShowDialog() == true)
         {
             using (ZipArchive zip = ZipFile.Open(open.FileName, ZipArchiveMode.Read))
             {
                 foreach (ZipArchiveEntry entry in zip.Entries)
                 {
                     if(entry.Name.Contains(".bin"))
                     {
                         Stream sfs = entry.Open();
                         BinaryFormatter formatter = new BinaryFormatter();
                         aktChar = (EDChar)formatter.Deserialize(sfs);
                         sfs.Close();
                     }
                     else if (entry.Name.Contains(".xaml"))
                     {
                         Stream nfs = entry.Open();
                         TextRange rng = new TextRange(Notizen.ContentStart, Notizen.ContentEnd);
                         if (rng.CanLoad(DataFormats.Xaml))
                         {
                             rng.Load(nfs, DataFormats.Xaml);
                         }
                         nfs.Close();
                     }
                 }
             }
             UpdateGUI();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #8
0
 private void OnClick_LoadScript(object sender, RoutedEventArgs e)
 {
     System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
     dlg.AddExtension = true;
     dlg.DefaultExt = ".bql";
     dlg.Title = "Specify the script file";
     dlg.Filter = "Building Query Language|*.bql";
     dlg.FilterIndex = 0;
     dlg.ValidateNames = true;
     dlg.FileOk += delegate(object s, System.ComponentModel.CancelEventArgs eArg)
     {
         Stream file = null;
         string dataFormat = "Text";
         try
         {
             file = dlg.OpenFile();
             TextRange txtRange = new TextRange(ScriptText.Document.ContentStart, ScriptText.Document.ContentEnd);
             if (txtRange.CanLoad(dataFormat))
             {
                 txtRange.Load(file, dataFormat);
             }
             this.Title = "BQL Console - " + System.IO.Path.GetFileName(dlg.FileName);
         }
         catch (Exception ex)
         {
             System.Windows.MessageBox.Show(string.Format("Loading script from file failed : {0}.", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         finally
         {
             if (file != null)
                 file.Close();
         }
     };
     dlg.ShowDialog();
     ScriptText.RefreshKeyColour();
     
 }