示例#1
0
	public IUsage Create(int? type, params object[] arguments)
	{
		if (arguments == null || arguments.Length != 5)
			throw new ArgumentException(
				"Expected arguments are [0] ResourceName, [1] Image Name, [2] Width, [3] Height and [4] Data!");

		// Initialize the usage with given arguments
		ImageStoreUsage result = new ImageStoreUsage(UsageManager)
		{
			ResourceName = (string)arguments[0],
			Data = new ImageStoreData(
				UsageManager.localNode.Id,
				(string)arguments[1],
				(int)arguments[2],
				(int)arguments[3],
				(byte[])arguments[4])
		};

		// Compute the total usage length
		result.Length = 0
			+ (uint)(result.ResourceName.Length + 2)
			+ (uint)(result.Data.NodeId.Digits)
			+ (uint)(result.Data.Name.Length + 2)
			+ (uint)(2)
			+ (uint)(2)
			+ (uint)(result.Data.Data.Length + 2);

		return result;
	}
示例#2
0
	public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long reload_msg_size)
	{
		ImageStoreUsage result = new ImageStoreUsage(UsageManager);
		var ASCII = Encoding.ASCII;
		var bytesCount = 0;

		try
		{
			// Deserialize the ResourceName
			{
				bytesCount = IPAddress.NetworkToHostOrder(reader.ReadInt32());
				result.ResourceName = ASCII.GetString(reader.ReadBytes(bytesCount), 0, bytesCount);
			}

			// Deserialize the ImageStoreData
			{
				var nodeId = new NodeId(reader.ReadBytes(ReloadGlobals.NODE_ID_DIGITS));

				bytesCount = IPAddress.NetworkToHostOrder(reader.ReadInt32());
				var name = ASCII.GetString(reader.ReadBytes(bytesCount), 0, bytesCount);

				var width = IPAddress.NetworkToHostOrder(reader.ReadInt16());

				var height = IPAddress.NetworkToHostOrder(reader.ReadInt16());

				bytesCount = IPAddress.NetworkToHostOrder(reader.ReadInt32());
				var data = reader.ReadBytes(bytesCount);

				result.Data = new ImageStoreData(nodeId, name, width, height, data);
			}

			// Compute the total usage length
			result.Length = 0
				+ (uint)(result.ResourceName.Length + 2)
				+ (uint)(result.Data.NodeId.Digits)
				+ (uint)(result.Data.Name.Length + 2)
				+ (uint)(2)
				+ (uint)(2)
				+ (uint)(result.Data.Data.Length + 2);
		}
		catch (Exception exception)
		{
			UsageManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
				 String.Format("ImageStoreUsage.FromBytes(): {0}", exception.Message));
		}

		return result;
	}