public StringBuilder ExecuteCommand(StringBuilder payload, Guid workspaceId)
        {
            if (payload == null || payload.Length == 0)
            {
                throw new ArgumentNullException("payload");
            }

            Dev2Logger.Log.Debug("Execute Command Payload [ " + payload + " ]");

            // build up payload
            var messageId = Guid.NewGuid();
            var envelope  = new Envelope
            {
                PartID  = 0,
                Type    = typeof(Envelope),
                Content = payload.ToString()
            };

            var            result = new StringBuilder();
            Task <Receipt> invoke = EsbProxy.Invoke <Receipt>("ExecuteCommand", envelope, true, workspaceId, Guid.Empty, messageId);

            Wait(invoke, result);
            if (invoke.IsFaulted)
            {
                var popupController = CustomContainer.Get <IPopupController>();
                if (popupController != null)
                {
                    popupController.Show("Error connecting to server. Please check your network connection.", "Error connecting", MessageBoxButton.OK, MessageBoxImage.Information, null);
                }
                return(result);
            }
            Task <string> fragmentInvoke = EsbProxy.Invoke <string>("FetchExecutePayloadFragment", new FutureReceipt {
                PartID = 0, RequestID = messageId
            });

            Wait(fragmentInvoke, result);
            if (!fragmentInvoke.IsFaulted && fragmentInvoke.Result != null)
            {
                result.Append(fragmentInvoke.Result);
            }

            // prune any result for old datalist junk ;)
            if (result.Length > 0)
            {
                // Only return Dev2System.ManagmentServicePayload if present ;)
                var start = result.LastIndexOf("<" + GlobalConstants.ManagementServicePayload + ">", false);
                if (start > 0)
                {
                    var end = result.LastIndexOf("</" + GlobalConstants.ManagementServicePayload + ">", false);
                    if (start < end && (end - start) > 1)
                    {
                        // we can return the trimmed payload instead
                        start += (GlobalConstants.ManagementServicePayload.Length + 2);
                        return(new StringBuilder(result.Substring(start, (end - start))));
                    }
                }
            }

            return(result);
        }
 public void FetchResourcesAffectedMemo(Guid resourceId)
 {
     if (ReceivedResourceAffectedMessage != null)
     {
         var result = Task.Run(async() => await EsbProxy.Invoke <string>("FetchResourcesAffectedMemo", resourceId).ConfigureAwait(true)).GetAwaiter().GetResult();
         if (!string.IsNullOrWhiteSpace(result))
         {
             FetchResourcesAffectedMemo(result);
         }
     }
 }
        public async Task <StringBuilder> ExecuteCommandAsync(StringBuilder payload, Guid workspaceId)
        {
            if (payload == null || payload.Length == 0)
            {
                throw new ArgumentNullException("payload");
            }

            Dev2Logger.Log.Debug("Execute Command Payload [ " + payload + " ]");

            // build up payload
            var messageId = Guid.NewGuid();
            var envelope  = new Envelope
            {
                PartID  = 0,
                Type    = typeof(Envelope),
                Content = payload.ToString()
            };

            var result = new StringBuilder();

            try
            {
                await EsbProxy.Invoke <Receipt>("ExecuteCommand", envelope, true, workspaceId, Guid.Empty, messageId);
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error(e);
            }
            var fragmentInvoke = await EsbProxy.Invoke <string>("FetchExecutePayloadFragment", new FutureReceipt { PartID = 0, RequestID = messageId }).ConfigureAwait(false);

            result.Append(fragmentInvoke);

            // prune any result for old datalist junk ;)
            if (result.Length > 0)
            {
                // Only return Dev2System.ManagmentServicePayload if present ;)
                var start = result.LastIndexOf("<" + GlobalConstants.ManagementServicePayload + ">", false);
                if (start > 0)
                {
                    var end = result.LastIndexOf("</" + GlobalConstants.ManagementServicePayload + ">", false);
                    if (start < end && (end - start) > 1)
                    {
                        // we can return the trimmed payload instead
                        start += (GlobalConstants.ManagementServicePayload.Length + 2);
                        return(new StringBuilder(result.Substring(start, (end - start))));
                    }
                }
            }

            return(result);
        }
 public void FetchResourcesAffectedMemo(Guid resourceId)
 {
     if (ReceivedResourceAffectedMessage != null)
     {
         var result = Task.Run(async() => await EsbProxy.Invoke <string>("FetchResourcesAffectedMemo", resourceId)).ConfigureAwait(false).GetAwaiter().GetResult();
         if (!string.IsNullOrWhiteSpace(result))
         {
             var obj = _serializer.Deserialize <CompileMessageList>(result);
             if (obj != null)
             {
                 ReceivedResourceAffectedMessage.Invoke(obj.ServiceID, obj);
             }
         }
     }
 }
 private void InitializeEsbProxy()
 {
     if (EsbProxy == null)
     {
         EsbProxy = HubConnection.CreateHubProxy("esb");
         EsbProxy.On <string>("SendMemo", OnMemoReceived);
         EsbProxy.On <string>("SendPermissionsMemo", OnPermissionsMemoReceived);
         EsbProxy.On <string>("SendDebugState", OnDebugStateReceived);
         EsbProxy.On <Guid>("SendWorkspaceID", OnWorkspaceIdReceived);
         EsbProxy.On <Guid>("SendServerID", OnServerIdReceived);
         EsbProxy.On <string>("ItemUpdatedMessage", OnItemUpdatedMessageReceived);
         EsbProxy.On <string>("ItemDeletedMessage", OnItemDeletedMessageReceived);
         EsbProxy.On <string>("ItemAddedMessage", OnItemAddedMessageReceived);
     }
 }
        public async Task <StringBuilder> ExecuteCommandAsync(StringBuilder payload, Guid workspaceId)
        {
            if (payload == null || payload.Length == 0)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            Dev2Logger.Debug("Execute Command Payload [ " + payload + " ]");

            var messageId = Guid.NewGuid();
            var envelope  = new Envelope
            {
                PartID  = 0,
                Type    = typeof(Envelope),
                Content = payload.ToString()
            };

            var result = new StringBuilder();

            try
            {
                await EsbProxy.Invoke <Receipt>("ExecuteCommand", envelope, true, workspaceId, Guid.Empty, messageId);

                var fragmentInvoke = await EsbProxy.Invoke <string>("FetchExecutePayloadFragment", new FutureReceipt { PartID = 0, RequestID = messageId }).ConfigureAwait(false);

                result.Append(fragmentInvoke);

                if (result.Length > 0)
                {
                    var start = result.LastIndexOf("<" + GlobalConstants.ManagementServicePayload + ">", false);
                    if (start > 0)
                    {
                        var end = result.LastIndexOf("</" + GlobalConstants.ManagementServicePayload + ">", false);
                        if (start < end && end - start > 1)
                        {
                            start += GlobalConstants.ManagementServicePayload.Length + 2;
                            return(new StringBuilder(result.Substring(start, end - start)));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Error(e);
            }
            return(result);
        }
Exemple #7
0
        public void AddDebugWriter(Guid workspaceId)
        {
            var t = EsbProxy.Invoke("AddDebugWriter", workspaceId);

            Wait(t);
        }
        public Task <StringBuilder> ExecuteCommandAsync(StringBuilder payload, Guid workspaceId)
        {
            if (payload == null || payload.Length == 0)
            {
                throw new ArgumentNullException("payload");
            }

            Dev2Logger.Log.Debug("Execute Command Payload [ " + payload + " ]");

            // build up payload
            var length   = payload.Length;
            var startIdx = 0;
            var rounds   = (int)Math.Ceiling(length / GlobalConstants.MAX_SIZE_FOR_STRING);

            var             messageId  = Guid.NewGuid();
            List <Envelope> mailToSend = new List <Envelope>();

            for (int i = 0; i < rounds; i++)
            {
                var envelope = new Envelope {
                    PartID = i, Type = typeof(Envelope)
                };

                var len = (int)GlobalConstants.MAX_SIZE_FOR_STRING;
                if (len > (payload.Length - startIdx))
                {
                    len = (payload.Length - startIdx);
                }

                envelope.Content = payload.Substring(startIdx, len);
                startIdx        += len;

                mailToSend.Add(envelope);
            }

            // Send and receive chunks from the server ;)
            var result = new StringBuilder();

            for (int i = 0; i < mailToSend.Count; i++)
            {
                bool           isEnd  = (i + 1 == mailToSend.Count);
                Task <Receipt> invoke = EsbProxy.Invoke <Receipt>("ExecuteCommand", mailToSend[i], isEnd, workspaceId, Guid.Empty, messageId);
                Wait(invoke, result);
                if (invoke.IsFaulted)
                {
                    break;
                }
                // now build up the result in fragments ;)
                if (isEnd)
                {
                    var totalToFetch = invoke.Result.ResultParts;
                    for (int q = 0; q < totalToFetch; q++)
                    {
                        Task <string> fragmentInvoke = EsbProxy.Invoke <string>("FetchExecutePayloadFragment", new FutureReceipt {
                            PartID = q, RequestID = messageId
                        });
                        Wait(fragmentInvoke, result);
                        if (!fragmentInvoke.IsFaulted && fragmentInvoke.Result != null)
                        {
                            result.Append(fragmentInvoke.Result);
                        }
                    }
                }
            }

            // prune any result for old datalist junk ;)
            if (result.Length > 0)
            {
                // Only return Dev2System.ManagmentServicePayload if present ;)
                var start = result.LastIndexOf("<" + GlobalConstants.ManagementServicePayload + ">", false);
                if (start > 0)
                {
                    var end = result.LastIndexOf("</" + GlobalConstants.ManagementServicePayload + ">", false);
                    if (start < end && (end - start) > 1)
                    {
                        // we can return the trimmed payload instead
                        start += (GlobalConstants.ManagementServicePayload.Length + 2);
                        return(Task.FromResult(new StringBuilder(result.Substring(start, (end - start)))));
                    }
                }
            }

            return(Task.FromResult(result));
        }