예제 #1
0
        //protected Queue<Tuple> tuple_queue = new Queue<Tuple>();
        public void initialComponent(Conf config, Context context)
        {
            string           information = StandardIO.readMsg();
            InitialHandshake handshake   = InitialHandshake.Parse(information);

            config  = handshake.conf;
            context = handshake.context;
            int process_id = Process.GetCurrentProcess().Id;
            PID temp       = new PID();

            temp.pid = process_id;
            string json_pid = JsonMapper.ToJson(temp);

            try
            {
                string dir_path = @handshake.pidDir;
                System.IO.Directory.CreateDirectory(dir_path);
                string file = handshake.pidDir + @"\" + process_id.ToString();
                if (!System.IO.File.Exists(file))
                {
                    System.IO.FileStream f = new System.IO.FileStream(file, System.IO.FileMode.CreateNew);
                }
            }
            catch (Exception e)
            {
                // do nothing
            }
            StandardIO.sendMsg(json_pid);
        }
예제 #2
0
        private void initialComponent(Conf config, Context context)
        {
            string           information = StandardIO.readMsg();
            InitialHandshake handshake   = InitialHandshake.Parse(information);

            config  = handshake.conf;
            context = handshake.context;
            int process_id = Process.GetCurrentProcess().Id;
            PID temp       = new PID();

            temp.pid = process_id;
            string json_pid = JsonMapper.ToJson(temp);

            StandardIO.sendMsg(json_pid);
            string file = handshake.pidDir + "/" + process_id.ToString();

            if (!System.IO.File.Exists(file))
            {
                System.IO.FileStream f = new System.IO.FileStream(file, System.IO.FileMode.CreateNew);
            }
        }
예제 #3
0
        public static InitialHandshake Parse(string s)
        {
            try
            {
                s = formatAdjust(s);
                JsonData         jd        = JsonMapper.ToObject(s);
                InitialHandshake handshake = new InitialHandshake();
                if (jd["pidDir"].IsString)
                {
                    handshake.pidDir = (string)jd["pidDir"];
                }
                JsonData temp_config_json = jd["conf"];
                foreach (string str_item in temp_config_json.getKeys())
                {
                    string key = str_item;
                    if (jd["conf"][key] != null)
                    {
                        object value = (object)jd["conf"][key];
                        if (!value.ToString().Equals("empty"))
                        {
                            handshake.conf.addItem(key, value);
                        }
                    }
                }

                JsonData temp_context_json = jd["context"];
                if (temp_context_json.hasKey("taskid"))
                {
                    //Console.WriteLine("has task id");
                    JsonData temp_task_id = jd["context"]["taskid"];
                    if (temp_task_id.IsInt || temp_task_id.IsLong)
                    {
                        handshake.context.taskid = (int)jd["context"]["taskid"];
                    }
                }

                if (temp_context_json.hasKey("task->component"))
                {
                    // Console.WriteLine("has task component");
                    JsonData temp_task_components = jd["context"]["task->component"];
                    foreach (string str_item in temp_task_components.getKeys())
                    {
                        string key = str_item;
                        //Console.WriteLine(key);
                        if (temp_task_components[key] != null)
                        {
                            string value = (string)temp_task_components[key];
                            handshake.context.component.addItem(key, value);
                            //Console.WriteLine(key + "   " + value);
                        }
                    }
                }
                else
                {
                    //Console.WriteLine("no task component");
                }
                return(handshake);
            }
            catch (Exception e)
            {
                return(new InitialHandshake());
            }
        }