/// <summary> /// Runs the specified command. /// </summary> /// <param name="commandName">The command name.</param> /// <param name="commandData">The key values collection of data.</param> public void Run(string commandName, StringDictionary commandData) { try { // Validate the arguments for this command ValidateDataArguments(commandData); // Get the InstanceID from the command arguments Guid instanceId; Guid.TryParse(commandData[ArgumentInstanceId].Trim(), out instanceId); Environment.SetEnvironmentVariable("InstanceID", "_" + instanceId, EnvironmentVariableTarget.Process); string modelNamespace = commandData[ArgumentModelNamespace].Trim(); string resourceType = commandData[ArgumentResourceTypeName].Trim(); string filePath = commandData[ArgumentChangeMessageFilePath].Trim(); Console.WriteLine(string.Format("Operation : Update Collection\n" + "InstanceID : {0}\n" + "Date Model : {1}\n" + "ResourceType : {2}\n" + "File Path : {3}", instanceId, modelNamespace, resourceType, filePath), CultureInfo.InvariantCulture); IEnumerable <ResourceChangeMessage> changeMessageList = ResourceChangeMessage.DeserializeResourceChangeMessageList(filePath); if (changeMessageList == null) { throw new ArgumentException("changeMessageList", "Update Collection operation will be aborted."); } using (CollectionHelper collectionHelper = new CollectionHelper(instanceId, modelNamespace, resourceType)) { collectionHelper.UpdateCollection(changeMessageList); try { File.Delete(filePath); } catch { } } } catch (Exception ex) { Globals.TraceMessage(TraceEventType.Error, ex.ToString(), ex.Message); throw; } }
/// <summary> /// Converts a ChangeMessageRecovery into a ResourceChangeMessage. /// </summary> /// <param name="changeMessage">The change message.</param> /// <returns>Resource change message.</returns> internal static ResourceChangeMessage ToResourceChangeMessage(this ChangeMessageRecovery changeMessage) { if (changeMessage == null) { return(null); } ResourceChangeMessage resChangeMessage = new ResourceChangeMessage { ResourceId = changeMessage.ResourceId, ResourceTypeId = changeMessage.ResourceTypeId, ResourceTypeName = changeMessage.ResourceTypeName, DataModelNamespace = changeMessage.DataModelNamespace, ChangeType = (ResourceChangeType)Enum.Parse(typeof(ResourceChangeType), changeMessage.ChangeType.ToString()), DateAdded = changeMessage.DateAdded, DateModified = changeMessage.DateModified }; return(resChangeMessage); }
/// <summary> /// Converts a ResourceChangeMessage into a ChangeMessageRecovery /// </summary> /// <param name="resChangeMessage">The res change message.</param> /// <returns>Change message recovery.</returns> internal static ChangeMessageRecovery ToChangeMessage(this ResourceChangeMessage resChangeMessage) { if (resChangeMessage == null) { return(null); } ChangeMessageRecovery changeMessage = new ChangeMessageRecovery { Id = Guid.NewGuid(), ResourceId = resChangeMessage.ResourceId, ResourceTypeId = resChangeMessage.ResourceTypeId, ResourceTypeName = resChangeMessage.ResourceTypeName, DataModelNamespace = resChangeMessage.DataModelNamespace, DateAdded = resChangeMessage.DateAdded, DateModified = resChangeMessage.DateModified, ChangeType = (short)resChangeMessage.ChangeType }; return(changeMessage); }