Example #1
0
        public static void Main(string[] args)
        {
            SCXML scxml = new SCXML("./lib/SCION-Java/js-lib/SCION/test/scxml-test-framework/test/basic/basic1.scxml");
            System.Console.WriteLine(scxml);
            IList<string> initialConfiguration = scxml.Start();
            System.Console.WriteLine(initialConfiguration);
            foreach (string stateId in initialConfiguration){
                System.Console.WriteLine(stateId);
            } 

            IList<string> nextConfiguration = scxml.Gen("t",null);
            System.Console.WriteLine(nextConfiguration);
            foreach (string stateId in nextConfiguration){
                System.Console.WriteLine(stateId);
            } 
        }
Example #2
0
        public static void Main(string[] args)
        {
            SCXML scxml = new SCXML("./lib/SCION-Java/js-lib/SCION/test/scxml-test-framework/test/basic/basic1.scxml");

            System.Console.WriteLine(scxml);
            IList <string> initialConfiguration = scxml.Start();

            System.Console.WriteLine(initialConfiguration);
            foreach (string stateId in initialConfiguration)
            {
                System.Console.WriteLine(stateId);
            }

            IList <string> nextConfiguration = scxml.Gen("t", null);

            System.Console.WriteLine(nextConfiguration);
            foreach (string stateId in nextConfiguration)
            {
                System.Console.WriteLine(stateId);
            }
        }
Example #3
0
        protected void b_upload_Click(object sender, EventArgs e)
        {
            if (fu_serviceconfig.FileName != "")
            {
                int index = fu_serviceconfig.FileName.LastIndexOf('.');

                if (fu_serviceconfig.FileName.Substring(0, index) == lb_BID.Text)
                {
                    fu_serviceconfig.SaveAs(xml_BusinessConfig_Path + fu_serviceconfig.FileName);
                    SCXML   scXML   = new SCXML();
                    SCModel scModel = scXML.GetSCModel(xml_BusinessConfig_Path, fu_serviceconfig.FileName);
                    bool    dbsave  = false;
                    SCDB    scDB    = new SCDB();
                    //采集数据
                    if (scModel.DataSourceType == "0")
                    {
                        User user = new Class.User();
                        dbsave = scDB.InsertSCCollectionModel(scModel, user);
                    }
                    //监控数据
                    else
                    {
                        dbsave = scDB.InsertSCNotifyModel(scModel, user);
                    }
                    if (dbsave)
                    {
                        Label1.Text = "上传成功!";
                    }
                }
                else
                {
                    Label1.Text = "文件名须与业务ID一致!";
                }
            }
            else
            {
                Label1.Text = "请选择需上传的业务配置文件!";
            }
        }
Example #4
0
    public static void Main(string[] args)
    {
        if (!HttpListener.IsSupported)
        {
            Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
            return;
        }

        // Create a listener.
        HttpListener listener = new HttpListener();

        // Add the prefixes.
        listener.Prefixes.Add("http://+:42000/");

        int sessionCounter = 0;
        Dictionary <int, SCXML> sessions = new Dictionary <int, SCXML>();

        listener.Start();

        while (true)
        {
            // Note: The GetContext method blocks while waiting for a request.
            HttpListenerContext context = listener.GetContext();
            HttpListenerRequest request = context.Request;

            // Obtain a response object.
            HttpListenerResponse response = context.Response;
            System.IO.Stream     output   = response.OutputStream;

            String jsonBody = new StreamReader(request.InputStream).ReadToEnd();

            //Dictionary<string, Dictionary<string,string>> values = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string,string>>>(jsonBody);
            JObject reqJson = JObject.Parse(jsonBody);

            JToken scxmlToken, eventToken, sessionJsonToken;
            int    sessionToken;

            try{
                if (reqJson.TryGetValue("load", out scxmlToken))
                {
                    Console.WriteLine("Loading new statechart");

                    string         scxmlStr             = scxmlToken.ToString();
                    SCXML          scxml                = new SCXML(new System.Uri(scxmlStr));
                    IList <string> initialConfiguration = scxml.Start();

                    sessionToken           = sessionCounter++;
                    sessions[sessionToken] = scxml;

                    // Construct a response.
                    string responseString = TestServer.getResponseJson(sessionToken, initialConfiguration);
                    System.Console.WriteLine(responseString);
                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
                    // Get a response stream and write the response to it.
                    response.ContentLength64 = buffer.Length;
                    output.Write(buffer, 0, buffer.Length);
                }
                else if (reqJson.TryGetValue("event", out eventToken) && reqJson.TryGetValue("sessionToken", out sessionJsonToken))
                {
                    string eventName = (string)reqJson["event"]["name"];
                    sessionToken = (int)reqJson["sessionToken"];

                    IList <string> nextConfiguration = sessions[sessionToken].Gen(eventName, null);

                    string responseString = TestServer.getResponseJson(sessionToken, nextConfiguration);
                    byte[] buffer         = System.Text.Encoding.UTF8.GetBytes(responseString);
                    response.ContentLength64 = buffer.Length;
                    output.Write(buffer, 0, buffer.Length);
                }
                else
                {
                    string responseString = "Unrecognized request.";
                    byte[] buffer         = System.Text.Encoding.UTF8.GetBytes(responseString);
                    response.ContentLength64 = buffer.Length;
                    output.Write(buffer, 0, buffer.Length);
                }
            }catch (Exception e) {
                string responseString = "An error occured: " + e.ToString();
                byte[] buffer         = System.Text.Encoding.UTF8.GetBytes(responseString);
                response.ContentLength64 = buffer.Length;
                output.Write(buffer, 0, buffer.Length);
            }

            output.Close();
        }
    }
Example #5
0
    public static void Main(string[] args)
    {
        if (!HttpListener.IsSupported)
        {
            Console.WriteLine ("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
            return;
        }

        // Create a listener.
        HttpListener listener = new HttpListener();
        // Add the prefixes.
        listener.Prefixes.Add("http://+:42000/");

        int sessionCounter = 0;
        Dictionary<int,SCXML> sessions = new Dictionary<int,SCXML>();

        listener.Start();

        while(true){
            // Note: The GetContext method blocks while waiting for a request. 
            HttpListenerContext context = listener.GetContext();
            HttpListenerRequest request = context.Request;

            // Obtain a response object.
            HttpListenerResponse response = context.Response;
            System.IO.Stream output = response.OutputStream;

            String jsonBody  = new StreamReader(request.InputStream).ReadToEnd();

            //Dictionary<string, Dictionary<string,string>> values = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string,string>>>(jsonBody);
            JObject reqJson = JObject.Parse(jsonBody);

            JToken scxmlToken,eventToken,sessionJsonToken;
            int sessionToken;

            try{
                if(reqJson.TryGetValue("load",out scxmlToken)){
                    Console.WriteLine("Loading new statechart");

                    string scxmlStr = scxmlToken.ToString();
                    SCXML scxml = new SCXML(new System.Uri(scxmlStr));
                    IList<string> initialConfiguration = scxml.Start();

                    sessionToken = sessionCounter++;
                    sessions[sessionToken] = scxml;

                    // Construct a response.
                    string responseString = TestServer.getResponseJson(sessionToken,initialConfiguration);
                    System.Console.WriteLine(responseString);
                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
                    // Get a response stream and write the response to it.
                    response.ContentLength64 = buffer.Length;
                    output.Write(buffer,0,buffer.Length);
                }else if(reqJson.TryGetValue("event",out eventToken) && reqJson.TryGetValue("sessionToken",out sessionJsonToken)){

                    string eventName = (string) reqJson["event"]["name"];
                    sessionToken = (int) reqJson["sessionToken"];
                    
                    IList<string> nextConfiguration = sessions[sessionToken].Gen(eventName,null);

                    string responseString = TestServer.getResponseJson(sessionToken,nextConfiguration);
                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
                    response.ContentLength64 = buffer.Length;
                    output.Write(buffer,0,buffer.Length);
                }else{
                    string responseString = "Unrecognized request.";
                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
                    response.ContentLength64 = buffer.Length;
                    output.Write(buffer,0,buffer.Length);
                }
            }catch(Exception e){
                string responseString = "An error occured: " + e.ToString();
                byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
                response.ContentLength64 = buffer.Length;
                output.Write(buffer,0,buffer.Length);
            }

            output.Close();
        }
        
    }