Example #1
0
        private HighscoreManager(GameState gameState, bool onlyHighscore)
        {
            _gameState = gameState;

            _pixelWhite = Main.ContentManager.Load<Texture2D>("images/pixelWhite");
            _highscore = Main.ContentManager.Load<Texture2D>("images/highscore/highscore");
            _score = Main.ContentManager.Load<Texture2D>("images/highscore/score");

            if (!onlyHighscore)
            {
                _updateDelegate = UpdateScore;
                _drawDelegate = DrawScore;
            }
            else
            {
                _updateDelegate = UpdateHighscore;
                _drawDelegate = DrawHighscore;
            }

            _font = Main.ContentManager.Load<SpriteFont>(Configuration.Get("defaultFont"));

            // Koordinaten
            DrawHelper.AddDimension("Score_Name", 300, 411);
            DrawHelper.AddDimension("Score_Gesamt", 1, 175);
            DrawHelper.AddDimension("Score_LineHeight", 1, 60);
            DrawHelper.AddDimension("Score_XKoods", 160, 560);

            DrawHelper.AddDimension("Highscore_XKoods", 200, 500);
        }
Example #2
0
		//------------------------------------------------------------------------------------------------------------------------
		//														Remove()
		//------------------------------------------------------------------------------------------------------------------------
		public void Remove(GameObject gameObject) {
			if (_updateReferences.ContainsKey(gameObject)) {
				UpdateDelegate onUpdate = _updateReferences[gameObject];
				if (onUpdate != null) _updateDelegates -= onUpdate;			
				_updateReferences.Remove(gameObject);
			}
		}
 public void AddPopUp()
 {
     uDelagate += PopUp;
     startPopTime = Time.time;
     if (doob != null)
         doob.PlayClip();
 }
 public void AddPopDown()
 {
     uDelagate += PopDown;
     startPopTime = Time.time;
     hasOverReachedX = false;
     hasOverReachedY = false;
 }
        public GuiVFlashPathBankTransitionConditions(IEnumerable<VFlashTypeBank.VFlashTypeComponentStepCondition> conditions, UpdateDelegate updateDelegate)
        {
            InitializeComponent();
            ConditionsDataGrid.ItemsSource = conditions;

            _assignmentDelegate += updateDelegate;
        }
Example #6
0
 /// <summary>
 /// Notify all observer that the queue have changed.
 /// </summary>
 private void NotifyAll()
 {
     foreach (IQueueObserver obs in _observerList)
     {
         UpdateDelegate upDelegate = new UpdateDelegate(obs.Update);
         upDelegate.BeginInvoke(null, null);
     }
 }
 public AnnotationView()
 {
     InitializeComponent();
      updateDel = new UpdateDelegate(DoUpdate);
      this.Height = timeLabel.Height;
      this.pictureBox.Width = this.Width;
      this.textLabel.Width = this.Width;
 }
Example #8
0
 public AnimationRenderer(Texture2D[] textures, float fps)
 {
     this.Textures = textures;
     this.framesPerSecond = fps;
     this.animationTimer = 0;
     this.frameDuration = 1 / framesPerSecond;
     update = UpdateLoop;
 }
 public BT_BehaviorDelegator(NodeDescription.BT_NodeType type, UpdateDelegate onUpdate, InitDelegate onInit = null, EnterDelegate onEnter = null, ExitDelegate onExit = null, TerminateDelegate onTerm = null)
 {
     Description.Type = type;
     
     initDel = onInit;
     enterDel = onEnter;
     updateDel = onUpdate;
     exitDel = onExit;
     terminateDel = onTerm;
 }
Example #10
0
		//------------------------------------------------------------------------------------------------------------------------
		//														Add()
		//------------------------------------------------------------------------------------------------------------------------
		public void Add(GameObject gameObject) {
			MethodInfo info = gameObject.GetType().GetMethod("Update", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
			if (info != null) {
				UpdateDelegate onUpdate = (UpdateDelegate)Delegate.CreateDelegate(typeof(UpdateDelegate), gameObject, info, false);
				if (onUpdate != null && !_updateReferences.ContainsKey(gameObject)) {
					_updateReferences[gameObject] = onUpdate;
					_updateDelegates += onUpdate;
				}
			} else {
				validateCase(gameObject);
			}
		}
Example #11
0
        public void UpdateLog(object sender, EventArgs e)
        {
            // Making this thread safe
            if(this.InvokeRequired)
            {
                UpdateDelegate updateDelgate = new UpdateDelegate(this.UpdateLog);
                this.Invoke(updateDelgate, new object[] { sender, e });
                return;
            }

            this.logTextBox.Text = "";
            this.logTextBox.AppendText(PkLogging.Log);
        }
Example #12
0
 /// <summary>
 /// Same as PushAndDo(desc, redo, undo) but also calls the specified UpdateDelegate after
 /// both the undo and redo operation.
 /// 
 /// This is to avoid code duplication if some UI elements needs to be updated in either case.
 /// </summary>
 /// <param name="description"></param>
 /// <param name="redo"></param>
 /// <param name="undo"></param>
 /// <param name="update"></param>
 public void PushAndDo(String description, RedoDelegate redo, UndoDelegate undo, UpdateDelegate update)
 {
     PushAndDo(description,
         () =>
         {
             redo();
             update();
         },
         () =>
         {
             undo();
             update();
         });
 }
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            var userchat = context.Update.ToUserchat();

            var cachedCtx = await GetCachedContextsAsync(context, userchat, cancellationToken)
                            .ConfigureAwait(false);

            if (cachedCtx.Bus != null && cachedCtx.Location != null)
            {
                _logger.LogTrace("Bus route and location is provided. Sending bus predictions.");

                var busStop = await _predictionsService.FindClosestBusStopAsync(
                    cachedCtx.Profile.DefaultAgencyTag,
                    cachedCtx.Bus.RouteTag,
                    cachedCtx.Bus.DirectionTag,
                    cachedCtx.Location.Longitude,
                    cachedCtx.Location.Latitude,
                    cancellationToken
                    ).ConfigureAwait(false);

                var predictions = await _predictionsService.GetPredictionsAsync(
                    cachedCtx.Profile.DefaultAgencyTag,
                    cachedCtx.Bus.RouteTag,
                    busStop.Tag,
                    cancellationToken
                    ).ConfigureAwait(false);

                IReplyMarkup locationReplyMarkup;
                if (string.IsNullOrWhiteSpace(cachedCtx.Bus.Origin))
                {
                    locationReplyMarkup = new ReplyKeyboardRemove();
                }
                else
                {
                    locationReplyMarkup = new InlineKeyboardMarkup(
                        InlineKeyboardButton.WithCallbackData("🚩 Remember this location", "loc/save")
                        );
                }

                await context.Bot.Client.MakeRequestWithRetryAsync(
                    new SendLocationRequest(userchat.ChatId, busStop.Latitude, busStop.Longitude)
                {
                    ReplyToMessageId = cachedCtx.Location.LocationMessageId,
                    ReplyMarkup      = locationReplyMarkup,
                },
                    cancellationToken
                    ).ConfigureAwait(false);

                string text = "👆 That's the nearest bus stop";
                if (!string.IsNullOrWhiteSpace(busStop.Title))
                {
                    text += $", *{busStop.Title}*";
                }
                text += " 🚏.";

                string message = RouteMessageFormatter.FormatBusPredictionsReplyText(predictions.Predictions);
                text += "\n\n" + message;

                var predictionsMessage = await context.Bot.Client.MakeRequestWithRetryAsync(
                    new SendMessageRequest(userchat.ChatId, text)
                {
                    ParseMode   = ParseMode.Markdown,
                    ReplyMarkup = (InlineKeyboardMarkup)InlineKeyboardButton.WithCallbackData("Update", "pred/"),
                },
                    cancellationToken
                    ).ConfigureAwait(false);

                var prediction = new BusPrediction
                {
                    AgencyTag    = cachedCtx.Profile.DefaultAgencyTag,
                    RouteTag     = cachedCtx.Bus.RouteTag,
                    DirectionTag = cachedCtx.Bus.DirectionTag,
                    BusStopTag   = busStop.Tag,
                    Origin       = cachedCtx.Bus.Origin,
                    UserLocation = new GeoJsonPoint <GeoJson2DCoordinates>(
                        new GeoJson2DCoordinates(cachedCtx.Location.Longitude, cachedCtx.Location.Latitude)),
                };

                await _predictionRepo.AddAsync(cachedCtx.Profile.Id, prediction, cancellationToken)
                .ConfigureAwait(false);

                await context.Bot.Client.MakeRequestWithRetryAsync(
                    new EditMessageReplyMarkupRequest(
                        predictionsMessage.Chat,
                        predictionsMessage.MessageId,
                        InlineKeyboardButton.WithCallbackData("Update", $"pred/id:{prediction.Id}")
                        ), cancellationToken
                    ).ConfigureAwait(false);
            }
            else if (cachedCtx.Bus != null)
            {
                _logger.LogTrace("Location is missing. Asking user to send his location.");

                var route = await _routeRepo.GetByTagAsync(
                    cachedCtx.Profile.DefaultAgencyTag,
                    cachedCtx.Bus.RouteTag,
                    cancellationToken
                    ).ConfigureAwait(false);

                var direction = route.Directions.Single(d => d.Tag == cachedCtx.Bus.DirectionTag);

                string text = _routeMessageFormatter.GetMessageTextForRouteDirection(route, direction);

                text += "\n\n*Send your current location* so I can find you the nearest bus stop 🚏 " +
                        "and get the bus predictions for it.";
                int replyToMessage = context.Update.Message?.MessageId
                                     ?? context.Update.CallbackQuery?.Message?.MessageId
                                     ?? 0;
                await context.Bot.Client.MakeRequestWithRetryAsync(
                    new SendMessageRequest(userchat.ChatId, text)
                {
                    ParseMode        = ParseMode.Markdown,
                    ReplyToMessageId = replyToMessage,
                    ReplyMarkup      = new ReplyKeyboardMarkup(new[]
                    {
                        KeyboardButton.WithRequestLocation("Share my location")
                    }, true, true)
                },
                    cancellationToken
                    ).ConfigureAwait(false);
            }
            else if (cachedCtx.Location != null)
            {
                _logger.LogTrace("Bus route and direction are missing. Asking user to provide them.");

                await context.Bot.Client.MakeRequestWithRetryAsync(
                    new SendMessageRequest(
                        userchat.ChatId,
                        "There you are! What's the bus you want to catch?\n" +
                        "Send me using 👉 /bus command."
                        )
                {
                    ReplyToMessageId = context.Update.Message.MessageId,
                    ReplyMarkup      = new ReplyKeyboardRemove()
                },
                    cancellationToken
                    ).ConfigureAwait(false);
            }

            // ToDo: Remove keyboard if that was set in /bus command
//
//            var userchat = context.Update.ToUserchat();
//
//            if (context.Update.Message?.Location != null)
//            {
//                await HandleLocationUpdateAsync(
//                    context.Bot,
//                    userchat,
//                    context.Update.Message.Location,
//                    context.Update.Message.MessageId,
//                    cancellationToken
//                ).ConfigureAwait(false);
//            }
//            else if (context.Update.Message?.Text != null)
//            {
//                _logger.LogTrace("Checking if this text message has location coordinates.");
//
//                var result = _locationService.TryParseLocation(context.Update.Message.Text);
//                if (result.Successful)
//                {
//                    _logger.LogTrace("Location is shared from text");
//                    await HandleLocationUpdateAsync(
//                        context.Bot,
//                        userchat,
//                        new Location { Latitude = result.Lat, Longitude = result.Lon },
//                        context.Update.Message.MessageId,
//                        cancellationToken
//                    ).ConfigureAwait(false);
//                }
//                else
//                {
//                    _logger.LogTrace("Message text does not have a location. Ignoring the update.");
//                }
//            }
//
//            var locationTuple = _locationsManager.TryParseLocation(context.Update);
//
//            if (locationTuple.Successful)
//            {
//                _locationsManager.AddLocationToCache(userchat, locationTuple.Location);
//
//                await _predictionsManager
//                    .TryReplyWithPredictionsAsync(context.Bot, userchat, context.Update.Message.MessageId)
//                    .ConfigureAwait(false);
//            }
//            else
//            {
//                // todo : if saved location available, offer it as keyboard
//                await context.Bot.Client.SendTextMessageAsync(
//                    context.Update.Message.Chat.Id,
//                    "_Invalid location!_",
//                    ParseMode.Markdown,
//                    replyToMessageId: context.Update.Message.MessageId
//                ).ConfigureAwait(false);
//            }
        }
Example #14
0
        private bool WriteBarcode(string barcode)
        {
            try
            {
                var result = ServiceProxy.packShell(barcode, Login.INDEX, package, Login.REGISTRARID);
                switch (result.status)
                {
                case 1:          //case 1:

                    //if (result.pack != 0)
                    //{
                    ChangeStatusInList(barcode, 1);
                    numberOfThings     = result.pack.ToString();        // result[1];
                    numberOfThingsUser = result.packUser.ToString();    // result[2];
                    UpdateNumberDelegate handler3 = DrowNumber;
                    Invoke(handler3, new object[] { numberOfThings + "/" + numberOfThingsUser });
                    // }
                    // else { MessageBox.Show("Змін по штрихкоду не внесено"); ChangeStatusInList(barcode, -1);  }
                    break;

                case -990: MessageBox.Show("Поштове відправлення зі штрихкодом " + barcode + " не знайдено серед прийнятої пошти (гілка «Сканована на вхід»)."); ChangeStatusInList(barcode, -1); break;

                case -999: MessageBox.Show("Штрихкод " + barcode + " не знайдено."); ChangeStatusInList(barcode, -1); break;

                case -998: MessageBox.Show("Штрихкод " + barcode + " являється оболонкою."); ChangeStatusInList(barcode, -1); break;

                case -997: MessageBox.Show("Штрихкод " + barcode + " не знайдено на індексі " + Login.INDEX); ChangeStatusInList(barcode, -1); break;

                case -996: MessageBox.Show("Статус оболонки " + package + " !=0 "); ChangeStatusInList(barcode, -1); break;

                case -1: MessageBox.Show("Штрихкод уже запакований в дану оболонку"); break;

                case -2: MessageBox.Show("Штрихкод уже вивантажено в АСРК (статус -2)"); ChangeStatusInList(barcode, -1); break;

                case 2: MessageBox.Show("Штрихкод уже вивантажено в АСРК (статус 2)"); ChangeStatusInList(barcode, -1); break;

                case -994: MessageBox.Show("Штрихкод запаковано в іншу оболонку"); ChangeStatusInList(barcode, -1); break;

                //-999 если не найден баркод
                //-barcode.getStatus() если статус баркода не 0 и не 99
                //-998 если баркод является шеллом (операция 20201)
                //-997 если не найден текой шелл для данного отделения
                //-996 если шелл имеет статус не 0 (то есть уже запакован или отменен)
                //-1 если упакован в текущий шелл
//-994 если упакован в другой шелл


                default:
                {
                    MessageBox.Show("Статус = " + result.status); ChangeStatusInList(barcode, -1); break;

                    /*
                     * if (result[0].Equals(package))
                     * {
                     *  ChangeStatusInLocalDB(barcode, 1);
                     *  UpdateDelegate handler1 = DrowFromLocalDB;
                     *  Invoke(handler1, new object[] { });
                     *  numberOfThings = result[1];
                     *  numberOfThingsUser = result[2];
                     *  UpdateNumberDelegate handler6 = DrowNumber;
                     *  Invoke(handler6, new object[] { numberOfThings + "/" + numberOfThingsUser });
                     *  MessageBox.Show("Річ уже додана в оболонку");
                     * }
                     * else
                     * {
                     *  MessageBox.Show("Річ прив'язана до оболонки: " + result[0] + ".");
                     *  ChangeStatusInLocalDB(barcode, -1);
                     * }*/
                }
                    UpdateDelegate handler = DrowFromLocalDB;
                    Invoke(handler, new object[] { });
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
                return(false);
            }
        }
Example #15
0
 public void AddUpdateListener(UpdateDelegate updateMethod)
 {
     //
     UpdateEvent += updateMethod;
 }
Example #16
0
 private void UpdateSceneCleanup()
 {
     System.GC.Collect();
     updateSceneDelegate = UpdateSceneLoad;
     if (background == null)
     {
         background = GameSettings.Background();
     }
     displayBackground = true;
     loadingFinished = false;
 }
        private static void GetBoardSpecificConfiguration(ISuperIO superIO,
            Manufacturer manufacturer, Model model, out IList<Voltage> v,
            out IList<Temperature> t, out IList<Fan> f, out IList<Ctrl> c,
            out ReadValueDelegate readVoltage,
            out ReadValueDelegate readTemperature,
            out ReadValueDelegate readFan,
            out ReadValueDelegate readControl,
            out UpdateDelegate postUpdate, out Mutex mutex)
        {
            readVoltage = (index) => superIO.Voltages[index];
              readTemperature = (index) => superIO.Temperatures[index];
              readFan = (index) => superIO.Fans[index];
              readControl = (index) => superIO.Controls[index];

              postUpdate = () => { };
              mutex = null;

              v = new List<Voltage>();
              t = new List<Temperature>();
              f = new List<Fan>();
              c = new List<Ctrl>();

              switch (superIO.Chip) {
            case Chip.IT8705F:
            case Chip.IT8712F:
            case Chip.IT8716F:
            case Chip.IT8718F:
            case Chip.IT8720F:
            case Chip.IT8726F:
              GetITEConfigurationsA(superIO, manufacturer, model, v, t, f, c,
            ref readFan, ref postUpdate, ref mutex);
              break;

            case Chip.IT8721F:
            case Chip.IT8728F:
            case Chip.IT8771E:
            case Chip.IT8772E:
              GetITEConfigurationsB(superIO, manufacturer, model, v, t, f, c);
              break;

            case Chip.F71858:
              v.Add(new Voltage("VCC3V", 0, 150, 150));
              v.Add(new Voltage("VSB3V", 1, 150, 150));
              v.Add(new Voltage("Battery", 2, 150, 150));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
            t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
            f.Add(new Fan("Fan #" + (i + 1), i));
              break;
            case Chip.F71862:
            case Chip.F71869:
            case Chip.F71869A:
            case Chip.F71882:
            case Chip.F71889AD:
            case Chip.F71889ED:
            case Chip.F71889F:
            case Chip.F71808E:
              GetFintekConfiguration(superIO, manufacturer, model, v, t, f);
              break;

            case Chip.W83627EHF:
              GetWinbondConfigurationEHF(manufacturer, model, v, t, f);
              break;
            case Chip.W83627DHG:
            case Chip.W83627DHGP:
            case Chip.W83667HG:
            case Chip.W83667HGB:
              GetWinbondConfigurationHG(manufacturer, model, v, t, f);
              break;
            case Chip.W83627HF:
            case Chip.W83627THF:
            case Chip.W83687THF:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("Voltage #3", 2, true));
              v.Add(new Voltage("AVCC", 3, 34, 51));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("5VSB", 5, 34, 51));
              v.Add(new Voltage("VBAT", 6));
              t.Add(new Temperature("CPU", 0));
              t.Add(new Temperature("Auxiliary", 1));
              t.Add(new Temperature("System", 2));
              f.Add(new Fan("System Fan", 0));
              f.Add(new Fan("CPU Fan", 1));
              f.Add(new Fan("Auxiliary Fan", 2));
              break;
            case Chip.NCT6771F:
            case Chip.NCT6776F:
              GetNuvotonConfigurationF(superIO, manufacturer, model, v, t, f, c);
              break;
            case Chip.NCT6779D:
            case Chip.NCT6791D:
              GetNuvotonConfigurationD(superIO, manufacturer, model, v, t, f, c);
              break;
            default:
              GetDefaultConfiguration(superIO, v, t, f, c);
              break;
              }
        }
Example #18
0
 protected void Start()
 {
     SwitchScene("Menu");
     updateSceneDelegate = UpdateSceneCleanup;
 }
Example #19
0
    private void OnTimerPause(FLEventBase e)
    {
//		Debug.Log("OnTimerPause");
        updateDelegate = null;
    }
Example #20
0
 public abstract Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args);
Example #21
0
 public void StartGame()
 {
     SwitchScene("Game");
     updateSceneDelegate = UpdateSceneUnload;
 }
Example #22
0
 private void UpdateSceneUnload()
 {
     if (sceneController != null)
     {
         Destroy(sceneController);
         sceneController = null;
     }
     currentScene = "";
     updateSceneDelegate = UpdateSceneCleanup;
 }
Example #23
0
 private void UpdateSceneRun()
 {
     if (currentScene != nextScene)
     {
         updateSceneDelegate = UpdateSceneUnload;
         updateGuiDelegate = UpdateGui;
     }
 }
Example #24
0
 private void UpdateSceneLoadingScreen()
 {
     if (loadingFinished)//(loadingProgress >= 1)
     {
         displayBackground = false;
         loadingFinished = false;
         updateSceneDelegate = UpdateSceneRun;
         updateGuiDelegate = UpdateGui;
     }
 }
Example #25
0
 private void UpdateSceneLoad()
 {
     sceneController = gameObject.AddComponent(nextScene + "Controller");
     if (sceneController == null)
     {
         Debug.LogWarning("Failed to add component: " + nextScene + "Controller");
     }
     currentScene = nextScene;
     updateSceneDelegate = UpdateSceneLoadingScreen;
     updateGuiDelegate = UpdateGui;
 }
Example #26
0
 public Task HandleAsync(IUpdateContext context, UpdateDelegate next)
 => _predicate(context)
         ? _branch(context)
         : next(context);
Example #27
0
 public FSMState( string stateName, UpdateDelegate del = null )
 {
     name = stateName;
     _updateDelegate = del;
 }
Example #28
0
 public Task HandleAsync(IUpdateContext context, UpdateDelegate next)
 {
     return(HandleAsync(context, next, ParseCommandArgs(context.Update.Message)));
 }
Example #29
0
 public void AddTick(ITick tick)
 {
     _ticks += tick.Update;
 }
Example #30
0
 public bool InstallInvestigation(Scenario.UpdateDelegate func)
 {
     OnInvestigateScenario += func;
     return(true);
 }
Example #31
0
 public StateCacheService(
     IBotBuilder botBuilder
     )
 {
     _updateDelegate = botBuilder.Build();
 }
Example #32
0
 public Update(double minRequiredVersion, UpdateDelegate updateMethod)
 {
     MinRequiredVersion = minRequiredVersion;
     UpdateMethod       = updateMethod;
 }
Example #33
0
 // ***************************************************************************
 // Frame weiterzählen
 public void PlayOnce()
 {
     update = UpdateOnce;
 }
Example #34
0
 public MouseButton(OpenTK.Input.MouseButton button, UpdateDelegate handler)
 {
     this.button  = button;
     this.handler = handler;
 }
Example #35
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            var msg    = context.Update.Message;
            var chatId = msg.Chat.Id;
            var fromId = msg.From.Id;

            _chatProcessor          = new ChatProcessor(context);
            _elasticSecurityService = new ElasticSecurityService(msg);

            if (fromId.IsSudoer())
            {
                if (msg.ReplyToMessage != null)
                {
                    var repMsg = msg.ReplyToMessage;
                    var userId = repMsg.From.Id;

                    ConsoleHelper.WriteLine("Execute Global Ban");
                    await _chatProcessor.SendAsync("Mempersiapkan..");

                    await _chatProcessor.DeleteAsync(msg.MessageId);

                    var isBan = await _elasticSecurityService.IsExist(userId);

                    ConsoleHelper.WriteLine($"IsBan: {isBan}");
                    if (isBan)
                    {
                        await _chatProcessor.EditAsync("Pengguna sudah di ban");
                    }
                    else
                    {
                        var data = new Dictionary <string, object>()
                        {
                            { "user_id", userId },
                            { "banned_by", fromId },
                            { "banned_from", chatId }
                        };

                        await _chatProcessor.EditAsync("Menyimpan informasi..");

                        var save = await _elasticSecurityService.SaveBanAsync(data);

                        ConsoleHelper.WriteLine($"SaveBan: {save}");

                        await _chatProcessor.EditAsync("Menulis ke Cache..");

                        await _elasticSecurityService.UpdateCacheAsync();

                        await _chatProcessor.EditAsync("Misi berhasil.");
                    }
                }
                else
                {
                    await _chatProcessor.SendAsync("Balas seseorang yang mau di ban");
                }
            }
            else
            {
                await _chatProcessor.SendAsync("Unauthorized");
            }

            await _chatProcessor.DeleteAsync(delay : 3000);
        }
Example #36
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _telegramService = new TelegramService(context);
            _rssService      = new RssService(context.Update.Message);

            var chatId = _telegramService.Message.Chat.Id;
            var fromId = _telegramService.Message.From.Id;
            var msg    = _telegramService.Message;

            if (fromId.IsSudoer())
            {
                Log.Information("Test started..");
                await _telegramService.SendTextAsync("Sedang mengetes sesuatu")
                .ConfigureAwait(false);

                // var data = await new Query("rss_history")
                //     .Where("chat_id", chatId)
                //     .ExecForMysql()
                //     .GetAsync();
                //
                // var rssHistories = data
                //     .ToJson()
                //     .MapObject<List<RssHistory>>();
                //
                // ConsoleHelper.WriteLine(data.GetType());
                // // ConsoleHelper.WriteLine(data.ToJson(true));
                //
                // ConsoleHelper.WriteLine(rssHistories.GetType());
                // // ConsoleHelper.WriteLine(rssHistories.ToJson(true));
                //
                // ConsoleHelper.WriteLine("Test completed..");

                // await "This test".LogToChannel();

                // await RssHelper.SyncRssHistoryToCloud();
                // await BotHelper.ClearLog();

                // await SyncHelper.SyncGBanToLocalAsync();
                // var greet = TimeHelper.GetTimeGreet();

                var inlineKeyboard = new InlineKeyboardMarkup(new[]
                {
                    // new[]
                    // {
                    // InlineKeyboardButton.WithCallbackData("Warn Username Limit", "info warn-username-limit"),
                    // InlineKeyboardButton.WithCallbackData("-", "callback-set warn_username_limit 3"),
                    // InlineKeyboardButton.WithCallbackData("4", "info setelah"),
                    // InlineKeyboardButton.WithCallbackData("+", "callback-set warn_username_limit 5")
                    // },
                    new[]
                    {
                        // InlineKeyboardButton.WithCallbackData("Warn Username Limit", "info warn-username-limit"),
                        InlineKeyboardButton.WithCallbackData("-", "callback-set warn_username_limit 3"),
                        InlineKeyboardButton.WithCallbackData("4", "info setelah"),
                        InlineKeyboardButton.WithCallbackData("+", "callback-set warn_username_limit 5")
                    }
                });

                // await _telegramService.EditAsync("Warn Username Limit", inlineKeyboard);

                // LearningHelper.Setup2();
                // LearningHelper.Predict();


                if (msg.ReplyToMessage != null)
                {
                    var repMsg     = msg.ReplyToMessage;
                    var repMsgText = repMsg.Text;

                    Log.Information("Predicting message");
                    var isSpam = MachineLearning.PredictMessage(repMsgText);
                    await _telegramService.EditAsync($"IsSpam: {isSpam}")
                    .ConfigureAwait(false);

                    return;
                }

                await _telegramService.EditAsync("Complete")
                .ConfigureAwait(false);
            }

            // else
            // {
            //     await _requestProvider.SendTextAsync("Unauthorized.");
            // }
        }
 private void Init()
 {
     switch (m_startPosition)
     {
         case ZonePosition.TopLeft:
             if (m_direction == ZoneDirection.Vertical)
             {
                 m_x = m_left;
                 m_y = m_top - m_stepY;
                 UpdateFunction = new UpdateDelegate(UpdateLocationTopLeftVertical);
             }
             else
             {
                 m_x = m_left - m_stepX;
                 m_y = m_top;
                 UpdateFunction = new UpdateDelegate(UpdateLocationTopLeftHorizontal);
             }
             break;
         case ZonePosition.TopRight:
             if (m_direction == ZoneDirection.Vertical)
             {
                 m_x = m_right - 1;
                 m_y = m_top - m_stepY;
                 UpdateFunction = new UpdateDelegate(UpdateLocationTopRightVertical);
             }
             else
             {
                 m_x = m_right - 1 + m_stepX;
                 m_y = m_top;
                 UpdateFunction = new UpdateDelegate(UpdateLocationTopRightHorizontal);
             }
             break;
         case ZonePosition.BottomLeft:
             if (m_direction == ZoneDirection.Vertical)
             {
                 m_x = m_left;
                 m_y = m_bottom - 1 + m_stepY;
                 UpdateFunction = new UpdateDelegate(UpdateLocationBottomLeftVertical);
             }
             else
             {
                 m_x = m_left - m_stepX;
                 m_y = m_bottom - 1;
                 UpdateFunction = new UpdateDelegate(UpdateLocationBottomLeftHorizontal);
             }
             break;
         case ZonePosition.BottomRight:
             if (m_direction == ZoneDirection.Vertical)
             {
                 m_x = m_right - 1;
                 m_y = m_bottom - 1 + m_stepY;
                 UpdateFunction = new UpdateDelegate(UpdateLocationBottomRightVertical);
             }
             else
             {
                 m_x = m_right - 1 + m_stepX;
                 m_y = m_bottom - 1;
                 UpdateFunction = new UpdateDelegate(UpdateLocationBottomRightHorizontal);
             }
             break;
     }
 }
Example #38
0
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                Socket clientSocket = (Socket)ar.AsyncState;
                clientSocket.EndReceive(ar);

                //Transform the array of bytes received from the user into an
                //intelligent form of object Data
                Data msgReceived = new Data(byteData);

                //We will send this object in response the users request
                Data msgToSend = new Data();

                byte[] message;

                //If the message is to login, logout, or simple text message
                //then when send to others the type of the message remains the same
                msgToSend.cmdCommand = msgReceived.cmdCommand;
                msgToSend.strName    = msgReceived.strName;
                msgToSend.strRec     = msgReceived.strRec;

                switch (msgReceived.cmdCommand)
                {
                case Command.Login:

                    //Check if the user is authorized for access
                    User connectedUser = new User(msgReceived.strName, msgReceived.strMessage);
                    if (connectedUser.SearchInList(_users) >= 0)
                    {
                        //When a user logs in to the server then we add her to our
                        //list of clients
                        msgToSend.cmdCommand = Command.Accept;
                        //message = msgToSend.ToByte();
                        //clientSocket.Send(message);

                        ClientInfo clientInfo = new ClientInfo();
                        clientInfo.socket  = clientSocket;
                        clientInfo.strName = msgReceived.strName;

                        clientList.Add(clientInfo);

                        //Set the text of the message that we will broadcast to all users
                        msgToSend.strMessage = "<<<" + msgReceived.strName + " csatlakozott a szobahoz>>>";
                    }
                    else
                    {
                        //Decline the user
                        msgToSend.cmdCommand = Command.Decline;
                        msgToSend.strName    = msgReceived.strName;
                        msgToSend.strMessage = null;
                        message = msgToSend.ToByte();

                        //Log it only on the server-side
                        UpdateDelegate update = new UpdateDelegate(UpdateMessage);
                        this.textBox1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, update,
                                                             "<<<" + msgReceived.strName + " megprobalt a szobahoz csatlakozni engedely nelkul>>>" + "\r\n");

                        //Send the message and close the connection
                        clientSocket.Send(message, 0, message.Length, SocketFlags.None);
                        clientSocket.Shutdown(SocketShutdown.Both);
                        clientSocket.Close();
                    }

                    break;

                case Command.Logout:

                    //When a user wants to log out of the server then we search for her
                    //in the list of clients and close the corresponding connection

                    int nIndex = 0;
                    foreach (ClientInfo client in clientList)
                    {
                        if (client.socket == clientSocket && client.strName.Equals(msgReceived.strName))
                        {
                            clientList.RemoveAt(nIndex);
                            break;
                        }
                        ++nIndex;
                    }

                    //Send ack data before closing - Only for the disconnectiong client
                    //msgToSend.cmdCommand = Command.Logout;
                    //msgToSend.strName = msgReceived.strName;
                    msgToSend.strMessage = null;        //A parancs és név marad, az üzenet törlődik.
                    message = msgToSend.ToByte();
                    clientSocket.Send(message, 0, message.Length, SocketFlags.None);

                    //Kapcsolat leállítása
                    clientSocket.Shutdown(SocketShutdown.Both);
                    clientSocket.Close();

                    msgToSend.strMessage = "<<<" + msgReceived.strName + " elhagyta a szobat>>>";
                    break;

                case Command.Message:

                    //Set the text of the message that we will broadcast to all  (if public)
                    msgToSend.strMessage = msgReceived.strName + " -> " +
                                           (msgReceived.strRec.Equals(Data.PUBLIC_ID) ? "Mindenki" : msgReceived.strRec) +
                                           " : " + msgReceived.strMessage;
                    break;

                case Command.Upload:
                    //Get the correct IP
                    IPEndPoint upEndPoint = clientSocket.RemoteEndPoint as IPEndPoint;

                    //Create a delegate for upload handling
                    string pathUp = Data.FILES_FOLDER + (msgReceived.strRec.Equals(Data.PUBLIC_ID) ? Data.PUBLIC_ID : (msgReceived.strName + "-" + msgReceived.strRec));
                    Directory.CreateDirectory(pathUp);
                    UploadDelegate upload = new UploadDelegate(BeginUpload);
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                upload, upEndPoint.Address, pathUp + "\\" + msgReceived.strMessage, msgReceived.strName, msgReceived.strRec);

                    msgToSend.strMessage = "<<<" + msgReceived.strName + " megkezdte a '" + System.IO.Path.GetFileName(msgReceived.strMessage) + "' nevu falj feltolteset>>>";

                    break;

                case Command.StartDownload:
                    //Get the correct IP
                    IPEndPoint downEndPoint = clientSocket.RemoteEndPoint as IPEndPoint;

                    //Delete message
                    msgToSend.strMessage = null;

                    //Create a delegate for upload handling
                    string pathDown = Data.FILES_FOLDER + (msgReceived.strName.Equals(Data.PUBLIC_ID) ? Data.PUBLIC_ID : (msgReceived.strName + "-" + msgReceived.strRec));
                    Directory.CreateDirectory(pathDown);
                    DownloadDelegate download = new DownloadDelegate(BeginDownload);
                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                download, downEndPoint.Address, pathDown + "\\" + msgReceived.strMessage);

                    msgToSend.strMessage = "<<<" + msgReceived.strRec + " megkezdte a '" + System.IO.Path.GetFileName(msgReceived.strMessage) + "' nevu falj letolteset>>>";

                    break;

                case Command.DownloadAck:

                    //Set the text of the message that we will broadcast to all  (if public)
                    msgToSend.strMessage = "<<<" + msgReceived.strRec + " befejezte a '" + System.IO.Path.GetFileName(msgReceived.strMessage) + "' nevu falj letolteset>>>";
                    break;

                case Command.DownloadList:
                    //Delete message
                    msgToSend.strMessage = null;

                    //Create a delegate for upload handling
                    string pathDirectory = Data.FILES_FOLDER + (msgReceived.strRec.Equals(Data.PUBLIC_ID) ? Data.PUBLIC_ID : (msgReceived.strRec + "-" + msgReceived.strName));
                    Directory.CreateDirectory(pathDirectory);

                    //Collect all filenames
                    bool notFirstDownFiles = false;
                    foreach (string file in Directory.GetFiles(pathDirectory))
                    {
                        if (notFirstDownFiles)
                        {
                            msgToSend.strMessage += "*";
                        }
                        else
                        {
                            notFirstDownFiles = true;
                        }
                        msgToSend.strMessage += System.IO.Path.GetFileName(file);
                    }

                    message = msgToSend.ToByte();

                    //Send the filenames
                    clientSocket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                           new AsyncCallback(OnSend), clientSocket);

                    break;

                case Command.List:

                    //Send the names of all users in the chat room to the new user
                    msgToSend.cmdCommand = Command.List;
                    msgToSend.strName    = msgReceived.strName;
                    msgToSend.strMessage = null;

                    //Collect the names of the user in the chat
                    bool notFirstList = false;
                    foreach (ClientInfo client in clientList)
                    {
                        //To keep things simple we use asterisk as the marker to separate the user names
                        if (notFirstList)
                        {
                            msgToSend.strMessage += "*";
                        }
                        else
                        {
                            notFirstList = true;
                        }
                        msgToSend.strMessage += client.strName;
                    }

                    message = msgToSend.ToByte();

                    //Send the name of the users in the chat room
                    clientSocket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                           new AsyncCallback(OnSend), clientSocket);
                    break;
                }

                if (!(msgToSend.cmdCommand == Command.List || msgToSend.cmdCommand == Command.DownloadList || msgToSend.cmdCommand == Command.Decline))     //List and decline messages are not broadcasted
                {
                    message = msgToSend.ToByte();

                    foreach (ClientInfo clientInfo in clientList)
                    {
                        if (clientInfo.socket != clientSocket || msgToSend.cmdCommand != Command.Login)
                        {
                            //A publikus az broadcast, amúgy csak a 2 partnernek megy. -> Figyelni kell, hogy PUBLIC legyen alapból a cél, és feladó is legyen mindig.
                            if (msgToSend.strRec.Equals(Data.PUBLIC_ID) || clientInfo.strName.Equals(msgReceived.strRec) || clientInfo.strName.Equals(msgReceived.strName))
                            {
                                //Send the message to all users
                                clientInfo.socket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                                            new AsyncCallback(OnSend), clientInfo.socket);
                                //clientInfo.socket.Send(message, 0, message.Length, SocketFlags.None);
                            }
                        }
                    }

                    UpdateDelegate update = new UpdateDelegate(UpdateMessage);
                    this.textBox1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, update,
                                                         msgToSend.strMessage + "\r\n");
                }

                //If the user is logging out or declined, then we need not listen from her
                if (!(msgReceived.cmdCommand == Command.Logout || msgToSend.cmdCommand == Command.Decline))
                {
                    //Start listening to the message send by the user
                    clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), clientSocket);
                }

                //Check if it's the last logout
                if (msgReceived.cmdCommand == Command.Logout && clientList.Count <= 0)
                {
                    //Check if we started a close
                    CloseReadDelegate closeRead = new CloseReadDelegate(GetCloseStarted);
                    bool closeStarted           = (bool)this.Dispatcher.Invoke(DispatcherPriority.Normal, closeRead);

                    //Finish the close
                    if (closeStarted)
                    {
                        CloseDelegate closeRun = new CloseDelegate(CloseRun);
                        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, closeRun);
                    }
                }
            }
            catch (Exception ex)
            {
                new Thread(() =>
                {
                    MessageBox.Show(ex.Message, "Server Receive");
                }).Start();
            }
        }
Example #39
0
    public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args)
    {
        await _telegramService.AddUpdateContext(context);

        var message = _telegramService.Message;

        if (!_telegramService.IsFromSudo)
        {
            Log.Information("This user is not sudoer");
            return;
        }

        if (message.ReplyToMessage != null)
        {
            var repMessage = message.ReplyToMessage;
            var repText    = repMessage.Text ?? repMessage.Caption;
            var param      = message.Text.SplitText(" ").ToArray();
            var mark       = param.ValueOfIndex(1);
            var opts       = new List <string>
            {
                "spam", "ham"
            };

            if (!opts.Contains(mark))
            {
                await _telegramService.SendTextMessageAsync("Spesifikasikan spam atau ham (bukan spam)");

                return;
            }

            await _telegramService.SendTextMessageAsync("Sedang memperlajari pesan");

            var learnData = new LearnData
            {
                Message = repText.Replace("\n", " "),
                Label   = mark,
                ChatId  = _telegramService.ChatId,
                FromId  = _telegramService.FromId
            };

            if (_learningService.IsExist(learnData))
            {
                Log.Information("This message has learned");
                await _telegramService.EditMessageTextAsync("Pesan ini mungkin sudah di tambahkan.");

                return;
            }

            await _learningService.Save(learnData);

            await _telegramService.EditMessageTextAsync("Memperbarui local dataset");

            await _telegramService.EditMessageTextAsync("Sedang mempelajari dataset");

            await MachineLearning.SetupEngineAsync();

            await _telegramService.EditMessageTextAsync("Pesan berhasil di tambahkan ke Dataset");
        }
        else
        {
            await _telegramService.SendTextMessageAsync("Sedang mempelajari dataset");

            await MachineLearning.SetupEngineAsync();

            await _telegramService.EditMessageTextAsync("Training selesai");
        }
    }
Example #40
0
        private async void BeginUpload(IPAddress address, string filename, string sender, string receiver)
        {
            //Wait for others to finish
            if (_uploading)
            {
                Thread.Sleep(2000);
            }

            //Set the pooling flag
            _uploading = true;

            try
            {
                var listener = new TcpListener(address, Data.UPLOAD_PORT);
                listener.Start();
                using (var client = await listener.AcceptTcpClientAsync())
                    using (var stream = client.GetStream())
                        using (var output = File.Create(filename))
                        {
                            try
                            {
                                //Console.WriteLine("Client connected. Starting to receive the file.");

                                // read the file in chunks of 1KB
                                var buffer = new byte[1024];
                                int bytesRead;
                                while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    output.Write(buffer, 0, bytesRead);
                                }
                            }
                            catch (Exception ex)
                            {
                                new Thread(() =>
                                {
                                    MessageBox.Show(ex.Message, "Server Upload");
                                }).Start();
                            }
                        }
                listener.Stop();
                //Console.WriteLine("Client Disconnected.");
            }
            catch (Exception ex)
            {
                new Thread(() =>
                {
                    MessageBox.Show(ex.Message, "Server Upload Using");
                }).Start();
            }

            _uploading = false;

            //Send an upload ack message
            byte[] message;
            Data   msgToSend = new Data();

            msgToSend.cmdCommand = Command.Message;
            msgToSend.strName    = sender;
            msgToSend.strRec     = receiver;
            msgToSend.strMessage = sender + " -> " +
                                   (receiver.Equals(Data.PUBLIC_ID) ? "Mindenki" : receiver) +
                                   " : '" + System.IO.Path.GetFileName(filename) + "' nevu fajl sikeresen megosztva.";

            message = msgToSend.ToByte();

            try
            {
                foreach (ClientInfo clientInfo in clientList)
                {
                    //A publikus az broadcast, amúgy csak a 2 partnernek megy. -> Figyelni kell, hogy PUBLIC legyen alapból a cél, és feladó is legyen mindig.
                    if (receiver.Equals(Data.PUBLIC_ID) || clientInfo.strName.Equals(sender) || clientInfo.strName.Equals(receiver))
                    {
                        //Send the message to all users
                        clientInfo.socket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                                    new AsyncCallback(OnSend), clientInfo.socket);
                    }
                }
            }
            catch (Exception ex)
            {
                new Thread(() =>
                {
                    MessageBox.Show(ex.Message, "Server Upload Message");
                }).Start();
            }

            UpdateDelegate update = new UpdateDelegate(UpdateMessage);

            await this.textBox1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, update,
                                                       msgToSend.strMessage + "\r\n");
        }
Example #41
0
 public MapWhenMiddleware(Predicate <IUpdateContext> predicate, UpdateDelegate branch)
 {
     _predicate = predicate;
     _branch    = branch;
 }
Example #42
0
 /// <summary>
 /// 添加更新委托
 /// </summary>
 /// <param name="d">更新委托</param>
 public void AddUpdate(UpdateDelegate d)
 {
     UpdateHandler += d;
 }
Example #43
0
        public Movie UpdateMovie(int Movie, string ProductionId, string MovieName, string ReleaseDate)
        {
            var d = new UpdateDelegate(Movie, ProductionId, MovieName, ReleaseDate);

            return(executor.ExecuteNonQuery(d));
        }
Example #44
0
 /// <summary>
 /// 移除更新委托
 /// </summary>
 /// <param name="d">更新委托</param>
 public void RemoveUpdate(UpdateDelegate d)
 {
     UpdateHandler -= d;
 }
Example #45
0
 public void UploadAsync(string path, string token, string message)
 {
     var worker = new UpdateDelegate(UploadInternal);
     var asyncOp = AsyncOperationManager.CreateOperation(null);
     worker.BeginInvoke(path, token, message, asyncOp, null, null);
 }
Example #46
0
 public LoggingMiddleware(UpdateDelegate next, ILogger logger)
 {
     _next   = next;
     _logger = logger;
 }
Example #47
0
 public void RemoveTick(ITick tick)
 {
     _ticks -= tick.Update;
 }
			public WorkerThread (FileSystem fileSystem, StringCollection the_filters, UpdateDelegate updateDelegate, Control calling_control)
			{
				this.fileSystem = fileSystem;
				this.the_filters = the_filters;
				this.updateDelegate = updateDelegate;
				this.calling_control = calling_control;
			}
Example #49
0
 private void ClearTicks()
 {
     _ticks     -= _ticks;
     _lateTicks -= _lateTicks;
 }
Example #50
0
 public bool InstallInvestigation(Scenario.UpdateDelegate func)
 {
     OnInvestigateScenario += func;
     return true;
 }
Example #51
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _telegramService = new TelegramService(context);
            var msg = context.Update.Message;

            _settingsService = new SettingsService(msg);


            Log.Information($"Args: {string.Join(" ", args)}");
            var sendText = "Perintah /welcome hanya untuk grup saja";

            if (msg.Chat.Type != ChatType.Private)
            {
                var chatTitle = msg.Chat.Title;
                var settings  = await _settingsService.GetSettingByGroup()
                                .ConfigureAwait(false);

                var welcomeMessage   = settings.WelcomeMessage;
                var welcomeButton    = settings.WelcomeButton;
                var welcomeMedia     = settings.WelcomeMedia;
                var welcomeMediaType = settings.WelcomeMediaType;
                // var splitWelcomeButton = welcomeButton.Split(',').ToList<string>();

                // var keyboard = welcomeButton.ToReplyMarkup(2);
                InlineKeyboardMarkup keyboard = null;
                if (!welcomeButton.IsNullOrEmpty())
                {
                    keyboard = welcomeButton.ToReplyMarkup(2);
                }

                sendText = $"👥 <b>{chatTitle}</b>\n";
                if (welcomeMessage.IsNullOrEmpty())
                {
                    var defaultWelcome = "Hai {allNewMember}" +
                                         "\nSelamat datang di kontrakan {chatTitle}" +
                                         "\nKamu adalah anggota ke-{memberCount}";
                    sendText += "Tidak ada konfigurasi pesan welcome, pesan default akan di terapkan" +
                                $"\n\n<code>{defaultWelcome}</code>" +
                                $"\n\nUntuk bantuan silakan ketik /help" +
                                $"\nBantuan pesan Welcome ke Bantuan > Grup > Welcome";
                }
                else
                {
                    sendText += welcomeMessage;
                }

//                sendText += " " + string.Join(", ",args);
                if (welcomeMediaType != MediaType.Unknown)
                {
                    await _telegramService.SendMediaAsync(welcomeMedia, welcomeMediaType, sendText, keyboard)
                    .ConfigureAwait(false);
                }
                else
                {
                    await _telegramService.SendTextAsync(sendText, keyboard)
                    .ConfigureAwait(false);
                }
            }
            else
            {
                await _telegramService.SendTextAsync(sendText)
                .ConfigureAwait(false);
            }
        }
Example #52
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args)
        {
            await _telegramService.AddUpdateContext(context);

            var from = _telegramService.Message.From;

            var url = _telegramService.MessageTextParts.ValueOfIndex(1);

            if (url.IsNullOrEmpty())
            {
                await _telegramService.SendTextMessageAsync("Sertakan Url yg akan di konversi");

                return;
            }

            if (!url.CheckUrlValid())
            {
                await _telegramService.SendTextMessageAsync("Masukan URL yang valid");

                return;
            }

            await _telegramService.SendTextMessageAsync($"🔄 Sedang menjalankan Debrid: " +
                                                        $"\n<b>URL:</b> {url}");

            var flurlResponse = await _heirroService.Debrid(url);

            var content = await flurlResponse.GetStringAsync();

            var config          = Configuration.Default;
            var browsingContext = BrowsingContext.New(config);
            var document        = await browsingContext.OpenAsync(req => req.Content(content));

            var div      = document.QuerySelectorAll("div").FirstOrDefault();
            var divText  = div.TextContent;
            var partsDiv = divText.Split(" ");
            var size     = (partsDiv.ValueOfIndex(2) + partsDiv.ValueOfIndex(3)).RemoveThisChar("()");


            var aHref = document.QuerySelectorAll("a").OfType <IHtmlAnchorElement>().FirstOrDefault();
            var href  = aHref.Href;
            var text  = aHref.InnerHtml;

            if (text.IsNullOrEmpty())
            {
                await _telegramService.EditMessageTextAsync("Sepertinya Debrid tidak berhasil. Silakan periksa URL Anda.");

                return;
            }

            var sendText = $"📁 <b>Name:</b> {text}" +
                           $"\n📦 <b>Ukuran:</b> {size}" +
                           $"\n👽 <b>Pengguna:</b> {from}";

            var inlineKeyboard = new InlineKeyboardMarkup(new[]
            {
                new[]
                {
                    InlineKeyboardButton.WithUrl("👥 Download", href),
                    InlineKeyboardButton.WithUrl("👥 Source", url),
                    InlineKeyboardButton.WithUrl("❤️ Bergabung", "https://t.me/WinTenChannel")
                }
            });

            await _telegramService.EditMessageTextAsync(sendText, inlineKeyboard);
        }
        private static void GetASRockConfiguration(ISuperIO superIO, 
            IList<Voltage> v, IList<Temperature> t, IList<Fan> f,
            ref ReadValueDelegate readFan, ref UpdateDelegate postUpdate,
            ref Mutex mutex)
        {
            v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+12V", 4, 30, 10));
              v.Add(new Voltage("+5V", 5, 6.8f, 10));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("CPU", 0));
              t.Add(new Temperature("Motherboard", 1));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("Chassis Fan #1", 1));

              // this mutex is also used by the official ASRock tool
              mutex = new Mutex(false, "ASRockOCMark");

              bool exclusiveAccess = false;
              try {
            exclusiveAccess = mutex.WaitOne(10, false);
              } catch (AbandonedMutexException) { }
            catch (InvalidOperationException) { }

              // only read additional fans if we get exclusive access
              if (exclusiveAccess) {

            f.Add(new Fan("Chassis Fan #2", 2));
            f.Add(new Fan("Chassis Fan #3", 3));
            f.Add(new Fan("Power Fan", 4));

            readFan = (index) => {
              if (index < 2) {
            return superIO.Fans[index];
              } else {
            // get GPIO 80-87
            byte? gpio = superIO.ReadGPIO(7);
            if (!gpio.HasValue)
              return null;

            // read the last 3 fans based on GPIO 83-85
            int[] masks = { 0x05, 0x03, 0x06 };
            return (((gpio.Value >> 3) & 0x07) ==
              masks[index - 2]) ? superIO.Fans[2] : null;
              }
            };

            int fanIndex = 0;
            postUpdate = () => {
              // get GPIO 80-87
              byte? gpio = superIO.ReadGPIO(7);
              if (!gpio.HasValue)
            return;

              // prepare the GPIO 83-85 for the next update
              int[] masks = { 0x05, 0x03, 0x06 };
              superIO.WriteGPIO(7,
            (byte)((gpio.Value & 0xC7) | (masks[fanIndex] << 3)));
              fanIndex = (fanIndex + 1) % 3;
            };
              }
        }
Example #54
0
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            var voice = context.Update.Message.Voice;

            // ToDo if the file size is large, don't download
            // ToDo check if the mime_type is always "audio/ogg"
            if (voice.Duration <= 10)
            {
                var tgFile = await context.Bot.Client.MakeRequestWithRetryAsync(
                    new GetFileRequest(voice.FileId), cancellationToken
                    ).ConfigureAwait(false);

                string fileUrl = $"https://api.telegram.org/file/bot{_botOptions.ApiToken}/{tgFile.FilePath}";

                Meaning meaning;
                using (var httpClient = new HttpClient())
                {
                    var response = await httpClient
                                   .GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
                                   .ConfigureAwait(false);

                    using (response)
                    {
                        response.EnsureSuccessStatusCode();

                        var voiceStream = await response.Content.ReadAsStreamAsync()
                                          .ConfigureAwait(false);

                        meaning = await _nlpService.ProcessVoiceAsync(voiceStream, voice.MimeType, cancellationToken)
                                  .ConfigureAwait(false);
                    }
                }

                string intent = meaning.Entities.ContainsKey("intent")
                    ? meaning.Entities["intent"][0]["value"]
                    : null;
                string route = meaning.Entities.ContainsKey("route")
                    ? meaning.Entities["route"][0]["value"]
                    : null;
                string direction = meaning.Entities.ContainsKey("direction_ttc")
                    ? meaning.Entities["direction_ttc"][0]["value"]
                    : null;
                string origin = meaning.Entities.ContainsKey("origin")
                    ? meaning.Entities["origin"][0]["value"]
                    : null;

                if (intent == "bus_predictions" && (route != null || direction != null))
                {
                    context.Items[nameof(BusPredictionsContext)] = new BusPredictionsContext
                    {
                        Query        = meaning.Text,
                        RouteTag     = route,
                        DirectionTag = direction,
                        Origin       = origin,
                        Interfaces   = new List <string>(new[] { "voice" })
                    };
                    await next(context, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    string text = "Sorry, what?👂 ";
                    if (!string.IsNullOrWhiteSpace(meaning.Text))
                    {
                        text += "I heard:\n" +
                                $"```\n{meaning.Text}\n```";
                    }

                    context.Items[nameof(WebhookResponse)] = new SendMessageRequest(
                        context.Update.Message.Chat,
                        text
                        )
                    {
                        ParseMode           = ParseMode.Markdown,
                        ReplyToMessageId    = context.Update.Message.MessageId,
                        DisableNotification = true,
                    };
                }
            }
        }
        private static void GetITEConfigurationsA(ISuperIO superIO, 
            Manufacturer manufacturer, Model model,
            IList<Voltage> v, IList<Temperature> t, IList<Fan> f, IList<Ctrl> c,
            ref ReadValueDelegate readFan, ref UpdateDelegate postUpdate,
            ref Mutex mutex)
        {
            switch (manufacturer) {
            case Manufacturer.ASUS:
              switch (model) {
            case Model.Crosshair_III_Formula: // IT8720F
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("CPU", 0));
              for (int i = 0; i < superIO.Fans.Length; i++)
                f.Add(new Fan("Fan #" + (i + 1), i));
              break;
            case Model.M2N_SLI_DELUXE:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("+3.3V", 1));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 4, 30, 10));
              v.Add(new Voltage("+5VSB", 7, 6.8f, 10));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("CPU", 0));
              t.Add(new Temperature("Motherboard", 1));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("Chassis Fan #1", 1));
              f.Add(new Fan("Power Fan", 2));
              break;
            case Model.M4A79XTD_EVO: // IT8720F
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("CPU", 0));
              t.Add(new Temperature("Motherboard", 1));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("Chassis Fan #1", 1));
              f.Add(new Fan("Chassis Fan #2", 2));
              break;
            default:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("Voltage #3", 2, true));
              v.Add(new Voltage("Voltage #4", 3, true));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("Voltage #8", 7, true));
              v.Add(new Voltage("VBat", 8));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
                t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
                f.Add(new Fan("Fan #" + (i + 1), i));
              for (int i = 0; i < superIO.Controls.Length; i++)
                c.Add(new Ctrl("Fan Control #" + (i + 1), i));
              break;
              }
              break;

            case Manufacturer.ASRock:
              switch (model) {
            case Model.P55_Deluxe: // IT8720F
              GetASRockConfiguration(superIO, v, t, f,
                ref readFan, ref postUpdate, ref mutex);
              break;
            default:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("Voltage #3", 2, true));
              v.Add(new Voltage("Voltage #4", 3, true));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("Voltage #8", 7, true));
              v.Add(new Voltage("VBat", 8));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
                t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
                f.Add(new Fan("Fan #" + (i + 1), i));
              break;
              };
              break;

            case Manufacturer.DFI:
              switch (model) {
            case Model.LP_BI_P45_T2RS_Elite: // IT8718F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("FSB VTT", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 4, 30, 10));
              v.Add(new Voltage("NB Core", 5));
              v.Add(new Voltage("VDIMM", 6));
              v.Add(new Voltage("+5VSB", 7, 6.8f, 10));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("CPU", 0));
              t.Add(new Temperature("System", 1));
              t.Add(new Temperature("Chipset", 2));
              f.Add(new Fan("Fan #1", 0));
              f.Add(new Fan("Fan #2", 1));
              f.Add(new Fan("Fan #3", 2));
              break;
            case Model.LP_DK_P55_T3eH9: // IT8720F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("VTT", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 4, 30, 10));
              v.Add(new Voltage("CPU PLL", 5));
              v.Add(new Voltage("DRAM", 6));
              v.Add(new Voltage("+5VSB", 7, 6.8f, 10));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("Chipset", 0));
              t.Add(new Temperature("CPU PWM", 1));
              t.Add(new Temperature("CPU", 2));
              f.Add(new Fan("Fan #1", 0));
              f.Add(new Fan("Fan #2", 1));
              f.Add(new Fan("Fan #3", 2));
              break;
            default:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("VTT", 1, true));
              v.Add(new Voltage("+3.3V", 2, true));
              v.Add(new Voltage("+5V", 3, 6.8f, 10, 0, true));
              v.Add(new Voltage("+12V", 4, 30, 10, 0, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("DRAM", 6, true));
              v.Add(new Voltage("+5VSB", 7, 6.8f, 10, 0, true));
              v.Add(new Voltage("VBat", 8));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
                t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
                f.Add(new Fan("Fan #" + (i + 1), i));
              for (int i = 0; i < superIO.Controls.Length; i++)
                c.Add(new Ctrl("Fan Control #" + (i + 1), i));
              break;
              }
              break;

            case Manufacturer.Gigabyte:
              switch (model) {
            case Model._965P_S3: // IT8718F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 7, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 1));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan", 1));
              break;
            case Model.EP45_DS3R: // IT8718F
            case Model.EP45_UD3R:
            case Model.X38_DS5:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 7, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 1));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan #2", 1));
              f.Add(new Fan("Power Fan", 2));
              f.Add(new Fan("System Fan #1", 3));
              break;
            case Model.EX58_EXTREME: // IT8720F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 1));
              t.Add(new Temperature("Northbridge", 2));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan #2", 1));
              f.Add(new Fan("Power Fan", 2));
              f.Add(new Fan("System Fan #1", 3));
              break;
            case Model.P35_DS3: // IT8718F
            case Model.P35_DS3L: // IT8718F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 7, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 1));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan #1", 1));
              f.Add(new Fan("System Fan #2", 2));
              f.Add(new Fan("Power Fan", 3));
              break;
            case Model.P55_UD4: // IT8720F
            case Model.P55A_UD3: // IT8720F
            case Model.P55M_UD4: // IT8720F
            case Model.H55_USB3: // IT8720F
            case Model.EX58_UD3R: // IT8720F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 5, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 2));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan #2", 1));
              f.Add(new Fan("Power Fan", 2));
              f.Add(new Fan("System Fan #1", 3));
              break;
            case Model.H55N_USB3: // IT8720F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 5, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 2));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan", 1));
              break;
            case Model.G41M_Combo: // IT8718F
            case Model.G41MT_S2: // IT8718F
            case Model.G41MT_S2P: // IT8718F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 7, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("CPU", 2));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan", 1));
              break;
            case Model.GA_970A_UD3: // IT8720F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 4, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 1));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan #1", 1));
              f.Add(new Fan("System Fan #2", 2));
              f.Add(new Fan("Power Fan", 4));
              c.Add(new Ctrl("PWM 1", 0));
              c.Add(new Ctrl("PWM 2", 1));
              c.Add(new Ctrl("PWM 3", 2));
              break;
            case Model.GA_MA770T_UD3: // IT8720F
            case Model.GA_MA770T_UD3P: // IT8720F
            case Model.GA_MA790X_UD3P: // IT8720F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 4, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 1));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan #1", 1));
              f.Add(new Fan("System Fan #2", 2));
              f.Add(new Fan("Power Fan", 3));
              break;
            case Model.GA_MA78LM_S2H: // IT8718F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 4, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 1));
              t.Add(new Temperature("VRM", 2));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan #1", 1));
              f.Add(new Fan("System Fan #2", 2));
              f.Add(new Fan("Power Fan", 3));
              break;
            case Model.GA_MA785GM_US2H: // IT8718F
            case Model.GA_MA785GMT_UD2H: // IT8718F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 4, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 1));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan", 1));
              f.Add(new Fan("NB Fan", 2));
              break;
            case Model.X58A_UD3R: // IT8720F
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1));
              v.Add(new Voltage("+3.3V", 2));
              v.Add(new Voltage("+5V", 3, 6.8f, 10));
              v.Add(new Voltage("+12V", 5, 24.3f, 8.2f));
              v.Add(new Voltage("VBat", 8));
              t.Add(new Temperature("System", 0));
              t.Add(new Temperature("CPU", 1));
              t.Add(new Temperature("Northbridge", 2));
              f.Add(new Fan("CPU Fan", 0));
              f.Add(new Fan("System Fan #2", 1));
              f.Add(new Fan("Power Fan", 2));
              f.Add(new Fan("System Fan #1", 3));
              break;
            default:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("DRAM", 1, true));
              v.Add(new Voltage("+3.3V", 2, true));
              v.Add(new Voltage("+5V", 3, 6.8f, 10, 0, true));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("Voltage #8", 7, true));
              v.Add(new Voltage("VBat", 8));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
                t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
                f.Add(new Fan("Fan #" + (i + 1), i));
              for (int i = 0; i < superIO.Controls.Length; i++)
                c.Add(new Ctrl("Fan Control #" + (i + 1), i));
              break;
              }
              break;

            default:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("Voltage #3", 2, true));
              v.Add(new Voltage("Voltage #4", 3, true));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("Voltage #8", 7, true));
              v.Add(new Voltage("VBat", 8));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
            t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
            f.Add(new Fan("Fan #" + (i + 1), i));
              for (int i = 0; i < superIO.Controls.Length; i++)
            c.Add(new Ctrl("Fan Control #" + (i + 1), i));
              break;
              }
        }
Example #56
0
        public SuperIOHardware(Mainboard mainboard, ISuperIO superIO, 
      Manufacturer manufacturer, Model model, ISettings settings)
            : base(ChipName.GetName(superIO.Chip), new Identifier("lpc", 
        superIO.Chip.ToString().ToLower(CultureInfo.InvariantCulture)), 
        settings)
        {
            this.mainboard = mainboard;
              this.superIO = superIO;

              this.readVoltage = (index) => superIO.Voltages[index];
              this.readTemperature = (index) => superIO.Temperatures[index];
              this.readFan = (index) => superIO.Fans[index];
              this.readControl = (index) => superIO.Controls[index];

              this.postUpdate = () => { };

              List<Voltage> v = new List<Voltage>();
              List<Temperature> t = new List<Temperature>();
              List<Fan> f = new List<Fan>();
              List<Ctrl> c = new List<Ctrl>();

              switch (superIO.Chip) {
            case Chip.IT8712F:
            case Chip.IT8716F:
            case Chip.IT8718F:
            case Chip.IT8720F:
            case Chip.IT8726F:
              switch (manufacturer) {
            case Manufacturer.ASUS:
              switch (model) {
                case Model.Crosshair_III_Formula: // IT8720F
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("CPU", 0));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
                case Model.M2N_SLI_DELUXE:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("+3.3V", 1));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 4, 30, 10));
                  v.Add(new Voltage("+5VSB", 7, 6.8f, 10));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Motherboard", 1));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("Chassis Fan #1", 1));
                  f.Add(new Fan("Power Fan", 2));
                  break;
                case Model.M4A79XTD_EVO: // IT8720F
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Motherboard", 1));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("Chassis Fan #1", 1));
                  f.Add(new Fan("Chassis Fan #2", 2));
                  break;
                default:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("Voltage #2", 1, true));
                  v.Add(new Voltage("Voltage #3", 2, true));
                  v.Add(new Voltage("Voltage #4", 3, true));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("Voltage #8", 7, true));
                  v.Add(new Voltage("VBat", 8));
                  for (int i = 0; i < superIO.Temperatures.Length; i++)
                    t.Add(new Temperature("Temperature #" + (i + 1), i));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
              }
              break;

            case Manufacturer.ASRock:
              switch (model) {
                case Model.P55_Deluxe: // IT8720F

                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+12V", 4, 30, 10));
                  v.Add(new Voltage("+5V", 5, 6.8f, 10));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Motherboard", 1));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("Chassis Fan #1", 1));

                  // this mutex is also used by the official ASRock tool
                  mutex = new Mutex(false, "ASRockOCMark");

                  bool exclusiveAccess = false;
                  try {
                    exclusiveAccess = mutex.WaitOne(10, false);
                  } catch (AbandonedMutexException) { }
                    catch (InvalidOperationException) { }

                  // only read additional fans if we get exclusive access
                  if (exclusiveAccess) {

                    f.Add(new Fan("Chassis Fan #2", 2));
                    f.Add(new Fan("Chassis Fan #3", 3));
                    f.Add(new Fan("Power Fan", 4));

                    readFan = (index) => {
                      if (index < 2) {
                        return superIO.Fans[index];
                      } else {
                        // get GPIO 80-87
                        byte? gpio = superIO.ReadGPIO(7);
                        if (!gpio.HasValue)
                          return null;

                        // read the last 3 fans based on GPIO 83-85
                        int[] masks = { 0x05, 0x03, 0x06 };
                        return (((gpio.Value >> 3) & 0x07) ==
                          masks[index - 2]) ? superIO.Fans[2] : null;
                      }
                    };

                    int fanIndex = 0;
                    postUpdate = () => {
                      // get GPIO 80-87
                      byte? gpio = superIO.ReadGPIO(7);
                      if (!gpio.HasValue)
                        return;

                      // prepare the GPIO 83-85 for the next update
                      int[] masks = { 0x05, 0x03, 0x06 };
                      superIO.WriteGPIO(7,
                        (byte)((gpio.Value & 0xC7) | (masks[fanIndex] << 3)));
                      fanIndex = (fanIndex + 1) % 3;
                    };
                  }

                  break;
                default:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("Voltage #2", 1, true));
                  v.Add(new Voltage("Voltage #3", 2, true));
                  v.Add(new Voltage("Voltage #4", 3, true));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("Voltage #8", 7, true));
                  v.Add(new Voltage("VBat", 8));
                  for (int i = 0; i < superIO.Temperatures.Length; i++)
                    t.Add(new Temperature("Temperature #" + (i + 1), i));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
              };
              break;

            case Manufacturer.DFI:
              switch (model) {
                case Model.LP_BI_P45_T2RS_Elite: // IT8718F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("FSB VTT", 1));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 4, 30, 10));
                  v.Add(new Voltage("NB Core", 5));
                  v.Add(new Voltage("VDIMM", 6));
                  v.Add(new Voltage("+5VSB", 7, 6.8f, 10));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("System", 1));
                  t.Add(new Temperature("Chipset", 2));
                  f.Add(new Fan("Fan #1", 0));
                  f.Add(new Fan("Fan #2", 1));
                  f.Add(new Fan("Fan #3", 2));
                  break;
                case Model.LP_DK_P55_T3eH9: // IT8720F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("VTT", 1));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 4, 30, 10));
                  v.Add(new Voltage("CPU PLL", 5));
                  v.Add(new Voltage("DRAM", 6));
                  v.Add(new Voltage("+5VSB", 7, 6.8f, 10));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("Chipset", 0));
                  t.Add(new Temperature("CPU PWM", 1));
                  t.Add(new Temperature("CPU", 2));
                  f.Add(new Fan("Fan #1", 0));
                  f.Add(new Fan("Fan #2", 1));
                  f.Add(new Fan("Fan #3", 2));
                  break;
                default:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("VTT", 1, true));
                  v.Add(new Voltage("+3.3V", 2, true));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10, 0, true));
                  v.Add(new Voltage("+12V", 4, 30, 10, 0, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("DRAM", 6, true));
                  v.Add(new Voltage("+5VSB", 7, 6.8f, 10, 0, true));
                  v.Add(new Voltage("VBat", 8));
                  for (int i = 0; i < superIO.Temperatures.Length; i++)
                    t.Add(new Temperature("Temperature #" + (i + 1), i));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
              }
              break;

            case Manufacturer.Gigabyte:
              switch (model) {
                case Model._965P_S3: // IT8718F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 7, 27, 9.1f));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 1));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan", 1));
                  break;
                case Model.EP45_DS3R: // IT8718F
                case Model.EP45_UD3R:
                case Model.X38_DS5:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 7, 27, 9.1f));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 1));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan #2", 1));
                  f.Add(new Fan("Power Fan", 2));
                  f.Add(new Fan("System Fan #1", 3));
                  break;
                case Model.EX58_EXTREME: // IT8720F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 1));
                  t.Add(new Temperature("Northbridge", 2));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan #2", 1));
                  f.Add(new Fan("Power Fan", 2));
                  f.Add(new Fan("System Fan #1", 3));
                  break;
                case Model.P35_DS3: // IT8718F
                case Model.P35_DS3L: // IT8718F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 7, 27, 9.1f));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 1));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan #1", 1));
                  f.Add(new Fan("System Fan #2", 2));
                  f.Add(new Fan("Power Fan", 3));
                  break;
                case Model.P55_UD4: // IT8720F
                case Model.P55M_UD4: // IT8720F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 5, 27, 9.1f));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 2));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan #2", 1));
                  f.Add(new Fan("Power Fan", 2));
                  f.Add(new Fan("System Fan #1", 3));
                  break;
                case Model.GA_MA770T_UD3: // IT8720F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 4, 27, 9.1f));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 1));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan #1", 1));
                  f.Add(new Fan("System Fan #2", 2));
                  f.Add(new Fan("Power Fan", 3));
                  break;
                case Model.GA_MA785GMT_UD2H: // IT8718F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 4, 27, 9.1f));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 1));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan", 1));
                  f.Add(new Fan("NB Fan", 2));
                  break;
                case Model.X58A_UD3R: // IT8720F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1));
                  v.Add(new Voltage("+3.3V", 2));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10));
                  v.Add(new Voltage("+12V", 5, 27, 9.1f));
                  v.Add(new Voltage("VBat", 8));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 1));
                  t.Add(new Temperature("Northbridge", 2));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan #2", 1));
                  f.Add(new Fan("Power Fan", 2));
                  f.Add(new Fan("System Fan #1", 3));
                  break;
                default:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1, true));
                  v.Add(new Voltage("+3.3V", 2, true));
                  v.Add(new Voltage("+5V", 3, 6.8f, 10, 0, true));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("Voltage #8", 7, true));
                  v.Add(new Voltage("VBat", 8));
                  for (int i = 0; i < superIO.Temperatures.Length; i++)
                    t.Add(new Temperature("Temperature #" + (i + 1), i));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
              }
              break;

            default:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("Voltage #3", 2, true));
              v.Add(new Voltage("Voltage #4", 3, true));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("Voltage #8", 7, true));
              v.Add(new Voltage("VBat", 8));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
                t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
                f.Add(new Fan("Fan #" + (i + 1), i));
              break;
              }
              break;

            case Chip.IT8721F:
            case Chip.IT8728F:
            case Chip.IT8771E:
            case Chip.IT8772E:
              switch (manufacturer) {
            case Manufacturer.ECS:
              switch (model) {
                case Model.A890GXM_A: // IT8721F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("VDIMM", 1));
                  v.Add(new Voltage("NB Voltage", 2));
                  v.Add(new Voltage("Analog +3.3V", 3, 10, 10));
                  // v.Add(new Voltage("VDIMM", 6, true));
                  v.Add(new Voltage("Standby +3.3V", 7, 10, 10));
                  v.Add(new Voltage("VBat", 8, 10, 10));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("System", 1));
                  t.Add(new Temperature("Northbridge", 2));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan", 1));
                  f.Add(new Fan("Power Fan", 2));
                  break;
                default:
                  v.Add(new Voltage("Voltage #1", 0, true));
                  v.Add(new Voltage("Voltage #2", 1, true));
                  v.Add(new Voltage("Voltage #3", 2, true));
                  v.Add(new Voltage("Analog +3.3V", 3, 10, 10, 0, true));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("Standby +3.3V", 7, 10, 10, 0, true));
                  v.Add(new Voltage("VBat", 8, 10, 10));
                  for (int i = 0; i < superIO.Temperatures.Length; i++)
                    t.Add(new Temperature("Temperature #" + (i + 1), i));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
              }
              break;
            case Manufacturer.Gigabyte:
              switch (model) {
                case Model.P67A_UD4_B3: // IT8728F
                  v.Add(new Voltage("+12V", 0, 100, 10));
                  v.Add(new Voltage("+5V", 1, 15, 10));
                  v.Add(new Voltage("Voltage #3", 2, true));
                  v.Add(new Voltage("Voltage #4", 3, true));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("CPU VCore", 5));
                  v.Add(new Voltage("DRAM", 6));
                  v.Add(new Voltage("Standby +3.3V", 7, 10, 10));
                  v.Add(new Voltage("VBat", 8, 10, 10));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 2));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan #2", 1));
                  f.Add(new Fan("Power Fan", 2));
                  f.Add(new Fan("System Fan #1", 3));
                  break;
                case Model.H67A_UD3H_B3: // IT8728F
                  v.Add(new Voltage("VTT", 0));
                  v.Add(new Voltage("+5V", 1, 15, 10));
                  v.Add(new Voltage("+12V", 2, 68, 22));
                  v.Add(new Voltage("Voltage #4", 3, true));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("CPU VCore", 5));
                  v.Add(new Voltage("DRAM", 6));
                  v.Add(new Voltage("Standby +3.3V", 7, 10, 10));
                  v.Add(new Voltage("VBat", 8, 10, 10));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 2));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("System Fan #1", 1));
                  f.Add(new Fan("Power Fan", 2));
                  f.Add(new Fan("System Fan #2", 3));
                  break;
                case Model.Z68X_UD7_B3: // IT8728F
                  v.Add(new Voltage("VTT", 0));
                  v.Add(new Voltage("+3.3V", 1, 13.3f, 20.5f));
                  v.Add(new Voltage("+12V", 2, 68, 22));
                  v.Add(new Voltage("+5V", 3, 14.3f, 20));
                  v.Add(new Voltage("CPU VCore", 5));
                  v.Add(new Voltage("DRAM", 6));
                  v.Add(new Voltage("Standby +3.3V", 7, 10, 10));
                  v.Add(new Voltage("VBat", 8, 10, 10));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 1));
                  t.Add(new Temperature("System 3", 2));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("Power Fan", 1));
                  f.Add(new Fan("System Fan #1", 2));
                  f.Add(new Fan("System Fan #2", 3));
                  f.Add(new Fan("System Fan #3", 4));
                  break;
                default:
                  v.Add(new Voltage("Voltage #1", 0, true));
                  v.Add(new Voltage("Voltage #2", 1, true));
                  v.Add(new Voltage("Voltage #3", 2, true));
                  v.Add(new Voltage("Voltage #4", 3, true));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("Standby +3.3V", 7, 10, 10, 0, true));
                  v.Add(new Voltage("VBat", 8, 10, 10));
                  for (int i = 0; i < superIO.Temperatures.Length; i++)
                    t.Add(new Temperature("Temperature #" + (i + 1), i));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
              }
              break;
            case Manufacturer.Shuttle:
              switch (model) {
                case Model.FH67: // IT8772E
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("DRAM", 1));
                  v.Add(new Voltage("PCH VCCIO", 2));
                  v.Add(new Voltage("CPU VCCIO", 3));
                  v.Add(new Voltage("Graphic Voltage", 4));
                  v.Add(new Voltage("Standby +3.3V", 7, 10, 10));
                  v.Add(new Voltage("VBat", 8, 10, 10));
                  t.Add(new Temperature("System", 0));
                  t.Add(new Temperature("CPU", 1));
                  f.Add(new Fan("Fan #1", 0));
                  f.Add(new Fan("CPU Fan", 1));
                  break;
                default:
                  v.Add(new Voltage("Voltage #1", 0, true));
                  v.Add(new Voltage("Voltage #2", 1, true));
                  v.Add(new Voltage("Voltage #3", 2, true));
                  v.Add(new Voltage("Voltage #4", 3, true));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("Standby +3.3V", 7, 10, 10, 0, true));
                  v.Add(new Voltage("VBat", 8, 10, 10));
                  for (int i = 0; i < superIO.Temperatures.Length; i++)
                    t.Add(new Temperature("Temperature #" + (i + 1), i));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
              }
              break;
            default:
              v.Add(new Voltage("Voltage #1", 0, true));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("Voltage #3", 2, true));
              v.Add(new Voltage("Voltage #4", 3, true));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("Standby +3.3V", 7, 10, 10, 0, true));
              v.Add(new Voltage("VBat", 8, 10, 10));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
                t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
                f.Add(new Fan("Fan #" + (i + 1), i));
              break;
              }
              break;

            case Chip.F71858:
              v.Add(new Voltage("VCC3V", 0, 150, 150));
              v.Add(new Voltage("VSB3V", 1, 150, 150));
              v.Add(new Voltage("Battery", 2, 150, 150));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
            t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
            f.Add(new Fan("Fan #" + (i + 1), i));
              break;
            case Chip.F71862:
            case Chip.F71869:
            case Chip.F71882:
            case Chip.F71889AD:
            case Chip.F71889ED:
            case Chip.F71889F:
              switch (manufacturer) {
            case Manufacturer.EVGA:
              switch (model) {
                case Model.X58_SLI_Classified: // F71882
                  v.Add(new Voltage("VCC3V", 0, 150, 150));
                  v.Add(new Voltage("CPU VCore", 1, 47, 100));
                  v.Add(new Voltage("DIMM", 2, 47, 100));
                  v.Add(new Voltage("CPU VTT", 3, 24, 100));
                  v.Add(new Voltage("IOH Vcore", 4, 24, 100));
                  v.Add(new Voltage("+5V", 5, 51, 12));
                  v.Add(new Voltage("+12V", 6, 56, 6.8f));
                  v.Add(new Voltage("3VSB", 7, 150, 150));
                  v.Add(new Voltage("VBat", 8, 150, 150));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("VREG", 1));
                  t.Add(new Temperature("System", 2));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("Power Fan", 1));
                  f.Add(new Fan("Chassis Fan", 2));
                  break;
                default:
                  v.Add(new Voltage("VCC3V", 0, 150, 150));
                  v.Add(new Voltage("CPU VCore", 1));
                  v.Add(new Voltage("Voltage #3", 2, true));
                  v.Add(new Voltage("Voltage #4", 3, true));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("VSB3V", 7, 150, 150));
                  v.Add(new Voltage("VBat", 8, 150, 150));
                  for (int i = 0; i < superIO.Temperatures.Length; i++)
                    t.Add(new Temperature("Temperature #" + (i + 1), i));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
              }
              break;
            default:
              v.Add(new Voltage("VCC3V", 0, 150, 150));
              v.Add(new Voltage("CPU VCore", 1));
              v.Add(new Voltage("Voltage #3", 2, true));
              v.Add(new Voltage("Voltage #4", 3, true));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("VSB3V", 7, 150, 150));
              v.Add(new Voltage("VBat", 8, 150, 150));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
                t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
                f.Add(new Fan("Fan #" + (i + 1), i));
              break;
              }
              break;

            case Chip.W83627EHF:
              switch (manufacturer) {
            case Manufacturer.ASRock:
              switch (model) {
                case Model.AOD790GX_128M: // W83627EHF
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("Analog +3.3V", 2, 34, 34));
                  v.Add(new Voltage("+3.3V", 4, 10, 10));
                  v.Add(new Voltage("+5V", 5, 20, 10));
                  v.Add(new Voltage("+12V", 6, 28, 5));
                  v.Add(new Voltage("Standby +3.3V", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Motherboard", 2));
                  f.Add(new Fan("CPU Fan", 0));
                  f.Add(new Fan("Chassis Fan", 1));
                  break;
                default:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("Voltage #2", 1, true));
                  v.Add(new Voltage("AVCC", 2, 34, 34));
                  v.Add(new Voltage("3VCC", 3, 34, 34));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("3VSB", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  v.Add(new Voltage("Voltage #10", 9, true));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Auxiliary", 1));
                  t.Add(new Temperature("System", 2));
                  f.Add(new Fan("System Fan", 0));
                  f.Add(new Fan("CPU Fan", 1));
                  f.Add(new Fan("Auxiliary Fan", 2));
                  f.Add(new Fan("CPU Fan #2", 3));
                  f.Add(new Fan("Auxiliary Fan #2", 4));
                  break;
              } break;
            default:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("AVCC", 2, 34, 34));
              v.Add(new Voltage("3VCC", 3, 34, 34));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("3VSB", 7, 34, 34));
              v.Add(new Voltage("VBAT", 8, 34, 34));
              v.Add(new Voltage("Voltage #10", 9, true));
              t.Add(new Temperature("CPU", 0));
              t.Add(new Temperature("Auxiliary", 1));
              t.Add(new Temperature("System", 2));
              f.Add(new Fan("System Fan", 0));
              f.Add(new Fan("CPU Fan", 1));
              f.Add(new Fan("Auxiliary Fan", 2));
              f.Add(new Fan("CPU Fan #2", 3));
              f.Add(new Fan("Auxiliary Fan #2", 4));
              break;
              }
              break;
            case Chip.W83627DHG:
            case Chip.W83627DHGP:
            case Chip.W83667HG:
            case Chip.W83667HGB:
              switch (manufacturer) {
            case Manufacturer.ASRock:
              switch (model) {
                case Model._880GMH_USB3: // W83627DHG-P
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("+3.3V", 3, 34, 34));
                  v.Add(new Voltage("+5V", 5, 15, 7.5f));
                  v.Add(new Voltage("+12V", 6, 56, 10));
                  v.Add(new Voltage("Standby +3.3V", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Motherboard", 2));
                  f.Add(new Fan("Chassis Fan", 0));
                  f.Add(new Fan("CPU Fan", 1));
                  f.Add(new Fan("Power Fan", 2));
                  break;
                default:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("Voltage #2", 1, true));
                  v.Add(new Voltage("AVCC", 2, 34, 34));
                  v.Add(new Voltage("3VCC", 3, 34, 34));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("3VSB", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Auxiliary", 1));
                  t.Add(new Temperature("System", 2));
                  f.Add(new Fan("System Fan", 0));
                  f.Add(new Fan("CPU Fan", 1));
                  f.Add(new Fan("Auxiliary Fan", 2));
                  f.Add(new Fan("CPU Fan #2", 3));
                  f.Add(new Fan("Auxiliary Fan #2", 4));
                  break;
              }
              break;
            case Manufacturer.ASUS:
              switch (model) {
                case Model.P6T: // W83667HG
                case Model.P6X58D_E: // W83667HG
                case Model.Rampage_II_GENE: // W83667HG
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("+12V", 1, 11.5f, 1.91f));
                  v.Add(new Voltage("Analog +3.3V", 2, 34, 34));
                  v.Add(new Voltage("+3.3V", 3, 34, 34));
                  v.Add(new Voltage("+5V", 4, 15, 7.5f));
                  v.Add(new Voltage("Standby +3.3V", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Motherboard", 2));
                  f.Add(new Fan("Chassis Fan #1", 0));
                  f.Add(new Fan("CPU Fan", 1));
                  f.Add(new Fan("Power Fan", 2));
                  f.Add(new Fan("Chassis Fan #2", 3));
                  f.Add(new Fan("Chassis Fan #3", 4));
                  break;
                case Model.Rampage_Extreme: // W83667HG
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("+12V", 1, 12, 2));
                  v.Add(new Voltage("Analog +3.3V", 2, 34, 34));
                  v.Add(new Voltage("+3.3V", 3, 34, 34));
                  v.Add(new Voltage("+5V", 4, 15, 7.5f));
                  v.Add(new Voltage("Standby +3.3V", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Motherboard", 2));
                  f.Add(new Fan("Chassis Fan #1", 0));
                  f.Add(new Fan("CPU Fan", 1));
                  f.Add(new Fan("Power Fan", 2));
                  f.Add(new Fan("Chassis Fan #2", 3));
                  f.Add(new Fan("Chassis Fan #3", 4));
                  break;
                default:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("Voltage #2", 1, true));
                  v.Add(new Voltage("AVCC", 2, 34, 34));
                  v.Add(new Voltage("3VCC", 3, 34, 34));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("3VSB", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Auxiliary", 1));
                  t.Add(new Temperature("System", 2));
                  f.Add(new Fan("System Fan", 0));
                  f.Add(new Fan("CPU Fan", 1));
                  f.Add(new Fan("Auxiliary Fan", 2));
                  f.Add(new Fan("CPU Fan #2", 3));
                  f.Add(new Fan("Auxiliary Fan #2", 4));
                  break;
              }
              break;
            default:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("AVCC", 2, 34, 34));
              v.Add(new Voltage("3VCC", 3, 34, 34));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("3VSB", 7, 34, 34));
              v.Add(new Voltage("VBAT", 8, 34, 34));
              t.Add(new Temperature("CPU", 0));
              t.Add(new Temperature("Auxiliary", 1));
              t.Add(new Temperature("System", 2));
              f.Add(new Fan("System Fan", 0));
              f.Add(new Fan("CPU Fan", 1));
              f.Add(new Fan("Auxiliary Fan", 2));
              f.Add(new Fan("CPU Fan #2", 3));
              f.Add(new Fan("Auxiliary Fan #2", 4));
              break;
              }
              break;
            case Chip.W83627HF:
            case Chip.W83627THF:
            case Chip.W83687THF:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("Voltage #3", 2, true));
              v.Add(new Voltage("AVCC", 3, 34, 51));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("5VSB", 5, 34, 51));
              v.Add(new Voltage("VBAT", 6));
              t.Add(new Temperature("CPU", 0));
              t.Add(new Temperature("Auxiliary", 1));
              t.Add(new Temperature("System", 2));
              f.Add(new Fan("System Fan", 0));
              f.Add(new Fan("CPU Fan", 1));
              f.Add(new Fan("Auxiliary Fan", 2));
              break;
            case Chip.NCT6771F:
            case Chip.NCT6776F:
              switch (manufacturer) {
            case Manufacturer.ASUS:
              switch (model) {
                case Model.P8P67: // NCT6776F
                case Model.P8P67_EVO: // NCT6776F
                case Model.P8P67_PRO: // NCT6776F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("+12V", 1, 11, 1));
                  v.Add(new Voltage("Analog +3.3V", 2, 34, 34));
                  v.Add(new Voltage("+3.3V", 3, 34, 34));
                  v.Add(new Voltage("+5V", 4, 12, 3));
                  v.Add(new Voltage("Standby +3.3V", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Auxiliary", 2));
                  t.Add(new Temperature("Motherboard", 3));
                  f.Add(new Fan("Chassis Fan #1", 0));
                  f.Add(new Fan("CPU Fan", 1));
                  f.Add(new Fan("Power Fan", 2));
                  f.Add(new Fan("Chassis Fan #2", 3));
                  c.Add(new Ctrl("Chassis Fan #2", 0));
                  c.Add(new Ctrl("CPU Fan", 1));
                  c.Add(new Ctrl("Chassis Fan #1", 2));
                  break;
                case Model.P8P67_M_PRO: // NCT6776F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("+12V", 1, 11, 1));
                  v.Add(new Voltage("Analog +3.3V", 2, 34, 34));
                  v.Add(new Voltage("+3.3V", 3, 34, 34));
                  v.Add(new Voltage("+5V", 4, 12, 3));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("Standby +3.3V", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Motherboard", 3));
                  f.Add(new Fan("Chassis Fan #1", 0));
                  f.Add(new Fan("CPU Fan", 1));
                  f.Add(new Fan("Chassis Fan #2", 2));
                  f.Add(new Fan("Power Fan", 3));
                  f.Add(new Fan("Auxiliary Fan", 4));
                  break;
                case Model.P8Z68_V_PRO: // NCT6776F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("+12V", 1, 11, 1));
                  v.Add(new Voltage("Analog +3.3V", 2, 34, 34));
                  v.Add(new Voltage("+3.3V", 3, 34, 34));
                  v.Add(new Voltage("+5V", 4, 12, 3));
                  v.Add(new Voltage("Standby +3.3V", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Auxiliary", 2));
                  t.Add(new Temperature("Motherboard", 3));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  for (int i = 0; i < superIO.Controls.Length; i++)
                    c.Add(new Ctrl("Fan #" + (i + 1), i));
                  break;
                case Model.P9X79: // NCT6776F
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("+12V", 1, 11, 1));
                  v.Add(new Voltage("Analog +3.3V", 2, 34, 34));
                  v.Add(new Voltage("+3.3V", 3, 34, 34));
                  v.Add(new Voltage("+5V", 4, 12, 3));
                  v.Add(new Voltage("Standby +3.3V", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("Motherboard", 3));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
                default:
                  v.Add(new Voltage("CPU VCore", 0));
                  v.Add(new Voltage("Voltage #2", 1, true));
                  v.Add(new Voltage("AVCC", 2, 34, 34));
                  v.Add(new Voltage("3VCC", 3, 34, 34));
                  v.Add(new Voltage("Voltage #5", 4, true));
                  v.Add(new Voltage("Voltage #6", 5, true));
                  v.Add(new Voltage("Voltage #7", 6, true));
                  v.Add(new Voltage("3VSB", 7, 34, 34));
                  v.Add(new Voltage("VBAT", 8, 34, 34));
                  t.Add(new Temperature("CPU", 0));
                  t.Add(new Temperature("CPU", 1));
                  t.Add(new Temperature("Auxiliary", 2));
                  t.Add(new Temperature("System", 3));
                  for (int i = 0; i < superIO.Fans.Length; i++)
                    f.Add(new Fan("Fan #" + (i + 1), i));
                  break;
              }
              break;
            default:
              v.Add(new Voltage("CPU VCore", 0));
              v.Add(new Voltage("Voltage #2", 1, true));
              v.Add(new Voltage("AVCC", 2, 34, 34));
              v.Add(new Voltage("3VCC", 3, 34, 34));
              v.Add(new Voltage("Voltage #5", 4, true));
              v.Add(new Voltage("Voltage #6", 5, true));
              v.Add(new Voltage("Voltage #7", 6, true));
              v.Add(new Voltage("3VSB", 7, 34, 34));
              v.Add(new Voltage("VBAT", 8, 34, 34));
              t.Add(new Temperature("CPU", 0));
              t.Add(new Temperature("CPU", 1));
              t.Add(new Temperature("Auxiliary", 2));
              t.Add(new Temperature("System", 3));
              for (int i = 0; i < superIO.Fans.Length; i++)
                f.Add(new Fan("Fan #" + (i + 1), i));
              break;
              }
              break;
            default:
              for (int i = 0; i < superIO.Voltages.Length; i++)
            v.Add(new Voltage("Voltage #" + (i + 1), i, true));
              for (int i = 0; i < superIO.Temperatures.Length; i++)
            t.Add(new Temperature("Temperature #" + (i + 1), i));
              for (int i = 0; i < superIO.Fans.Length; i++)
            f.Add(new Fan("Fan #" + (i + 1), i));
              for (int i = 0; i < superIO.Controls.Length; i++)
            c.Add(new Ctrl("Fan Control #" + (i + 1), i));
              break;
              }

              const string formula = "Voltage = value + (value - Vf) * Ri / Rf.";
              foreach (Voltage voltage in v)
            if (voltage.Index < superIO.Voltages.Length) {
              Sensor sensor = new Sensor(voltage.Name, voltage.Index,
            voltage.Hidden, SensorType.Voltage, this, new [] {
            new ParameterDescription("Ri [kΩ]", "Input resistance.\n" +
              formula, voltage.Ri),
            new ParameterDescription("Rf [kΩ]", "Reference resistance.\n" +
              formula, voltage.Rf),
            new ParameterDescription("Vf [V]", "Reference voltage.\n" +
              formula, voltage.Vf)
            }, settings);
              voltages.Add(sensor);
              }

              foreach (Temperature temperature in t)
            if (temperature.Index < superIO.Temperatures.Length) {
            Sensor sensor = new Sensor(temperature.Name, temperature.Index,
              SensorType.Temperature, this, new [] {
              new ParameterDescription("Offset [°C]", "Temperature offset.", 0)
            }, settings);
            temperatures.Add(sensor);
              }

              foreach (Fan fan in f)
            if (fan.Index < superIO.Fans.Length) {
              Sensor sensor = new Sensor(fan.Name, fan.Index, SensorType.Fan,
            this, settings);
              fans.Add(sensor);
            }

              foreach (Ctrl ctrl in c) {
            int index = ctrl.Index;
            if (index < superIO.Controls.Length) {
              Sensor sensor = new Sensor(ctrl.Name, index, SensorType.Control,
            this, settings);
              Control control = new Control(sensor, settings, 0, 100);
              control.ControlModeChanged += (cc) => {
            if (cc.ControlMode == ControlMode.Default) {
              superIO.SetControl(index, null);
            } else {
              superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55));
            }
              };
              control.SoftwareControlValueChanged += (cc) => {
            if (cc.ControlMode == ControlMode.Software)
              superIO.SetControl(index, (byte)(cc.SoftwareValue * 2.55));
              };
              if (control.ControlMode == ControlMode.Software)
            superIO.SetControl(index, (byte)(control.SoftwareValue * 2.55));
              sensor.Control = control;
              controls.Add(sensor);
            }
              }
        }
Example #57
0
 public AppRunnerService(UpdateDelegate app, ITelegramBotClient client, ILogger logger)
 {
     _client           = client;
     _logger           = logger;
     _client.OnUpdate += (sender, args) => app(args.Update);
 }
Example #58
0
 protected void Start()
 {
     SwitchScene("Loader");
     updateSceneDelegate = UpdateSceneCleanup;
     updateGuiDelegate = UpdateGui;
 }
		public void RegisterUpdateDelegate(UpdateDelegate updateDelegate, Control control)
		{
			this.updateDelegate = updateDelegate;
			calling_control = control;
		}
Example #60
0
 public AppRunnerService(UpdateDelegate app, ITelegramBotClient client) : this(app, client, Logger.None)
 {
 }