private void TaskResultUpdateCallback(IAsyncResult ar)
    {
        TransportClassTaskResult oTransportClassTaskResult = ar.AsyncState as TransportClassTaskResult;
        try
        {
            ErrorTypes eError = oTransportClassTaskResult.m_oTaskResult.UpdateEnd(ar);
            if (ErrorTypes.NoError == eError)
            {
                
                InputCommand cmd = oTransportClassTaskResult.m_oInputCommand;
                int nToFormat = FileFormats.AVS_OFFICESTUDIO_FILE_CANVAS;
                TaskQueueData oTaskQueueData = new TaskQueueData(cmd.id, nToFormat, "Editor.bin");
                if ("reopen" == cmd.c)
                {
                    oTaskQueueData.m_sFromKey = cmd.id;
                    oTaskQueueData.m_bFromSettings = true;
                }
                else
                    oTaskQueueData.m_sFromUrl = cmd.url;

                oTaskQueueData.m_sFromFormat = cmd.format;
                if (cmd.codepage.HasValue)
                    oTaskQueueData.m_nCsvTxtEncoding = cmd.codepage.Value;
                if (cmd.delimiter.HasValue)
                    oTaskQueueData.m_nCsvDelimiter = cmd.delimiter.Value;
                oTaskQueueData.m_bEmbeddedFonts = false;

                CTaskQueue oTaskQueue = new CTaskQueue();
                TransportClassTaskQueue oTransportClassTaskQueue = new TransportClassTaskQueue(oTransportClassTaskResult, oTaskQueue, null);
                oTaskQueue.AddTaskBegin(oTaskQueueData, Priority.High, TaskQueueAddCallback, oTransportClassTaskQueue);

				WriteOutputCommand(oTransportClassTaskQueue, new OutputCommand("waitopen", "0"));
            }
            else
                WriteOutputCommand(oTransportClassTaskResult, new OutputCommand(eError));
        }
        catch
        {
            WriteOutputCommand(oTransportClassTaskResult, new OutputCommand(ErrorTypes.Unknown));
        }
    }
    private void AddTask(InputCommand cmd, TransportClassMainAshx oTransportClassMainAshx)
    {
        try
        {
            
            int nToFormat = FileFormats.AVS_OFFICESTUDIO_FILE_CANVAS;

            TaskQueueData oTaskQueueData = new TaskQueueData(cmd.id, nToFormat, "Editor.bin");

            oTaskQueueData.m_sFromUrl = cmd.url;
            oTaskQueueData.m_sFromFormat = cmd.format;

            if (cmd.codepage.HasValue)
                oTaskQueueData.m_nCsvTxtEncoding = cmd.codepage.Value;
            if (cmd.delimiter.HasValue)
                oTaskQueueData.m_nCsvDelimiter = cmd.delimiter.Value;
            oTaskQueueData.m_bEmbeddedFonts = false;

            CTaskQueue oTaskQueue = new CTaskQueue();
            TransportClassTaskQueue oTransportClassTaskQueue = new TransportClassTaskQueue(oTransportClassMainAshx, oTaskQueue, null);

            oTaskQueue.AddTaskBegin(oTaskQueueData, Priority.High, TaskQueueAddCallback, oTransportClassTaskQueue);
			
            WriteOutputCommand(oTransportClassTaskQueue, new OutputCommand("waitopen", "0"));
        }
        catch
        {
            WriteOutputCommand(oTransportClassMainAshx, new OutputCommand(ErrorTypes.Unknown));
        }
    }
    private void StorageWriteFileAsyncCallback(IAsyncResult ar)
    {
        TransportClassStorage oTransportClassStorage = ar.AsyncState as TransportClassStorage;
        try
        {
            int nReadWriteBytes;
            ErrorTypes eError = oTransportClassStorage.m_oStorage.WriteFileEnd(ar, out nReadWriteBytes);
            if (null != oTransportClassStorage.m_oStream)
                oTransportClassStorage.m_oStream.Dispose();
            if (ErrorTypes.NoError == eError)
            {
                InputCommand cmd = oTransportClassStorage.m_oInputCommand;
                if (c_sSaveTypeCompleteAll == cmd.savetype || c_sSaveTypeComplete == cmd.savetype)
                {
                    
                    int nOutputFormat = cmd.outputformat.Value;
                    TaskQueueData oTaskQueueData = new TaskQueueData(oTransportClassStorage.m_sKey, nOutputFormat, "output." + FileFormats.ToString(nOutputFormat));
                    oTaskQueueData.m_sFromKey = cmd.id;
                    oTaskQueueData.m_sFromFormat = "bin";
                    if (cmd.codepage.HasValue)
                        oTaskQueueData.m_nCsvTxtEncoding = cmd.codepage.Value;
                    if (cmd.delimiter.HasValue)
                        oTaskQueueData.m_nCsvDelimiter = cmd.delimiter.Value;
                    if (null != cmd.vkey)
                    {
                        bool bPaid;
                        Signature.getVKeyParams(cmd.vkey, out bPaid);
                        oTaskQueueData.m_bPaid = bPaid;
                    }

                    Priority oPriority = Priority.Low;
                    if (cmd.innersave)
                        oPriority = Priority.Normal;
                    CTaskQueue oTaskQueue = new CTaskQueue();
                    TransportClassTaskQueue oTransportClassTaskQueue = new TransportClassTaskQueue(oTransportClassStorage, oTaskQueue, oTaskQueueData);
                    oTaskQueue.AddTaskBegin(oTaskQueueData, oPriority, TaskQueueAddCallbackSave, oTransportClassTaskQueue);
                }
                else
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    OutputSavePartData oOutputSavePartData = new OutputSavePartData(oTransportClassStorage.m_sKey, cmd.outputformat.Value);
                    WriteOutputCommand(oTransportClassStorage, new OutputCommand("savepart", serializer.Serialize(oOutputSavePartData)));
                }
            }
            else
                WriteOutputCommand(oTransportClassStorage, new OutputCommand(eError));

        }
        catch
        {
            WriteOutputCommand(oTransportClassStorage, new OutputCommand(ErrorTypes.Unknown));
        }
    }
    private void TaskResultAddRandomKeyAsyncCallback2(IAsyncResult ar)
    {
        TransportClassTaskResult oTransportClassTaskResult = ar.AsyncState as TransportClassTaskResult;
        try
        {
            TaskResultData oTaskResultData;
            ErrorTypes eError = oTransportClassTaskResult.m_oTaskResult.AddRandomKeyEnd(ar, out oTaskResultData);
            if (ErrorTypes.NoError == eError)
            {
                
                InputCommand cmd = oTransportClassTaskResult.m_oInputCommand;
                TaskQueueData oTaskQueueData = new TaskQueueData(oTaskResultData.sKey, FileFormats.AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF, "output.pdf");
                oTaskQueueData.m_sFromKey = cmd.id;
                oTaskQueueData.m_sFromFormat = "pdf";
                oTaskQueueData.m_bFromOrigin = true;
                if (cmd.codepage.HasValue)
                    oTaskQueueData.m_nCsvTxtEncoding = cmd.codepage.Value;
                if (cmd.delimiter.HasValue)
                    oTaskQueueData.m_nCsvDelimiter = cmd.delimiter.Value;
                if (null != cmd.vkey)
                {
                    
                    bool bPaid;
                    Signature.getVKeyParams(cmd.vkey, out bPaid);
                    oTaskQueueData.m_bPaid = bPaid;
                }

                CTaskQueue oTaskQueue = new CTaskQueue();
                TransportClassTaskQueue oTransportClassTaskQueue = new TransportClassTaskQueue(oTransportClassTaskResult, oTaskQueue, oTaskQueueData);
                oTaskQueue.AddTaskBegin(oTaskQueueData, Priority.Low, TaskQueueAddCallbackSave, oTransportClassTaskQueue);
            }
            else
                WriteOutputCommand(oTransportClassTaskResult, new OutputCommand(eError));
        }
        catch
        {
            WriteOutputCommand(oTransportClassTaskResult, new OutputCommand(ErrorTypes.Unknown));
        }
    }
    private void ChangesWriteCallback(IAsyncResult ar)
    {
        TransportClassStorage2 oTransportClassStorage = ar.AsyncState as TransportClassStorage2;
        try
        {
            int nReadWriteBytes;
            oTransportClassStorage.m_oStorage.WriteFileEnd(ar, out nReadWriteBytes);
            if (null != oTransportClassStorage.m_oStream)
                oTransportClassStorage.m_oStream.Dispose();
            InputCommand cmd = oTransportClassStorage.m_oInputCommand;
            if (c_sSaveTypeComplete == cmd.savetype || c_sSaveTypeCompleteAll == cmd.savetype)
            {
                
                int nOutputFormat = cmd.outputformat.HasValue ? cmd.outputformat.Value : FileFormats.AVS_OFFICESTUDIO_FILE_OTHER_TEAMLAB_INNER;
                TaskQueueData oTaskQueueData = new TaskQueueData(oTransportClassStorage.m_sKey, nOutputFormat, "output." + FileFormats.ToString(nOutputFormat));
                oTaskQueueData.m_sFromKey = cmd.id;
                oTaskQueueData.m_sFromFormat = "bin";
                if (cmd.codepage.HasValue)
                    oTaskQueueData.m_nCsvTxtEncoding = cmd.codepage.Value;
                if (cmd.delimiter.HasValue)
                    oTaskQueueData.m_nCsvDelimiter = cmd.delimiter.Value;
                if (null != cmd.vkey)
                {
                    bool bPaid;
                    Signature.getVKeyParams(cmd.vkey, out bPaid);
                    oTaskQueueData.m_bPaid = bPaid;
                }
                Priority oPriority = Priority.Low;
                if (cmd.innersave)
                    oPriority = Priority.Normal;
                CTaskQueue oTaskQueue = new CTaskQueue();
                TransportClassTaskQueue oTransportClassTaskQueue = new TransportClassTaskQueue(oTransportClassStorage, oTaskQueue, oTaskQueueData);
                oTaskQueue.AddTaskBegin(oTaskQueueData, oPriority, TaskQueueAddCallbackSave, oTransportClassTaskQueue);
            }
            else
                WriteOutputCommand(oTransportClassStorage, oTransportClassStorage.m_oOutputCommand);
        }
        catch(Exception e)
        {
			_log.Error("Exception catched in ChangesWriteCallback:", e);
            WriteOutputCommand(oTransportClassStorage, new OutputCommand(ErrorTypes.Unknown));
        }
    }
    private void TaskResultAddRandomKeyAsyncCallback4(IAsyncResult ar)
    {
        TransportClassTaskResult oTransportClassTaskResult = ar.AsyncState as TransportClassTaskResult;
        try
        {
            TaskResultData oTaskResultData;
            ErrorTypes eError = oTransportClassTaskResult.m_oTaskResult.AddRandomKeyEnd(ar, out oTaskResultData);
            if (ErrorTypes.NoError == eError)
            {
                
                InputCommand cmd = oTransportClassTaskResult.m_oInputCommand;
                TaskQueueData oTaskQueueData = new TaskQueueData(oTaskResultData.sKey, cmd.outputformat.Value, "output." + FileFormats.ToString(cmd.outputformat.Value));
                oTaskQueueData.m_sFromKey = cmd.id;
                oTaskQueueData.m_sFromFormat = "doct";
                oTaskQueueData.m_bFromChanges = true;

                CTaskQueue oTaskQueue = new CTaskQueue();
                TransportClassTaskQueue oTransportClassTaskQueue = new TransportClassTaskQueue(oTransportClassTaskResult, oTaskQueue, oTaskQueueData);
                oTaskQueue.AddTaskBegin(oTaskQueueData, Priority.Low, TaskQueueAddCallbackSave3, oTransportClassTaskQueue);
            }
            else
                WriteOutputCommand(oTransportClassTaskResult, new OutputCommand(eError));
        }
        catch
        {
            WriteOutputCommand(oTransportClassTaskResult, new OutputCommand(ErrorTypes.Unknown));
        }
    }