Beispiel #1
0
            public override void Start()
            {
                State = VKOperationState.Executing;

                var serverRequest = _getServerRequestFunc();

                serverRequest.Completed += (s, o) =>
                {
                    try
                    {
                        var response = o.Response;

                        var httpRequest = WebRequest.CreateHttp(response.Content["response"].Value <string>("upload_url"));

                        var fileDict = new Dictionary <string, VKHttpOperation.FileParameter>();
                        fileDict["file1"] = _file;
                        var uploadFileOperation = new VKJsonOperation(httpRequest, fileDict);

                        uploadFileOperation.Completed += (sender, args) =>
                        {
                            var saveRequest = _getSaveRequestFunc(args.JsonResponse);

                            saveRequest.Completed += (saveSender, saveArgs) =>
                            {
                                State = VKOperationState.Finished;

                                _successCallback(saveArgs.Response);
                            };

                            saveRequest.Error += (saveSender, saveArgs) =>
                            {
                                _errorCallback(saveArgs.Error);
                            };
                        };

                        uploadFileOperation.Failed += (sender, args) =>
                        {
                            _errorCallback(args.Error);
                        };

                        uploadFileOperation.Start();
                        _lastOperation = uploadFileOperation;
                    }
                    catch (Exception exc)
                    {
                        VKError error = new VKError(VKError.JSON_FAILED);
                        error.HttpError    = exc;
                        error.ErrorMessage = exc.Message;
                        _errorCallback(error);
                    }

                    serverRequest.Error += (s1, o1) =>
                    {
                        _errorCallback(o1.Error);
                    };

                    _lastOperation = serverRequest.GetOperation();

                    _lastOperation.Start();
                };
            }
            public override void Start()
            {
                State = VKOperationState.Executing;

                var serverRequest = _getServerRequestFunc();

                serverRequest.Completed += (s, o) =>
                    {
                        try
                        {
                            var response = o.Response;

                            var httpRequest = WebRequest.CreateHttp(response.Content["response"].Value<string>("upload_url"));

                            var fileDict = new Dictionary<string, VKHttpOperation.FileParameter>();
                            fileDict["file1"] = _file;
                            var uploadFileOperation = new VKJsonOperation(httpRequest, fileDict);

                            uploadFileOperation.Completed += (sender, args) =>
                                {
                                    var saveRequest = _getSaveRequestFunc(args.JsonResponse);

                                    saveRequest.Completed += (saveSender, saveArgs) =>
                                        {

                                            State = VKOperationState.Finished;

                                            _successCallback(saveArgs.Response);
                                        };

                                    saveRequest.Error += (saveSender, saveArgs) =>
                                        {
                                            _errorCallback(saveArgs.Error);
                                        };


                                };

                            uploadFileOperation.Failed += (sender, args) =>
                                {
                                    _errorCallback(args.Error);
                                };

                            uploadFileOperation.Start();
                            _lastOperation = uploadFileOperation;


                        }
                        catch (Exception exc)
                        {
                            VKError error = new VKError(VKError.JSON_FAILED);
                            error.HttpError = exc;
                            error.ErrorMessage = exc.Message;
                            _errorCallback(error);
                        }

                        serverRequest.Error += (s1, o1) =>
                            {
                                _errorCallback(o1.Error);
                            };

                        _lastOperation = serverRequest.GetOperation();

                        _lastOperation.Start();

                    };
            }