예제 #1
0
        private void btnRequest_Click(object sender, EventArgs e)
        {
            CFXEnvelope request = new CFXEnvelope("CFX.Sensor.Identification.IdentifyUnitsRequest");

            request.Source = CFXHandle;
            request.Target = reqHandle.Text;

            string target = reqUri.Text;

            CFXEnvelope response = null;

            try
            {
                response = theEndpoint.ExecuteRequest(target, request);
            }
            catch (Exception ex)
            {
                lstResults.Items.Insert(0, "Exception during request process:  " + ex.Message);
            }

            if (response != null)
            {
                response.ToJson().Split(new string[] { "\r\n" }, StringSplitOptions.None).Reverse().ToList().ForEach(s => lstResults.Items.Insert(0, s));
            }
        }
예제 #2
0
        private void MakeRequest(CFXEnvelope env)
        {
            CFXEnvelope response = null;

            try
            {
                response = MyEndpoint.ExecuteRequest(FactoryLogixMESEndpointUri, env);
            }
            catch (Exception ex)
            {
                AddToResults($"ERROR OCCURRED MAKING REQUEST TO {FactoryLogixMESEndpointUri}, handle {FactoryLogixMESEndpointHandle}.\nERROR MESSAGE:  {ex.Message} \n{ex.StackTrace}");
            }

            if (response.MessageBody is NotSupportedResponse)
            {
                NotSupportedResponse r = response.MessageBody as NotSupportedResponse;
                AddToResults($"NOT SUPPORTED RESPONSE: {r.RequestResult.ResultCode.ToString()}.\n{r.RequestResult.Message}");
            }
            else if (response.MessageBody is ValidateUnitsResponse)
            {
                ValidateUnitsResponse r = response.MessageBody as ValidateUnitsResponse;
                if (r.Result.Result != StatusResult.Success)
                {
                    AddToResults($"ERROR OCCURRED PROCESSING VALIDATATION REQUEST: {r.PrimaryResult.Result.ToString()}.\n{r.PrimaryResult.Message}");
                }
                else
                {
                    AddToResults($"VALIDATATION RESULT RECEIVED: {r.PrimaryResult.Result.ToString()}.\n{r.PrimaryResult.Message}");
                }
            }
            else
            {
                AddToResults($"UNEXPLAINED RESPONSE:  {response.MessageName}\n{response.ToJson(true)}");
            }
        }
예제 #3
0
        public void WriteMessage(CFXEnvelope cfxMessage)
        {
            string connectionString = @"Data Source=aishqcfx01v\sqlexpress;Initial Catalog=CFXDemo;Integrated Security=True";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string json = cfxMessage.ToJson().Replace("'", "''");

                string sql = string.Format("INSERT INTO CFXMessages (CFXHandle, TimeStamp, MessageName, MessageData) VALUES('{0}','{1}','{2}','{3}')",
                                           cfxMessage.Source, cfxMessage.TimeStamp.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fff"), cfxMessage.MessageName, json);

                SqlCommand command = new SqlCommand(sql, connection);
                command.Connection.Open();
                command.ExecuteNonQuery();
            }
        }
예제 #4
0
        private void SendStateChange()
        {
            if (!IsOpen)
            {
                return;
            }

            TimeSpan duration = TimeSpan.FromSeconds(1);

            if (LastStateChange != DateTime.MinValue)
            {
                duration        = LastStateChange - DateTime.Now;
                LastStateChange = DateTime.Now;
            }

            ResourceState oldState = LastState;
            ResourceState newState = ResourceState.USD;

            if (oldState == ResourceState.USD)
            {
                newState = ResourceState.PRD;
            }
            else
            {
                newState = ResourceState.USD;
            }

            LastState = newState;

            // Create a CFXEnvelope containing a new StationStateChanged message
            CFXEnvelope env = new CFXEnvelope(new StationStateChanged()
            {
                OldState         = oldState,
                NewState         = newState,
                OldStateDuration = duration,
            });

            // Publish the message.
            MyEndpoint.Publish(env);

            AddToResults($"MESSAGE PUBLISHED:\n {env.ToJson(true)}");
        }