public static bool TryParse(string val, out InvokeStoredProcExeMessage msgOut)
 {
     msgOut = null;
     if (string.IsNullOrWhiteSpace(val))
         return false;
     try
     {
         if (val.Split(',').Length < 2)
             return false;
         msgOut = new InvokeStoredProcExeMessage();
         Enum.TryParse(val.Split(',')[0], true, out msgOut.State);
         msgOut.StoredProcName = val.Split(',')[1];
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemple #2
0
 public static bool TryParse(string val, out InvokeStoredProcExeMessage msgOut)
 {
     msgOut = null;
     if (string.IsNullOrWhiteSpace(val))
     {
         return(false);
     }
     try
     {
         if (val.Split(',').Length < 2)
         {
             return(false);
         }
         msgOut = new InvokeStoredProcExeMessage();
         Enum.TryParse(val.Split(',')[0], true, out msgOut.State);
         msgOut.StoredProcName = val.Split(',')[1];
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #3
0
        /// <summary>
        /// This function is intended to be invoked async in that the invoking thread
        /// will not return but continue to listen on a socket.
        /// This communication channel is the means of sending info from the autonomous
        /// NoFuture.Hbm.InvokeStoredProc.exe to this manager.
        /// </summary>
        internal void BeginReceiveMsgFromProcess()
        {
            using (
                var processListeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP))
            {
                processListeningSocket.Bind(new IPEndPoint(IPAddress.Loopback, DefaultPort));
                processListeningSocket.Listen(5);

                for (; ;)
                {
                    try
                    {
                        var received = new List <byte>();
                        var client   = processListeningSocket.Accept();

                        var bytesReceived = 0;
                        while (client.Available > 0)
                        {
                            byte[] bytes;
                            if (client.Available < NfConfig.DefaultBlockSize)
                            {
                                bytes          = new byte[client.Available];
                                bytesReceived += client.Receive(bytes, 0, client.Available, 0);
                            }
                            else
                            {
                                bytes          = new byte[NfConfig.DefaultBlockSize];
                                bytesReceived += client.Receive(bytes, 0, (int)NfConfig.DefaultBlockSize, 0);
                            }

                            received.AddRange(bytes);
                        }
                        InvokeStoredProcExeMessage processMsg;
                        var messageStr = Encoding.UTF8.GetString(received.ToArray());
                        Settings.WriteToStoredProcLog(string.Format("Received from process '{0}'", messageStr));
                        if (InvokeStoredProcExeMessage.TryParse(messageStr, out processMsg))
                        {
                            switch (processMsg.State)
                            {
                            case InvokeStoredProcExeState.BadSyntax:
                                if (!Sorting.BadSyntaxProx.Contains(processMsg.StoredProcName))
                                {
                                    Sorting.BadSyntaxProx.Add(processMsg.StoredProcName);
                                }
                                break;

                            case InvokeStoredProcExeState.MultiTableDs:
                                if (!Sorting.MultiTableDsProx.Contains(processMsg.StoredProcName))
                                {
                                    Sorting.MultiTableDsProx.Add(processMsg.StoredProcName);
                                }
                                break;

                            case InvokeStoredProcExeState.TimedOut:
                                if (!Sorting.TimedOutProx.Contains(processMsg.StoredProcName))
                                {
                                    Sorting.TimedOutProx.Add(processMsg.StoredProcName);
                                }
                                break;

                            case InvokeStoredProcExeState.NoDsReturned:
                                if (!Sorting.NoDatasetReturnedProx.Contains(processMsg.StoredProcName))
                                {
                                    Sorting.NoDatasetReturnedProx.Add(processMsg.StoredProcName);
                                }
                                break;

                            case InvokeStoredProcExeState.OtherError:
                                if (!Sorting.UnknownErrorProx.Contains(processMsg.StoredProcName))
                                {
                                    Sorting.UnknownErrorProx.Add(processMsg.StoredProcName);
                                }
                                break;
                            }
                        }

                        client.Close();
                    }
                    catch (Exception ex)
                    {
                        Settings.WriteToStoredProcLog(ex, string.Format("Socket error while listening for external NoFuture.Hbm.InvokeStoredProc.exe on port '{0}'.", DefaultPort));
                    }
                }
            }
        }