本文整理汇总了C#中HomeOS.Hub.Platform.Views.VPort类的典型用法代码示例。如果您正苦于以下问题:C# VPort类的具体用法?C# VPort怎么用?C# VPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VPort类属于HomeOS.Hub.Platform.Views命名空间,在下文中一共展示了VPort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnNotification
public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
{
string message;
string sensorData;
string sensorTag = senderPort.GetInfo().GetFriendlyName() + roleName;
lock (this)
{
if (roleName.Contains(RoleSensor.RoleName) && opName.Equals(RoleSensor.OpGetName))
{
byte rcvdNum = (byte) (int) retVals[0].Value();
sensorData = rcvdNum.ToString();
}
else if (roleName.Contains(RoleSensorMultiLevel.RoleName) && opName.Equals(RoleSensorMultiLevel.OpGetName))
{
double rcvdNum = (double) retVals[0].Value();
sensorData = rcvdNum.ToString();
}
else
{
sensorData = String.Format("Invalid role->op {0}->{1} from {2}", roleName, opName, sensorTag);
}
}
//Write to the stream
WriteToStream(sensorTag, sensorData);
//Create local list of alerts for display
message = String.Format("{0} {1},{2}", DateTime.Now, sensorTag, sensorData);
this.receivedMessageList.Add(message);
//Log
logger.Log("{0},{1}", this.ToString(), message);
}
示例2: PortRegistered
public override void PortRegistered(VPort port)
{
lock (this)
{
if (Role.ContainsRole(port, RoleSensor.RoleName))
{
VCapability capability = GetCapability(port, Constants.UserSystem);
if (registeredSensors.ContainsKey(port))
registeredSensors[port] = capability;
else
registeredSensors.Add(port, capability);
if (capability != null)
{
port.Subscribe(RoleSensor.RoleName, RoleSensor.OpGetName,
this.ControlPort, capability, this.ControlPortCapability);
}
}
if (Role.ContainsRole(port, RoleActuator.RoleName))
{
VCapability capability = GetCapability(port, Constants.UserSystem);
if (registeredActuators.ContainsKey(port))
registeredActuators[port] = capability;
else
registeredActuators.Add(port, capability);
if (capability != null)
{
port.Subscribe(RoleActuator.RoleName, RoleActuator.OpPutName, this.ControlPort, capability, this.ControlPortCapability);
}
}
}
}
示例3: ContainsRole
/// <summary>
/// Does the given port contain the given role
/// </summary>
/// <param name="port"></param>
/// <param name="roleName"></param>
/// <returns></returns>
public static bool ContainsRole(VPort port, string roleName)
{
foreach (VRole role in port.GetInfo().GetRoles())
{
if (ContainsRole(role.Name(), roleName))
return true;
}
return false;
}
示例4: PortDeregistered
public override void PortDeregistered(VPort port)
{
lock (this)
{
if (accessibleDummyPorts.Contains(port))
{
accessibleDummyPorts.Remove(port);
logger.Log("{0} deregistered port {1}", this.ToString(), port.GetInfo().ModuleFacingName());
}
}
}
示例5: OnNotification
public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
{
logger.Log("Notitification from {0} for {0}", roleName, opName);
if (retVals.Count >= 1)
{
this.Temperature = (int)retVals[0].Value();
}
else
{
logger.Log("{0}: got unexpected retvals [{1}] from {2}", ToString(), retVals.Count.ToString(), senderPort.ToString());
}
}
示例6: PortDeregistered
public override void PortDeregistered(VPort port)
{
lock (this)
{
if (Role.ContainsRole(port, RoleSensor.RoleName))
{
if (registeredValves.ContainsKey(port))
{
registeredValves.Remove(port);
logger.Log("{0} removed valve port {1}", this.ToString(), port.ToString());
}
}
}
}
示例7: PortRegistered
/// <summary>
/// Called when a new port is registered with the platform
/// </summary>
public override void PortRegistered(VPort port)
{
logger.Log("{0} got registeration notification for {1}", ToString(), port.ToString());
lock (this)
{
if (!accessibleWeatherPorts.Contains(port) &&
Role.ContainsRole(port, RoleWeather.RoleName) &&
GetCapabilityFromPlatform(port) != null)
{
accessibleWeatherPorts.Add(port);
logger.Log("{0} added port {1}", this.ToString(), port.ToString());
}
}
}
示例8: V2C
internal static IPort V2C(VPort view)
{
if (view == null)
{
return null;
}
if (!System.Runtime.Remoting.RemotingServices.IsObjectOutOfAppDomain(view) &&
(view.GetType().Equals(typeof(PortC2V))))
{
return ((PortC2V)(view)).GetSourceContract();
}
else
{
return new PortV2C(view);
}
}
示例9: OnNotification
public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
{
string message;
lock (this)
{
switch (opName.ToLower())
{
case RoleDummy2.OpEchoSubName:
int rcvdNum = (int)retVals[0].Value();
message = String.Format("async echo response from {0}. rcvd = {1}", senderPort.ToString(), rcvdNum.ToString());
this.receivedMessageList.Add(message);
break;
default:
message = String.Format("Invalid async operation return {0} from {1}", opName.ToLower(), senderPort.ToString());
break;
}
}
logger.Log("{0} {1}", this.ToString(), message);
}
示例10: OnNotification
public override void OnNotification(string roleName, string opName, IList<VParamType> retVals, VPort senderPort)
{
string message;
lock (this)
{
switch (opName.ToLower())
{
case "echosub":
string rcvdData = (string)retVals[0].Value();
irDataList.Add(rcvdData);
//ProcessData(rcvdData);
message = String.Format("async echo response from {0}. rcvd = {1}", senderPort.ToString(), rcvdData.ToString());
this.receivedMessageList.Add(message);
break;
default:
message = String.Format("Invalid async operation return {0} from {1}", opName.ToLower(), senderPort.ToString());
break;
}
}
//logger.Log("{0} {1}", this.ToString(), message);
}
示例11: PortRegistered
/// <summary>
/// Called when a new port is registered with the platform
/// </summary>
public override void PortRegistered(VPort port)
{
logger.Log("{0} got registeration notification for {1}", ToString(), port.ToString());
lock (this)
{
if (!accessibleDummyPorts.Contains(port) &&
Role.ContainsRole(port, RoleDummy2.RoleName) &&
GetCapabilityFromPlatform(port) != null)
{
accessibleDummyPorts.Add(port);
logger.Log("{0} added port {1}", this.ToString(), port.ToString());
if (Subscribe(port, RoleDummy2.Instance, RoleDummy2.OpEchoSubName))
logger.Log("{0} subscribed to port {1}", this.ToString(), port.ToString());
else
logger.Log("failed to subscribe to port {1}", this.ToString(), port.ToString());
}
}
}
示例12: WriteObjectImage
private void WriteObjectImage(VPort cameraPort, Bitmap image, Rectangle rectSrc, bool center)
{
Rectangle rectTarget = rectSrc;
int srcPixelShiftX = 0;
int srcPixelShiftY = 0;
if (rectSrc.Width == 0 && rectSrc.Height == 0)
{
logger.Log("Write Object Image Called with Rect with zero height and width!");
return;
}
if (center)
{
rectTarget.X = (int)((image.Width - rectSrc.Width) / 2.0);
rectTarget.Y = (int)((image.Height - rectSrc.Height) / 2.0);
srcPixelShiftX = rectTarget.X - rectSrc.X;
srcPixelShiftY = rectTarget.Y - rectSrc.Y;
}
// create the destination based upon layer one
BitmapData bmpData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
int stride = bmpData.Stride;
image.UnlockBits(bmpData);
WriteableBitmap composite = new WriteableBitmap(image.Width, image.Height, 96, 96, System.Windows.Media.PixelFormats.Rgb24, null);
Int32Rect sourceRect = new Int32Rect(0, 0, (int)image.Width, (int)image.Height);
byte[] pixels = new byte[stride * image.Height];
for (int x = 0; x < image.Width; ++x)
{
for (int y = 0; y < image.Height; ++y)
{
if (rectSrc.Contains(x, y))
{
Color clr = image.GetPixel(x, y);
pixels[stride * (y + srcPixelShiftY) + 3 * (x + srcPixelShiftX)] = clr.R;
pixels[stride * (y + srcPixelShiftY) + 3 * (x + srcPixelShiftX) + 1] = clr.G;
pixels[stride * (y + srcPixelShiftY) + 3 * (x + srcPixelShiftX) + 2] = clr.B;
}
else if (!rectTarget.Contains(x, y))
{
pixels[stride * y + 3 * x] = 0x00;
pixels[stride * y + 3 * x + 1] = 0x00;
pixels[stride * y + 3 * x + 2] = 0x00;
}
}
}
composite.WritePixels(sourceRect, pixels, stride, 0);
// encode the bitmap to the output file
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(composite));
string filepath = GetMediaFileName(cameraPort.GetInfo().GetFriendlyName(), MediaType.MediaType_Image_JPEG);
if (null == filepath)
{
logger.Log("GetMediaFileName failed to get a file name, are there more than 10 files of the same name?");
return;
}
using (var stream = new FileStream(filepath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
{
encoder.Save(stream);
}
}
示例13: Subscribe
public override bool Subscribe(string roleName, string opName, VPort fromPort, VCapability reqCap, VCapability respCap)
{
return _contract.Subscribe(roleName, opName, PortAdapter.V2C(fromPort), CapabilityAdapter.V2C(reqCap), CapabilityAdapter.V2C(respCap));
}
示例14: PortDeregisteredWithHooks
public virtual void PortDeregisteredWithHooks(VPort port) { }
示例15: AddFrameToVideo
private void AddFrameToVideo(Bitmap image, VPort cameraPort, long sampleTime)
{
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
BitmapData bmpData = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat);
// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;
int result;
unsafe
{
result = registeredCameras[cameraPort].VideoWriter.AddFrame((byte*)ptr, 3 * image.Width * image.Height, image.Width, image.Height, sampleTime);
}
image.UnlockBits(bmpData);
if (result != 0)
{
string message = String.Format("Failed to add frame for {0}. ResultCode: {1:x}", cameraPort.GetInfo().GetFriendlyName(), ((uint)result));
logger.Log(message);
}
}