/// <summary>
    /// Create new HiveGalleryItem based on HiveData
    /// </summary>
    /// <param name="hiveData">HiveData of the wanted HiveGalleryItem</param>
    private void CreateHiveGalleryItem(HiveData hiveData)
    {
        HiveGalleryItem newHive = Instantiate(hiveGalleryItemPrefab, hiveGalleryContainer);

        newHive.Setup(hiveData);
        galleryItems.Add(newHive);
    }
    public void ChangeData(string key, string data)
    {
        hiveData = hiveDataModifier.UpdateData(hiveData, key, data);
        hiveDataModifier.SaveJson(hiveData, true);

        button.interactable = HiveActive;
    }
Beispiel #3
0
    public SnmpWorkHost()
    {
        try
        {
            // SnmpWorkSettings を読み込む
            this.SettingsHive = new HiveData <SnmpWorkSettings>(Hive.SharedLocalConfigHive, $"SnmpWork", null, HiveSyncPolicy.AutoReadFromFile);

            // データベース
            this.InternalDbHive = new HiveData <SnmpWorkInternalDb>(Hive.SharedLocalConfigHive, "InternalDatabase/SnmpWorkInternalDb",
                                                                    getDefaultDataFunc: () => new SnmpWorkInternalDb(),
                                                                    policy: HiveSyncPolicy.AutoReadWriteFile,
                                                                    serializer: HiveSerializerSelection.RichJson);

            // HTTP サーバーを立ち上げる
            this.Cgi = new CgiHttpServer(new SnmpWorkCgiHandler(this), new HttpServerOptions()
            {
                AutomaticRedirectToHttpsIfPossible = false,
                DisableHiveBasedSetting            = true,
                DenyRobots                 = true,
                UseGlobalCertVault         = false,
                LocalHostOnly              = true,
                HttpPortsList              = new int[] { Settings.HttpPort }.ToList(),
                HttpsPortsList             = new List <int>(),
                UseKestrelWithIPACoreStack = true,
            },
                                         true);
        }
        catch
        {
            this._DisposeSafe();
            throw;
        }
    }
    public HadbBasedServiceBase(HadbBasedServiceStartupParam startupParam, THook hook)
    {
        try
        {
            this.Hook = hook;

            this.ServiceStartupParam = startupParam._CloneDeep();

            this.HeavyRequestRateLimiter = new RateLimiter <string>(new RateLimiterOptions(burst: this.ServiceStartupParam.HeavyRequestRateLimiter_Burst, limitPerSecond: this.ServiceStartupParam.HeavyRequestRateLimiter_LimitPerSecond, mode: RateLimiterMode.NoPenalty));

            this._SettingsHive = new HiveData <THiveSettings>(Hive.SharedLocalConfigHive,
                                                              this.ServiceStartupParam.HiveDataName,
                                                              () => new THiveSettings {
                HadbSystemName = this.ServiceStartupParam.HadbSystemName
            },
                                                              HiveSyncPolicy.AutoReadWriteFile,
                                                              HiveSerializerSelection.RichJson);

            this.DnsResolver = new DnsClientLibBasedDnsResolver(new DnsResolverSettings(flags: DnsResolverFlags.RoundRobinServers,
                                                                                        dnsServersList: this.SettingsFastSnapshot.DnsResolverServerIpAddressList.Select(x => x._ToIPEndPoint(Consts.Ports.Dns, noExceptionAndReturnNull: true))
                                                                                        .Where(x => x != null) !));

            this.Hadb = this.CreateHadb();
        }
        catch
        {
            this._DisposeSafe();
            throw;
        }
    }
    public void Setup(HiveData data)
    {
        hiveData         = data;
        numberLabel.text = data.number;
        if (button)
        {
            button.interactable = HiveActive;
        }

        // TODO: maybe don't load all checkups here?
        string             checkupPath = Path.Combine("CheckupData", hiveData.id);
        List <CheckupData> allCheckups = JsonLoader.LoadAllFilesInDirectory <CheckupData>(checkupPath);

        if (allCheckups.Count > 0)
        {
            allCheckups = allCheckups.OrderBy
                              (x =>
                              DateTime.ParseExact(x.dateString,
                                                  "dd.MM.yyyy",
                                                  System.Globalization.CultureInfo.InvariantCulture))
                          .ToList();

            allCheckups.Reverse();

            lastCheckupDateLabel.text = allCheckups[0].dateString;
        }
        else
        {
            lastCheckupDateLabel.text = "-";
        }
    }
Beispiel #6
0
    public ThinWebClient(ThinWebClientOptions options, ThinWebClientHookBase hook, Func <ThinWebClientSettings>?getDefaultSettings = null)
    {
        try
        {
            this.Options = options;

            this.Hook = hook;

            this.SettingsHive = new HiveData <ThinWebClientSettings>(
                Hive.SharedLocalConfigHive,
                "ThinWebClient",
                getDefaultSettings,
                HiveSyncPolicy.AutoReadWriteFile,
                HiveSerializerSelection.RichJson);

            this.DnsResolver = new DnsClientLibBasedDnsResolver(new DnsResolverSettings());

            this.SessionManager = new DialogSessionManager(new DialogSessionManagerOptions(sessionIdPrefix: "thin"), cancel: this.GrandCancel);

            this.RateLimit = this.Hook.GetRateLimiterForNewSession();
        }
        catch (Exception ex)
        {
            this._DisposeSafe(ex);
            throw;
        }
    }
Beispiel #7
0
    protected override void Awake()
    {
        currentHive =
            JsonLoader.LoadFromJSON <HiveData>(PlayerPrefs.GetString("CurrentHivePath"));
        today = DateTime.Today;

        base.Awake();
    }
Beispiel #8
0
        public PersistentLocalCache(string name, TimeSpan lifetime, bool ignoreUpdateError, Func <CancellationToken, Task <T> > updateProcAsync)
        {
            if (name._IsEmpty())
            {
                throw new ArgumentException("name is empty.");
            }

            this.IgnoreUpdateError = ignoreUpdateError;
            this.HiveKv            = Hive.LocalAppSettingsEx[$"cache/{name}"];
            this.LifeTime          = lifetime;
            this.UpdateProcAsync   = updateProcAsync;
        }
        public UserModeService(string name, Action onStart, Action onStop, int telnetLogWatcherPort)
        {
            this.Name = name;

            this.OnStart = onStart;
            this.OnStop  = onStop;

            this.TelnetLogWatcherPort = telnetLogWatcherPort;

            this.Hive     = new Hive(new HiveOptions(CoresConfig.UserModeServiceSettings.GetLocalHiveDirProc.Value(), globalLock: true));
            this.HiveData = new HiveData <UserModeServicePidData>(this.Hive, this.Name, () => new UserModeServicePidData());
        }
Beispiel #10
0
    /// <summary>
    /// Setup scene based on currenntHive (loaded from PlayerPrefs path)
    /// </summary>
    void SetupCurrentHive()
    {
        HiveData currentHive =
            JsonLoader.LoadFromJSON <HiveData>(PlayerPrefs.GetString("CurrentHivePath"));

        // Setup texts
        hiveNameLabel.text = "Beute " + currentHive.number;
        hiveInfoLabel.text =
            "Beute " + currentHive.number + "\n" +
            currentHive.location;

        hiveGalleryItem.Setup(currentHive);
        checkupGallery.Setup(currentHive.id);
    }
Beispiel #11
0
    public MyIpServerHost()
    {
        try
        {
            // Settings を読み込む
            this.SettingsHive = new HiveData <MyIpServerSettings>(Hive.SharedLocalConfigHive, $"MyIpServer", null, HiveSyncPolicy.AutoReadFromFile);

            List <IPEndPoint> dnsServers = new List <IPEndPoint>();

            foreach (var host in this.Settings.DnsServerList)
            {
                var ep = host._ToIPEndPoint(53, allowed: AllowedIPVersions.IPv4, true);
                if (ep != null)
                {
                    dnsServers.Add(ep);
                }
            }

            if (dnsServers.Count == 0)
            {
                throw new CoresLibException("dnsServers.Count == 0");
            }

            this.Dns = new DnsClientLibBasedDnsResolver(
                new DnsResolverSettings(
                    flags: DnsResolverFlags.RoundRobinServers | DnsResolverFlags.UdpOnly,
                    dnsServersList: dnsServers
                    )
                );

            // HTTP サーバーを立ち上げる
            this.Cgi = new CgiHttpServer(new MyIpServerCgiHandler(this), new HttpServerOptions()
            {
                AutomaticRedirectToHttpsIfPossible = false,
                UseKestrelWithIPACoreStack         = false,
                HttpPortsList      = new int[] { 80, 992 }.ToList(),
                HttpsPortsList     = new int[] { 443 }.ToList(),
                UseStaticFiles     = false,
                MaxRequestBodySize = 32 * 1024,
                ReadTimeoutMsecs   = this.Settings.HttpTimeoutMsecs,
            },
                                         true);
        }
        catch
        {
            this._DisposeSafe();
            throw;
        }
    }
Beispiel #12
0
    public EmptyDaemonApp()
    {
        try
        {
            // Settings を読み込む
            this.SettingsHive = new HiveData <EmptyDaemonSettings>(Hive.SharedLocalConfigHive, $"EmptyDaemon", null, HiveSyncPolicy.AutoReadFromFile);


            // TODO: ここでサーバーを立ち上げるなどの初期化処理を行なう
        }
        catch
        {
            this._DisposeSafe();
            throw;
        }
    }
Beispiel #13
0
        public FastReader()
        {
            try
            {
                this.Inbox = new Inbox(new InboxOptions(recordRealtimeTextLog: true));

                this.Inbox.StateChangeEventListener.RegisterCallback(async(caller, type, state, args) => { UpdatedCallback(); await Task.CompletedTask; });

                this.AccountsHive = Hive.LocalAppSettingsEx["Accounts"];

                this.AccountsHive.AccessData(true, k =>
                {
                    var initial = new AccountSettingList();

                    AccountSettingList o = k.Get("AccountList", initial) !;

                    foreach (AccountSetting account in o.List)
                    {
                        if (account.ProviderName._IsSamei(Consts.InboxProviderNames.Slack_Old))
                        {
                            account.ProviderName = Consts.InboxProviderNames.Slack_App;
                        }

                        InboxAdapter a = this.Inbox.AddAdapter(account.Guid, account.ProviderName, new InboxAdapterAppCredential {
                            ClientId = account.AppClientId, ClientSecret = account.AppClientSecret
                        });

                        if (account.UserAccessToken._IsFilled())
                        {
                            a.Start(new InboxAdapterUserCredential {
                                AccessToken = account.UserAccessToken
                            });
                        }
                        else if (account.ProviderName._IsSamei(Consts.InboxProviderNames.Slack_User))
                        {
                            // Special: Slack legacy tokens
                            a.Start(new InboxAdapterUserCredential());
                        }
                    }
                });
            }
            catch
            {
                this._DisposeSafe();
                throw;
            }
        }
        public IpConnectionRateLimiter(string hiveName)
        {
            hiveName._NotEmptyCheck(nameof(hiveName));

            this.HiveName = hiveName;

            using var config = new HiveData <IpConnectionRateLimiterOptions>(Hive.SharedLocalConfigHive, $"NetworkSettings/IpConnectionRateLimiter/{hiveName}",
                                                                             () => new IpConnectionRateLimiterOptions(),
                                                                             policy: HiveSyncPolicy.None);

            lock (config.DataLock)
            {
                this.Options = config.ManagedData;
            }

            this.RateLimiter = new RateLimiter <HashKeys.SingleIPAddress>(new RateLimiterOptions(this.Options.RateLimiter_Burst, this.Options.RateLimiter_LimitPerSecond, this.Options.RateLimiter_ExpiresMsec,
                                                                                                 this.Options.RateLimiter_EnablePenalty ? RateLimiterMode.Penalty : RateLimiterMode.NoPenalty,
                                                                                                 this.Options.RateLimiter_MaxEntries,
                                                                                                 this.Options.RateLimiter_GcIntervalMsec));

            this.ConcurrentLimiter = new ConcurrentLimiter <HashKeys.SingleIPAddress>(this.Options.ConcurrentLimiter_MaxConcurrentRequestsPerSrcSubnet);

            if (this.Options.Common_ReportDebugLog)
            {
                this.RateLimiter.EventListener.RegisterCallback((a, b, c, d) =>
                {
                    string?str = d as string;
                    if (str._IsFilled())
                    {
                        Dbg.WriteLine($"IpConnectionRateLimiter[{this.HiveName}]: {str}");
                    }
                });

                this.ConcurrentLimiter.EventListener.RegisterCallback((a, b, c, d) =>
                {
                    string?str = d as string;
                    if (str._IsFilled())
                    {
                        Dbg.WriteLine($"IpConnectionRateLimiter[{this.HiveName}]: {str}");
                    }
                });
            }
        }
    public GitLabMainteDaemonApp()
    {
        try
        {
            // Settings を読み込む
            this.SettingsHive = new HiveData <GitLabMainteDaemonSettings>(Hive.SharedLocalConfigHive, $"GitLabMainteDaemon", null, HiveSyncPolicy.AutoReadFromFile);

            this.GitLabClient = new GitLabMainteClient(this.Settings.GitLabClientSettings);

            // TODO: ここでサーバーを立ち上げるなどの初期化処理を行なう

            this.MainLoop1Task = TaskUtil.StartAsyncTaskAsync(Loop1_MainteUsersAsync(this.GrandCancel));

            this.MainLoop2Task = TaskUtil.StartAsyncTaskAsync(Loop2_MainteUsersAsync(this.GrandCancel));

            // Log Browser を立ち上げる
            var logBrowserOptions = new LogBrowserOptions(
                this.Settings.GitWebDataRootDir, this.Settings.Title, flags: LogBrowserFlags.SecureJson | LogBrowserFlags.SecureJson_FlatDir | LogBrowserFlags.NoRootDirectory,
                extsAsMimeTypeUtf8: this.Settings.ExtsAsMimeTypeUtf8, logFileMaxSizePerDir: this.Settings.MaxAccessLogFileSizeInSpecificDir);

            this.LogBrowser = new LogBrowser(logBrowserOptions, "/d");

            // HTTP サーバーを立ち上げる
            this.Cgi = new CgiHttpServer(new CgiHandler(this), new HttpServerOptions()
            {
                AutomaticRedirectToHttpsIfPossible = false,
                UseKestrelWithIPACoreStack         = false,
                HttpPortsList      = new int[] { 80 }.ToList(),
                HttpsPortsList     = new int[] { 443 }.ToList(),
                UseStaticFiles     = false,
                MaxRequestBodySize = 32 * 1024,
                ReadTimeoutMsecs   = this.Settings.HttpTimeoutMsecs,
                DenyRobots         = true,
            },
                                         true);
        }
        catch
        {
            this._DisposeSafe();
            throw;
        }
    }
        public Server(CancellationToken cancel = default) : base(cancel)
        {
            try
            {
                this.SingleInstance = new SingleInstance("Cores.Basic.App.DaemonCenter");

                // データベース
                this.HiveData = new HiveData <DbHive>(Hive.SharedLocalConfigHive, "DaemonCenterServer/Database",
                                                      getDefaultDataFunc: () => new DbHive(),
                                                      policy: HiveSyncPolicy.AutoReadWriteFile,
                                                      serializer: HiveSerializerSelection.RichJson);

                this.JsonRpcServer = new JsonRpcHttpServer(this);
            }
            catch
            {
                this._DisposeSafe();
                throw;
            }
        }