// private methods private BsonValue GetParameterValue(FeatureContext context) { // allow environment variable to provide value in case authentication prevents use of getParameter command var environmentVariableName = "mongod." + _parameterName; var environmentVariableValue = Environment.GetEnvironmentVariable(environmentVariableName); if (environmentVariableValue != null) { return environmentVariableValue; } var command = new CommandDocument { { "getParameter", 1 }, { _parameterName, 1 } }; var commandOperation = new CommandOperation<CommandResult>( "admin", // databaseName new BsonBinaryReaderSettings(), // readerSettings new BsonBinaryWriterSettings(), // writerSettings command, QueryFlags.SlaveOk, null, // options null, // readPreference null, // serializationOptions BsonSerializer.LookupSerializer(typeof(CommandResult)) // resultSerializer ); var result = commandOperation.Execute(context.Connection); return result.Response[_parameterName]; }
private static bool MoveDirectory(string rootDirectory, string directoryNameEntry) { bool success = false; string sourceDirectory = Path.Combine(rootDirectory, directoryNameEntry); string destinationDirectory = Path.Combine(rootDirectory, _UnusedDirectoryName, directoryNameEntry.Substring(0, directoryNameEntry.LastIndexOf('\\'))); if (!Directory.Exists(destinationDirectory)) { Directory.CreateDirectory(destinationDirectory); } Console.WriteLine(" Directory \"{0}\" -> \"{1}\"", sourceDirectory, destinationDirectory); try { string command = "move \"" + sourceDirectory + "\" \"" + destinationDirectory + "\""; // Directory.Move(sourceDirectory, destinationDirectory); string currentDirectory = Directory.GetCurrentDirectory(); success = CommandOperation.RunCommand(currentDirectory, command, CommandOperation.DebugProgress.None, CommandOperation.CommandOutputDisplayType.StandardErrorOnly); } catch (Exception ex) { Console.WriteLine("Exception: Moving directory \"{0}\" to \"{1}\" = \"{2}\"", sourceDirectory, destinationDirectory, ex.ToString()); } return(success); }
/// <summary> /// Apply a command operation /// </summary> /// <param name="observed">observed operation</param> /// <param name="activator">command parameters</param> /// <returns>command operation</returns> public static CommandOperation DbCommand(this IObservableOperation observed, CommandActivator activator) { var cmd = new CommandOperation(activator); observed.Subscribe(cmd); return(cmd); }
public static int Promote(string pvcsArchivePathAndFilename, string fromPromotionGroup) { int error = WindowsErrorDefinition.Success; List <string> stdout = new List <string>(); List <string> stderr = new List <string>(); // Use the "-q" option to suppress questions string command = "vpromote -q -g" + fromPromotionGroup + " \"" + pvcsArchivePathAndFilename + "\""; bool success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(), command, 1, CommandOperation.DebugProgress.Enabled, CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError, stdout, stderr); if (!success) { Console.WriteLine("PvcsCommandOperation.Promote : Failed to Promote from Promotion Group \"{0}\" in PVCS Archive \"{1}\"", fromPromotionGroup, pvcsArchivePathAndFilename); error = WindowsErrorDefinition.InvalidFunction; } return(error); } // Promote
public static byte[] GetMessageBodyForOperation(Type type, CommandOperation oper) { byte[] Header = new byte[ipcDefines.NET_UPLOAD_HEADER_BYTES]; Header[ipcDefines.MessageHeader_Command_Pos] = (byte)oper; Header[ipcDefines.MessageHeader_CommandType_Pos] = (byte)GetCommandOperationType(type, oper); return(Header); }
} // GetArchivePromotionGroupNames public static int AssignPromotionGroup(string pvcsArchivePathAndFilename, string promotionGroup) { int error = WindowsErrorDefinition.Success; List <string> stdout = new List <string>(); List <string> stderr = new List <string>(); // Assign the Promotion Group to the tip revision string command = "vcs -q -g" + promotionGroup + " -r \"" + pvcsArchivePathAndFilename + "\""; bool success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(), command, 1, CommandOperation.DebugProgress.Enabled, CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError, stdout, stderr); if (!success) { Console.WriteLine("PvcsCommandOperation.AssignPromotionGroup : Failed to assign Promotion Group \"{0}\" to the tip of PVCS Archive \"{1}\"", promotionGroup, pvcsArchivePathAndFilename); error = WindowsErrorDefinition.InvalidFunction; } return(error); }
protected void RaiseOperationExecuted(ICommand item, CommandOperation operation) { if (OperationExecuted != null) { OperationExecuted(this, new OperationExecutionEventArgs(item, operation, stack.CanUndo, stack.CanRedo)); } }
/// <summary> /// Apply a command operation /// </summary> /// <param name="observed">observed operation</param> /// <param name="activator">command parameters</param> /// <returns>command operation</returns> public static CommandOperation DbCommand(this IObservableOperation observed, CommandActivator activator) { var cmd = new CommandOperation(activator, LogProvider.GetLogger(typeof(CommandOperation).ToString())); observed.Subscribe(cmd); return(cmd); }
// private methods private BsonValue GetParameterValue(FeatureContext context) { // allow environment variable to provide value in case authentication prevents use of getParameter command var environmentVariableName = "mongod." + _parameterName; var environmentVariableValue = Environment.GetEnvironmentVariable(environmentVariableName); if (environmentVariableValue != null) { return(environmentVariableValue); } var command = new CommandDocument { { "getParameter", 1 }, { _parameterName, 1 } }; var commandOperation = new CommandOperation <CommandResult>( "admin", // databaseName new BsonBinaryReaderSettings(), // readerSettings new BsonBinaryWriterSettings(), // writerSettings command, QueryFlags.SlaveOk, null, // options null, // readPreference null, // serializationOptions BsonSerializer.LookupSerializer(typeof(CommandResult)) // resultSerializer ); var result = commandOperation.Execute(context.Connection); return(result.Response[_parameterName]); }
public OperationExecutionEventArgs(ICommand item, CommandOperation action, bool hasUndoItems, bool hasRedoItems) : base() { CurrentItem = item; Action = action; HasUndoItems = hasUndoItems; HasRedoItems = hasRedoItems; }
internal CommandMessageReceivedEventArgs(CommandMessage message, string endpoint, string dsId, int invokeId) { DSId = dsId; Operation = message.Operation; Endpoint = endpoint; Message = message; InvokeId = invokeId; }
internal CommandMessageReceivedEventArgs(CommandMessage message, string endpoint, string dsId, int invokeId) { this.DsId = dsId; this.Operation = message.Operation; this.Endpoint = endpoint; this.Message = message; this.InvokeId = invokeId; }
public static byte[] GetHeaderForOperationParametrized(Type type, CommandOperation oper, int EntityId) { byte[] Header = new byte[ipcDefines.NET_UPLOAD_HEADER_BYTES]; Header[ipcDefines.MessageHeader_Command_Pos] = (byte)oper; Header[ipcDefines.MessageHeader_CommandType_Pos] = (byte)GetCommandOperationType(type, oper); Header[ipcDefines.MessageHeader_CommandParam_Pos] = GetCommandValueParam(type, oper, (byte)EntityId); return(Header); }
public static byte[] GetHeaderForOperationRegisterParametrized(CommandOperation oper, byte CfgType, int RegisterId) { byte[] Header = new byte[ipcDefines.NET_UPLOAD_HEADER_BYTES]; Header[ipcDefines.MessageHeader_Command_Pos] = (byte)oper; Header[ipcDefines.MessageHeader_CommandType_Pos] = (byte)CfgType; Header[ipcDefines.MessageHeader_Command_Reg_Low_Pos] = (byte)(RegisterId >> 8); Header[ipcDefines.MessageHeader_Command_Reg_High_Pos] = (byte)(RegisterId); return(Header); }
public void AddCommandArguments(string listIdentifier, string value, SelectListOperation op) { string opChar = (op == SelectListOperation.Add) ? "A" : "D"; string argString = string.Format("{0}{1}{2}{1}{3}", listIdentifier, Caret, value, opChar); this.CommandArgs = new object[] { argString }; this.Operation = CommandOperation.AddToList; }
public static bool CreateAndSwitchToBranch(string branchName, string rootWorkingDirectory, int indent, CommandOperation.DebugProgress debugProgress) { bool success = false; if (CheckedOutBranchIs(branchName, rootWorkingDirectory)) { // Already on the specified branch success = true; } else { // Create the branch List <string> standardOutput = new List <string>(); List <string> standardError = new List <string>(); string command = "git branch " + branchName; success = CommandOperation.RunMonitoredCommand(rootWorkingDirectory, command, indent, debugProgress, CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError, standardOutput, standardError); if (!success) { // Check that the error was a real error and not just that the branch already existed if (standardOutput.Count >= 1) { if (standardOutput[0].StartsWith("fatal: A branch named")) { Console.WriteLine("{0}The failure of the creation of branch \"{1}\" is not an error because a branch of that name already exists", ConsoleDisplay.Indent(indent), branchName); success = true; } } } if (success) { // Switch to the branch success = CheckOutBranch(branchName, rootWorkingDirectory, indent, debugProgress); } // Switch to the branch } // Create the branch if (success) { Console.WriteLine("{0}Staging to branch \"{1}\"", ConsoleDisplay.Indent(indent + 1), branchName); } else { Console.WriteLine("{0}*** Failed to switch to branch \"{1}\"", ConsoleDisplay.Indent(indent + 1), branchName); } return(success); } // CreateAndSwitchToBranch
private void InitOperation() { mInfoOperation = new InfoOperation(this); mObjectOperation = new ObjectOperation(this); mCommandOperation = new CommandOperation(this); mInfoOperation.Init(); mObjectOperation.Init(); mCommandOperation.Init(); }
/// <summary> /// Apply a command operation /// </summary> /// <param name="observed">observed operation</param> /// <param name="act">callback on command activator</param> /// <returns>command operation</returns> public static CommandOperation DbCommand(this IObservableOperation observed, Action <CommandActivator> act) { var activator = new CommandActivator(); act(activator); CommandOperation cmd = new CommandOperation(activator); observed.Subscribe(cmd); return(cmd); }
/// <summary> /// Carries out the specified action for the CommandSource's command as a RoutedCommand if possible, /// otherwise as a regular Command. /// </summary> /// <param name="parameter">The parameter to the ICommandSource.</param> /// <param name="commandSource">The ICommandSource being executed.</param> internal static void InvokeCommandSource(object parameter, object previewParameter, ICommandSource commandSource, CommandOperation operation) { ICommand command = commandSource.Command; if (command != null) { RoutedCommand routed = command as RoutedCommand; if (routed != null) { IInputElement target = commandSource.CommandTarget; if (target == null) { target = commandSource as IInputElement; } if (routed.CanExecute(parameter, target)) { //Debug.Assert(operation == CommandOperation.Execute, "We do not support Previewing RoutedCommands."); switch (operation) { case CommandOperation.Execute: routed.Execute(parameter, target); break; } } } else if (command.CanExecute(parameter)) { IPreviewCommand previewCommand; switch (operation) { case CommandOperation.Preview: previewCommand = command as IPreviewCommand; if (previewCommand != null) { previewCommand.Preview(previewParameter); } break; case CommandOperation.CancelPreview: previewCommand = command as IPreviewCommand; if (previewCommand != null) { previewCommand.CancelPreview(); } break; case CommandOperation.Execute: command.Execute(parameter); break; } } } }
public static int GetArchivePromotionGroupNames(string pvcsArchivePathAndFilename, ref SortedSet <string> promotionGroupList) { int error = WindowsErrorDefinition.Success; promotionGroupList.Clear(); List <string> stdout = new List <string>(); List <string> stderr = new List <string>(); string command = "vlog -q -bg \"" + pvcsArchivePathAndFilename + "\""; bool success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(), command, 1, CommandOperation.DebugProgress.Enabled, CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError, stdout, stderr); if (!success) { Console.WriteLine("PvcsCommandOperation.GetArchivePromotionGroupNames : Failed to get Promotions Groups from PVCS Archive \"{0}\"", pvcsArchivePathAndFilename); error = WindowsErrorDefinition.InvalidFunction; } else { // Look for the Promotion Groups in the output from the command foreach (string line in stdout) { Console.WriteLine("{0}", line); if (line.StartsWith(pvcsArchivePathAndFilename)) { // Output line begins with the Archive Name string promotionGroup = null; string[] words = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int wordIndex = 0; (promotionGroup == null) && (wordIndex < words.Count()); ++wordIndex ) { if (words[wordIndex] == ":") { // The word prior to the colon is the Promotion Group promotionGroup = words[wordIndex - 1]; promotionGroupList.Add(promotionGroup); } } // for } // Output line begins with the Archive Name } // foreach } // Look for the Promotion Groups in the output from the command return(error); } // GetArchivePromotionGroupNames
internal static void InvokeCommandSource( object parameter, object previewParameter, ICommandSource commandSource, CommandOperation operation) { var command = commandSource.Command; if (command == null) { return; } if (command is RoutedCommand routedCommand) { var target = commandSource.CommandTarget ?? commandSource as IInputElement; if (!routedCommand.CanExecute(parameter, target) || operation != CommandOperation.Execute) { return; } routedCommand.Execute(parameter, target); } else { if (!command.CanExecute(parameter)) { return; } switch (operation) { case CommandOperation.Preview: if (!(command is IPreviewCommand previewCommand)) { break; } previewCommand.Preview(previewParameter); break; case CommandOperation.CancelPreview: if (!(command is IPreviewCommand previewCommand2)) { break; } previewCommand2.CancelPreview(); break; case CommandOperation.Execute: command.Execute(parameter); break; } } }
#pragma warning restore private TCommandResult RunCommandAs <TCommandResult>( IMongoCommand command, IBsonSerializer <TCommandResult> resultSerializer) where TCommandResult : CommandResult { var readerSettings = new BsonBinaryReaderSettings { Encoding = _settings.ReadEncoding ?? MongoDefaults.ReadEncoding, GuidRepresentation = _settings.GuidRepresentation }; var writerSettings = new BsonBinaryWriterSettings { Encoding = _settings.WriteEncoding ?? MongoDefaults.WriteEncoding, GuidRepresentation = _settings.GuidRepresentation }; var readPreference = _settings.ReadPreference; if (readPreference != ReadPreference.Primary) { if (_server.ProxyType == MongoServerProxyType.Unknown) { _server.Connect(); } if (_server.ProxyType == MongoServerProxyType.ReplicaSet && !CanCommandBeSentToSecondary.Delegate(command.ToBsonDocument())) { readPreference = ReadPreference.Primary; } } var flags = (readPreference == ReadPreference.Primary) ? QueryFlags.None : QueryFlags.SlaveOk; var commandOperation = new CommandOperation <TCommandResult>( _name, readerSettings, writerSettings, command, flags, null, // options readPreference, resultSerializer); var connection = _server.AcquireConnection(readPreference); try { return(commandOperation.Execute(connection)); } finally { _server.ReleaseConnection(connection); } }
} // CreateAndSwitchToBranch public static bool Add(string rootWorkingDirectory, string sourceRelativePath, int indent, CommandOperation.DebugProgress debugProgress) { bool success = false; // Add the file to the Repo string command = "git add -f \"" + sourceRelativePath + "\""; success = CommandOperation.RunMonitoredCommand(rootWorkingDirectory, command, indent, debugProgress, CommandOperation.CommandOutputDisplayType.StandardOutputOnly); return(success); } // Add
public static bool CheckOutBranch(string branchName, string rootWorkingDirectory, int indent, CommandOperation.DebugProgress debugProgress) { bool success = false; string command = "git checkout " + branchName; success = CommandOperation.RunMonitoredCommand(rootWorkingDirectory, command, indent, debugProgress, CommandOperation.CommandOutputDisplayType.StandardOutputOnly); return(success); }
private static int CheckIn(string pvcsUserId, string changeDescription, string promotionGroup, string pvcsArchivePathAndFilename, string workfilePathAndName) { int error = WindowsErrorDefinition.Success; string changeDescriptionPathAndFilename = null; error = WriteChangeDescriptionFile(changeDescription, out changeDescriptionPathAndFilename); if (error == WindowsErrorDefinition.Success) { // Change description filename exists List <string> stdout = new List <string>(); List <string> stderr = new List <string>(); string command = "put -y \"-m@" + changeDescriptionPathAndFilename + "\""; if (promotionGroup != null) { // Assign a Promotion Group upon CheckIn which will only work for an empty Archive command += " -g" + promotionGroup; } command += " \"" + pvcsArchivePathAndFilename + "(" + workfilePathAndName + ")" + "\""; bool success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(), command, 1, CommandOperation.DebugProgress.Enabled, CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError, stdout, stderr); if (!success) { Console.WriteLine("PvcsCommandOperation.CheckIn : Failed to CheckIn revision from \"{0}\" to PVCS Archive \"{1}\"", workfilePathAndName, pvcsArchivePathAndFilename); error = WindowsErrorDefinition.InvalidFunction; } // Tidy up the change description file File.Delete(changeDescriptionPathAndFilename); } // Change description filename exists return(error); }
} // GitStatus // Perform a Git Status and return the standard output and standard error to the caller for subsequent perocessing public static bool GitStatus(string rootWorkingDirectory, int indent, CommandOperation.DebugProgress debugProgress, List <string> standardOutput, List <string> errorOutput) { bool success = false; string command = "git status"; success = CommandOperation.RunMonitoredCommand(rootWorkingDirectory, command, indent, debugProgress, CommandOperation.CommandOutputDisplayType.StandardOutputOnly, standardOutput, errorOutput); return(success); } // GitStatus
public static bool Init(string rootWorkingDirectory, int indent, CommandOperation.DebugProgress debugProgress) { bool success = false; string command; command = "git init"; success = CommandOperation.RunMonitoredCommand(rootWorkingDirectory, command, indent, debugProgress, CommandOperation.CommandOutputDisplayType.StandardOutputOnly, null, null); return(success); }
static bool RunOverFileList(string command, string streamName, StreamReader fileListStream) { bool success = true; Console.WriteLine(); Console.WriteLine("Executing command \"{0}\" over files contained in \"{1}\"", command, streamName); Console.WriteLine(); int lineNumber = 0; string filename = null; while ((filename = fileListStream.ReadLine()) != null) { lineNumber += 1; if (!filename.StartsWith("#")) { // Not a comment line filename = filename.Trim(new char[] { ' ', '\"' }); if (!File.Exists(filename)) { Console.WriteLine("File \"{0}\" does not exist", filename); } else { string fullCommand = String.Format("{0} \"{1}\"", command, Path.GetFullPath(filename)); string currentDirectory = Directory.GetCurrentDirectory(); bool commandSuccess = CommandOperation.RunVisibleCommand(currentDirectory, fullCommand, 1, CommandOperation.DebugProgress.Enabled, CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError); if (!commandSuccess) { Console.WriteLine("Command \"{0}\" failed", fullCommand); } success = commandSuccess && success; } } // Not a comment line } // while return(success); } // RunOverListOfFiles
// private methods private CommandResult RunCommand(MongoConnection connection, string databaseName, IMongoCommand command) { var readerSettings = new BsonBinaryReaderSettings(); var writerSettings = new BsonBinaryWriterSettings(); var resultSerializer = BsonSerializer.LookupSerializer <CommandResult>(); var commandOperation = new CommandOperation <CommandResult>( databaseName, readerSettings, writerSettings, command, QueryFlags.None, null, // options null, // readPreference resultSerializer); return(commandOperation.Execute(connection)); }
} // Promote public static int ArchiveIsEmpty(string pvcsArchivePathAndFilename, out bool isEmpty) { int error = WindowsErrorDefinition.Success; // Initialise to the Archive being empty isEmpty = true; List <string> stdout = new List <string>(); List <string> stderr = new List <string>(); // Generate just a brief report of the newest revision string command = "vlog -q -bn \"" + pvcsArchivePathAndFilename + "\""; bool success = CommandOperation.RunVisibleCommand(Directory.GetCurrentDirectory(), command, 1, CommandOperation.DebugProgress.Enabled, CommandOperation.CommandOutputDisplayType.StandardOutputAndStandardError, stdout, stderr); if (!success) { Console.WriteLine("PvcsCommandOperation.ArchiveIsEmpty : Failed to determine empty status of PVCS Archive \"{0}\"", pvcsArchivePathAndFilename); error = WindowsErrorDefinition.GeneralFailure; } else { // Look for details about any revision for (int lineIndex = 0; (isEmpty) && (lineIndex < stdout.Count); ++lineIndex) { string line = stdout[lineIndex]; Console.WriteLine("{0}", line); if (line.StartsWith(pvcsArchivePathAndFilename)) { // Found a revision so the Archive is not empty isEmpty = false; } } } // Look for details about any revision return(error); } // ArchiveIsEmpty
private TCommandResult RunCommandAs <TCommandResult>(MongoConnection connection, string databaseName, IMongoCommand command) where TCommandResult : CommandResult { var readerSettings = new BsonBinaryReaderSettings(); var writerSettings = new BsonBinaryWriterSettings(); var resultSerializer = BsonSerializer.LookupSerializer(typeof(TCommandResult)); var commandOperation = new CommandOperation <TCommandResult>( databaseName, readerSettings, writerSettings, command, QueryFlags.SlaveOk, null, // options null, // readPreference null, // serializationOptions resultSerializer); return(commandOperation.Execute(connection)); }
private bool IsResultSuccessForOperation(byte[] result, CommandOperation oper) { if (oper == CommandOperation.Set) { return(result.Contains(ipcCMD.ACK)); } else if (oper == CommandOperation.Get) { return(result.Contains(ipcCMD.SVAL)); } else if (oper == CommandOperation.Push) { return(result.Contains(ipcCMD.ACKNXT)); } else if (oper == CommandOperation.PushFin) { return(result.Contains(ipcCMD.ACKFIN)); } return(false); }
// private methods private CommandResult RunCommand(MongoConnection connection, string databaseName, IMongoCommand command) { var readerSettings = new BsonBinaryReaderSettings(); var writerSettings = new BsonBinaryWriterSettings(); var resultSerializer = BsonSerializer.LookupSerializer(typeof(CommandResult)); var commandOperation = new CommandOperation<CommandResult>( databaseName, readerSettings, writerSettings, command, QueryFlags.SlaveOk, null, // options null, // readPreference null, // serializationOptions resultSerializer); return commandOperation.Execute(connection); }