示例#1
0
        private static void Build(BuilderController builderController)
        {
            var dbChunk = new DbChunk(Settings.Current.Building.BuilderConnectionString);
             int? chunkId = null;
             while (true)
             {
            try
            {
               builderController.RefreshState();
               if (builderController.Builder.State == BuilderState.Stopping)
                  break;

               if (builderController.Builder.State == BuilderState.Stopped)
                  break;

               if (builderController.Builder.State == BuilderState.Error)
                  break;

               if (builderController.Builder.State == BuilderState.Unknown || builderController.Builder.State == BuilderState.Idle)
                  continue;

               chunkId = dbChunk.TakeChunk(Settings.Current.Building.Id.Value);
               if (!chunkId.HasValue) break;

               var builder = new ChunkBuilder(new ChunkData { Id = chunkId.Value }, GetBuilderType(Settings.Current.Building.Vendor));
               var loaded_chunk = builder.Load();
               var built_chunk = loaded_chunk.Build();
               var task = built_chunk.Save();
               tasks.Add(task);
            }
            catch (Exception e)
            {
               if (chunkId.HasValue)
                  Logger.WriteError(chunkId, e);
               else
                  Logger.Write(null, Settings.Current.Building.Id.Value, null, LogMessageTypes.Error, Logger.CreateExceptionString(e));

               builderController.UpdateState(BuilderState.Error);
            }
             }
        }
示例#2
0
        private static void Build(BuilderController builderController)
        {
            var dbChunk = new DbChunk(Settings.Current.Building.BuilderConnectionString);
            int?chunkId = null;

            while (true)
            {
                try
                {
                    builderController.RefreshState();
                    if (builderController.Builder.State == BuilderState.Stopping)
                    {
                        break;
                    }

                    if (builderController.Builder.State == BuilderState.Stopped)
                    {
                        break;
                    }

                    if (builderController.Builder.State == BuilderState.Error)
                    {
                        break;
                    }

                    if (builderController.Builder.State == BuilderState.Unknown ||
                        builderController.Builder.State == BuilderState.Idle)
                    {
                        continue;
                    }

                    chunkId = dbChunk.TakeChunk(Settings.Current.Building.Id.Value, Settings.Current.Builder.Id.Value, GetRandomBoolean());
                    if (!chunkId.HasValue)
                    {
                        break;
                    }

                    Console.WriteLine($"ChunkId={chunkId} in progress...");

                    var attempt    = 0;
                    var processing = false;
                    var chunk      = Settings.Current.Building.SourceEngine.GetChunkBuilder(chunkId.Value, CreatePersonBuilder);
                    while (!processing)
                    {
                        try
                        {
                            attempt++;
                            chunk.Process();
                            processing = true;
                        }
                        catch (Exception ex)
                        {
                            if (attempt <= 3)
                            {
                                Logger.Write(chunkId, LogMessageTypes.Warning, "chunk.Process attempt=" + attempt + ") " + Logger.CreateExceptionString(ex));
                                chunk = Settings.Current.Building.SourceEngine.GetChunkBuilder(chunkId.Value, CreatePersonBuilder);
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                    chunkId = null;
                }
                catch (Exception e)
                {
                    if (chunkId.HasValue)
                    {
                        Logger.WriteError(chunkId, e);
                        dbChunk.ChunkFailed(chunkId.Value, Settings.Current.Building.Id.Value);
                    }
                    else
                    {
                        Logger.Write(null, Settings.Current.Building.Id.Value, null, LogMessageTypes.Error,
                                     Logger.CreateExceptionString(e));
                    }


                    builderController.UpdateState(BuilderState.Error);
                }
            }
        }
示例#3
0
        private static void Build(BuilderController builderController)
        {
            var dbChunk = new DbChunk(Settings.Current.Building.BuilderConnectionString);
            int?chunkId = null;

            while (true)
            {
                try
                {
                    builderController.RefreshState();
                    if (builderController.Builder.State == BuilderState.Stopping)
                    {
                        break;
                    }

                    if (builderController.Builder.State == BuilderState.Stopped)
                    {
                        break;
                    }

                    if (builderController.Builder.State == BuilderState.Error)
                    {
                        break;
                    }

                    if (builderController.Builder.State == BuilderState.Unknown || builderController.Builder.State == BuilderState.Idle)
                    {
                        continue;
                    }


                    chunkId = dbChunk.TakeChunk(Settings.Current.Building.Id.Value);
                    if (!chunkId.HasValue)
                    {
                        break;
                    }

                    var builder = new ChunkBuilder(new ChunkData {
                        Id = chunkId.Value
                    }, GetBuilderType(Settings.Current.Building.Vendor));
                    var loaded_chunk = builder.Load();
                    var built_chunk  = loaded_chunk.Build();
                    var task         = built_chunk.Save();
                    tasks.Add(task);
                }
                catch (Exception e)
                {
                    if (chunkId.HasValue)
                    {
                        Logger.WriteError(chunkId, e);
                    }
                    else
                    {
                        Logger.Write(null, Settings.Current.Building.Id.Value, null, LogMessageTypes.Error, Logger.CreateExceptionString(e));
                    }


                    builderController.UpdateState(BuilderState.Error);
                }
            }
        }