コード例 #1
0
        public static BackendResponse GetBackendResponse(string responseContent)
        {
            BackendResponse backendResponse = null;

            try
            {
                if (!string.IsNullOrEmpty(responseContent))
                {
                    using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(responseContent)))
                    {
                        backendResponse = Serializer.ReadObject(ms) as BackendResponse;
                    }
                }
            }
            catch (ArgumentException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }
            catch (InvalidOperationException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }
            catch (SerializationException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }

            return(backendResponse);
        }
コード例 #2
0
            public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                byte[] buffer = new byte[] {};
                UUID   ownerID;

                // Split the URL up to get the asset ID out
                string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');

                if (rawUrl.Length >= 3 && rawUrl[2].Length >= 36 && UUID.TryParse(rawUrl[2].Substring(0, 36), out ownerID))
                {
                    Uri owner = Utils.GetOpenSimUri(ownerID);
                    InventoryCollection inventory;
                    BackendResponse     storageResponse = m_server.InventoryProvider.TryFetchInventory(owner, out inventory);

                    if (storageResponse == BackendResponse.Success)
                    {
                        m_log.DebugFormat("[INVENTORYARCHIVE]: Archiving inventory for user UUID {0}", ownerID);
                        buffer = ArchiveInventoryCollection(inventory);
                        httpResponse.StatusCode = (int)HttpStatusCode.OK;
                    }
                    else
                    {
                        httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
                    }
                }
                else
                {
                    m_log.Warn("[INVENTORYARCHIVE]: Unrecognized inventory archive request: " + httpRequest.Url.PathAndQuery);
                }

                return(buffer);
            }
コード例 #3
0
            public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                UUID agentID, sessionID;
                InventoryFolderWithChildren folder = DeserializeFolder(httpRequest.InputStream, out agentID, out sessionID);

                if (folder != null)
                {
                    Uri owner = Utils.GetOpenSimUri(folder.Owner);

                    // Some calls that are moving or updating a folder instead
                    // of creating a new one will pass in an InventoryFolder
                    // without the name set and type set to 0. If this is the
                    // case we need to look up the name first and preserver
                    // it's type.
                    if (String.IsNullOrEmpty(folder.Name))
                    {
                        InventoryFolderWithChildren oldFolder;
                        if (m_server.InventoryProvider.TryFetchFolder(owner, folder.ID, out oldFolder) == BackendResponse.Success)
                        {
                            folder.Name = oldFolder.Name;
                            folder.Type = oldFolder.Type;
                        }
                    }

                    BackendResponse storageResponse = m_server.InventoryProvider.TryCreateFolder(owner, folder);

                    if (storageResponse == BackendResponse.Success)
                    {
                        return SerializeBool(true);
                    }
                }

                return SerializeBool(false);
            }
コード例 #4
0
        public async Task <BackendResponse <AccountChargeManuallyResponse> > ChargeManually([FromBody] AccountChargeManuallyRequest request)
        {
            if (string.IsNullOrEmpty(request?.Reason?.Trim()))
            {
                return(BackendResponse <AccountChargeManuallyResponse> .Error("Reason must be set."));
            }

            var account = _accountsCacheService.Get(request.ClientId, request.AccountId);

            try
            {
                var transactionId = await _accountManager.UpdateBalanceAsync(account, request.Amount,
                                                                             AccountHistoryType.Manual, request.Reason, auditLog : request.ToJson());

                _operationsLogService.AddLog("account charge manually", request.ClientId, request.AccountId,
                                             request.ToJson(), true.ToJson());

                return(BackendResponse <AccountChargeManuallyResponse> .Ok(
                           new AccountChargeManuallyResponse { TransactionId = transactionId }));
            }
            catch (Exception e)
            {
                await _log.WriteErrorAsync(nameof(AccountsBalanceController), "ChargeManually", request?.ToJson(), e);

                return(BackendResponse <AccountChargeManuallyResponse> .Error(e.Message));
            }
        }
コード例 #5
0
        public async Task <BackendResponse <AccountDepositWithdrawResponse> > AccountWithdraw([FromBody] AccountDepositWithdrawRequest request)
        {
            var account    = _accountsCacheService.Get(request.ClientId, request.AccountId);
            var freeMargin = account.GetFreeMargin();

            if (freeMargin < Math.Abs(request.Amount))
            {
                return(BackendResponse <AccountDepositWithdrawResponse> .Error(
                           "Requested withdrawal amount is less than free margin"));
            }

            var changeTransferLimit = _marginSettings.IsLive &&
                                      request.PaymentType == PaymentType.Transfer &&
                                      !IsCrypto(account.BaseAssetId);

            try
            {
                var transactionId = await _accountManager.UpdateBalanceAsync(account, -Math.Abs(request.Amount),
                                                                             AccountHistoryType.Withdraw, "Account withdraw", null, changeTransferLimit);

                _operationsLogService.AddLog($"account withdraw {request.PaymentType}", request.ClientId, request.AccountId, request.ToJson(), true.ToJson());

                return(BackendResponse <AccountDepositWithdrawResponse> .Ok(
                           new AccountDepositWithdrawResponse { TransactionId = transactionId }));
            }
            catch (Exception e)
            {
                await _log.WriteErrorAsync(nameof(AccountsBalanceController), "AccountWithdraw", request?.ToJson(), e);

                return(BackendResponse <AccountDepositWithdrawResponse> .Error(e.Message));
            }
        }
コード例 #6
0
        public BackendResponse SendRequest(string data, string uri, string method)
        {
            BackendResponse result  = new BackendResponse();
            HttpWebRequest  request = WebRequest.CreateHttp(String.Format("{0}{1}", baseUrl, uri));

            request.ContentType = "application/json";
            request.Method      = method;

            if (method == "POST")
            {
                using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                {
                    streamWriter.Write(data);
                }
            }

            try
            {
                result = HandleResponse(request.GetResponse());
            }
            catch (WebException ex)
            {
                result.ErrorMessage = ex.Message;
                result.Status       = (int)((HttpWebResponse)ex.Response).StatusCode;
            }

            return(result);
        }
コード例 #7
0
            public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                UUID ownerID = DeserializeUUID(httpRequest.InputStream);

                if (ownerID != UUID.Zero)
                {
                    Uri owner = Utils.GetOpenSimUri(ownerID);
                    m_log.DebugFormat("[OPENSIMINVENTORYFRONTEND]: Created URI {0} for inventory creation", owner);

                    InventoryFolderWithChildren rootFolder = new InventoryFolderWithChildren("My Inventory", ownerID, UUID.Zero, (short)AssetType.Folder);
                    BackendResponse storageResponse = m_server.InventoryProvider.TryCreateInventory(owner, rootFolder);
                    if (storageResponse == BackendResponse.Success)
                    {
                        // TODO: The CreateFolder calls need to be executed in SimpleStorage.
                        //CreateFolder("Animations", ownerID, rootFolder.ID, AssetType.Animation);
                        //CreateFolder("Body Parts", ownerID, rootFolder.ID, AssetType.Bodypart);
                        //CreateFolder("Calling Cards", ownerID, rootFolder.ID, AssetType.CallingCard);
                        //CreateFolder("Clothing", ownerID, rootFolder.ID, AssetType.Clothing);
                        //CreateFolder("Gestures", ownerID, rootFolder.ID, AssetType.Gesture);
                        //CreateFolder("Landmarks", ownerID, rootFolder.ID, AssetType.Landmark);
                        //CreateFolder("Lost and Found", ownerID, rootFolder.ID, AssetType.LostAndFoundFolder);
                        //CreateFolder("Notecards", ownerID, rootFolder.ID, AssetType.Notecard);
                        //CreateFolder("Objects", ownerID, rootFolder.ID, AssetType.Object);
                        //CreateFolder("Photo Album", ownerID, rootFolder.ID, AssetType.SnapshotFolder);
                        //CreateFolder("Scripts", ownerID, rootFolder.ID, AssetType.LSLText);
                        //CreateFolder("Sounds", ownerID, rootFolder.ID, AssetType.Sound);
                        //CreateFolder("Textures", ownerID, rootFolder.ID, AssetType.Texture);
                        //CreateFolder("Trash", ownerID, rootFolder.ID, AssetType.TrashFolder);

                        return SerializeBool(true);
                    }
                }

                return SerializeBool(false);
            }
コード例 #8
0
 public BackendResponseResult(BackendResponse response)
 {
     _response   = response;
     Content     = response.Content;
     ContentType = response.ContentType;
     StatusCode  = (int)response.StatusCode;
 }
コード例 #9
0
 public BackendResponseResult(
     BackendResponse response,
     BackendResponseResultOptions options = default)
 {
     _response   = response;
     _options    = options ?? new BackendResponseResultOptions();
     Content     = response.Content;
     ContentType = response.ContentType;
     StatusCode  = (int)response.StatusCode;
 }
コード例 #10
0
            public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                byte[] buffer = new byte[] {};
                UUID sessionID, agentID;
                UUID ownerID = DeserializeUUID(httpRequest.InputStream, out agentID, out sessionID);

                if (ownerID != UUID.Zero)
                {
                    m_log.Warn("[OPENSIMINVENTORYFRONTEND]: GetInventory is not scalable on some inventory backends, avoid calling it wherever possible");

                    Uri owner = Utils.GetOpenSimUri(ownerID);
                    InventoryCollection inventory;
                    BackendResponse storageResponse = m_server.InventoryProvider.TryFetchInventory(owner, out inventory);

                    if (storageResponse == BackendResponse.Success)
                    {
                        //collectionSerializer.Serialize(httpResponse.Body, inventory);
                        //httpResponse.Body.Flush();
                        MemoryStream ms = new MemoryStream();
                        m_collectionSerializer.Serialize(ms, inventory);
                        ms.Seek(0, SeekOrigin.Begin);
                        buffer = ms.GetBuffer();
                        Array.Resize<byte>(ref buffer, (int) ms.Length);
                        ms.Close();
                        httpResponse.StatusCode = (int) HttpStatusCode.OK;
                    }
                    else if (storageResponse == BackendResponse.NotFound)
                    {
                        // Return an empty inventory set to mimic OpenSim.Grid.InventoryServer.exe
                        inventory = new InventoryCollection();
                        inventory.UserID = ownerID;
                        inventory.Folders = new Dictionary<UUID, InventoryFolderWithChildren>();
                        inventory.Items = new Dictionary<UUID, InventoryItemBase>();
                        //collectionSerializer.Serialize(httpResponse.Body, inventory);
                        //httpResponse.Body.Flush();
                        MemoryStream ms = new MemoryStream();
                        m_collectionSerializer.Serialize(ms, inventory);
                        ms.Seek(0, SeekOrigin.Begin);
                        buffer = ms.GetBuffer();
                        Array.Resize<byte>(ref buffer, (int) ms.Length);
                        ms.Close();
                        httpResponse.StatusCode = (int) HttpStatusCode.OK;
                    }
                    else
                    {
                        httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
                    }
                }
                else
                {
                    httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
                }

                return buffer;
            }
コード例 #11
0
    public static void DisconnectWithFacebook()
    {
        PlayerPrefs.SetString("facebookId", "");
        //FB.LogOut();
        DisconnectFromFacebookRequest request = new DisconnectFromFacebookRequest();
        BackendResponse response2             = new BackendResponse();

        Manager <BackendManager> .instance.SendRequest(request, response2, delegate
        {
        });
    }
コード例 #12
0
        public static BackendListResponseResult Create(
            BackendResponse response,
            IQueryCollection requestQuery,
            string nextPageUrlTemplate)
        {
            var nonPagedQueryCollection = new NonPagedQueryCollection(requestQuery);

            response.UpdateNextPageUrlWithQueryParameters(nonPagedQueryCollection, nextPageUrlTemplate);

            return(new BackendListResponseResult(response));
        }
コード例 #13
0
        private BackendResponse HandleResponse(WebResponse response)
        {
            BackendResponse result = new BackendResponse();

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                result.Data         = reader.ReadToEnd();
                result.Status       = (int)((HttpWebResponse)response).StatusCode;
                result.ErrorMessage = String.Empty;
            }

            return(result);
        }
コード例 #14
0
        public async Task <BackendResponse <AccountResetResponse> > AccountResetDemo([FromBody] AccounResetRequest request)
        {
            if (_marginSettings.IsLive)
            {
                return(BackendResponse <AccountResetResponse> .Error("Account reset is available only for DEMO accounts"));
            }

            var transactionId = await _accountManager.ResetAccountAsync(request.ClientId, request.AccountId);

            _operationsLogService.AddLog("account reset", request.ClientId, request.AccountId, request.ToJson(), true.ToJson());

            return(BackendResponse <AccountResetResponse> .Ok(
                       new AccountResetResponse { TransactionId = transactionId }));
        }
コード例 #15
0
        public BackendResponse <T> BuildBackendResponse <T>(string message, SOJStatusCodes statusCode, T content = null) where T : class
        {
            var backendResponse = new BackendResponse <T>
            {
                Content               = content,
                Message               = message,
                StatusCode            = SOJStatusCode.HttpStatusCodesToString(statusCode),
                IsSuccess             = SOJStatusCode.GetStatusCodeSuccess(statusCode),
                ResponseTime          = Helper.GetDateTimeNowBrazil(),
                StatusCodeDescription = SOJStatusCode.GetStatusCodeDescription(statusCode)
            };

            return(backendResponse);
        }
        public static BackendResponse GetBackendResponse(string responseContent)
        {
            BackendResponse backendResponse = null;

            try
            {
                if (!string.IsNullOrEmpty(responseContent))
                {
#if NETSTANDARD1_3
                    backendResponse = JsonConvert.DeserializeObject <BackendResponse>(responseContent);
#else
                    using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(responseContent)))
                    {
                        backendResponse = Serializer.ReadObject(ms) as BackendResponse;
                    }
#endif
                }
            }
            catch (ArgumentException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }
            catch (InvalidOperationException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }
            catch (SerializationException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }
#if NETSTANDARD1_3
            catch (JsonReaderException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }
            catch (JsonSerializationException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }
#endif
            return(backendResponse);
        }
コード例 #17
0
            public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                byte[] buffer = new byte[] {};
                UUID ownerID = DeserializeUUID(httpRequest.InputStream);

                if (ownerID != UUID.Zero)
                {
                    Uri owner = Utils.GetOpenSimUri(ownerID);
                    List<InventoryFolderWithChildren> skeleton;
                    BackendResponse storageResponse = m_server.InventoryProvider.TryFetchFolderList(owner, out skeleton);

                    if (storageResponse == BackendResponse.Success)
                    {
                        MemoryStream ms = new MemoryStream();
                        SerializeFolderList(ms, skeleton);
                        ms.Seek(0, SeekOrigin.Begin);
                        buffer = ms.GetBuffer();
                        Array.Resize<byte>(ref buffer, (int) ms.Length);
                        ms.Close();
                        httpResponse.StatusCode = (int) HttpStatusCode.OK;
                    }
                    else if (storageResponse == BackendResponse.NotFound)
                    {
                        // Return an empty set of inventory so the requester knows that
                        // an inventory needs to be created for this agent
                        MemoryStream ms = new MemoryStream();
                        SerializeFolderList(ms, new List<InventoryFolderWithChildren>(0));
                        ms.Seek(0, SeekOrigin.Begin);
                        buffer = ms.GetBuffer();
                        Array.Resize<byte>(ref buffer, (int) ms.Length);
                        ms.Close();
                        httpResponse.StatusCode = (int) HttpStatusCode.OK;
                    }
                    else
                    {
                        httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
                    }
                }
                else
                {
                    httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
                }

                return buffer;
            }
コード例 #18
0
            public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                UUID agentID, sessionID;
                InventoryFolderWithChildren folder = DeserializeFolder(httpRequest.InputStream, out agentID, out sessionID);

                if (folder != null)
                {
                    Uri owner = Utils.GetOpenSimUri(folder.Owner);
                    BackendResponse storageResponse = m_server.InventoryProvider.TryPurgeFolder(owner, folder.ID);

                    if (storageResponse == BackendResponse.Success)
                    {
                        return SerializeBool(true);
                    }
                }

                return SerializeBool(false);
            }
コード例 #19
0
            public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                UUID agentID, sessionID;
                InventoryItemBase item = DeserializeItem(httpRequest.InputStream, out agentID, out sessionID);

                if (item != null)
                {
                    Uri owner = Utils.GetOpenSimUri(item.Owner);
                    BackendResponse storageResponse = m_server.InventoryProvider.TryDeleteItem(owner, item.ID);

                    if (storageResponse == BackendResponse.Success)
                    {
                        return SerializeBool(true);
                    }
                }

                return SerializeBool(false);
            }
コード例 #20
0
            public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                byte[] buffer = new byte[] {};
                UUID ownerID = DeserializeUUID(httpRequest.InputStream);

                if (ownerID != UUID.Zero)
                {
                    Uri owner = Utils.GetOpenSimUri(ownerID);
                    List<InventoryItemBase> gestures;
                    BackendResponse storageResponse = m_server.InventoryProvider.TryFetchActiveGestures(owner, out gestures);

                    if (storageResponse == BackendResponse.Success)
                    {
                        MemoryStream ms = new MemoryStream();
                        SerializeItemList(ms, gestures);
                        ms.Seek(0, SeekOrigin.Begin);
                        buffer = ms.GetBuffer();
                        Array.Resize<byte>(ref buffer, (int) ms.Length);
                        ms.Close();
                        httpResponse.StatusCode = (int) HttpStatusCode.OK;
                    }
                    else if (storageResponse == BackendResponse.NotFound)
                    {
                        // Return an empty set of gestures to match OpenSim.Grid.InventoryServer.exe behavior
                        MemoryStream ms = new MemoryStream();
                        SerializeItemList(ms, new List<InventoryItemBase>(0));
                        ms.Seek(0, SeekOrigin.Begin);
                        buffer = ms.GetBuffer();
                        Array.Resize<byte>(ref buffer, (int) ms.Length);
                        ms.Close();
                        httpResponse.StatusCode = (int) HttpStatusCode.OK;
                    }
                    else
                    {
                        httpResponse.StatusCode = (int) HttpStatusCode.InternalServerError;
                    }
                }
                else
                {
                    httpResponse.StatusCode = (int) HttpStatusCode.BadRequest;
                }

                return buffer;
            }
コード例 #21
0
            public byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                byte[] assetData = null;
                UUID   assetID;

                // Split the URL up into an AssetID and a method
                string[] rawUrl = httpRequest.Url.PathAndQuery.Split('/');

                if (rawUrl.Length >= 3 && UUID.TryParse(rawUrl[1], out assetID))
                {
                    UUID authToken = Utils.GetAuthToken(httpRequest);

                    if (m_server.AuthorizationProvider.IsDataAuthorized(authToken, assetID))
                    {
                        BackendResponse storageResponse = m_server.StorageProvider.TryFetchData(assetID, out assetData);

                        if (storageResponse == BackendResponse.Success)
                        {
                            httpResponse.StatusCode  = (int)HttpStatusCode.OK;
                            httpResponse.ContentType = "application/octet-stream";
                            httpResponse.AddHeader("Content-Disposition", "attachment; filename=" + assetID.ToString());
                            httpResponse.ContentLength = assetData.Length;
                            httpResponse.Body.Write(assetData, 0, assetData.Length);
                        }
                        else if (storageResponse == BackendResponse.NotFound)
                        {
                            httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                        }
                        else
                        {
                            httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
                        }
                    }
                    else
                    {
                        httpResponse.StatusCode = (int)HttpStatusCode.Forbidden;
                    }

                    return(assetData);
                }

                httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                return(assetData);
            }
コード例 #22
0
            public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
            {
                AssetBase asset = null;

                try
                {
                    asset = (AssetBase) new XmlSerializer(typeof(AssetBase)).Deserialize(httpRequest.InputStream);
                }
                catch (Exception ex)
                {
                    m_log.Warn("[OPENSIMASSETFRONTEND]: Failed to parse POST data (expecting AssetBase): " + ex.Message);
                    httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                }

                if (asset != null && asset.Data != null && asset.Data.Length > 0)
                {
                    BackendResponse storageResponse = m_server.StorageProvider.TryCreateAsset(asset);

                    if (storageResponse == BackendResponse.Success)
                    {
                        httpResponse.StatusCode = (int)HttpStatusCode.Created;
                    }
                    else if (storageResponse == BackendResponse.NotFound)
                    {
                        httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
                    }
                    else
                    {
                        httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
                    }
                }
                else
                {
                    m_log.Warn("[OPENSIMASSETFRONTEND]: AssetPostHandler called with no asset data");
                    httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
                }

                return(new byte[] {});
            }
コード例 #23
0
        public async Task <BackendResponse <bool> > CloseOrder([FromBody] CloseOrderBackendRequest request)
        {
            if (!_ordersCache.ActiveOrders.TryGetOrderById(request.OrderId, out var order))
            {
                return(BackendResponse <bool> .Error("Order not found"));
            }

            if (_assetDayOffService.IsDayOff(order.Instrument))
            {
                return(BackendResponse <bool> .Error("Trades for instrument are not available"));
            }

            if (order.ClientId != request.ClientId || order.AccountId != request.AccountId)
            {
                return(BackendResponse <bool> .Error("Order is not available for user"));
            }

            if (request.IsForcedByBroker && string.IsNullOrEmpty(request.Comment))
            {
                return(BackendResponse <bool> .Error("For operation forced by broker, comment is mandatory"));
            }

            var reason = request.IsForcedByBroker ? OrderCloseReason.ClosedByBroker : OrderCloseReason.Close;

            order = await _tradingEngine.CloseActiveOrderAsync(request.OrderId, reason, request.Comment);

            var result = new BackendResponse <bool>
            {
                Result  = order.Status == OrderStatus.Closed || order.Status == OrderStatus.Closing,
                Message = order.CloseRejectReasonText
            };

            _consoleWriter.WriteLine(
                $"action order.close for clientId = {request.ClientId}, orderId = {request.OrderId}");
            _operationsLogService.AddLog("action order.close", request.ClientId, order.AccountId, request.ToJson(),
                                         result.ToJson());

            return(result);
        }
コード例 #24
0
        public async Task <BackendResponse <bool> > CancelOrder([FromBody] CloseOrderBackendRequest request)
        {
            if (!_ordersCache.WaitingForExecutionOrders.TryGetOrderById(request.OrderId, out var order))
            {
                return(BackendResponse <bool> .Error("Order not found"));
            }

            if (_assetDayOffService.IsDayOff(order.Instrument))
            {
                return(BackendResponse <bool> .Error("Trades for instrument are not available"));
            }

            if (order.ClientId != request.ClientId || order.AccountId != request.AccountId)
            {
                return(BackendResponse <bool> .Error("Order is not available for user"));
            }

            if (request.IsForcedByBroker && string.IsNullOrEmpty(request.Comment))
            {
                return(BackendResponse <bool> .Error("For operation forced by broker, comment is mandatory"));
            }

            var reason = request.IsForcedByBroker ? OrderCloseReason.CanceledByBroker : OrderCloseReason.Canceled;

            _tradingEngine.CancelPendingOrder(order.Id, reason, request.Comment);

            var result = new BackendResponse <bool> {
                Result = true
            };

            _consoleWriter.WriteLine(
                $"action order.cancel for clientId = {request.ClientId}, orderId = {request.OrderId}");
            _operationsLogService.AddLog("action order.cancel", request.ClientId, order.AccountId, request.ToJson(),
                                         result.ToJson());

            return(result);
        }
コード例 #25
0
        public BackendResponse GetBackendResponse(string responseContent)
        {
            BackendResponse backendResponse = null;

            try
            {
                if (!string.IsNullOrEmpty(responseContent))
                {
                    backendResponse = Serializer.Deserialize <BackendResponse>(responseContent);
                }
            }
            catch (ArgumentException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }
            catch (InvalidOperationException exp)
            {
                TelemetryChannelEventSource.Log.BreezeResponseWasNotParsedWarning(exp.Message, responseContent);
                backendResponse = null;
            }

            return(backendResponse);
        }
コード例 #26
0
        public Backend(ref SQLDatabase db, Netvision.Backend.Backend backend)
        {
            backendhub              = new BackendHub(ref db, this);
            backend.BackendRequest += (sender, e) =>
            {
                var evArgs = new BackendHubRequestEventArgs();
                evArgs.Context    = e.Context;
                evArgs.Action     = e.Action;
                evArgs.Target     = e.Target;
                evArgs.Parameters = e.Parameters;

                BackendHubRequest?.Invoke(this, evArgs);
            };

            backendhub.BackendHubResponse += (sender, e) =>
            {
                var evArgs = new BackendResponseEventArgs();
                evArgs.Context  = e.Context;
                evArgs.Response = e.Response;
                evArgs.Target   = e.Target;

                BackendResponse?.Invoke(this, evArgs);
            };
        }
コード例 #27
0
ファイル: NullMetricsPlugin.cs プロジェクト: boodie/Opensim2
 public void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryCreateInventory(): Response: {1}", extension,
                       response);
 }
コード例 #28
0
ファイル: NullMetricsPlugin.cs プロジェクト: ChrisD/opensim
 public void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryFetchFolderContents(): FolderID: {1}, OwnerID: {2}, Response: {3}", extension,
         folderID, owner, response);
 }
コード例 #29
0
ファイル: NullMetricsPlugin.cs プロジェクト: boodie/Opensim2
 public void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryFetchActiveGestures(): OwnerID: {1}, Response: {2}", extension,
                       owner, response);
 }
コード例 #30
0
ファイル: NullMetricsPlugin.cs プロジェクト: boodie/Opensim2
 public void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryCreate(): OwnerID: {1}, Response: {2}", extension,
                       owner, response);
 }
コード例 #31
0
ファイル: NullMetricsPlugin.cs プロジェクト: ChrisD/opensim
 public void LogInventoryCreateInventory(string extension, BackendResponse response, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryCreateInventory(): Response: {1}", extension,
         response);
 }
コード例 #32
0
ファイル: NullMetricsPlugin.cs プロジェクト: boodie/Opensim2
 public void LogInventoryFetchFolderContents(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryFetchFolderContents(): FolderID: {1}, OwnerID: {2}, Response: {3}", extension,
                       folderID, owner, response);
 }
コード例 #33
0
ファイル: NullMetricsPlugin.cs プロジェクト: ChrisD/opensim
 public void LogInventoryCreate(string extension, BackendResponse response, Uri owner, bool folder, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryCreate(): OwnerID: {1}, Response: {2}", extension,
         owner, response);
 }
コード例 #34
0
ファイル: NullMetricsPlugin.cs プロジェクト: ChrisD/opensim
 public void LogInventoryFetchActiveGestures(string extension, BackendResponse response, Uri owner, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryFetchActiveGestures(): OwnerID: {1}, Response: {2}", extension,
         owner, response);
 }
コード例 #35
0
 public RegistrationResponse(IEnumerable<ValidationResult> validationErrors = null, BackendResponse response = BackendResponse.Error)
 {
     ValidationErrors = validationErrors;
     BackendResponse = response;
 }
コード例 #36
0
ファイル: NullMetricsPlugin.cs プロジェクト: ChrisD/opensim
 public void LogInventoryFetch(string extension, BackendResponse response, Uri owner, UUID objID, bool folder, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryFetch(): ObjID: {1}, Folder: {2}, OwnerID: {3}, Response: {4}", extension,
         objID, folder, owner, response);
 }
コード例 #37
0
ファイル: NullMetricsPlugin.cs プロジェクト: ChrisD/opensim
 public void LogAssetCreate(string extension, BackendResponse response, UUID assetID, int dataSize, DateTime time)
 {
     m_log.DebugFormat("[{0}]: AssetCreate(): AssetID: {1}, DataSize: {2}, Response: {3}", extension, assetID,
         dataSize, response);
 }
コード例 #38
0
ファイル: NullMetricsPlugin.cs プロジェクト: ChrisD/opensim
 public void LogInventoryPurgeFolder(string extension, BackendResponse response, Uri owner, UUID folderID, DateTime time)
 {
     m_log.DebugFormat("[{0}]: InventoryPurgeFolder(): OwnerID: {1}, FolderID: {2}, Response: {3}", extension,
         owner, folderID, response);
 }
コード例 #39
0
ファイル: NullMetricsPlugin.cs プロジェクト: ChrisD/opensim
 public void LogAssetMetadataFetch(string extension, BackendResponse response, UUID assetID, DateTime time)
 {
     m_log.DebugFormat("[{0}]: AssetMetadataFetch(): AssetID: {1}, Response: {2}", extension, assetID, response);
 }