示例#1
0
        //-------------------------------------------------------------------------------------------------//

        public override ExecuteCommandInfo ProcessCommand(ExecuteCommandInfo executeCommandInfo)
        {
            const string STRLOG_MethodName = "ProcessCommand";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            CommandInfo commandInfo = (CommandInfo)executeCommandInfo;

            bool   success      = true;
            string errorMessage = null;

            try
            {
                //
                // Process the execute command
                //
                ExecuteCommands executeCommand = (ExecuteCommands)commandInfo.command;

                switch (executeCommand)
                {
                //
                // YOUR CODE HERE
                //
                case ExecuteCommands.DoSomething:
                    // Remove this command in your implementation
                    break;

                default:

                    //
                    // Unknown command
                    //
                    errorMessage = STRERR_UnknownCommand + executeCommand.ToString();
                    success      = false;
                    break;
                }
            }
            catch (Exception ex)
            {
                success      = false;
                errorMessage = ex.Message;
            }

            //
            // Update success of command execution
            //
            executeCommandInfo.success = success;

            string logMessage = STRLOG_Success + success.ToString();

            if (success == false)
            {
                executeCommandInfo.errorMessage = errorMessage;
                logMessage += Logfile.STRLOG_Spacer + STRLOG_ErrorMessage + errorMessage;
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(executeCommandInfo);
        }
示例#2
0
        /// <summary>
        /// Executes a db command and fills in a list of objects with the result data
        /// </summary>
        /// <typeparam name="ReturnType">The type of object to return</typeparam>
        /// <param name="objectType">The type of object to return.</param>
        /// <param name="command">The command to execute</param>
        /// <returns></returns>
        protected virtual IEnumerable <ReturnType> ExecuteCommandLoadList <ReturnType>(Type objectType, IDbCommand command)
        {
            DatabaseTypeInfo ti = Connection.CommandGenerator.TypeParser.GetTypeInfo(objectType);

            using (IQueryData dt = ExecuteCommands.ExecuteCommandQuery(command, Connection))
            {
                if (dt.QuerySuccessful)
                {
                    foreach (IQueryRow row in dt)
                    {
                        ReturnType toAdd;

                        if (objectType.IsSystemType())
                        {
                            toAdd = (ReturnType)Connection.CLRConverter.ConvertToType(row.GetDataForRowField(0), typeof(ReturnType));
                        }
                        else
                        {
                            toAdd = (ReturnType)BuildObject(row, ti);
                        }

                        yield return(toAdd);
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Determines if an object already exists in the data store, based on the primary key
        /// </summary>
        /// <param name="item">The object to check</param>
        /// <returns></returns>
        public virtual bool IsNew(object item)
        {
            IDbCommand cmd = Connection.CommandGenerator.GetSelectCommand(item);

            using (IQueryData qd = ExecuteCommands.ExecuteCommandQuery(cmd, Connection))
            {
                var enumerator = qd.GetEnumerator();
                enumerator.MoveNext();

                return(enumerator.Current == null);
            }
        }
示例#4
0
 public async Task <bool> IsNew(object item)
 {
     using (IQueryData qd = await Task.Run(() => {
         IDbCommand cmd = Connection.CommandGenerator.GetSelectCommand(item, false);
         return(ExecuteCommands.ExecuteCommandQuery(cmd, Connection));
     }))
     {
         var enumerator = qd.GetEnumerator();
         enumerator.MoveNext();
         return(enumerator.Current == null);
     }
 }
        private string InstallAzurePowershell(string pathToWebPIExe)
        {
            // .\WebpiCmdLine.exe /Products:AzureNodePowershell
            String     logFileName = String.Concat("WebPiLog_", Guid.NewGuid().ToString(), ".txt");
            FileStream logFileFs   = File.Create(logFileName);

            logFileFs.Close();

            String installCommand = String.Format(CultureInfo.InvariantCulture, "Start-Process -File \"{0}\" -ArgumentList \" /Install /Products:WindowsAzurePowershell /Log:{1} /AcceptEULA \" -Wait", pathToWebPIExe, logFileName);

            ExecuteCommands.ExecuteCommand(installCommand, this.Host);
            return(logFileName);
        }
示例#6
0
        private void CopyBinaries()
        {
            string roleDir = Path.Combine(CurrentLocation, this.RoleName);

            if (Directory.Exists(roleDir) == true)
            {
                WriteObject(string.Format(CultureInfo.InvariantCulture, Resources.RoleDirAlreadyPresent, this.RoleName));
            }
            else
            {
                Directory.CreateDirectory(roleDir);
                ExecuteCommands.ExecuteCommand(string.Format(CultureInfo.InvariantCulture, "COPY-ITEM \"{0}\" \"{1}\" -recurse", Path.Combine(this.RoleBinariesFolder, "*"), roleDir), this.Host);
            }
        }
    public static void Main()
    {
        DraftManager manager = new DraftManager();

        while (true)
        {
            List <string> input = Console.ReadLine().Split().ToList();

            ExecuteCommands.ExecuteCommand(input, manager);
            if (input[0].Equals("Shutdown"))
            {
                break;
            }
        }
    }
示例#8
0
        private void Unzip(string downloadLocation)
        {
            String unzipCommand = String.Format(CultureInfo.InvariantCulture, @"function Unzip([string]$locationOfZipFile, [string]$unzipLocation)
                                                {{
                                                    Write-Host $locationOfZipFile
                                                    Write-Host $unzipLocation
                                                    $shell_app = new-object -com shell.application
                                                    $zip_file = $shell_app.namespace($locationOfZipFile)
                                                    $destination = $shell_app.namespace($unzipLocation)
                                                    $destination.Copyhere($zip_file.items(), 0x10)
                                                }}
                                                Unzip ""{0}""  ""{1}""
                                                ", downloadLocation, UnzipLoc);

            ExecuteCommands.ExecuteCommand(unzipCommand, this.Host);
        }
示例#9
0
        protected virtual bool ProcessCommand(Func <IQueryData, bool> OnDone, IDbCommand command, bool FailIfNoRecords)
        {
            using (IQueryData dt = ExecuteCommands.ExecuteCommandQuery(command, Connection))
            {
                if (dt.QuerySuccessful)
                {
                    bool records = OnDone(dt);

                    if (FailIfNoRecords)
                    {
                        return(records);
                    }
                }
                return(true);
            }
        }
示例#10
0
        /// <summary>
        /// Deletes objects based on an expression
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="criteria"></param>
        public int DeleteObjects <T>(Expression <Func <T, bool> > criteria)
        {
            StringBuilder sb = new StringBuilder("DELETE FROM ");

            sb.Append(Connection.CommandGenerator.ResolveTableName(typeof(T)));
            sb.Append(" WHERE ");
            IDbCommand                  cmd         = Connection.GetCommand();
            IDeleteFormatter            formatter   = Connection.GetDeleteFormatter(this);
            Dictionary <string, object> whereParams = new Dictionary <string, object>();
            string whereString = formatter.FormatDelete(DataAccess.Core.Linq.Common.PartialEvaluator.Eval(criteria), out whereParams);

            foreach (KeyValuePair <string, object> par in whereParams)
            {
                cmd.Parameters.Add(Connection.GetParameter(par.Key, par.Value));
            }

            sb.Append(whereString);
            cmd.CommandText = sb.ToString();
            return(ExecuteCommands.ExecuteCommand(cmd, Connection));
        }
示例#11
0
文件: PaintForm.cs 项目: aiten/CNCLib
		void AsyncRunCommand(ExecuteCommands todo)
		{
			if (Com.IsConnected)
			{
				new Task(() =>
				{
					Invoke(new MethodInvoker(() =>
					{
						EnableComControls(false);
						_plotterCtrl.ReadOnly = true;
						_load.Enabled = false;
						_clear.Enabled = false;
						_undo.Enabled = false;
						_del.Enabled = false;
					}));

					try
					{
						Com.ClearCommandHistory();

						todo();

						Com.WriteCommandHistory(@"c:\tmp\Command.txt");
					}
					finally
					{
						Invoke(new MethodInvoker(() =>
						{
							EnableComControls(true);
							_load.Enabled = false;
							_plotterCtrl.ReadOnly = false;
							_clear.Enabled = true;
							_undo.Enabled = true;
							_del.Enabled = true;
						}));
					}
				}
				).Start();
			}
		}
示例#12
0
        public async Task <IEnumerable <ReturnType> > ExecuteCommandLoadList <ReturnType>(Type objectType, IDbCommand command)
        {
            List <ReturnType> toReturn = new List <ReturnType>();

            using (IQueryData dt = await Task.Run(() => ExecuteCommands.ExecuteCommandQuery(command, Connection)))
            {
                if (dt.QuerySuccessful)
                {
                    DatabaseTypeInfo ti = TypeInformationParser.GetTypeInfo(objectType);
                    foreach (IQueryRow row in dt)
                    {
                        if (objectType.IsSystemType())
                        {
                            toReturn.Add((ReturnType)Connection.CLRConverter.ConvertToType(row.GetDataForRowField(0), typeof(ReturnType)));
                        }
                        else
                        {
                            toReturn.Add((ReturnType)await BuildObjectAsync(row, ti));
                        }
                    }
                }
                return(toReturn);
            }
        }
示例#13
0
        public async Task <ExecuteCommandsResponse> ExecuteCommandsRPCHandler(ExecuteCommands request)
        {
            int index     = _nodeStorage.AddCommands(request.Commands.ToArray(), _nodeStorage.CurrentTerm);
            var startDate = DateTime.Now;

            while (request.WaitForCommits)
            {
                if ((startDate - DateTime.Now).TotalMilliseconds > ClusterOptions.CommitsTimeout)
                {
                    return(new ExecuteCommandsResponse()
                    {
                        EntryNo = index,
                        IsSuccessful = false
                    });
                }

                Logger.LogDebug(NodeStateService.GetNodeLogId() + "Waiting for " + request.RequestName + " to complete.");
                if (NodeStateService.CommitIndex >= index)
                {
                    return(new ExecuteCommandsResponse()
                    {
                        EntryNo = index,
                        IsSuccessful = true
                    });
                }
                else
                {
                    await Task.Delay(100);
                }
            }
            return(new ExecuteCommandsResponse()
            {
                EntryNo = index,
                IsSuccessful = true
            });
        }
示例#14
0
 public async Task <int> ExecuteCommand(IDbCommand command)
 {
     return(await Task.Run(() => ExecuteCommands.ExecuteCommand(command, Connection)));
 }
示例#15
0
        //-------------------------------------------------------------------------------------------------//

        public override ExecuteCommandInfo ProcessCommand(ExecuteCommandInfo executeCommandInfo)
        {
            const string STRLOG_MethodName = "ProcessCommand";

            Logfile.WriteCalled(this.logLevel, STRLOG_ClassName, STRLOG_MethodName);

            CommandInfo commandInfo = (CommandInfo)executeCommandInfo;

            bool   success      = true;
            string errorMessage = null;

            try
            {
                //
                // Process the execute command
                //
                ExecuteCommands executeCommand = (ExecuteCommands)commandInfo.command;

                switch (executeCommand)
                {
                case ExecuteCommands.CreateConnection:

                    //
                    // Create a connection to the RedLion controller
                    //
                    if ((success = this.redLion.CreateConnection()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.CloseConnection:

                    //
                    // Close the connection to the RedLion controller
                    //
                    if ((success = this.redLion.CloseConnection()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.ResetACDrive:

                    //
                    // Reset the AC drive
                    //
                    if ((success = this.redLion.ResetACDrive()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.ConfigureACDrive:

                    //
                    // Get AC drive configuration from parameters
                    //
                    RedLion.ACDriveConfigs acCDriveConfig = (RedLion.ACDriveConfigs)commandInfo.parameters[0];

                    //
                    // Configure the AC drive with the specified configuration
                    //
                    if ((success = this.redLion.ConfigureACDrive(acCDriveConfig)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.StartACDrive:

                    //
                    // Start the AC drive
                    //
                    if ((success = this.redLion.StartACDrive()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.StopACDrive:

                    //
                    // Stop the AC drive
                    //
                    if ((success = this.redLion.StopACDrive()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.ResetDCDriveMut:

                    //
                    // Reset the DC drive
                    //
                    if ((success = this.redLion.ResetDCDriveMut()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.ConfigureDCDriveMut:

                    //
                    // Get DC drive configuration from parameters
                    //
                    RedLion.DCDriveMutConfigs dcDriveMutConfig = (RedLion.DCDriveMutConfigs)commandInfo.parameters[0];

                    //
                    // Configure the AC drive with the specified configuration
                    //
                    if ((success = this.redLion.ConfigureDCDriveMut(dcDriveMutConfig)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.StartDCDriveMut:

                    //
                    // Get DC drive mode from parameters
                    //
                    RedLion.DCDriveMutModes dcDriveMutMode = (RedLion.DCDriveMutModes)commandInfo.parameters[0];

                    //
                    // Start the DC drive
                    //
                    if ((success = this.redLion.StartDCDriveMut(dcDriveMutMode)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.StopDCDriveMut:

                    //
                    // Stop the DC drive
                    //
                    if ((success = this.redLion.StopDCDriveMut()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.SetSpeedACDrive:

                    //
                    // Get speed from parameters
                    //
                    int speedACDrive = (int)commandInfo.parameters[0];

                    //
                    // Set the speed of the AC drive
                    //
                    if ((success = this.redLion.SetSpeedACDrive(speedACDrive)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.SetSpeedDCDriveMut:

                    //
                    // Get speed from parameters
                    //
                    int speedDCDriveMut = (int)commandInfo.parameters[0];

                    //
                    // Set the speed of the DC drive
                    //
                    if ((success = this.redLion.SetSpeedDCDriveMut(speedDCDriveMut)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.SetTorqueDCDriveMut:

                    //
                    // Get torque from parameters
                    //
                    int torqueDCDriveMut = (int)commandInfo.parameters[0];

                    //
                    // Set the torque of the DC drive
                    //
                    if ((success = this.redLion.SetTorqueDCDriveMut(torqueDCDriveMut)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.SetFieldDCDriveMut:

                    //
                    // Get torque from parameters
                    //
                    int fieldDCDriveMut = (int)commandInfo.parameters[0];

                    //
                    // Set the field of the DC drive
                    //
                    if ((success = this.redLion.SetFieldDCDriveMut(fieldDCDriveMut)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.TakeMeasurement:

                    //
                    // Take a measurement
                    //
                    RedLion.Measurements measurement = new RedLion.Measurements();
                    if ((success = this.redLion.TakeMeasurement(ref measurement)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    else
                    {
                        //
                        // Add the measurement values to results
                        //
                        commandInfo.results = new object[] {
                            measurement.speed,
                            measurement.voltage,
                            measurement.fieldCurrent,
                            measurement.load
                        };
                    }
                    break;

                default:

                    //
                    // Unknown command
                    //
                    errorMessage = STRERR_UnknownCommand + executeCommand.ToString();
                    success      = false;
                    break;
                }
            }
            catch (Exception ex)
            {
                success      = false;
                errorMessage = ex.Message;
            }

            //
            // Update success of command execution
            //
            executeCommandInfo.success = success;

            string logMessage = STRLOG_Success + success.ToString();

            if (success == false)
            {
                executeCommandInfo.errorMessage = errorMessage;
                logMessage += Logfile.STRLOG_Spacer + STRLOG_ErrorMessage + errorMessage;
            }

            Logfile.WriteCompleted(this.logLevel, STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(executeCommandInfo);
        }
示例#16
0
        //-------------------------------------------------------------------------------------------------//

        public override string ExecuteXmlRequest(string xmlRequest)
        {
            string strXmlResponse = string.Empty;

            const string STRLOG_MethodName = "ExecuteXmlRequest";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            EquipmentEngine equipmentEngine = (EquipmentEngine)this.labEquipmentEngine;

            try
            {
                bool        success      = true;
                string      errorMessage = string.Empty;
                CommandInfo commandInfo  = null;
                CommandInfo resultInfo   = null;

                //
                // Create the XML response
                //
                XmlDocument xmlResponseDocument = new XmlDocument();
                XmlElement  xmlElement          = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_Response);
                xmlResponseDocument.AppendChild(xmlElement);

                //
                // Add success of command execution and update later
                //
                xmlElement           = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_RspSuccess);
                xmlElement.InnerText = success.ToString();
                xmlResponseDocument.DocumentElement.AppendChild(xmlElement);

                //
                // Parse XML request for the command
                //
                XmlDocument xmlRequestDocument = new XmlDocument();
                xmlRequestDocument.LoadXml(xmlRequest);
                XmlNode xmlRequestNode = XmlUtilities.GetXmlRootNode(xmlRequestDocument, Engine.Consts.STRXML_Request);
                string  strCommand     = XmlUtilities.GetXmlValue(xmlRequestNode, Engine.Consts.STRXML_Command, false);

                NonExecuteCommands nonExecuteCommand = (NonExecuteCommands)(-1);
                ExecuteCommands    executeCommand    = (ExecuteCommands)(-1);
                try
                {
                    //
                    // Try to convert to a non-execute command type that doesn't require powerdown to be suspended
                    //
                    nonExecuteCommand = (NonExecuteCommands)Enum.Parse(typeof(NonExecuteCommands), strCommand);
                    Logfile.Write(STRLOG_Command + nonExecuteCommand.ToString());
                }
                catch
                {
                    try
                    {
                        //
                        // Try to convert to an execute command type that does require powerdown to be suspended
                        //
                        executeCommand = (ExecuteCommands)Enum.Parse(typeof(ExecuteCommands), strCommand);
                        Logfile.Write(STRLOG_Command + executeCommand.ToString());

                        //
                        // Check that powerdown has been suspended before executing the command
                        //
                        if (this.labEquipmentEngine.IsPowerdownSuspended == false)
                        {
                            //
                            // Suspend the powerdown before executing the command
                            //
                            this.labEquipmentEngine.SuspendPowerdown();
                        }
                    }
                    catch
                    {
                        //
                        // Unknown command
                        //
                        success      = false;
                        errorMessage = STRERR_UnknownCommand + strCommand;
                    }
                }

                if (success == true && nonExecuteCommand != (NonExecuteCommands)(-1))
                {
                    //
                    // Process the non-execute command
                    //
                    switch (nonExecuteCommand)
                    {
                    case NonExecuteCommands.GetTubeHomeDistance:

                        //
                        // Get tube home distance
                        //
                        int tubeHomeDistance = equipmentEngine.GetTubeHomeDistance();

                        //
                        // Add tube home distance to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspTubeHomeDistance);
                        xmlElement.InnerText = tubeHomeDistance.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetTubeMoveTime:

                        //
                        // Get distance 'from' and 'to' from request
                        //
                        int distanceFrom = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqTubeDistanceFrom, 0);
                        int distanceTo   = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqTubeDistanceTo, 0);

                        //
                        // Get tube move time
                        //
                        double tubeMoveTime = equipmentEngine.GetTubeMoveTime(distanceFrom, distanceTo);

                        //
                        // Add tube move time to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspTubeMoveTime);
                        xmlElement.InnerText = tubeMoveTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetSourceHomeLocation:

                        //
                        // Get source home location
                        //
                        char sourceHomeLocation = equipmentEngine.GetSourceHomeLocation();

                        //
                        // Add source home location to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspSourceHomeLocation);
                        xmlElement.InnerText = sourceHomeLocation.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetSourceSelectTime:

                        //
                        // Get source location from request
                        //
                        char sourceLocation = XmlUtilities.GetCharValue(xmlRequestNode, Consts.STRXML_ReqSourceLocation, Char.MinValue);

                        //
                        // Get source select time
                        //
                        double sourceSelectTime = equipmentEngine.GetSourceSelectTime(sourceLocation);

                        //
                        // Add source select time to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspSourceSelectTime);
                        xmlElement.InnerText = sourceSelectTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetSourceReturnTime:

                        //
                        // Get source location from request
                        //
                        sourceLocation = XmlUtilities.GetCharValue(xmlRequestNode, Consts.STRXML_ReqSourceLocation, Char.MinValue);

                        //
                        // Get source return time
                        //
                        double sourceReturnTime = equipmentEngine.GetSourceReturnTime(sourceLocation);

                        //
                        // Add source return time to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspSourceReturnTime);
                        xmlElement.InnerText = sourceReturnTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetAbsorberHomeLocation:

                        //
                        // Get absorber home location
                        //
                        char absorberHomeLocation = equipmentEngine.GetAbsorberHomeLocation();

                        //
                        // Add absorber home location to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspAbsorberHomeLocation);
                        xmlElement.InnerText = absorberHomeLocation.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetAbsorberSelectTime:

                        //
                        // Get absorber location from request
                        //
                        char absorberLocation = XmlUtilities.GetCharValue(xmlRequestNode, Consts.STRXML_ReqAbsorberLocation, Char.MinValue);

                        //
                        // Get absorber select time
                        //
                        double absorberSelectTime = equipmentEngine.GetAbsorberSelectTime(absorberLocation);

                        //
                        // Add absorber select time to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspAbsorberSelectTime);
                        xmlElement.InnerText = absorberSelectTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetAbsorberReturnTime:

                        //
                        // Get absorber location from request
                        //
                        absorberLocation = XmlUtilities.GetCharValue(xmlRequestNode, Consts.STRXML_ReqAbsorberLocation, Char.MinValue);

                        //
                        // Get absorber return time
                        //
                        double absorberReturnTime = equipmentEngine.GetAbsorberReturnTime(absorberLocation);

                        //
                        // Add absorber return time to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspAbsorberReturnTime);
                        xmlElement.InnerText = absorberReturnTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetLcdWriteLineTime:
                        //
                        // Get LCD writeline time
                        //
                        double lcdWriteLineTime = equipmentEngine.GetLcdWriteLineTime();

                        //
                        // Add capture data time to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspLcdWriteLineTime);
                        xmlElement.InnerText = lcdWriteLineTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetCaptureDataTime:
                        //
                        // Get duration from request
                        //
                        int duration = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqDuration, 0);

                        //
                        // Get capture data time
                        //
                        double captureDataTime = equipmentEngine.GetCaptureDataTime(duration);

                        //
                        // Add capture data time to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspCaptureDataTime);
                        xmlElement.InnerText = captureDataTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;
                    }
                }
                else if (success == true && executeCommand != (ExecuteCommands)(-1))
                {
                    //
                    // Only one execute command allowed at a time
                    //
                    lock (this.managerLock)
                    {
                        //
                        // Create an instance of the command info ready to fill in
                        //
                        commandInfo = new CommandInfo(executeCommand);

                        //
                        // Process the execute command
                        //
                        switch (executeCommand)
                        {
                        case ExecuteCommands.SetTubeDistance:

                            //
                            // Get tube distance from request
                            //
                            int tubeDistance = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqTubeDistance, 0);

                            //
                            // Set tube distance
                            //
                            commandInfo.parameters = new object[] { tubeDistance };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.SetSourceLocation:

                            //
                            // Get source location from request
                            //
                            char sourceLocation = XmlUtilities.GetCharValue(xmlRequestNode, Consts.STRXML_ReqSourceLocation, Char.MinValue);

                            //
                            // Set source location
                            //
                            commandInfo.parameters = new object[] { sourceLocation };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.SetAbsorberLocation:

                            //
                            // Get absorber location from request
                            //
                            char absorberLocation = XmlUtilities.GetCharValue(xmlRequestNode, Consts.STRXML_ReqAbsorberLocation, Char.MinValue);

                            //
                            // Set absorber location
                            //
                            commandInfo.parameters = new object[] { absorberLocation };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.GetCaptureData:

                            //
                            // Get duration from request
                            //
                            int duration = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqDuration, 0);

                            //
                            // Get radiation count
                            //
                            int count = -1;
                            commandInfo.parameters = new object[] { duration };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            if (commandInfo.success == true)
                            {
                                count = (int)commandInfo.results[0];
                            }

                            //
                            // Add radiation count to response
                            //
                            xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspCount);
                            xmlElement.InnerText = count.ToString();
                            xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                            break;

                        case ExecuteCommands.WriteLcdLine:

                            //
                            // Get LCD line number and message from request
                            //
                            int    lcdLineNo  = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqLcdLineNo, 0);
                            string lcdMessage = XmlUtilities.GetXmlValue(xmlRequestNode, Consts.STRXML_ReqLcdMessage, false);

                            //
                            // Write message to LCD
                            //
                            commandInfo.parameters = new object[] { lcdLineNo, lcdMessage };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;
                        }

                        success      = resultInfo.success;
                        errorMessage = resultInfo.errorMessage;
                    }
                }

                //
                // Update success of command execution
                //
                XmlNode xmlResponseNode = XmlUtilities.GetXmlRootNode(xmlResponseDocument, Engine.Consts.STRXML_Response);
                XmlUtilities.SetXmlValue(xmlResponseNode, Engine.Consts.STRXML_RspSuccess, success.ToString(), false);
                if (success == false)
                {
                    //
                    // Create error response
                    //
                    xmlElement           = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_RspErrorMessage);
                    xmlElement.InnerText = errorMessage;
                    xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                }
                strXmlResponse = xmlResponseDocument.InnerXml;
            }
            catch (ArgumentException)
            {
                //
                // Unknown command so pass to base class to process
                //
                strXmlResponse = base.ExecuteXmlRequest(xmlRequest);
            }
            catch (Exception ex)
            {
                Logfile.Write(ex.Message);
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName);

            return(strXmlResponse);
        }
示例#17
0
        //-------------------------------------------------------------------------------------------------//

        public override ExecuteCommandInfo ProcessCommand(ExecuteCommandInfo executeCommandInfo)
        {
            const string STRLOG_MethodName = "ProcessCommand";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            CommandInfo commandInfo = (CommandInfo)executeCommandInfo;

            bool   success      = false;
            string errorMessage = null;

            try
            {
                //
                // Process the execute command
                //
                ExecuteCommands executeCommand = (ExecuteCommands)commandInfo.command;

                switch (executeCommand)
                {
                case ExecuteCommands.StartExecution:
                    //
                    // Get the specification in XML format from the parameters and parse
                    //
                    string           xmlSpecification = (string)commandInfo.parameters[0];
                    Specification    specification    = new Specification(this.xmlNodeEquipmentConfig);
                    ValidationReport validationReport = specification.Parse(xmlSpecification);
                    if (validationReport.accepted == false)
                    {
                        errorMessage = validationReport.errorMessage;
                        break;
                    }

                    //
                    // Create an instance of the driver for the specified setup
                    // and then start the driver with the specification
                    //
                    if (specification.SetupId.Equals(Consts.STRXML_SetupId_OpenCircuitVaryField) == true)
                    {
                        this.driverMachine = new DriverMachine_OCVF(this.xmlNodeEquipmentConfig, specification);
                    }
                    else if (specification.SetupId.Equals(Consts.STRXML_SetupId_OpenCircuitVarySpeed) == true)
                    {
                        this.driverMachine = new DriverMachine_OCVS(this.xmlNodeEquipmentConfig, specification);
                    }
                    else if (specification.SetupId.Equals(Consts.STRXML_SetupId_ShortCircuitVaryField) == true)
                    {
                        this.driverMachine = new DriverMachine_SCVF(this.xmlNodeEquipmentConfig, specification);
                    }
                    else if (specification.SetupId.Equals(Consts.STRXML_SetupId_PreSynchronisation) == true)
                    {
                        this.driverMachine = new DriverMachine_PreSync(this.xmlNodeEquipmentConfig, specification);
                    }
                    else if (specification.SetupId.Equals(Consts.STRXML_SetupId_Synchronisation) == true)
                    {
                        this.driverMachine = new DriverMachine_Sync(this.xmlNodeEquipmentConfig, specification);
                    }
                    else
                    {
                        //
                        // Unknown SetupId
                        //
                        throw new Exception(STRERR_UnknownSetupId + specification.SetupId);
                    }

                    //
                    // Start execution of the specified setup
                    //
                    if ((success = this.driverMachine.Start()) == false)
                    {
                        errorMessage = this.driverMachine.LastError;
                    }
                    break;

                default:
                    //
                    // Unknown command
                    //
                    throw new Exception(STRERR_UnknownCommand + executeCommand.ToString());
                }
            }
            catch (Exception ex)
            {
                success      = false;
                errorMessage = ex.Message;
            }

            //
            // Update success of command execution
            //
            executeCommandInfo.success = success;

            string logMessage = STRLOG_Success + success.ToString();

            if (success == false)
            {
                executeCommandInfo.errorMessage = errorMessage;
                logMessage += Logfile.STRLOG_Spacer + STRLOG_ErrorMessage + errorMessage;
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(executeCommandInfo);
        }
        //-------------------------------------------------------------------------------------------------//

        public override string ExecuteXmlRequest(string xmlRequest)
        {
            string strXmlResponse = string.Empty;

            const string STRLOG_MethodName = "ExecuteXmlRequest";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            EquipmentEngine equipmentEngine = (EquipmentEngine)this.labEquipmentEngine;

            try
            {
                bool        success      = true;
                string      errorMessage = string.Empty;
                CommandInfo commandInfo  = null;
                CommandInfo resultInfo   = null;

                //
                // Create the XML response
                //
                XmlDocument xmlResponseDocument = new XmlDocument();
                XmlElement  xmlElement          = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_Response);
                xmlResponseDocument.AppendChild(xmlElement);

                //
                // Add success of command execution and update later
                //
                xmlElement           = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_RspSuccess);
                xmlElement.InnerText = success.ToString();
                xmlResponseDocument.DocumentElement.AppendChild(xmlElement);

                //
                // Parse XML request for the command
                //
                XmlDocument xmlRequestDocument = new XmlDocument();
                xmlRequestDocument.LoadXml(xmlRequest);
                XmlNode xmlRequestNode = XmlUtilities.GetXmlRootNode(xmlRequestDocument, Engine.Consts.STRXML_Request);
                string  strCommand     = XmlUtilities.GetXmlValue(xmlRequestNode, Engine.Consts.STRXML_Command, false);

                NonExecuteCommands nonExecuteCommand = (NonExecuteCommands)(-1);
                ExecuteCommands    executeCommand    = (ExecuteCommands)(-1);
                try
                {
                    //
                    // Try to convert to a non-execute command type that doesn't require powerdown to be suspended
                    //
                    nonExecuteCommand = (NonExecuteCommands)Enum.Parse(typeof(NonExecuteCommands), strCommand);
                    Logfile.Write(STRLOG_Command + nonExecuteCommand.ToString());
                }
                catch
                {
                    try
                    {
                        //
                        // Try to convert to an execute command type that does require powerdown to be suspended
                        //
                        executeCommand = (ExecuteCommands)Enum.Parse(typeof(ExecuteCommands), strCommand);
                        Logfile.Write(STRLOG_Command + executeCommand.ToString());

                        //
                        // Check that powerdown has been suspended before executing the command
                        //
                        if (this.labEquipmentEngine.IsPowerdownSuspended == false)
                        {
                            //
                            // Suspend the powerdown before executing the command
                            //
                            this.labEquipmentEngine.SuspendPowerdown();
                        }
                    }
                    catch
                    {
                        //
                        // Unknown command
                        //
                        success      = false;
                        errorMessage = STRERR_UnknownCommand + strCommand;
                    }
                }

                if (success == true && nonExecuteCommand != (NonExecuteCommands)(-1))
                {
                    //
                    // Process the non-execute command
                    //
                    switch (nonExecuteCommand)
                    {
                    case NonExecuteCommands.GetExecutionTime:
                        //
                        // Get specification in XML format from request
                        //
                        string xmlSpecification = XmlUtilities.GetXmlValue(xmlRequestNode, Consts.STRXML_ReqSpecification, false);

                        //
                        // Get the time to execute the specified setup
                        //
                        int executionTime = equipmentEngine.GetExecutionTime(xmlSpecification);

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspExecutionTime);
                        xmlElement.InnerText = executionTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetExecutionStatus:
                        //
                        // Get the execution status
                        //
                        DriverMachine.ExecutionStatus executionStatus = equipmentEngine.GetExecutionStatus();

                        //
                        // Add the execution status to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspExecutionStatus);
                        xmlElement.InnerText = executionStatus.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);

                        //
                        // Get the execution time remaining
                        //
                        int executionTimeRemaining = equipmentEngine.GetExecutionTimeRemaining();

                        //
                        // Add the execution status to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspExecutionTimeRemaining);
                        xmlElement.InnerText = executionTimeRemaining.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetExecutionResultStatus:
                        //
                        // Get the execution result status
                        //
                        DriverMachine.ExecutionStatus executionResultStatus = equipmentEngine.GetExecutionResultStatus();

                        //
                        // Add the execution result status to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspExecutionResultStatus);
                        xmlElement.InnerText = executionResultStatus.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetExecutionResults:
                        //
                        // Get the execution results
                        //
                        string executionResults = equipmentEngine.GetExecutionResults();

                        //
                        // Add the execution status to the response
                        //
                        xmlElement          = xmlResponseDocument.CreateElement(Consts.STRXML_RspExecutionResults);
                        xmlElement.InnerXml = executionResults;
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;
                    }
                }
                else if (success == true && executeCommand != (ExecuteCommands)(-1))
                {
                    //
                    // Only one execute command allowed at a time
                    //
                    lock (this.managerLock)
                    {
                        //
                        // Create an instance of the command info ready to fill in
                        //
                        commandInfo = new CommandInfo(executeCommand);

                        //
                        // Process the execute command
                        //
                        switch (executeCommand)
                        {
                        case ExecuteCommands.StartExecution:
                            //
                            // Get specification in XML format from request
                            //
                            string xmlSpecification = XmlUtilities.GetXmlValue(xmlRequestNode, Consts.STRXML_ReqSpecification, false);

                            //
                            // Start execution with the given specification
                            //
                            commandInfo.parameters = new object[] { xmlSpecification };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;
                        }

                        success      = resultInfo.success;
                        errorMessage = resultInfo.errorMessage;
                    }
                }

                //
                // Update success of command execution
                //
                XmlNode xmlResponseNode = XmlUtilities.GetXmlRootNode(xmlResponseDocument, Engine.Consts.STRXML_Response);
                XmlUtilities.SetXmlValue(xmlResponseNode, Engine.Consts.STRXML_RspSuccess, success.ToString(), false);
                if (success == false)
                {
                    //
                    // Create error response
                    //
                    xmlElement           = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_RspErrorMessage);
                    xmlElement.InnerText = errorMessage;
                    xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                }
                strXmlResponse = xmlResponseDocument.InnerXml;
            }
            catch (ArgumentException)
            {
                //
                // Unknown command so pass to base class to process
                //
                strXmlResponse = base.ExecuteXmlRequest(xmlRequest);
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName);

            return(strXmlResponse);
        }
        //-------------------------------------------------------------------------------------------------//

        public override ExecuteCommandInfo ProcessCommand(ExecuteCommandInfo executeCommandInfo)
        {
            const string STRLOG_MethodName = "ProcessCommand";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            CommandInfo commandInfo = (CommandInfo)executeCommandInfo;

            bool   success      = true;
            string errorMessage = null;

            try
            {
                //
                // Process the execute command
                //
                ExecuteCommands executeCommand = (ExecuteCommands)commandInfo.command;

                switch (executeCommand)
                {
                case ExecuteCommands.SetTubeDistance:

                    //
                    // Set tube distance
                    //
                    int tubeDistance = (int)commandInfo.parameters[0];
                    if ((success = this.flexMotion.SetTubeDistance(tubeDistance)) == false)
                    {
                        errorMessage = this.flexMotion.GetLastError();
                    }
                    break;

                case ExecuteCommands.SetSourceLocation:

                    //
                    // Set source location
                    //
                    char sourceLocation = (char)commandInfo.parameters[0];
                    if ((success = this.flexMotion.SetSourceLocation(sourceLocation)) == false)
                    {
                        errorMessage = this.flexMotion.GetLastError();
                    }
                    break;

                case ExecuteCommands.SetAbsorberLocation:

                    //
                    // Set absorber location
                    //
                    char absorberLocation = (char)commandInfo.parameters[0];
                    if ((success = this.flexMotion.SetAbsorberLocation(absorberLocation)) == false)
                    {
                        errorMessage = this.flexMotion.GetLastError();
                    }
                    break;

                case ExecuteCommands.GetCaptureData:

                    //
                    // Get duration from parameters
                    //
                    int duration = (int)commandInfo.parameters[0];

                    //
                    // Get radiation count
                    //
                    int count = -1;
                    if (this.radiationCounterType == RadiationCounterTypes.ST360)
                    {
                        int[] counts = new int[1];
                        if (this.st360Counter.CaptureData(duration, counts) == true)
                        {
                            count = counts[0];
                        }
                    }
                    else if (this.radiationCounterType == RadiationCounterTypes.Physics)
                    {
                        count = this.physicsCounter.CaptureData(duration);
                    }

                    //
                    // Add radiation count to results
                    //
                    commandInfo.results = new object[] { count };
                    break;

                case ExecuteCommands.WriteLcdLine:

                    //
                    // Get LCD line number from request
                    //
                    int lcdLineNo = (int)commandInfo.parameters[0];

                    //
                    // Get LCD message from request and 'URL Decode' to preserve spaces
                    //
                    string lcdMessage = (string)commandInfo.parameters[1];
                    lcdMessage = HttpUtility.UrlDecode(lcdMessage);

                    //
                    // Write message to LCD
                    //
                    if ((success = this.serialLcd.WriteLine(lcdLineNo, lcdMessage)) == false)
                    {
                        errorMessage = this.serialLcd.GetLastError();
                    }
                    break;

                default:

                    //
                    // Unknown command
                    //
                    errorMessage = STRERR_UnknownCommand + executeCommand.ToString();
                    success      = false;
                    break;
                }
            }
            catch (Exception ex)
            {
                success      = false;
                errorMessage = ex.Message;
            }

            //
            // Update success of command execution
            //
            executeCommandInfo.success = success;

            string logMessage = STRLOG_Success + success.ToString();

            if (success == false)
            {
                executeCommandInfo.errorMessage = errorMessage;
                logMessage += Logfile.STRLOG_Spacer + STRLOG_ErrorMessage + errorMessage;
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(executeCommandInfo);
        }
        //-------------------------------------------------------------------------------------------------//

        public override string ExecuteXmlRequest(string xmlRequest)
        {
            string strXmlResponse = string.Empty;

            const string STRLOG_MethodName = "ExecuteXmlRequest";

            Logfile.WriteCalled(this.logLevel, STRLOG_ClassName, STRLOG_MethodName);

            EquipmentEngine equipmentEngine = (EquipmentEngine)this.labEquipmentEngine;

            try
            {
                bool        success      = true;
                string      errorMessage = string.Empty;
                CommandInfo commandInfo  = null;
                CommandInfo resultInfo   = null;

                //
                // Create the XML response
                //
                XmlDocument xmlResponseDocument = new XmlDocument();
                XmlElement  xmlElement          = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_Response);
                xmlResponseDocument.AppendChild(xmlElement);

                //
                // Add success of command execution and update later
                //
                xmlElement           = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_RspSuccess);
                xmlElement.InnerText = success.ToString();
                xmlResponseDocument.DocumentElement.AppendChild(xmlElement);

                //
                // Parse XML request for the command
                //
                XmlDocument xmlRequestDocument = new XmlDocument();
                xmlRequestDocument.LoadXml(xmlRequest);
                XmlNode xmlRequestNode = XmlUtilities.GetXmlRootNode(xmlRequestDocument, Engine.Consts.STRXML_Request);
                string  strCommand     = XmlUtilities.GetXmlValue(xmlRequestNode, Engine.Consts.STRXML_Command, false);

                NonExecuteCommands nonExecuteCommand = (NonExecuteCommands)(-1);
                ExecuteCommands    executeCommand    = (ExecuteCommands)(-1);
                try
                {
                    //
                    // Try to convert to a non-execute command type that doesn't require powerdown to be suspended
                    //
                    nonExecuteCommand = (NonExecuteCommands)Enum.Parse(typeof(NonExecuteCommands), strCommand);
                    Logfile.Write(this.logLevel, STRLOG_Command + nonExecuteCommand.ToString());
                }
                catch
                {
                    try
                    {
                        //
                        // Try to convert to an execute command type that does require powerdown to be suspended
                        //
                        executeCommand = (ExecuteCommands)Enum.Parse(typeof(ExecuteCommands), strCommand);
                        Logfile.Write(this.logLevel, STRLOG_Command + executeCommand.ToString());

                        //
                        // Check that powerdown has been suspended before executing the command
                        //
                        if (this.labEquipmentEngine.IsPowerdownSuspended == false)
                        {
                            //
                            // Suspend the powerdown before executing the command
                            //
                            this.labEquipmentEngine.SuspendPowerdown();
                        }
                    }
                    catch
                    {
                        //
                        // Unknown command
                        //
                        success      = false;
                        errorMessage = STRERR_UnknownCommand + strCommand;
                    }
                }

                if (success == true && nonExecuteCommand != (NonExecuteCommands)(-1))
                {
                    //
                    // Process the non-execute command
                    //
                    switch (nonExecuteCommand)
                    {
                    case NonExecuteCommands.GetResetACDriveTime:

                        //
                        // Get the time to reset the AC drive
                        //
                        int resetACDriveTime = equipmentEngine.GetResetACDriveTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspResetACDriveTime);
                        xmlElement.InnerText = resetACDriveTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetConfigureACDriveTime:

                        //
                        // Get the time to configure the AC drive
                        //
                        int configureACDriveTime = equipmentEngine.GetConfigureACDriveTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspConfigureACDriveTime);
                        xmlElement.InnerText = configureACDriveTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetStartACDriveTime:

                        //
                        // Get the time to start the AC drive
                        //
                        int startACDriveTime = equipmentEngine.GetStartACDriveTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspStartACDriveTime);
                        xmlElement.InnerText = startACDriveTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetStopACDriveTime:

                        //
                        // Get the time to stop the AC drive
                        //
                        int stopACDriveTime = equipmentEngine.GetStopACDriveTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspStopACDriveTime);
                        xmlElement.InnerText = stopACDriveTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetResetDCDriveMutTime:

                        //
                        // Get the time to reset the DC drive
                        //
                        int resetDCDriveMutTime = equipmentEngine.GetResetDCDriveMutTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspResetDCDriveMutTime);
                        xmlElement.InnerText = resetDCDriveMutTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetConfigureDCDriveMutTime:

                        //
                        // Get the time to configure the DC drive
                        //
                        int configureDCDriveMutTime = equipmentEngine.GetConfigureDCDriveMutTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspConfigureDCDriveMutTime);
                        xmlElement.InnerText = configureDCDriveMutTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetStartDCDriveMutTime:

                        //
                        // Get DC drive mode from request
                        //
                        string strDCDriveMutMode = XmlUtilities.GetXmlValue(xmlRequestNode, Consts.STRXML_ReqDCDriveMutMode, false);
                        RedLion.DCDriveMutModes dcDriveMutMode = (RedLion.DCDriveMutModes)Enum.Parse(typeof(RedLion.DCDriveMutModes), strDCDriveMutMode);

                        //
                        // Get the time to start the DC drive for the specified mode
                        //
                        int startDCDriveMutTime = equipmentEngine.GetStartDCDriveMutTime(dcDriveMutMode);

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspStartDCDriveMutTime);
                        xmlElement.InnerText = startDCDriveMutTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetStopDCDriveMutTime:

                        //
                        // Get the time to stop the DC drive
                        //
                        int stopDCDriveMutTime = equipmentEngine.GetStopDCDriveMutTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspStopDCDriveMutTime);
                        xmlElement.InnerText = stopDCDriveMutTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetSetSpeedACDriveTime:

                        //
                        // Get the time to set the speed of the AC drive
                        //
                        int setSpeedACDriveTime = equipmentEngine.GetSetSpeedACDriveTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspSetSpeedACDriveTime);
                        xmlElement.InnerText = setSpeedACDriveTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetSetSpeedDCDriveMutTime:

                        //
                        // Get the time to set the speed of the DC drive
                        //
                        int setSpeedDCDriveMutTime = equipmentEngine.GetSetSpeedDCDriveMutTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspSetSpeedDCDriveMutTime);
                        xmlElement.InnerText = setSpeedDCDriveMutTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetSetTorqueDCDriveMutTime:

                        //
                        // Get the time to set the torque of the DC drive
                        //
                        int setTorqueDCDriveMutTime = equipmentEngine.GetSetTorqueDCDriveMutTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspSetTorqueDCDriveMutTime);
                        xmlElement.InnerText = setTorqueDCDriveMutTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetSetFieldDCDriveMutTime:

                        //
                        // Get the time to set the field of the DC drive
                        //
                        int setFieldDCDriveMutTime = equipmentEngine.GetSetFieldDCDriveMutTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspSetFieldDCDriveMutTime);
                        xmlElement.InnerText = setFieldDCDriveMutTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetTakeMeasurementTime:

                        //
                        // Get the time to take a measurement
                        //
                        int takeMeasurementTime = equipmentEngine.GetTakeMeasurementTime();

                        //
                        // Add the time to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspTakeMeasurementTime);
                        xmlElement.InnerText = takeMeasurementTime.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetACDriveInfo:

                        //
                        // Get the info about the AC drive
                        //
                        RedLion.ACDriveInfo aCDriveInfo = equipmentEngine.GetACDriveInfo();

                        //
                        // Add the info to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspMinSpeed);
                        xmlElement.InnerText = aCDriveInfo.minSpeed.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspMaxSpeed);
                        xmlElement.InnerText = aCDriveInfo.maxSpeed.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;

                    case NonExecuteCommands.GetDCDriveMutInfo:

                        //
                        // Get the info about the AC drive
                        //
                        RedLion.DCDriveMutInfo dCDriveMutInfo = equipmentEngine.GetDCDriveMutInfo();

                        //
                        // Add the info to the response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspMinSpeed);
                        xmlElement.InnerText = dCDriveMutInfo.minSpeed.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspMaxSpeed);
                        xmlElement.InnerText = dCDriveMutInfo.maxSpeed.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspDefaultField);
                        xmlElement.InnerText = dCDriveMutInfo.defaultField.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspDefaultTorque);
                        xmlElement.InnerText = dCDriveMutInfo.defaultTorque.ToString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;
                    }
                }
                else if (success == true && executeCommand != (ExecuteCommands)(-1))
                {
                    //
                    // Only one execute command allowed at a time
                    //
                    lock (this.managerLock)
                    {
                        //
                        // Create an instance of the command info ready to fill in
                        //
                        commandInfo = new CommandInfo(executeCommand);

                        //
                        // Process the execute command
                        //
                        switch (executeCommand)
                        {
                        case ExecuteCommands.CreateConnection:

                            //
                            // Create a connection to the RedLion controller
                            //
                            resultInfo = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.CloseConnection:

                            //
                            // Close the connection to the RedLion controller
                            //
                            resultInfo = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.ResetACDrive:

                            //
                            // Reset the AC drive controller
                            //
                            resultInfo = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.ConfigureACDrive:

                            //
                            // Get AC drive configuration from request
                            //
                            string strACDriveConfig = XmlUtilities.GetXmlValue(xmlRequestNode, Consts.STRXML_ReqACDriveConfig, false);
                            RedLion.ACDriveConfigs aCDriveConfig = (RedLion.ACDriveConfigs)Enum.Parse(typeof(RedLion.ACDriveConfigs), strACDriveConfig);

                            //
                            // Configure the AC drive with the specified configuration
                            //
                            commandInfo.parameters = new object[] { aCDriveConfig };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.StartACDrive:

                            //
                            // Start the AC drive
                            //
                            resultInfo = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.StopACDrive:

                            //
                            // Stop the AC drive
                            //
                            resultInfo = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.ResetDCDriveMut:

                            //
                            // Reset the DC drive
                            //
                            resultInfo = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.ConfigureDCDriveMut:

                            //
                            // Get DC drive configuration from request
                            //
                            string strDCDriveMutConfig = XmlUtilities.GetXmlValue(xmlRequestNode, Consts.STRXML_ReqDCDriveMutConfig, false);
                            RedLion.DCDriveMutConfigs dcDriveMutConfig = (RedLion.DCDriveMutConfigs)Enum.Parse(typeof(RedLion.DCDriveMutConfigs), strDCDriveMutConfig);

                            //
                            // Configure the AC drive with the specified configuration
                            //
                            commandInfo.parameters = new object[] { dcDriveMutConfig };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.StartDCDriveMut:

                            //
                            // Get DC drive mode from request
                            //
                            string strDCDriveMutMode = XmlUtilities.GetXmlValue(xmlRequestNode, Consts.STRXML_ReqDCDriveMutMode, false);
                            RedLion.DCDriveMutModes dcDriveMutMode = (RedLion.DCDriveMutModes)Enum.Parse(typeof(RedLion.DCDriveMutModes), strDCDriveMutMode);

                            //
                            // Start the DC drive
                            //
                            commandInfo.parameters = new object[] { dcDriveMutMode };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.StopDCDriveMut:

                            //
                            // Stop the DC drive
                            //
                            resultInfo = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.SetSpeedACDrive:

                            //
                            // Get speed from request
                            //
                            int speedACDrive = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqSpeedACDrive, 0);

                            //
                            // Set the speed of the AC drive
                            //
                            commandInfo.parameters = new object[] { speedACDrive };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.SetSpeedDCDriveMut:

                            //
                            // Get speed from request
                            //
                            int speedDCDriveMut = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqSpeedDCDriveMut, 0);

                            //
                            // Set the speed of the DC drive
                            //
                            commandInfo.parameters = new object[] { speedDCDriveMut };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.SetTorqueDCDriveMut:

                            //
                            // Get torque from request
                            //
                            int torqueDCDriveMut = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqTorqueDCDriveMut, 0);

                            //
                            // Set the torque of the DC drive
                            //
                            commandInfo.parameters = new object[] { torqueDCDriveMut };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.SetFieldDCDriveMut:

                            //
                            // Get torque from request
                            //
                            int fieldDCDriveMut = XmlUtilities.GetIntValue(xmlRequestNode, Consts.STRXML_ReqFieldDCDriveMut, 100);

                            //
                            // Set the field of the DC drive
                            //
                            commandInfo.parameters = new object[] { fieldDCDriveMut };
                            resultInfo             = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            break;

                        case ExecuteCommands.TakeMeasurement:

                            //
                            // Take a measurement
                            //
                            resultInfo = (CommandInfo)equipmentEngine.ExecuteCommand((ExecuteCommandInfo)commandInfo);
                            if (commandInfo.success == true)
                            {
                                //
                                // Get measurement values from the result
                                //
                                int   speed        = (int)commandInfo.results[0];
                                int   voltage      = (int)commandInfo.results[1];
                                float fieldCurrent = (float)commandInfo.results[2];
                                int   load         = (int)commandInfo.results[3];

                                //
                                // Add the measurement values to the response
                                //
                                xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspSpeed);
                                xmlElement.InnerText = speed.ToString();
                                xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                                xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspVoltage);
                                xmlElement.InnerText = voltage.ToString();
                                xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                                xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspFieldCurrent);
                                xmlElement.InnerText = fieldCurrent.ToString();
                                xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                                xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspLoad);
                                xmlElement.InnerText = load.ToString();
                                xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                            }
                            break;
                        }

                        success      = resultInfo.success;
                        errorMessage = resultInfo.errorMessage;
                    }
                }

                //
                // Update success of command execution
                //
                XmlNode xmlResponseNode = XmlUtilities.GetXmlRootNode(xmlResponseDocument, Engine.Consts.STRXML_Response);
                XmlUtilities.SetXmlValue(xmlResponseNode, Engine.Consts.STRXML_RspSuccess, success.ToString(), false);
                if (success == false)
                {
                    //
                    // Create error response
                    //
                    xmlElement           = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_RspErrorMessage);
                    xmlElement.InnerText = errorMessage;
                    xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                }
                strXmlResponse = xmlResponseDocument.InnerXml;
            }
            catch (ArgumentException)
            {
                //
                // Unknown command so pass to base class to process
                //
                strXmlResponse = base.ExecuteXmlRequest(xmlRequest);
            }
            catch (Exception ex)
            {
                Logfile.Write(ex.Message);
            }

            Logfile.WriteCompleted(this.logLevel, STRLOG_ClassName, STRLOG_MethodName);

            return(strXmlResponse);
        }
示例#21
0
        /// <summary>
        /// Deletes objects based on an expression
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="criteria"></param>
        public int DeleteObjects <T>(Expression <Func <T, bool> > criteria)
        {
            IDbCommand command = Connection.CommandGenerator.GetDeleteCommand <T>(criteria);

            return(ExecuteCommands.ExecuteCommand(command, Connection));
        }
        //-------------------------------------------------------------------------------------------------//

        public override ExecuteCommandInfo ProcessCommand(ExecuteCommandInfo executeCommandInfo)
        {
            const string STRLOG_MethodName = "ProcessCommand";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            CommandInfo commandInfo = (CommandInfo)executeCommandInfo;

            bool   success      = true;
            string errorMessage = null;

            try
            {
                //
                // Process the execute command
                //
                ExecuteCommands executeCommand = (ExecuteCommands)commandInfo.command;

                switch (executeCommand)
                {
                case ExecuteCommands.CreateConnection:

                    //
                    // Create a connection to the RedLion controller
                    //
                    if ((success = this.redLion.CreateConnection()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.CloseConnection:

                    //
                    // Close the connection to the RedLion controller
                    //
                    if ((success = this.redLion.CloseConnection()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.ResetACDrive:

                    //
                    // Reset the AC drive controller
                    //
                    if ((success = this.redLion.ResetACDrive()) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.ConfigureACDrive:

                    //
                    // Get AC drive configuration from parameters
                    //
                    RedLion.ACDriveConfigs acDriveConfig = (RedLion.ACDriveConfigs)commandInfo.parameters[0];

                    //
                    // Configure the AC drive
                    //
                    if ((success = this.redLion.ConfigureACDrive(acDriveConfig)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.StartACDrive:

                    //
                    // Get AC drive mode from parameters
                    //
                    RedLion.ACDriveModes acDriveMode = (RedLion.ACDriveModes)commandInfo.parameters[0];

                    //
                    // Start the AC drive
                    //
                    if ((success = this.redLion.StartACDrive(acDriveMode)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.StopACDrive:

                    //
                    // Get AC drive mode from parameters
                    //
                    acDriveMode = (RedLion.ACDriveModes)commandInfo.parameters[0];

                    //
                    // Stop the AC drive
                    //
                    if ((success = this.redLion.StopACDrive(acDriveMode)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    break;

                case ExecuteCommands.TakeMeasurement:

                    //
                    // Take a measurement
                    //
                    RedLion.Measurements measurement = new RedLion.Measurements();
                    if ((success = this.redLion.TakeMeasurement(ref measurement)) == false)
                    {
                        errorMessage = this.redLion.GetLastError();
                    }
                    else
                    {
                        //
                        // Add the measurement values to results - ensure the order of the measurement values is the
                        // same as in EquipmentManager.cs
                        //
                        commandInfo.results = new object[] {
                            measurement.voltageMut,
                            measurement.currentMut,
                            measurement.powerFactorMut,
                            measurement.voltageVsd,
                            measurement.currentVsd,
                            measurement.powerFactorVsd,
                            measurement.speed,
                            measurement.torque
                        };
                    }
                    break;

                default:

                    //
                    // Unknown command
                    //
                    errorMessage = STRERR_UnknownCommand + executeCommand.ToString();
                    success      = false;
                    break;
                }
            }
            catch (Exception ex)
            {
                success      = false;
                errorMessage = ex.Message;
            }

            //
            // Update success of command execution
            //
            executeCommandInfo.success = success;

            string logMessage = STRLOG_Success + success.ToString();

            if (success == false)
            {
                executeCommandInfo.errorMessage = errorMessage;
                logMessage += Logfile.STRLOG_Spacer + STRLOG_ErrorMessage + errorMessage;
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(executeCommandInfo);
        }
        //-------------------------------------------------------------------------------------------------//

        public virtual string ExecuteXmlRequest(string xmlRequest)
        {
            string strXmlResponse = string.Empty;

            const string STRLOG_MethodName = "ExecuteXmlRequest";

            Logfile.WriteCalled(this.logLevel, STRLOG_ClassName, STRLOG_MethodName);

            try
            {
                bool               success            = true;
                string             errorMessage       = string.Empty;
                ExecuteCommandInfo executeCommandInfo = null;
                ExecuteCommandInfo executeResultInfo  = null;

                //
                // Create the XML response
                //
                XmlDocument xmlResponseDocument = new XmlDocument();
                XmlElement  xmlElement          = xmlResponseDocument.CreateElement(Consts.STRXML_Response);
                xmlResponseDocument.AppendChild(xmlElement);

                //
                // Add success of command execution and update later
                //
                xmlElement           = xmlResponseDocument.CreateElement(Consts.STRXML_RspSuccess);
                xmlElement.InnerText = success.ToString();
                xmlResponseDocument.DocumentElement.AppendChild(xmlElement);

                //
                // Parse XML request for the command
                //
                XmlDocument xmlRequestDocument = new XmlDocument();
                xmlRequestDocument.LoadXml(xmlRequest);
                XmlNode xmlRequestNode = XmlUtilities.GetXmlRootNode(xmlRequestDocument, Consts.STRXML_Request);
                string  strCommand     = XmlUtilities.GetXmlValue(xmlRequestNode, Consts.STRXML_Command, false);

                NonExecuteCommands nonExecuteCommand = (NonExecuteCommands)(-1);
                ExecuteCommands    executeCommand    = (ExecuteCommands)(-1);
                try
                {
                    //
                    // Try to convert to a non-execute command type that doesn't require powerdown to be suspended
                    //
                    nonExecuteCommand = (NonExecuteCommands)Enum.Parse(typeof(NonExecuteCommands), strCommand);
                    Logfile.Write(STRLOG_Command + nonExecuteCommand.ToString());
                }
                catch
                {
                    try
                    {
                        //
                        // Try to convert to an execute command type that does require powerdown to be suspended
                        //
                        executeCommand = (ExecuteCommands)Enum.Parse(typeof(ExecuteCommands), strCommand);
                        Logfile.Write(STRLOG_Command + executeCommand.ToString());

                        //
                        // Check that powerdown has been suspended before executing the command
                        //
                        if (this.labEquipmentEngine.IsPowerdownSuspended == false)
                        {
                            //
                            // Unable to execute the command
                            //
                            success      = false;
                            errorMessage = STRERR_PowerdownMustBeSuspended + executeCommand.ToString();
                        }
                    }
                    catch
                    {
                        //
                        // Unknown command
                        //
                        success      = false;
                        errorMessage = STRERR_UnknownCommand + strCommand;
                    }
                }

                if (success == true && nonExecuteCommand != (NonExecuteCommands)(-1))
                {
                    //
                    // Process the non-execute command
                    //
                    switch (nonExecuteCommand)
                    {
                    case NonExecuteCommands.GetTime:

                        //
                        // Add time to response
                        //
                        xmlElement           = xmlResponseDocument.CreateElement("Time");
                        xmlElement.InnerText = DateTime.Now.ToShortTimeString();
                        xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                        break;
                    }
                }
                else if (success == true && executeCommand != (ExecuteCommands)(-1))
                {
                    //
                    // Only one execute command allowed at a time
                    //
                    lock (this.managerLock)
                    {
                        //
                        // Create an instance of the command info ready to fill in
                        //
                        executeCommandInfo = new ExecuteCommandInfo(executeCommand);

                        //
                        // Process the execute command
                        //
                        switch (executeCommand)
                        {
                        case ExecuteCommands.SetTime:

                            //
                            // Pretend to change the time
                            //
                            executeCommandInfo.parameters = new object[] { DateTime.Now };
                            executeCommandInfo.timeout    = 20;
                            executeResultInfo             = this.labEquipmentEngine.ExecuteCommand(executeCommandInfo);
                            if (executeResultInfo.success == true)
                            {
                                DateTime dateTime = (DateTime)executeCommandInfo.results[0];
                            }
                            break;
                        }
                    }
                }

                //
                // Update success of command execution
                //
                XmlNode xmlResponseNode = XmlUtilities.GetXmlRootNode(xmlResponseDocument, Engine.Consts.STRXML_Response);
                XmlUtilities.SetXmlValue(xmlResponseNode, Engine.Consts.STRXML_RspSuccess, executeResultInfo.success.ToString(), false);
                if (success == false)
                {
                    //
                    // Create error response
                    //
                    xmlElement           = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_RspErrorMessage);
                    xmlElement.InnerText = executeResultInfo.errorMessage;
                    xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                }
                strXmlResponse = xmlResponseDocument.InnerXml;
            }
            catch (Exception ex)
            {
                Logfile.Write(ex.Message);
            }

            Logfile.WriteCompleted(this.logLevel, STRLOG_ClassName, STRLOG_MethodName);

            return(strXmlResponse);
        }
示例#24
0
 /// <summary>
 /// Executes a command on the data store
 /// </summary>
 /// <param name="command">The command to execute</param>
 public virtual int ExecuteCommand(IDbCommand command)
 {
     return(ExecuteCommands.ExecuteCommand(command, Connection));
 }
示例#25
0
 /// <summary>
 /// Executes a command
 /// </summary>
 /// <param name="command">The command to execute</param>
 /// <returns></returns>
 public virtual IQueryData ExecuteQuery(IDbCommand command)
 {
     return(ExecuteCommands.ExecuteCommandQuery(command, Connection));
 }
示例#26
0
        //-------------------------------------------------------------------------------------------------//

        public override string ExecuteXmlRequest(string xmlRequest)
        {
            string strXmlResponse = string.Empty;

            const string STRLOG_MethodName = "ExecuteXmlRequest";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            EquipmentEngine equipmentEngine = (EquipmentEngine)this.labEquipmentEngine;

            try
            {
                bool        success      = true;
                string      errorMessage = string.Empty;
                CommandInfo commandInfo  = null;
                CommandInfo resultInfo   = null;

                //
                // Create the XML response
                //
                XmlDocument xmlResponseDocument = new XmlDocument();
                XmlElement  xmlElement          = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_Response);
                xmlResponseDocument.AppendChild(xmlElement);

                //
                // Add success of command execution and update later
                //
                xmlElement           = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_RspSuccess);
                xmlElement.InnerText = success.ToString();
                xmlResponseDocument.DocumentElement.AppendChild(xmlElement);

                //
                // Parse XML request for the command
                //
                XmlDocument xmlRequestDocument = new XmlDocument();
                xmlRequestDocument.LoadXml(xmlRequest);
                XmlNode xmlRequestNode = XmlUtilities.GetXmlRootNode(xmlRequestDocument, Engine.Consts.STRXML_Request);
                string  strCommand     = XmlUtilities.GetXmlValue(xmlRequestNode, Engine.Consts.STRXML_Command, false);

                NonExecuteCommands nonExecuteCommand = (NonExecuteCommands)(-1);
                ExecuteCommands    executeCommand    = (ExecuteCommands)(-1);
                try
                {
                    //
                    // Try to convert to a non-execute command type that doesn't require powerdown to be suspended
                    //
                    nonExecuteCommand = (NonExecuteCommands)Enum.Parse(typeof(NonExecuteCommands), strCommand);
                    Logfile.Write(STRLOG_Command + nonExecuteCommand.ToString());
                }
                catch
                {
                    try
                    {
                        //
                        // Try to convert to an execute command type that does require powerdown to be suspended
                        //
                        executeCommand = (ExecuteCommands)Enum.Parse(typeof(ExecuteCommands), strCommand);
                        Logfile.Write(STRLOG_Command + executeCommand.ToString());

                        //
                        // Check that powerdown has been suspended before executing the command
                        //
                        if (this.labEquipmentEngine.IsPowerdownSuspended == false)
                        {
                            //
                            // Suspend the powerdown before executing the command
                            //
                            this.labEquipmentEngine.SuspendPowerdown();
                        }
                    }
                    catch
                    {
                        //
                        // Unknown command
                        //
                        success      = false;
                        errorMessage = STRERR_UnknownCommand + strCommand;
                    }
                }

                if (success == true && nonExecuteCommand != (NonExecuteCommands)(-1))
                {
                    //
                    // Process the non-execute command
                    //
                    switch (nonExecuteCommand)
                    {
                    case NonExecuteCommands.GetTimeToDoSomething:
                        // Remove this command in your implementation
                        break;
                    }
                }
                else if (success == true && executeCommand != (ExecuteCommands)(-1))
                {
                    //
                    // Only one execute command allowed at a time
                    //
                    lock (this.managerLock)
                    {
                        //
                        // Create an instance of the command info ready to fill in
                        //
                        commandInfo = new CommandInfo(executeCommand);

                        //
                        // Process the execute command
                        //
                        switch (executeCommand)
                        {
                        case ExecuteCommands.DoSomething:
                            // Remove this command in your implementation
                            break;
                        }

                        success      = resultInfo.success;
                        errorMessage = resultInfo.errorMessage;
                    }
                }

                //
                // Update success of command execution
                //
                XmlNode xmlResponseNode = XmlUtilities.GetXmlRootNode(xmlResponseDocument, Engine.Consts.STRXML_Response);
                XmlUtilities.SetXmlValue(xmlResponseNode, Engine.Consts.STRXML_RspSuccess, success.ToString(), false);
                if (success == false)
                {
                    //
                    // Create error response
                    //
                    xmlElement           = xmlResponseDocument.CreateElement(Engine.Consts.STRXML_RspErrorMessage);
                    xmlElement.InnerText = errorMessage;
                    xmlResponseDocument.DocumentElement.AppendChild(xmlElement);
                }
                strXmlResponse = xmlResponseDocument.InnerXml;
            }
            catch (ArgumentException)
            {
                //
                // Unknown command so pass to base class to process
                //
                strXmlResponse = base.ExecuteXmlRequest(xmlRequest);
            }
            catch (Exception ex)
            {
                Logfile.Write(ex.Message);
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName);

            return(strXmlResponse);
        }
        //-------------------------------------------------------------------------------------------------//

        public override ExecuteCommandInfo ProcessCommand(ExecuteCommandInfo executeCommandInfo)
        {
            const string STRLOG_MethodName = "ProcessCommand";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            CommandInfo commandInfo = (CommandInfo)executeCommandInfo;

            bool   success      = true;
            string errorMessage = null;

            try
            {
                //
                // Process the execute command
                //
                ExecuteCommands executeCommand = (ExecuteCommands)commandInfo.command;

                switch (executeCommand)
                {
                case ExecuteCommands.GetTimeOfDay:

                    //
                    // Get server URL from parameters
                    //
                    string serverUrl = (string)commandInfo.parameters[0];

                    //
                    // Get the time-of-day
                    //
                    DateTime dateTime = DateTime.MinValue;
                    if ((success = this.timeOfDay.GetTimeOfDay(serverUrl, ref dateTime)) == false)
                    {
                        errorMessage = this.timeOfDay.GetLastError();
                    }
                    else
                    {
                        //
                        // Add the measurement values to results
                        //
                        commandInfo.results = new object[] {
                            dateTime
                        };
                    }
                    break;

                default:

                    //
                    // Unknown command
                    //
                    errorMessage = STRERR_UnknownCommand + executeCommand.ToString();
                    success      = false;
                    break;
                }
            }
            catch (Exception ex)
            {
                success      = false;
                errorMessage = ex.Message;
            }

            //
            // Update success of command execution
            //
            executeCommandInfo.success = success;

            string logMessage = STRLOG_Success + success.ToString();

            if (success == false)
            {
                executeCommandInfo.errorMessage = errorMessage;
                logMessage += Logfile.STRLOG_Spacer + STRLOG_ErrorMessage + errorMessage;
            }

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(executeCommandInfo);
        }