示例#1
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (acnSocket != null)
     {
         acnSocket.Dispose();
     }
 }
示例#2
0
        private static void ProcessDmxInput(Guid senderId, List <int> universes, int timeout, Action <StreamingAcnDmxPacket> handler)
        {
            ManualResetEvent waitForDMX      = new ManualResetEvent(false);
            Exception        socketException = null;

            StreamingAcnSocket acnSocket = new StreamingAcnSocket(Guid.NewGuid(), "DMX Assert");

            try
            {
                acnSocket.UnhandledException += (object sender, UnhandledExceptionEventArgs e)
                                                =>
                {
                    socketException = (Exception)e.ExceptionObject;
                    waitForDMX.Set();
                };

                acnSocket.NewPacket += (object sender, NewPacketEventArgs <Acn.Packets.sAcn.StreamingAcnDmxPacket> e) =>
                {
                    if ((senderId == Guid.Empty || senderId == e.Packet.Root.SenderId) &&
                        (universes.Contains(e.Packet.Framing.Universe)))
                    {
                        try
                        {
                            handler(e.Packet);

                            universes.Remove(e.Packet.Framing.Universe);
                            if (universes.Count == 0)
                            {
                                waitForDMX.Set();
                            }
                        }
                        finally
                        {
                            if (universes.Count == 0)
                            {
                                acnSocket.Close();
                            }
                        }
                    }
                };
                acnSocket.Open(IPAddress.Any);
                foreach (int universe in universes)
                {
                    acnSocket.JoinDmxUniverse(universe);
                }

                if (!waitForDMX.WaitOne(timeout))
                {
                    throw new TimeoutException(string.Format("A timeout ocurred whil waiting for DMX on universe {0}.", string.Join(",", universes)));
                }

                if (socketException != null)
                {
                    throw socketException;
                }
            }
            finally
            {
                acnSocket.Dispose();
            }
        }