public void StopAll()
        {
            foreach (WorkerThread thread in ThreadList)
            {
                if (!IsDead(thread))
                {
                    thread.Stop();
                }
            }

            ThreadList.Clear();
        }
예제 #2
0
        protected override void OnLoad()
        {
            Logger.Print("Space scene start load");

            EventManager.AddEventListener(EventManager.Events.ShootEvent, Shoot);
            EventManager.AddEventListener(EventManager.Events.ChangeScoreEvent, OnChangeScore);

            Score = 0;

            _stars.Clear();
            _asteroids.Clear();
            _bullets.Clear();

            for (var i = 0; i < 100; i++)
            {
                _stars.Add(GameObjectsFactory.CreateStar());
            }

            Logger.Print("Created {0} stars", _stars.Count);

            _ship = GameObjectsFactory.CreateSpaceShip();

            var random = new Random();

            _timer          = new Timer();
            _timer.Interval = 2000;
            _timer.Tick    += (sender, args) =>
            {
                GameObjects obj;
                var         next = random.Next(100);
                if (next % 2 == 0)
                {
                    obj = GameObjectsFactory.CreateAsteroid();
                    _asteroids.Add(obj as Asteroid);
                    AddUpdatable(obj);
                }
                else
                {
                    obj = GameObjectsFactory.CreateMedic();
                    _medics.Add(obj as Medic);
                }

                AddDrawable(obj);
            };
            _timer.Start();

            AddDrawable(_stars);
            AddDrawable(_ship);

            AddUpdatable(_stars);
        }
예제 #3
0
        public override SceneState Load(ThreadList <IDrawable> drawList, ThreadList <IUpdatable> updateList,
                                        Action onLoad)
        {
            var dateTime = DateTime.Now;

            drawList.Clear();
            updateList.Clear();

            onLoad();

            Logger.Print("Scene loaded with {0:f3} seconds", (DateTime.Now - dateTime).TotalSeconds);

            return(new SceneStateLoaded());
        }
예제 #4
0
        // Нельзя вызывать Load дважды
        // Остальные методы, кроме добавления, не отработают, пока загрузка не будет завершена
        public void Load()
        {
            if (_loaded)
            {
                return;
            }

            var dateTime = DateTime.Now;

            _toDraw.Clear();
            _toUpdate.Clear();

            OnLoad();

            Logger.Print("Scene loaded with {0:f3} seconds", (DateTime.Now - dateTime).TotalSeconds);

            _loaded = true;
        }
예제 #5
0
            public void WriterThread()
            {
                //while download is ongoing : do while buffer < 100 do remove from queu and put in buffer till its @ 100 end write buffer to db; reset buffer end
                bool DownloadIsOngoing = ThreadList.Exists(x => x.IsAlive == true);

                while (DownloadIsOngoing)                                             //while there is at least one thread executing
                {
                    while (DownloadIsOngoing && BufferList.Count() < MaxObjectBuffer) //while buffer is not max size AND download threads are open
                    {
                        Match match = new Match();
                        if (QueuRef.TryDequeue(out match))
                        {
                            BufferList.Add(match);
                        }
                        else
                        {
                            //if we fail to retrieve an item it might signal that the download is finished so we have to evaluate downloadisongoing
                            //in fact this is the only place we should re evaluate it, its kind of a hack but it ensures that we continue to write to
                            //db while there are items left in the queu even though the download can be done already
                            DownloadIsOngoing = ThreadList.Exists(x => x.IsAlive == true);
                        }
                    }
                    //bufferlist now has 100 items in it, time to write
                    Writer.InsertRange(BufferList);
                    //raise event
                    //technically not the highest id but should be close
                    ReferenceToParent.OnDataWritten(new DownloaderEventArgs()
                    {
                        AmountWritten = BufferList.Count, HighestMatchIdWritten = BufferList.Last().match_id
                    });
                    log.Info("Wrote some matches, count is " + BufferList.Count.ToString());
                    BufferList.Clear(); //and reset it
                }
                //raise event
                ReferenceToParent.OnDownloadIsFinished();
                //cleanup the threads
                ThreadList.Clear();
            }
예제 #6
0
        protected override void OnLoad()
        {
            Logger.Print("Space scene start load");

            EventManager <ThrowObjectWaveEventArgs> .AddEventListener(GameEvents.WAVE_NEXT_OBJECT, OnNextObject);

            EventManager.AddEventListener(GameEvents.SHOOT, Shoot);
            EventManager.AddEventListener(GameEvents.STAGE_COMPLETE, OnStageCompleted);
            EventManager.AddEventListener(GameEvents.STAGE_GENERATED, OnStageGenerated);
            EventManager.AddEventListener(GameEvents.STAGE_GENERATE, OnStageGenerate);

            _generateWaveState.Init(_objects);
            _throwObjectWaveState.Init(_objects);
            _waitForNewWaveState.Init(_objects);

            _player = new Player();

            _stars.Clear();
            _asteroids.Clear();
            _bullets.Clear();

            for (var i = 0; i < 100; i++)
            {
                _stars.Add(GameObjectsFactory.CreateStar());
            }

            Logger.Print("Created {0} stars", _stars.Count);

            _ship = GameObjectsFactory.CreateSpaceShip();

            AddDrawable(_stars);
            AddDrawable(_ship);

            AddUpdatable(_stars);

            EventManager.DispatchEvent(GameEvents.STAGE_GENERATE);
        }
        async Task LoadData(int page)
        {
            ObservableCollection <messages> tempOpenData;

            if (page == 1)
            {
                tempOpenData = new ObservableCollection <messages>();
            }
            else
            {
                tempOpenData = new ObservableCollection <messages>(MessageList);
            }
            using (HttpClient hc = new HttpClient())
            {
                try
                {
                    IsBusy = true;
                    bool IsBookMarkSelect = false;

                    if (App.FrameImage != null)
                    {
                        ImageUrl       = App.FrameImage;
                        isImageVisible = true;
                    }
                    if (App.FileName != null)
                    {
                        FileName      = App.FileName;
                        isDocsVisible = true;
                    }

                    var jsonString = await hc.GetStringAsync(Config.MESSAGE_THREAD_API + threadId + "/" + page);

                    if (jsonString != "")
                    {
                        var obj = JsonConvert.DeserializeObject <DealMessageThreadList>(jsonString);
                        if (obj != null)
                        {
                            foreach (var user in obj.messages)
                            {
                                ThreadList.Clear();

                                if (string.IsNullOrEmpty(user.plainContent))
                                {
                                    user.plainContent = "";
                                }

                                if (user.plainContent.Contains("<p><br/></p>"))
                                {
                                    string value = user.plainContent.Replace("<p><br/></p>", null);
                                    user.plainContent = value;
                                }

                                if (user.plainContent.Contains("<li>"))
                                {
                                    string value = user.plainContent.Replace("?", "");
                                    user.plainContent = value;
                                }

                                if (user.plainContent.Contains("data:image"))
                                {
                                    string[] delim1       = { "<img src=\"data:image/png;base64," };
                                    var      MessageValue = user.plainContent.Split(delim1, StringSplitOptions.None)[0];
                                    var      image        = user.plainContent.Split(delim1, StringSplitOptions.None)[1];
                                    var      image1       = image.Split('"')[0];
                                    //Debug.Write(image1);

                                    string[] delim     = { "alt=\"\">" };
                                    var      stringMsg = image.Split(delim, StringSplitOptions.None);

                                    var Base64Stream = Convert.FromBase64String(image1);
                                    user.MsgImageUrl    = ImageSource.FromStream(() => new MemoryStream(Base64Stream));
                                    user.IsImageVisible = true;

                                    int index = 2;
                                    if (index == stringMsg.Length)
                                    {
                                        if (stringMsg[1] != null)
                                        {
                                            user.plainContent = MessageValue + stringMsg[1];
                                        }
                                    }
                                    else
                                    {
                                        string message = Regex.Replace(MessageValue, HTML_TAG_PATTERN, string.Empty);
                                        if (!string.IsNullOrEmpty(message))
                                        {
                                            user.plainContent = MessageValue;
                                        }
                                        else
                                        {
                                            user.plainContent = string.Empty;
                                        }
                                    }
                                }

                                string authorIdStr = user.authorId;
                                if (user.messageUsers != null)
                                {
                                    foreach (var thread in user.messageUsers)
                                    {
                                        if (thread.userid_10 == userId)
                                        {
                                            if (thread.followUp == true)
                                            {
                                                IsBookMarkSelect = true;
                                            }
                                            else
                                            {
                                                IsBookMarkSelect = false;
                                            }
                                        }
                                        ThreadList.Add(thread);
                                    }

                                    if (IsBookMarkSelect == true)
                                    {
                                        user.BookMarkImg = "orange_bookmark.png";
                                    }
                                    else
                                    {
                                        user.BookMarkImg = "bookmark.png";
                                    }
                                }

                                if (authorIdStr == null)
                                {
                                    user.HorizontalOption        = LayoutOptions.StartAndExpand;
                                    user.IsSenderBookMarkVisible = false;
                                    user.IsSenderProfileVisible  = true;
                                    user.IsProfileVisible        = false;
                                    user.IsBookMarkVisible       = true;
                                }
                                else if (authorIdStr.Equals(userId))
                                {
                                    user.HorizontalOption        = LayoutOptions.EndAndExpand;
                                    user.IsSenderBookMarkVisible = true;
                                    user.IsSenderProfileVisible  = false;
                                    user.IsProfileVisible        = true;
                                    user.IsBookMarkVisible       = false;
                                }
                                else
                                {
                                    user.HorizontalOption        = LayoutOptions.StartAndExpand;
                                    user.IsSenderBookMarkVisible = false;
                                    user.IsSenderProfileVisible  = true;
                                    user.IsProfileVisible        = false;
                                    user.IsBookMarkVisible       = true;
                                }

                                if (user.plainContent == null)
                                {
                                    user.IsStopVisible = false;
                                    user.HeightRequest = 0;
                                }
                                else if (user.plainContent.Count() < 150)
                                {
                                    user.IsStopVisible = false;
                                    user.HeightRequest = 0;
                                }

                                else if (user.plainContent.Count() > 150)
                                {
                                    user.IsStopVisible = true;
                                    user.moreBtnText   = "more";
                                    user.HeightRequest = 35;
                                    user.MaxLines      = 3;
                                }
                                tempOpenData.Add(user);
                            }
                            TotalRecords = obj.totalRecords;
                            _LastPage    = Convert.ToInt32(obj.totalPages);
                            ObservableCollection <messages> OrderbyIdDesc = new ObservableCollection <messages>(tempOpenData.OrderByDescending(x => x.createdDate.Date));
                            MessageList = new ObservableCollection <messages>(OrderbyIdDesc);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception:>" + ex);
                }
                finally
                {
                    IsBusy = false;
                }
            }
        }
        async Task LoadData(int page)
        {
            var tempOpenData = new ObservableCollection <messages>(MessageList);

            using (HttpClient hc = new HttpClient())
            {
                try
                {
                    IsBusy = true;
                    bool IsBookMarkSelect = false;
                    if (Settings.TypedMessage != null)
                    {
                        TypedMessage = Settings.TypedMessage;
                    }

                    var jsonString = await hc.GetStringAsync(Config.MESSAGE_THREAD_API + threadId + "/" + page);

                    if (jsonString != "")
                    {
                        var obj = JsonConvert.DeserializeObject <DealMessageThreadList>(jsonString);
                        if (obj != null)
                        {
                            foreach (var user in obj.messages)
                            {
                                ThreadList.Clear();
                                string authorIdStr = user.authorId;

                                if (user.messageUsers != null)
                                {
                                    foreach (var thread in user.messageUsers)
                                    {
                                        if (thread.userid_10 == userId)
                                        {
                                            if (thread.followUp == true)
                                            {
                                                IsBookMarkSelect = true;
                                            }
                                            else
                                            {
                                                IsBookMarkSelect = false;
                                            }
                                        }
                                        ThreadList.Add(thread);
                                    }

                                    if (IsBookMarkSelect == true)
                                    {
                                        user.BookMarkImg = "orange_bookmark.png";
                                    }
                                    else
                                    {
                                        user.BookMarkImg = "bookmark.png";
                                    }
                                }

                                if (authorIdStr == null)
                                {
                                    user.HorizontalOption        = LayoutOptions.StartAndExpand;
                                    user.IsSenderBookMarkVisible = false;
                                    user.IsSenderProfileVisible  = true;
                                    user.IsProfileVisible        = false;
                                    user.IsBookMarkVisible       = true;
                                }
                                else if (authorIdStr.Equals(userId))
                                {
                                    user.HorizontalOption        = LayoutOptions.EndAndExpand;
                                    user.IsSenderBookMarkVisible = true;
                                    user.IsSenderProfileVisible  = false;
                                    user.IsProfileVisible        = true;
                                    user.IsBookMarkVisible       = false;
                                }
                                else
                                {
                                    user.HorizontalOption        = LayoutOptions.StartAndExpand;
                                    user.IsSenderBookMarkVisible = false;
                                    user.IsSenderProfileVisible  = true;
                                    user.IsProfileVisible        = false;
                                    user.IsBookMarkVisible       = true;
                                }

                                if (user.plainContent == null)
                                {
                                    user.IsStopVisible = false;
                                    user.HeightRequest = 0;
                                }
                                else if (user.plainContent.Count() < 150)
                                {
                                    user.IsStopVisible = false;
                                    user.HeightRequest = 0;
                                }

                                else if (user.plainContent.Count() > 150)
                                {
                                    user.IsStopVisible = true;
                                    user.moreBtnText   = "more";
                                    user.HeightRequest = 35;
                                    user.MaxLines      = 3;
                                }
                                TotalRecords = obj.totalRecords;
                                _LastPage    = Convert.ToInt32(obj.totalPages);
                                tempOpenData.Add(user);
                            }

                            ObservableCollection <messages> OrderbyIdDesc = new ObservableCollection <messages>(tempOpenData.OrderByDescending(x => x.createdDate.Date));
                            MessageList = new ObservableCollection <messages>(OrderbyIdDesc);
                        }
                    }
                }
                finally
                {
                    IsBusy = false;
                }
            }
        }