private static void ProcessItems(Queue<ISocketCallback> queue, CallbackOperation operation)

        {
            if (queue == null) return;
            while (true)
            {
                // get the next item (note we could be competing with a worker here, hence lock)
                ISocketCallback callback;
                lock (queue)
                {
                    if (queue.Count == 0) break;
                    callback = queue.Dequeue();
                }
                if (callback != null)
                {
                    try
                    {
                        switch (operation)
                        {
                            case CallbackOperation.Read: callback.Read(); break;
                            case CallbackOperation.Error: callback.Error(); break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex);
                    }
                }
            }
        }
 public static CallbackOperationResult ToDto(CallbackOperation op)
 {
     return(new CallbackOperationResult
     {
         Url = op.Url
     });
 }
Ejemplo n.º 3
0
        void broadcastIdMessage(string id, CallbackOperation op)
        {
            List <IDatabaseCallback> deleteitems = new List <IDatabaseCallback>();

            foreach (IDatabaseCallback client in klijenti)
            {
                try
                {
                    switch (op)
                    {
                    case CallbackOperation.ADD:
                        LogEntity entity = GetLogEntityById(id);
                        client.broadcastAddLogEntity(entity.Region, entity.Id);
                        break;

                    case CallbackOperation.UPDATE:
                        client.broadcastUpdateId(id);
                        break;

                    case CallbackOperation.DELETE:
                        client.broadcastDeleteId(id);
                        break;
                    }
                    Console.WriteLine("Hi from thread!");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0}", ex.Message);
                    deleteitems.Add(client);
                }
            }

            // Brisanje ugasenih klijenata..
            foreach (IDatabaseCallback client in deleteitems)
            {
                klijenti.Remove(client);
            }
        }
Ejemplo n.º 4
0
        private static void ProcessItems(Queue <ISocketCallback> queue, CallbackOperation operation)

        {
            if (queue == null)
            {
                return;
            }
            while (true)
            {
                // get the next item (note we could be competing with a worker here, hence lock)
                ISocketCallback callback;
                lock (queue)
                {
                    if (queue.Count == 0)
                    {
                        break;
                    }
                    callback = queue.Dequeue();
                }
                if (callback != null)
                {
                    try
                    {
                        switch (operation)
                        {
                        case CallbackOperation.Read: callback.Read(); break;

                        case CallbackOperation.Error: callback.Error(); break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static void ProcessItems(Dictionary<IntPtr, SocketPair> socketLookup, Queue<IntPtr> queue, CallbackOperation operation)

        {
            if (queue == null) return;
            while (true)
            {
                // get the next item (note we could be competing with a worker here, hence lock)
                IntPtr handle;
                lock (queue)
                {
                    if (queue.Count == 0) break;
                    handle = queue.Dequeue();
                }
                SocketPair pair;
                lock (socketLookup)
                {
                    if (!socketLookup.TryGetValue(handle, out pair)) continue;
                }
                var callback = pair.Callback;
                if (callback != null)
                {
                    try
                    {
                        switch (operation)
                        {
                            case CallbackOperation.Read: callback.Read(); break;
                            case CallbackOperation.Error: callback.Error(); break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex);
                    }
                }
            }
        }
        private static void ProcessItems(Dictionary <IntPtr, SocketPair> socketLookup, Queue <IntPtr> queue, CallbackOperation operation)

        {
            if (queue == null)
            {
                return;
            }
            while (true)
            {
                // get the next item (note we could be competing with a worker here, hence lock)
                IntPtr handle;
                lock (queue)
                {
                    if (queue.Count == 0)
                    {
                        break;
                    }
                    handle = queue.Dequeue();
                }
                SocketPair pair;
                lock (socketLookup)
                {
                    if (!socketLookup.TryGetValue(handle, out pair))
                    {
                        continue;
                    }
                }
                var callback = pair.Callback;
                if (callback != null)
                {
                    try
                    {
                        switch (operation)
                        {
                        case CallbackOperation.Read: callback.Read(); break;

                        case CallbackOperation.Error: callback.Error(); break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex);
                    }
                }
            }
        }