static int _m_BeginWrite(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.IO.FileStream gen_to_be_invoked = (System.IO.FileStream)translator.FastGetCSObj(L, 1);



                {
                    byte[] _array    = LuaAPI.lua_tobytes(L, 2);
                    int    _offset   = LuaAPI.xlua_tointeger(L, 3);
                    int    _numBytes = LuaAPI.xlua_tointeger(L, 4);
                    System.AsyncCallback _userCallback = translator.GetDelegate <System.AsyncCallback>(L, 5);
                    object _stateObject = translator.GetObject(L, 6, typeof(object));

                    System.IAsyncResult gen_ret = gen_to_be_invoked.BeginWrite(_array, _offset, _numBytes, _userCallback, _stateObject);
                    translator.PushAny(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemplo n.º 2
0
 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     return(InternalFileStream.BeginWrite(buffer, offset, count, callback, state));
 }
Exemplo n.º 3
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);
            }
        }