So I try to create opensource C# project for slicing FLVs I began with translating of existing project called flvslicer
Can any one please help me with translating one of their classes
package org.bytearray.video.events
{
import flash.events.Event;
import flash.utils.ByteArray;
public final class MergedEvent extends Event
{
public var time:Number;
public var stream:ByteArray;
public static const COMPLETE:String = "mergeComplete";
public function MergedEvent(type:String, stream:ByteArray, duration:Number)
{
super(type, false, false); // base
this.stream = stream;
this.time = duration;
}
}
}
In C# you have two separate items, an EventHandler<TArgs> declaration and the custom EventArgs subclass.
public event EventHandler<MergedEventArgs> MergeComplete;
public class MergedEventArgs : EventArgs {
public double Time { get; set; }
public byte[] Stream { get; set;
}
Related
I'm currently working on a sonar named "Imagenex 831L" and I'm trying to extract the data published by a driver with ROS and send it to Unity with RosBridge and ROS#. So I'm trying to subscribe to this topic and visualize it on Unity.
My problem is that the topic generated by the driver isn't a native topic of ROS, it's created by the driver and it's not known by the ROS# library.
I tried this method to create a new MessageType : https://github.com/siemens/ros-sharp/wiki/Dev_NewMessageTypes but that doesn't work at all.
I've also thought to change the MessageType created by the driver but I'm a begginer in ROS and I don't want to messed up the driver.
So I started a script in C# to create a new message type but I'm really not sure if this gonna work. As you can see below my code to create a new MessageType :
using RosSharp.RosBridgeClient.MessageTypes.Std;
namespace RosSharp.RosBridgeClient.MessageTypes.imagenex831l
{
public class ProcessedRange : Message
{
public const string RosMessageName = "imagenex831l/ProcessedRange";
public float Head_position { get; set; }
public UInt8 Intensity { get; set; }
public ProcessedRange() { }
public ProcessedRange(Header header, UInt8[] Intensity, float Head_position) { }
public Header header { get; set; }
}
}
Then I tried to code a subscriber :
using RosSharp.RosBridgeClient.MessageTypes.imagenex831l;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RosSharp.RosBridgeClient.MessageTypes.Std;
namespace RosSharp.RosBridgeClient
{
public class ProcessedRangeSuscriber : UnitySubscriber<MessageTypes.imagenex831l.ProcessedRange>
{
//public Transform PublishedTransform;
public UInt8[] Intensity;
public Float32 Head_position;
private bool isMessageReceived;
protected override void Start()
{
base.Start();
}
private void Update()
{
if (isMessageReceived)
ProcessMessage();
}
protected override void ReceiveMessage(MessageTypes.imagenex831l.ProcessedRange message)
{
//position = GetPosition(message).Ros2Unity();
//rotation = GetIntensity(message).Ros2Unity();
//isMessageReceived = true;
}
private void ProcessMessage()
{
//PublishedTransform.position = position;
//PublishedTransform.rotation = rotation;
}
private Float32 GetPosition(MessageTypes.imagenex831l.ProcessedRange message)
{
return new Float32(message.head_position);
}
private UInt8 GetIntensity(MessageTypes.imagenex831l.ProcessedRange message)
{
return new UInt8(message.intensity);
}
}
}
I get the following error message : CS1503 C# Argument 1: cannot convert from to 'byte'
If someone has also use this sonar or know ROS# I'm very interesting to discuss with them.
Thank you for your consideration regarding my request
I'been developing a library on C# for the last days, and now, I need to build that library into a dll, and use that dll from Qt.
The library includes three classes I need to access, and my original idea was to simply build the dll, use dumpcpp to get the headers and use them from Qt along with activeqt, which I have used before.
The problem is that I cannot manage to get the headers from dumpcpp, it fails, returning:
dumpcpp: loading '.\Wrapper.dll' as a type library failed
dumpcpp: error processing type library '.\Wrapper.dll'
The Visual Studio project I'm using is a Class library (.Net Standard), and I'm using building it for x86 architecture. I've seen this link and tried using
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
with the three classes I need in order to get a COM dll which I suppose must be usable by dumpcpp, but it fails with the same error I mentioned before. Almost every documentation I have found is about using C++ dlls on C#, and there's nothing about using dumpcpp with C# dlls.
Do somebody has any ideas on how to get this dll working with dumpcpp, so that I can use it with Qt? I'd be really grateful.
Thanks a lot!
Edit: In case it helps, here it's the basic structure (without the complex funcionality) of the unique main .cs file the dll includes:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Wrapper
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class Device
{
public string host;
public string username;
public string password;
public uint port;
private bool _serverConnected;
public uint serverGroupId { get; private set; }
public uint serverId { get; private set; }
private object[] _cameraIds;
public Device(string host, string username, string password, uint port)
{
this.host = host;
this.username = username;
this.password = password;
this.port = port;
this._serverConnected = false;
Debug.WriteLine("Device Initialized");
}
public bool isConnected() => _serverConnected;
public void onServerConnected(uint serverGroupId, uint serverId)
{
Debug.WriteLine("ServerConnectedEventHandler"); // TODO: Remove, just for testing
_serverConnected = true;
}
public void onServerGroupDisconnected(uint serverGroupId)
{
Debug.WriteLine("ServerGroupDisconnectedEventHandler"); // TODO: Remove, just for testing
_serverConnected = false;
}
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
class Player
{
private Device _device;
private static readonly int NUM_FRAMES = 10;
private Frame[] _lastFrames = new Frame[NUM_FRAMES];
private int _toReadFrame, _toReceivedFrame;
public Player(Device device)
{
this._device = device;
_toReadFrame = 0;
_toReceivedFrame = 0;
}
public Frame Image()
{
Frame tmp = _lastFrames[_toReadFrame];
_toReadFrame = (++_toReadFrame) % NUM_FRAMES;
return tmp;
}
void FrameAvailableEventHandler(int width, int height, byte[] data)
{
_lastFrames[_toReceivedFrame] = new Frame(width, height, data);
_toReceivedFrame = (++_toReceivedFrame) % NUM_FRAMES;
}
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
class Frame
{
public int width { get; private set; }
public int height { get; private set; }
public byte[] data { get; private set; }
public Frame(int width, int height, byte[] data)
{
this.data = data;
this.width = width;
this.height = height;
}
}
}
I have these classes, one is a model, other is Listener and the third one is an Util class. I want to access Terrains by the variable map in the first one, but don't want public access to the inner class Terrain. Is there any way to do it?
It prints error CS0052: Inconsistent accessibility: field type
System.Collections.Generic.List is less
accessible than field `MapaMundiInfoScript.map'
public class MapaMundiInfoScript : MonoBehaviour {
public static bool changeInMap= false;
public static List<Terrain>map = new List<Terrain>();
void Start(){
Terrain terrain = new Terrain(0,0);
Terrain.TerrainPart initialPart = new Terrain.TerrainPart(20,20,0,0);
terrain.terrainParts.Add (initialPart);
map.Add(terrain);
changeInMap=true;
}
class Terrain{
int XPosition;
int ZPosition;
public List <TerrainPart> terrainParts = new List<TerrainPart> ();
public Terrain(int XPosition, int ZPosition){
this.XPosition=XPosition; this.ZPosition=ZPosition;
}
public class TerrainPart
{
int XSize;
int ZSize;
int XPosition;
int ZPosition;
TerrainPartReturn ReturnTerrainPart(int num1,int num2,int num3,int num4)
{
return new TerrainPart (num1,num2,num3,num4);
}
public TerrainPart(int XSize,int ZSize,int XPosition,int ZPosition){
this.XSize = XSize;
this.ZSize = ZSize;
this.XPosition=XPosition;
this.ZPosition =ZPosition;
}
}
}
public class MapListener : MonoBehaviour {
void Update () {
if (MapaMundiInfoScript.changeInMap) {
foreach(MapaMundiInfoScript.Terrain terrain in MapaMundiInfoScript.mapMundi)
{
foreach(terrain.terrainPart terrainPart in terrain.terrainParts)
{
RegionDraw.Draw(terrainPart);
}
}
MapaMundiInfoScript.changeInMap = false;
}
}
public class RegionDraw
{
/***
Implementantion Draw Method
***/
}
You cannot reference a private class as a public property. You will need to have the class public for public access. Consider making your properties and methods private, private protected, internal etc.
If you need to provide read only attributes, you can use public getters and private setters, etc. If you need to prevent the execution of some methods consider setting those to private, etc. The class can be public while still locking down properties and methods inside the class. Consider what it is that you actually need to expose.
You could also expose the functionality of these hidden classes through interfaces
public interface ITerrain
{
List<ITerrainPart> TerrainParts { get; }
ITerrainPart CreateTerrainPart(int XSize, int ZSize, int XPosition, int ZPosition);
}
public interface ITerrainPart
{
// ...
}
Implement them like this
private class Terrain : ITerrain
{
int XPosition;
int ZPosition;
public List<ITerrainPart> TerrainParts { get; } = new List<ITerrainPart>();
public Terrain(int XPosition, int ZPosition)
{
this.XPosition = XPosition; this.ZPosition = ZPosition;
}
public ITerrainPart CreateTerrainPart(int XSize, int ZSize, int XPosition,
int ZPosition)
{
return new TerrainPart(XSize, ZSize, ZPosition, ZPosition);
}
private class TerrainPart : ITerrainPart
{
// ...
}
}
Your listener can then draw like this (after changing the parameter type of Draw to ITerrainPart):
void Update()
{
if (MapaMundiInfoScript.changeInMap) {
foreach (ITerrain terrain in MapaMundiInfoScript.map) {
foreach (ITerrainPart terrainPart in terrain.TerrainParts) {
RegionDraw.Draw(terrainPart);
}
}
MapaMundiInfoScript.changeInMap = false;
}
}
Let MapaMundiInfoScript have a method DrawTerrain() and let Terrain have a method DrawParts. Should you end up with to many incoherent methods in MapaMundiInfoScript, you might want to use a visitor.
This is code inside Proizvod.cs file
namespace mateo_zadatak
{
class Proizvod
{
public string Šifra = "šifra";
public string Naziv = "naziv";
public string Proizvođač = "proizvođač";
public float Cijena;
public int Količina;
private float Ukupno;
private int Popust;
private float UkupnoPopust;
private void variable()
{
Ukupno = Cijena * Količina;
{
if (Količina < 10)
{
Popust = 0;
}
else if (Količina > 9 && Količina < 31)
{
Popust = 5;
}
else Popust = 10;
}
}
}
}
I have to use this variables in Form1.cs file , because i will need some calculations from datagrid. How to connect those two files?
There are no "Global" variables in C# but what you can do is create a new Class with Static variables and assign/use them. For example:
public static class GlobalVariables
{
public static int IntVariable;
public static string StringVariable;
}
And then you can reference them as GlobalVariables.IntVariable and GlobalVariables.StringVariable.
A Form is just a class - Add public properties/members to the Form and access them from a reference to the form.
Make your class public, and make sure you include Proizvod.cs file into your project or add a reference to it from your project.
You can use public properties instead of variables from another class
Perhaps I'm missing something, but:
public class Form1 : ...
{
public Proizvod Foo;
Form1()
{
Foo = new Proizvod();
}
SomeMethod()
{
MessageBox.Show(Foo.Naziv);
}
}
I am using a facade design pattern for a C# program. The program basically
looks like this...
public class Api
{
#region Constants
private const int version = 1;
#endregion
#region Private Data
private XProfile _profile;
private XMembership _membership;
private XRoles _role;
#endregion Private Data
public Api()
{
_membership = new XMembership();
_profile = new XProfile();
_role = new XRoles();
}
public int GetUserId(string name)
{
return _membership.GetIdByName(name);
}
}
Now, as I would like subclass my methods into three categories: Role, Profile, and Member.
This will be easier on the developers eye because both Profile and Membership expose a lot of methods that look similar (and a few by Role). For example, getting a user's ID would look like:
int _id = Namespace.Api.Member.GetUserId("Henry222");
Can somebody "illustrate" how subclassing should work in this case to achieve the effect I am looking for?
Thanks in advance.
I would argue that you might mean "inner class" from the context of your question. You might try something like the following...
public class Api
{
public class MemberApi
{
private readonly Api _parent;
internal MemberApi(Api parent) { _parent = parent; }
public int GetUserId(string name)
{
return _parent._membership.GetIdByName(name);
}
}
#region Constants
private const int version = 1;
#endregion
#region Private Data
private XProfile _profile;
private XMembership _membership;
private XRoles _role;
public MemberApi { get; private set; }
#endregion Private Data
public Api()
{
_membership = new XMembership();
_profile = new XProfile();
_role = new XRoles();
Member = new MemberApi(this);
}
}