Esempio n. 1
0
 public OpenedDocument(FileTreeItem item)
 {
     Text = item.Text;
     Name = item.Name;
 }
Esempio n. 2
0
        private void SaveToFileAsync(string fileToSave, FileTreeItem fti)
        {
            try
            {
                var fs  = new System.IO.FileStream(fileToSave, System.IO.FileMode.Create);
                var src = fti.GetDataStream();

                const int CHUNK_SIZE = 1024 * 10; //kilobytes
                byte[]    buffer     = new byte[CHUNK_SIZE];

                Action <Exception> Done = (exc) =>
                {
                    if (exc != null)
                    {
                        this.Dispatcher.BeginInvoke(new Action(() => Utils.UIHelper.DefaultErrHandling(exc)));
                    }

                    fs.Close();
                    src.Close();
                };

                AsyncCallback CallbackExpr = null;
                CallbackExpr = (IAsyncResult readResult) =>
                {
                    try
                    {
                        int read = src.EndRead(readResult);
                        if (read > 0)
                        {
                            fs.BeginWrite(buffer, 0, read, writeResult =>
                            {
                                try
                                {
                                    fs.EndWrite(writeResult);
                                    src.BeginRead(buffer, 0, buffer.Length, CallbackExpr, null);
                                }
                                catch (Exception exc)
                                {
                                    Done(exc);
                                }
                            },
                                          null);
                        }
                        else
                        {
                            Done(null);
                        }
                    }
                    catch (Exception exc)
                    {
                        Done(exc);
                    }
                };

                // Here we go!
                src.BeginRead(buffer, 0, buffer.Length, CallbackExpr, null);
            }
            catch (Exception exc)
            {
                Utils.UIHelper.DefaultErrHandling(exc);
            }
        }