<commit_before>#include "requestUpdate.h"
#include "hackPrint.h"
#include "messaging.h"

#include "maya/MSelectionList.h"
#include "maya/MDagPath.h"
#include "maya/MDagPathArray.h"
#include "maya/MFnDependencyNode.h"
#include "maya/MPlug.h"
#include "maya/MArgDatabase.h"
#include "maya/MPlugArray.h"
#include "maya/MUuid.h"

#include "testTypes.h"
#include "tweakHandler.h"
#include "serverAddress.h"
#include "callbackHandler.h"
#include "mayaUtils.h"

RequestUpdate::RequestUpdate()
	:
	pMessenger(new Messaging("localhost", 8080))
{
}

RequestUpdate::~RequestUpdate()
{
}

void* RequestUpdate::creator()
{
	return new RequestUpdate;
}

MStatus	RequestUpdate::doIt(const MArgList& args)
{
	MStatus status = MStatus::kSuccess;

	// reset socket
	if (!ServerAddress::getInstance().isServerSet())
	{
		HackPrint::print("Set Server using \"SetServer\" command");
		return status;
	}

	pMessenger->resetSocket(ServerAddress::getInstance().getAddress(), ServerAddress::getInstance().getPort());

	json data;
	
	// if false then we couldnt connect to server
	if (!pMessenger->requestMesh(data, ReqType::REQUEST_MESH_UPDATE, CallbackHandler::getInstance().getCurrentRegisteredMesh(), ServerAddress::getInstance().getUserID())) return MStatus::kFailure;

	// is there actually anything?
	if (data.empty())
	{
		HackPrint::print("Nothing to update");
		return status;
	}
	else if (data["edits"].empty())
	{
		HackPrint::print("No Edits");
		return status;
	}

	auto editList = data["edits"];

	for (auto& edit : editList)
	{
		for (auto& itr : edit["nodes"])
		{

			if (itr["edit"] == EditType::ADD)
			{
				std::string stringID = itr["id"];
				bool nodeExists = MayaUtils::doesItExist(stringID);

				if (!nodeExists)
				{
					status = createNode(itr);
					MObject node;
					MString id = itr["id"].get<std::string>().c_str();
					status = MayaUtils::getNodeObjectFromUUID(id, node);
					CallbackHandler::getInstance().registerCallbacksToNode(node);

					// connect
					status = setConnections(edit, itr);
				}
			}
			else if (itr["edit"] == EditType::EDIT)
			{
				status = setNodeValues(itr);
			}
			else if (itr["edit"] == EditType::DEL)
			{
				MObject node;
				MString id = itr["id"].get<std::string>().c_str();
				status = MayaUtils::getNodeObjectFromUUID(id, node);
				deleteNode(node);
			}

			// TODO check connection order possibly?
		}
	}

	return status;
}

MStatus RequestUpdate::deleteNode(MObject& node)
{
	fDGModifier.deleteNode(node);
	fDGModifier.doIt();<commit_msg>return status vals<commit_after>#include "requestUpdate.h"
#include "hackPrint.h"
#include "messaging.h"

#include "maya/MSelectionList.h"
#include "maya/MDagPath.h"
#include "maya/MDagPathArray.h"
#include "maya/MFnDependencyNode.h"
#include "maya/MPlug.h"
#include "maya/MArgDatabase.h"
#include "maya/MPlugArray.h"
#include "maya/MUuid.h"

#include "testTypes.h"
#include "tweakHandler.h"
#include "serverAddress.h"
#include "callbackHandler.h"
#include "mayaUtils.h"

RequestUpdate::RequestUpdate()
	:
	pMessenger(new Messaging("localhost", 8080))
{
}

RequestUpdate::~RequestUpdate()
{
}

void* RequestUpdate::creator()
{
	return new RequestUpdate;
}

MStatus	RequestUpdate::doIt(const MArgList& args)
{
	MStatus status = MStatus::kSuccess;

	// reset socket
	if (!ServerAddress::getInstance().isServerSet())
	{
		HackPrint::print("Set Server using \"SetServer\" command");
		return status;
	}

	pMessenger->resetSocket(ServerAddress::getInstance().getAddress(), ServerAddress::getInstance().getPort());

	json data;
	
	// if false then we couldnt connect to server
	if (!pMessenger->requestMesh(data, ReqType::REQUEST_MESH_UPDATE, CallbackHandler::getInstance().getCurrentRegisteredMesh(), ServerAddress::getInstance().getUserID())) return MStatus::kFailure;

	// is there actually anything?
	if (data.empty())
	{
		HackPrint::print("Nothing to update");
		return status;
	}
	else if (data["edits"].empty())
	{
		HackPrint::print("No Edits");
		return status;
	}

	auto editList = data["edits"];

	for (auto& edit : editList)
	{
		for (auto& itr : edit["nodes"])
		{

			if (itr["edit"] == EditType::ADD)
			{
				std::string stringID = itr["id"];
				bool nodeExists = MayaUtils::doesItExist(stringID);

				if (!nodeExists)
				{
					status = createNode(itr);
					MObject node;
					MString id = itr["id"].get<std::string>().c_str();
					status = MayaUtils::getNodeObjectFromUUID(id, node);
					CallbackHandler::getInstance().registerCallbacksToNode(node);

					// connect
					status = setConnections(edit, itr);
				}
			}
			else if (itr["edit"] == EditType::EDIT)
			{
				status = setNodeValues(itr);
			}
			else if (itr["edit"] == EditType::DEL)
			{
				MObject node;
				MString id = itr["id"].get<std::string>().c_str();
				status = MayaUtils::getNodeObjectFromUUID(id, node);
				deleteNode(node);
			}

			// TODO check connection order possibly?
		}
	}

	return status;
}

MStatus RequestUpdate::deleteNode(MObject& node)
{
	MStatus status = fDGModifier.deleteNode(node);
	if (status != MStatus::kSuccess) return status;
	status = fDGModifier.doIt();
	return status;
{'fraction_non_alphanumeric': 0.1587426326129666, 'fraction_numerical': 0.0015717092337917485, 'mean_word_length': 4.746049661399549, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4484746', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1749, 'n_words': 341}