Пример #1
0
        public string ConnectorExecute(string cartName, string hookName, string publishingCartName, string connectionType, string inputArgs)
        {
            // TODO: this method is not fully implemented - its Linux counterpart has extra functionality
            Manifest cartridge = GetCartridge(cartName);

            bool envVarHook = (connectionType.StartsWith("ENV:") && !string.IsNullOrEmpty(publishingCartName));

            if (envVarHook)
            {
                SetConnectionHookEnvVars(cartName, publishingCartName, inputArgs);
            }

            PubSubConnector connector = new PubSubConnector(connectionType, hookName);

            if (connector.Reserved)
            {
                MethodInfo action = this.GetType().GetMethod(connector.ActioName);

                if (action != null)
                {
                    return(action.Invoke(this, new object[] { cartridge, inputArgs }).ToString());
                }
                else
                {
                    // TODO: log debug info
                }
            }

            string cartridgeHome = Path.Combine(this.container.ContainerDir, cartridge.Dir);
            string script        = Path.Combine(cartridgeHome, "hooks", string.Format("{0}.bat", connector.Name));

            if (!File.Exists(script))
            {
                if (envVarHook)
                {
                    return("Set environment variables successfully");
                }
                else
                {
                    throw new InvalidOperationException(string.Format("ERROR: action '{0}' not found", hookName));
                }
            }

            // TODO: vladi: add hourglass
            ProcessResult processResult = this.container.RunProcessInContainerContext(this.container.ContainerDir, string.Format("cd {0} ; {1} {2}", cartridgeHome, script, inputArgs));

            if (processResult.ExitCode == 0)
            {
                // TODO: vladi: add logging
                return(processResult.StdOut);
            }

            // TODO: vladi: add error logging
            throw new Exception(string.Format("Control action '{0}' returned an error. rc={1}\n{2}", connector, processResult.ExitCode, processResult.StdErr));
        }
Пример #2
0
        public static void ReadCallback(IAsyncResult ar)
        {
            String content = String.Empty;

            // Retrieve the state object and the handler socket
            // from the asynchronous state object.
            StateObject state   = (StateObject)ar.AsyncState;
            Socket      handler = state.workSocket;

            // Read data from the client socket.
            int bytesRead = handler.EndReceive(ar);

            if (bytesRead > 0)
            {
                // There  might be more data, so store the data received so far.
                state.sb.Append(Encoding.ASCII.GetString(
                                    state.buffer, 0, bytesRead));

                // Check for end-of-file tag. If it is not there, read
                // more data.
                content = state.sb.ToString();
                if (content.IndexOf("<EOF>") > -1)
                {
                    PubSubConnector.PublishToTopic(content);
                    // All the data has been read from the
                    // client. Display it on the console.
                    Console.WriteLine("Read {0} bytes from socket. \n Data : {1}",
                                      content.Length, content);
                    // Echo the data back to the client.
                    Send(handler, "Booked" + content);
                }
                else
                {
                    // Not all data received. Get more.
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                         new AsyncCallback(ReadCallback), state);
                }
            }
        }