CreoOtkPluging/BatchOperationManager.h

92 lines
3.6 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <map>
#include "CreoManager.h"
#include "PathDeleteManager.h"
#include "ShrinkwrapManager.h"
#include "CreoUtilities.h"
// Single operation request structure
struct BatchOperation {
std::string operation_type; // "save_model", "export_model", "delete_by_path", etc.
std::map<std::string, std::string> parameters; // Operation-specific parameters
std::vector<std::string> array_parameters; // For array parameters like component_paths
};
// Single operation result structure
struct BatchOperationResult {
int operation_index = 0;
std::string operation_type;
bool success = false;
std::string result_json; // JSON string of operation result
std::string error_message;
std::string execution_time;
};
// Batch operations request structure
struct BatchOperationsRequest {
std::string software_type = "creo";
std::vector<BatchOperation> operations;
};
// Batch operations overall result structure
struct BatchOperationsResponse {
bool success = false;
std::string message;
int total_operations = 0;
int successful_operations = 0;
int failed_operations = 0;
std::string execution_time;
std::vector<BatchOperationResult> results;
std::string error_message;
};
// Batch Operation Manager Class
class BatchOperationManager {
public:
// Get singleton instance
static BatchOperationManager& Instance() {
static BatchOperationManager instance;
return instance;
}
// Main entry point: execute batch operations
BatchOperationsResponse ExecuteBatchOperations(const BatchOperationsRequest& request);
private:
// Private constructor for singleton
BatchOperationManager() = default;
BatchOperationManager(const BatchOperationManager&) = delete;
BatchOperationManager& operator=(const BatchOperationManager&) = delete;
// Execute individual operations
BatchOperationResult ExecuteSaveModel(int index, const BatchOperation& operation);
BatchOperationResult ExecuteExportModel(int index, const BatchOperation& operation);
BatchOperationResult ExecuteDeleteByPath(int index, const BatchOperation& operation);
BatchOperationResult ExecuteHierarchyDelete(int index, const BatchOperation& operation);
BatchOperationResult ExecuteShrinkwrapShell(int index, const BatchOperation& operation);
BatchOperationResult ExecuteCloseModel(int index, const BatchOperation& operation);
BatchOperationResult ExecuteOpenModel(int index, const BatchOperation& operation);
// Execute workflow operations
BatchOperationResult ExecuteHierarchyDeleteWorkflow(int index, const BatchOperation& operation);
BatchOperationResult ExecuteShrinkwrapWorkflow(int index, const BatchOperation& operation);
// Helper functions
std::string GetCurrentTimeString();
std::string EscapeJsonString(const std::string& str);
std::string BuildSaveResultJson(const SaveResult& result);
std::string BuildExportResultJson(const ExportResult& result);
std::string BuildDeleteByPathResultJson(const PathDeleteManager::PathDeleteResult& result);
std::string BuildHierarchyDeleteResultJson(const CreoManager::HierarchyDeleteResult& result);
std::string BuildShrinkwrapResultJson(const ShrinkwrapShellResult& result);
std::string BuildCloseResultJson(const CloseResult& result);
std::string BuildOpenResultJson(const OpenResult& result);
// Workflow step helper
std::string BuildWorkflowStepJson(const std::string& step_name, bool success,
const std::string& time, const std::string& error = "");
};