/// <summary>
 /// Posts the ChemStationStatus (serialized in JSON) to a particular Url.
 /// </summary>
 /// <param name="status"></param>
 public void ConsumeChemStationStatus(ChemStationStatus status)
 {
     var serializer = new JavaScriptSerializer();
     serializer.RegisterConverters(new[] { new ChemStationStatusConverter() });
     var js = serializer.Serialize(status);
     using (WebClient wc = new WebClient())
     {
         wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
         string HtmlResult = wc.UploadString(_postUrl, "json=" + HttpUtility.UrlEncode(js));
     }
 }
        /// <summary>
        /// Gets the current status of the ChemStation app via DDE and maps it to our model object.
        /// </summary>
        /// <returns>The ORMed ChemStation Status.</returns>
        public ChemStationStatus GetCurrentStatus()
        {
            var status = new ChemStationStatus();
            status.Time = DateTime.Now;
            var appName = string.Empty;
            try
            {
                appName = GetChemStationAppName();
            }
            catch (ApplicationException e)
            {
                status.Status = e.Message;
                status.MethodName = string.Empty;
                status.SequenceName = string.Empty;
                return status;
            }

            using (DdeClient client = new DdeClient(appName, _DDETopicName))
            {
                client.Connect();
                foreach (var variable in _chemStationVariableNameToPropertyMap)
                {
                    var rawVariable = client.Request(variable.Key, 60000);

                    // Use reflection to map the raw variable just extracted from ChemStation to the model object.
                    if (variable.Value.PropertyType == typeof(bool))
                    {
                        var val = rawVariable[0] == '1' ? true : false;
                        _chemStationVariableNameToPropertyMap[variable.Key].SetValue(status, val, null);
                    }
                    else
                    {
                        // String variables tend to come out of ChemStation with a bizarre amount of control characters followed by jibberish at the end.
                        var val = rawVariable.Remove(rawVariable.IndexOf(rawVariable.Where(c => char.IsControl(c)).First()));
                        _chemStationVariableNameToPropertyMap[variable.Key].SetValue(status, val, null);
                    }
                }
            }
            return status;
        }
 /// <summary>
 /// Method to encapsulate all the calls necessary for polling the provider.
 /// </summary>
 public void GetData()
 {
     Status = _provider.GetCurrentStatus();
 }