Esempio n. 1
0
        /// <summary>
        /// Get command keys and values
        /// </summary>
        /// <param name="Command">String</param>
        /// <param name="Outputs">Dictionary</param>
        /// <returns>bool</returns>
        private void GetCmdOutputs(String Command, IDictionary <String, String> Outputs)
        {
            if (String.IsNullOrEmpty(Command))
            {
                throw new System.ArgumentNullException("Command cannot be null or empty string.");
            }

            do
            {
                byte[] Items = new byte[OutBufferSize];
                int    nLen  = 0;
                nLen = ParseResponses.GetPrivateProfileSection(Command, Items,
                                                               Items.GetUpperBound(0), m_Filenam);

                if (nLen == 0)
                {
                    break;
                }

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < nLen; i++)
                {
                    if (Items[i] != 0)
                    {
                        sb.Append((char)Items[i]);
                    }
                    else
                    {
                        if (sb.Length > 0)
                        {
                            String[] Values = sb.ToString().Split('=');
                            String   Key    = Values[0];
                            // only want the output keys and values
                            if (Key.Contains("Output") || Key.Contains("output"))
                            {
                                Outputs[Values[0].Trim()] = Values[1].Trim();
                            }
                            sb = new StringBuilder();
                        }
                    }
                }
            } while (false); /* ONCE */
        }
Esempio n. 2
0
        /// <summary>
        /// Get commands names
        /// </summary>
        private void GetCommandsNames()
        {
            do
            {
                byte[] SectionNames = new byte[BufferSize];
                int    nLen         = 0;
                nLen = ParseResponses.GetPrivateProfileSectionNames(SectionNames,
                                                                    SectionNames.GetUpperBound(0), m_Filenam);

                if (nLen == 0)
                {
                    break;
                }

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < nLen; i++)
                {
                    if (SectionNames[i] != 0)
                    {
                        sb.Append((char)SectionNames[i]);
                    }
                    else
                    {
                        if (sb.Length > 0)
                        {
                            String Cmd = sb.ToString();
                            IDictionary <String, String> Outputs = new Dictionary <String, String>();

                            // Get the command output keys and values
                            GetCmdOutputs(Cmd, Outputs);
                            m_Commands.Add(Cmd, Outputs);

                            sb = new StringBuilder();
                        }
                    }
                }
            } while (false); /* ONCE */
        }