Beispiel #1
0
        public string Post(PharoSession session)
        {
            try
            {
                if (session.Id == new Guid("00000000-0000-0000-0000-000000000000"))
                {
                    return("Post rejected: session.Identifier equal 00000000-0000-0000-0000-000000000000.");
                }

                SessionSingleton.Instance.PostSessionList.Enqueue(session);

                SessionSingleton.Instance.ProcessPosting();

                return("Object created or updated!");
            }
            catch (Exception ex)
            {
                throw InternalError.ThrowError(ex);
            }
        }
Beispiel #2
0
            public async System.Threading.Tasks.Task ProcessPosting()
            {
                await System.Threading.Tasks.Task.Run(() =>
                {
                    lock (PostSessionList)
                    {
                        using (SwarmData context = new SwarmData())
                        {
                            while (PostSessionList.Count > 0)
                            {
                                PharoSession session = PostSessionList.Dequeue();

                                if (session == null)
                                {
                                    continue;
                                }

                                if (session.Id == new Guid("00000000-0000-0000-0000-000000000000"))
                                {
                                    continue;
                                }

                                PharoSession original = context.PharoSessions.FirstOrDefault(s => s.Id == session.Id);

                                if (original == null)
                                {
                                    context.PharoSessions.Add(session);
                                }
                                else
                                {
                                    context.Entry(original).CurrentValues.SetValues(session);
                                }

                                context.SaveChanges();
                            }
                        }
                    }
                });
            }