示例#1
0
        protected void getRequestStreamCallback(IAsyncResult asynchronousResult)
        {
            RequestToCancel requestToCancel = (RequestToCancel)asynchronousResult.AsyncState;

            if (log.isDebugEnabled())
            {
                log.debug("getRequestStreamCallback(" + requestToCancel);
            }
            try
            {
                HttpWebRequest conn       = requestToCancel.getConnection();
                Stream         postStream = conn.EndGetRequestStream(asynchronousResult);
                if (requestToCancel.buf != null)
                {
                    if (log.isDebugEnabled())
                    {
                        log.debug("bufferToStream");
                    }
                    bufferToStream(requestToCancel.buf, postStream);
                }
                else if (requestToCancel.stream != null)
                {
                    if (log.isDebugEnabled())
                    {
                        log.debug("copy stream");
                    }
                    requestToCancel.stream.CopyTo(postStream);
                    postStream.Close();
                }
                conn.BeginGetResponse(new AsyncCallback(this.getResponseCallback), requestToCancel);
            }
            catch (Exception e)
            {
                if (log.isDebugEnabled())
                {
                    log.debug("Exception:", e);
                }
                BException bex = null;
                if (_cancelAllRequests)
                {
                    bex = new BException(BExceptionC.CANCELLED, "");
                }
                else
                {
                    bex = new BException(BExceptionC.IOERROR, e.Message, e);
                }
                removeRequest(requestToCancel, null, bex);
            }
            finally
            {
                if (requestToCancel.stream != null)
                {
                    requestToCancel.stream.Close();
                }
            }
            if (log.isDebugEnabled())
            {
                log.debug(")getRequestStreamCallback");
            }
        }
示例#2
0
        public void setException(Exception ex)
        {
            if (ex.GetType() == typeof(BException))
            {
                header.error = ((BException)ex).Code;
            }
            else
            {
                header.error = BExceptionC.REMOTE_ERROR;
                BSerializer ser = registry.getSerializer(ex, false);
                if (ser == null)
                {
                    ex = new BException(BExceptionC.REMOTE_ERROR, "", ex);
                }
            }
            store(ex);

            // Alle Streams schließen. Sie werden nicht gesendet.
            if (streams != null)
            {
                foreach (BContentStream bstream in streams)
                {
                    try
                    {
                        bstream.Close();
                    }
                    catch (Exception) { }
                }
                streams = null;
            }
        }
示例#3
0
            protected override Stream openStream()
            {
                try
                {
                    String         url  = wire.url + "?serverId=" + TargetId.getServerId() + "&messageid=" + TargetId.getMessageId() + "&streamid=" + TargetId.getStreamId();
                    HttpWebRequest conn = (HttpWebRequest)HttpWebRequest.Create(url);
                    request = wire.createRequestForGetStream(TargetId, this);
                    request.setConnection(conn);

                    conn.Method = "GET";
                    wire.applySession(conn);

                    response           = (HttpWebResponse)conn.GetResponse();
                    ContentType        = response.ContentType;
                    ContentLength      = response.ContentLength;
                    ContentDisposition = response.Headers["Content-Disposition"];

                    responseStream = response.GetResponseStream();
                }
                catch (Exception ex)
                {
                    BException bex = new BException(BExceptionC.IOERROR, "", ex);
                    setAsyncResult(null, bex);
                    wire.removeRequest(request, null, bex);
                }

                throwExceptionIf();

                return(responseStream);
            }
示例#4
0
        public void setException(Exception ex)
        {
            if (ex.GetType() == typeof(BException))
            {
                header.error = ((BException)ex).Code;
            }
            else
            {
                header.error = BExceptionC.REMOTE_ERROR;
                BSerializer ser = registry.getSerializer(ex, false);
                if (ser == null)
                {
                    ex = new BException(BExceptionC.REMOTE_ERROR, "", ex);
                }
            }
            store(ex);

            // Alle Streams schließen. Sie werden nicht gesendet.
            if (streams != null)
            {
                foreach (BContentStream bstream in streams)
                {
                    try
                    {
                        bstream.Close();
                    }
                    catch (Exception) { }
                }
                streams = null;
            }
        }
示例#5
0
        public override Object read(Object obj, BInput bin1, long version)
        {
		    BInputBin bin = ((BInputBin)bin1);
		    int code = bin.bbuf.getInt();
		    String msg = bin.bbuf.getString();
		    String details = bin.bbuf.getString();
		    BException e = new BException(code, msg, details);
		    return e;
	    }
示例#6
0
        public override void write(Object obj, BOutput bout1, long version)
        {
            BOutputBin bout = ((BOutputBin)bout1);
            BException e    = (BException)obj;

            bout.bbuf.putInt(e.Code);
            bout.bbuf.putString(e.Message);
            bout.bbuf.putString(e.Details);
        }
示例#7
0
        public override Object read(Object obj, BInput bin1, long version)
        {
            BInputBin  bin     = ((BInputBin)bin1);
            int        code    = bin.bbuf.getInt();
            String     msg     = bin.bbuf.getString();
            String     details = bin.bbuf.getString();
            BException e       = new BException(code, msg, details);

            return(e);
        }
		public virtual async void ReadAllText(String path, BAsyncResult<String> asyncResult) {
			String __byps__ret = default(String);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				__byps__ret = ReadAllText(path);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				__byps__ret = await ReadAllTextAsync(path);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
示例#9
0
		public virtual async void IncrementInt(int a, BAsyncResult<int> asyncResult) {
			int __byps__ret = default(int);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				__byps__ret = IncrementInt(a);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				__byps__ret = await IncrementIntAsync(a);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
示例#10
0
		public virtual async void GetStreams(int ctrl, BAsyncResult<IList<System.IO.Stream>> asyncResult) {
			IList<System.IO.Stream> __byps__ret = default(IList<System.IO.Stream>);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				__byps__ret = GetStreams(ctrl);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				__byps__ret = await GetStreamsAsync(ctrl);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
		public virtual async void FindFiles(String path, FindOptions findOptions, BAsyncResult<IList<FileInfo>> asyncResult) {
			IList<FileInfo> __byps__ret = default(IList<FileInfo>);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				__byps__ret = FindFiles(path, findOptions);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				__byps__ret = await FindFilesAsync(path, findOptions);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
示例#12
0
		public virtual async void PutStreams(IList<System.IO.Stream> strm, int ctrl, BAsyncResult<Object> asyncResult) {
			Object __byps__ret = default(Object);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				PutStreams(strm, ctrl);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				await PutStreamsAsync(strm, ctrl);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
		public virtual async void Notify(NotifyInfo notifyInfo, BAsyncResult<Object> asyncResult) {
			Object __byps__ret = default(Object);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				Notify(notifyInfo);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				await NotifyAsync(notifyInfo);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
示例#14
0
        public bool isReloginException(Exception ex, int typeId)
        {
            if (log.isDebugEnabled())
            {
                log.debug("isReloginException(ex=" + ex + ", typeId=" + typeId);
            }
            bool ret = false;

            // Check exception
            if (ex is BException)
            {
                BException bex = (BException)ex;
                ret = (bex.Code == BExceptionC.UNAUTHORIZED);
            }

            if (log.isDebugEnabled())
            {
                log.debug(")isReloginException=" + ret);
            }
            return(ret);
        }
示例#15
0
        public virtual void recv(BTargetId clientTargetId, Object methodObj, BAsyncResultIF<Object> methodResult)
        {
		
		    try {
                BMethodRequest method = (BMethodRequest)methodObj;

                BRemote remote = null;
			    int remoteId = method.getRemoteId();
			    BTargetId serverTargetId = this.transport.getTargetId();
			
			    // Die Target-ID aus dem Header ist gleich der Target-ID des BServer-Objekts
			    // für einen normalen Client-Server-Request
			    if (clientTargetId.Equals(serverTargetId)) {
				    remotes.TryGetValue(remoteId, out remote);
			    }
			    else {
				
				    // Es wird eine andere Target-ID angesteuert.
				    // Ermittle hier die BRemote-Schnittstelle dieser Target-ID.
				    // Sie kommt möglicherweise von einem anderen Client.
				
				    remote = this.transport.getRemoteRegistry().getRemote(serverTargetId, clientTargetId, remoteId);
			    }
			
                if (remote != null)
                {
                    method.execute(remote, methodResult);
                }
                else
                {
                    BException ex = new BException(BExceptionC.SERVICE_NOT_IMPLEMENTED,
                        "Service not implemented: remoteId=" + remoteId);
                    methodResult.setAsyncResult(null, ex);
			    }
		    }
		    catch (Exception e) {
                methodResult.setAsyncResult(null, e);
		    }
		
	    }
示例#16
0
            public void setAsyncResult(BMessage obj, Exception e)
            {
                try {
                    if (e == null)
                    {
                        // Methode ausführen
                        pthis.transport.recv(pthis.server, obj, asyncResult);
                    }
                    else
                    {
                        BException ex = (BException)e;
                        switch (ex.Code)
                        {
                        case BExceptionC.SESSION_CLOSED:   // Session was invalidated.
                        case BExceptionC.UNAUTHORIZED:     // Re-login required
                        case BExceptionC.CANCELLED:
                            // no retry
                            break;

                        case BExceptionC.RESEND_LONG_POLL    /* USE THIS FILE ACCORDING TO THE COPYRIGHT RULES IN LICENSE.TXT WHICH IS PART OF THE SOURCE CODE PACKAGE */
                            :
                            // HWireClientR has released the expried long-poll.
                            // Ignore the error and send a new long-poll.
                            pthis.sendLongPoll(null);
                            break;

                        default:
                            // retry after pause
                            if (pthis.waitBeforeRetry())
                            {     // e.g. Socket error
                                pthis.sendLongPoll(null);
                            }
                            break;
                        }
                    }
                } catch (Exception e2) {
                    asyncResult.setAsyncResult(null, e2);
                }
            }
示例#17
0
        public virtual void recv(BTargetId clientTargetId, Object methodObj, BAsyncResultIF <Object> methodResult)
        {
            try {
                BMethodRequest method = (BMethodRequest)methodObj;

                BRemote   remote         = null;
                int       remoteId       = method.getRemoteId();
                BTargetId serverTargetId = this.transport.getTargetId();

                // Die Target-ID aus dem Header ist gleich der Target-ID des BServer-Objekts
                // für einen normalen Client-Server-Request
                if (clientTargetId.Equals(serverTargetId))
                {
                    remotes.TryGetValue(remoteId, out remote);
                }
                else
                {
                    // Es wird eine andere Target-ID angesteuert.
                    // Ermittle hier die BRemote-Schnittstelle dieser Target-ID.
                    // Sie kommt möglicherweise von einem anderen Client.

                    remote = this.transport.getRemoteRegistry().getRemote(serverTargetId, clientTargetId, remoteId);
                }

                if (remote != null)
                {
                    method.execute(remote, methodResult);
                }
                else
                {
                    BException ex = new BException(BExceptionC.SERVICE_NOT_IMPLEMENTED,
                                                   "Service not implemented: remoteId=" + remoteId);
                    methodResult.setAsyncResult(null, ex);
                }
            }
            catch (Exception e) {
                methodResult.setAsyncResult(null, e);
            }
        }
		public virtual async void WriteAllText(String path, String text, BAsyncResult<Object> asyncResult) {
			Object __byps__ret = default(Object);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				WriteAllText(path, text);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				await WriteAllTextAsync(path, text);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
示例#19
0
        public void negotiateProtocolClient(BAsyncResultIF <Boolean> asyncResult)
        {
            if (log.isDebugEnabled())
            {
                log.debug("negotiateProtocolClient(");
            }
            if (log.isDebugEnabled())
            {
                log.debug("negotiateActive=" + negotiateActive);
            }

            // Check that we do not run into recursive authentication requests.
            lock (asyncResultsWaitingForAuthentication)
            {
                // Already have an active negotiation request?
                if (negotiateActive)
                {
                    // Are there threads waiting?
                    if (asyncResultsWaitingForAuthentication.Count != 0)
                    {
                        // Most likely slow or recursive authentication
                        BException ex = new BException(BExceptionC.FORBIDDEN,
                                                       "Authentication procedure failed. Server returned 401 for every request. "
                                                       + "A common reason for this error is slow authentication handling.");
                        // ... or calling a function that requires authentication in BAuthentication.authenticate() - see. TestRemoteWithAuthentication.testAuthenticateBlocksRecursion
                        asyncResult.setAsyncResult(false, ex);
                        return;
                    }
                    else
                    {
                        // Correction: if no threads are waiting then there cannot be an aktive negotiation request.
                        negotiateActive = true;
                    }
                }
                else
                {
                    // Now, this is the active negotiation request.
                    negotiateActive = true;
                }
            }


            ByteBuffer buf  = ByteBuffer.allocate(BNegotiate.NEGOTIATE_MAX_SIZE);
            BNegotiate nego = new BNegotiate(apiDesc);

            nego.write(buf);
            buf.flip();

            BAsyncResultIF <BMessage> outerResult = new MyNegoAsyncResult(this, asyncResult);

            if (log.isDebugEnabled())
            {
                log.debug("wire.send");
            }
            BMessageHeader header = new BMessageHeader();

            header.messageId = wire.makeMessageId();
            BMessage msg = new BMessage(header, buf, null);

            wire.send(msg, outerResult);
            if (log.isDebugEnabled())
            {
                log.debug(")negotiateProtocolClient");
            }
        }
		public virtual async void ExecuteNotifyExit(String[] args, ExecuteOptions opts, BAsyncResult<Object> asyncResult) {
			Object __byps__ret = default(Object);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				ExecuteNotifyExit(args, opts);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				await ExecuteNotifyExitAsync(args, opts);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
示例#21
0
        protected void getResponseCallback(IAsyncResult asynchronousResult)
        {
            RequestToCancel requestToCancel = (RequestToCancel)asynchronousResult.AsyncState;

            if (log.isDebugEnabled())
            {
                log.debug("getResponseCallback(" + requestToCancel);
            }
            HttpWebResponse response        = null;
            ByteBuffer      returnBuffer    = null;
            Exception       returnException = null;
            HttpWebRequest  conn            = requestToCancel.getConnection();

            try
            {
                response = (HttpWebResponse)conn.EndGetResponse(asynchronousResult);
                if (log.isDebugEnabled())
                {
                    log.debug("status=" + response.StatusCode);
                }
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    requestToCancel.setAsyncResult(null, new BException(BExceptionC.IOERROR, "HTTP Status " + response.StatusCode));
                }
                else
                {
                    saveSession(conn);

                    if (log.isDebugEnabled())
                    {
                        log.debug("bufferFromStream");
                    }

                    Stream responseStream = response.GetResponseStream();
                    returnBuffer = bufferFromStream(responseStream, false);
                }
            }
            catch (WebException e)
            {
                BException bex = null;
                if (_cancelAllRequests)
                {
                    bex = new BException(BExceptionC.CANCELLED, "");
                }
                else
                {
                    if (e.Response != null)
                    {
                        int code = Convert.ToInt32(((HttpWebResponse)e.Response).StatusCode);
                        bex = new BException(code, "HTTP Status " + code);
                    }
                    else
                    {
                        int code = Convert.ToInt32(HttpStatusCode.BadRequest);
                        bex = new BException(code, e.ToString());
                    }
                }
                returnException = bex;
            }
            catch (Exception e)
            {
                if (log.isDebugEnabled())
                {
                    log.debug("Exception", e);
                }
                returnException = new BException(BExceptionC.IOERROR, e.Message, e);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }

                removeRequest(requestToCancel, returnBuffer, returnException);
            }

            if (log.isDebugEnabled())
            {
                log.debug(")getResponseCallback");
            }
        }
		public virtual async void BeginWatchFolder(String dir, bool recursive, String extraInfo, BAsyncResult<int> asyncResult) {
			int __byps__ret = default(int);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				__byps__ret = BeginWatchFolder(dir, recursive, extraInfo);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				__byps__ret = await BeginWatchFolderAsync(dir, recursive, extraInfo);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
示例#23
0
		public virtual async void SendChat(ChatStructure cs, BAsyncResult<ChatStructure> asyncResult) {
			ChatStructure __byps__ret = default(ChatStructure);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				__byps__ret = SendChat(cs);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				__byps__ret = await SendChatAsync(cs);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
		public virtual async void EndWatchFolder(int handle, BAsyncResult<Object> asyncResult) {
			Object __byps__ret = default(Object);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				EndWatchFolder(handle);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				await EndWatchFolderAsync(handle);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
		public virtual async void UploadFilesMultipartFormdata(FormItem[] items, String url, String method, BAsyncResult<Object> asyncResult) {
			Object __byps__ret = default(Object);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				UploadFilesMultipartFormdata(items, url, method);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				await UploadFilesMultipartFormdataAsync(items, url, method);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}
		public virtual async void UploadFile(String path, String url, BAsyncResult<Object> asyncResult) {
			Object __byps__ret = default(Object);
			Exception __byps__ex = null;
			bool __byps__callAsync = false;
			try {
				UploadFile(path, url);
			}
			catch (NotImplementedException) { __byps__callAsync = true; }
			catch (Exception e) { __byps__ex = e; }
			if (__byps__callAsync) try {
				await UploadFileAsync(path, url);
			}
			catch (NotImplementedException) { __byps__ex = new BException(BExceptionC.UNSUPPORTED_METHOD, ""); }
			catch (Exception e) { __byps__ex = e; }
			asyncResult(__byps__ret, __byps__ex);
		}