Exemplo n.º 1
0
        /// <summary>
        /// 初始化视图
        /// </summary>
        private void InitView(LocalizationManager.LanguageType languageType)
        {
            TMPro.TextMeshProUGUI text = GetComponent <TMPro.TextMeshProUGUI>();
            text.text = LocalizationManager.GetInstance().GetLocalTextString("UIStatic/" + fileName, key, languageType);

            TextConfig textConfig = textConfigs.FirstOrDefault(x => x.languageType == languageType);

            if (textConfig == null)
            {
                return;
            }

            TextFontProperty fontProperty = textConfig.fontProperty;

            if (enableFontProperty)
            {
                text.font = fontProperty.font;
                text.fontSharedMaterial = fontProperty.fontSharedMaterial;
                text.fontStyle          = fontProperty.fontStyle;
                text.color              = fontProperty.color;
                text.colorGradient      = fontProperty.colorGradient;
                text.fontSize           = fontProperty.fontSize;
                text.alignment          = fontProperty.alignment;
                text.enableWordWrapping = fontProperty.enableWordWrapping;
                text.overflowMode       = fontProperty.overflowMode;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 从配置读取
 /// </summary>
 public static void readConfig()
 {
     NetNotOpen       = TextConfig.getText("netNotOpen");
     ServerNotRespond = TextConfig.getText("serverNotRespond");
     SocketClosed     = TextConfig.getText("socketClosed");
     NeedHotfix       = TextConfig.getText("needHotfix");
 }
Exemplo n.º 3
0
 public TextContainer(IFileContainer c, TextConfig t = null, bool remap = false)
 {
     Remap     = remap;
     Config    = t;
     Container = c;
     Cache     = new string[Container.Count][];
 }
Exemplo n.º 4
0
        private void EnableDefault(bool enable, TextConfig def)
        {
            caretColorCombo.DefaultColor     = def.CaretColor.Value;
            caretLineColorCombo.DefaultColor = def.CaretLineColor.Value;
            selBackgroundCombo.DefaultColor  = def.SelectionBackColor.Value;
            selColorCombo.DefaultColor       = def.SelectionForeColor.Value;

            var seq = GetControls();

            seq.Where(c => c is CheckBox).OfType <CheckBox>()
            .ForEach(c => c.ThreeState = enable);

            seq.Where(c => c is ColorPicker).OfType <ColorPicker>()
            .ForEach(c => c.SetShowDefault(enable));

            if (!enable)
            {
                seq.Where(c => c is DefaultComboBox).OfType <DefaultComboBox>()
                .ForEach(c => c.RemoveDefault());
            }
            else
            {
                tabSizeCombo.AddDefault(def.TabSize.ToString());
                indentSizeCombo.AddDefault(def.IndentSize.ToString());
                indentModeCombo.AddDefault(def.IndentMode.ToString());
                longLineIndicatorCombo.AddDefault(def.LongLine.ToString());
                lineEndingsCombo.AddDefault(def.LineEndings.ToString());
                caretStyleCombo.AddDefault(def.CaretStyle.ToString());
                caretWidthCombo.AddDefault(def.CaretWidth.ToString());
                blinkCombo.AddDefault(def.CaretBlinkPeriod.ToString());
                caretLineTransparencyCombo.AddDefault(caretLineTransparencyCombo.Items.OfType <Object>().Where(o => o is Value).OfType <Value>().First(v => v.Val == def.CaretLineAlpha).Text);
                selTransparencyCombo.AddDefault(selTransparencyCombo.Items.OfType <Object>().Where(o => o is Value).OfType <Value>().First(v => v.Val == def.SelectionTransparency).Text);
                wrapCombo.AddDefault(def.WordWrap.ToString());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 保存视图
        /// </summary>
        private void SaveView(LocalizationManager.LanguageType languageType)
        {
            TextConfig textConfig = textConfigs.FirstOrDefault(x => x.languageType == languageType);

            if (textConfig == null)
            {
                return;
            }

            TextFontProperty fontProperty = textConfig.fontProperty;

            if (enableFontProperty)
            {
                TMPro.TextMeshProUGUI text = GetComponent <TMPro.TextMeshProUGUI>();
                fontProperty.font = text.font;
                fontProperty.fontSharedMaterial = text.fontSharedMaterial;
                fontProperty.fontStyle          = text.fontStyle;
                fontProperty.color              = text.color;
                fontProperty.colorGradient      = text.colorGradient;
                fontProperty.fontSize           = text.fontSize;
                fontProperty.alignment          = text.alignment;
                fontProperty.enableWordWrapping = text.enableWordWrapping;
                fontProperty.overflowMode       = text.overflowMode;
            }
        }
Exemplo n.º 6
0
        public ButtonAnimation ToItem(AGSSerializationContext context)
        {
            var button = new ButtonAnimation(Border.ToItem(context), TextConfig.ToItem(context),
                                             Tint == null ? (Color?)null : Color.FromHexa(Tint.Value));

            button.Animation = Animation.ToItem(context);
            return(button);
        }
Exemplo n.º 7
0
        public ITextComponent ToItem(AGSSerializationContext context)
        {
            var component = context.Resolver.Container.Resolve <ITextComponent>();

            component.TextConfig      = TextConfig.ToItem(context);
            component.Text            = Text;
            component.LabelRenderSize = new SizeF(Width, Height);
            return(component);
        }
Exemplo n.º 8
0
        public static TMP_FontAsset Get(TextConfig colorConfig)
        {
            switch (colorConfig)
            {
            default:
            case TextConfig.Standard:
                return(FontStandard);

            case TextConfig.Header:
                return(FontHeader);
            }
        }
Exemplo n.º 9
0
        public void EditScript()
        {
            var text   = ROM.GetFilteredFolder(GameFile.StoryText, z => Path.GetExtension(z) == ".dat");
            var config = new TextConfig(ROM.Game);
            var tc     = new TextContainer(text, config);

            using var form = new TextEditor(tc, TextEditor.TextEditorMode.Script);
            form.ShowDialog();
            if (!form.Modified)
            {
                text.CancelEdits();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 重置
        /// </summary>
        public void Reset()
        {
            GenConfigKey();
            currentLanguageType = LocalizationManager.LanguageType.cn;
            m_lastLanguageType  = currentLanguageType;

            textConfigs.Clear();
            foreach (var obj in System.Enum.GetValues(typeof(LocalizationManager.LanguageType)))
            {
                LocalizationManager.LanguageType languageType = (LocalizationManager.LanguageType)obj;
                TextConfig textConfig = new TextConfig();
                textConfig.languageName = languageType.ToString();
                textConfig.languageType = languageType;
                textConfigs.Add(textConfig);
            }
        }
Exemplo n.º 11
0
        protected void UpdateTextEditorSettings(TextConfig c)
        {
            var def = App.Config <TextEditorsConfig>().Default;

            var cc = (Func <KnownColor?, Color>)(k => Color.FromKnownColor(k.Value));

            sci.CaretLineVisible = c.CaretLineVisible == null ? def.CaretLineVisible.Value : c.CaretLineVisible.Value;
            sci.CaretLineAlpha   = c.CaretLineAlpha == null ? def.CaretLineAlpha.Value : c.CaretLineAlpha.Value;
            sci.CaretLineColor   = c.CaretLineColor == null?cc(def.CaretLineColor) : cc(c.CaretLineColor);

            sci.CaretColor = c.CaretColor == null?cc(def.CaretColor) : cc(c.CaretColor);

            sci.CaretStyle  = c.CaretStyle == null ? def.CaretStyle.Value : c.CaretStyle.Value;
            sci.CaretWidth  = c.CaretWidth == null ? def.CaretWidth.Value : c.CaretWidth.Value;
            sci.CaretPeriod = c.CaretBlinkPeriod == null ? def.CaretBlinkPeriod.Value : c.CaretBlinkPeriod.Value;
            sci.CaretSticky = c.CaretSticky == null ? def.CaretSticky.Value : c.CaretSticky.Value;

            sci.UseTabs     = c.UseTabs == null ? def.UseTabs.Value : c.UseTabs.Value;
            sci.TabSize     = c.TabSize == null ? def.TabSize.Value : c.TabSize.Value;
            sci.IndentSize  = c.IndentSize == null ? def.IndentSize.Value : c.IndentSize.Value;
            sci.IndentMode  = c.IndentMode == null ? def.IndentMode.Value : c.IndentMode.Value;
            sci.LineEndings = c.LineEndings == null ? def.LineEndings.Value : c.LineEndings.Value;

            sci.MultipleSelection       = c.MultipleSelection == null ? def.MultipleSelection.Value : c.MultipleSelection.Value;
            sci.MultipleSelectionTyping = c.MultipleSelectionTyping == null ? def.MultipleSelectionTyping.Value : c.MultipleSelectionTyping.Value;
            sci.MultipleSelectionPaste  = c.MultipleSelectionPaste == null ? def.MultipleSelectionPaste.Value : c.MultipleSelectionPaste.Value;
            sci.VirtualSpace            = c.VirtualSpace == null ? (def.VirtualSpace.Value ? VirtualSpaceMode.AllSelections : VirtualSpaceMode.Disabled) :
                                          (c.VirtualSpace.Value ? VirtualSpaceMode.AllSelections : VirtualSpaceMode.Disabled);

            sci.IndentationGuides      = c.IndentationGuides == null ? def.IndentationGuides.Value : c.IndentationGuides.Value;
            sci.ViewWhiteSpace         = c.VisibleWhiteSpace == null ? def.VisibleWhiteSpace.Value : c.VisibleWhiteSpace.Value;
            sci.ViewEol                = c.VisibleLineEndings == null ? def.VisibleLineEndings.Value : c.VisibleLineEndings.Value;
            sci.WordWrapMode           = c.WordWrap == null ? def.WordWrap.Value : c.WordWrap.Value;
            sci.WordWrapIndicators     = c.WordWrapIndicator == null ? def.WordWrapIndicator.Value : c.WordWrapIndicator.Value;
            sci.LongLineIndicator      = c.LongLineIndicator == null ? def.LongLineIndicator.Value : c.LongLineIndicator.Value;
            sci.LongLineColumn         = c.LongLine == null ? def.LongLine.Value : c.LongLine.Value;
            sci.UseSelectionColor      = c.UseSelectionColor == null ? def.UseSelectionColor.Value : c.UseSelectionColor.Value;
            sci.MainSelectionBackColor = c.SelectionBackColor == null?cc(def.SelectionBackColor) : cc(c.SelectionBackColor);

            sci.MainSelectionForeColor = c.SelectionForeColor == null?cc(def.SelectionForeColor) : cc(c.SelectionForeColor);

            sci.SelectionAlpha = c.SelectionTransparency == null ? def.SelectionTransparency.Value : c.SelectionTransparency.Value;
        }
Exemplo n.º 12
0
    public virtual void OnValidate()
    {
        if (realText == null)
        {
            realText = gameObject.GetComponent <TextMeshProUGUI>();
        }

        if (strTid != null && strTid.Length > 0)
        {
            TextConfig c = TextDao.Inst.GetCfg(strTid);
            if (c == null)
            {
                realText.text = "该tid:" + strTid + "未配置";
            }
            else
            {
                realText.text = c.Text;
            }
        }
    }
Exemplo n.º 13
0
 public void SetString()
 {
     m_isPrint = false;
     if (realText == null)
     {
         realText = gameObject.GetComponent <TextMeshProUGUI>();
     }
     realText.maxVisibleCharacters = 1000;
     if (strTid.Length > 0)
     {
         TextConfig c = TextDao.Inst.GetCfg(strTid);
         if (c == null)
         {
             realText.text = "该tid:" + strTid + "未配置";
         }
         else
         {
             realText.text = c.Text;
         }
     }
 }
Exemplo n.º 14
0
 public TextManager(GameVersion game, TextConfig config = null)
 {
     References = TextMapping.GetMapping(game);
     Config     = config ?? new TextConfig(game);
 }
Exemplo n.º 15
0
        void parseXML(string filePath)
        {
            XDocument xDoc = XDocument.Load(filePath);

            List <XElement> element = xDoc.Elements("locale").ToList();

            if (element != null)
            {
                lManager.Enter(Sender.MANAGER, Level.DEBUG, "<locale/> found for locale:{0}", key);

                Locale locale = new Locale();

                if (!element[0].HasAttributes)
                {
                    lManager.Enter(Sender.MANAGER, Level.ERROR, "<locale/> element does not have expected attributes!");
                    return;
                }

                locale.Name = element[0].FirstAttribute.Value;

                List <XElement> childNodes = element[0].Elements().ToList();
                locale.DisplayName = childNodes[0].Value;
                locale.Encoding    = Convert.ToInt32(childNodes[1].Value);

                FontConfig globalFont = new FontConfig();
                System.Windows.Forms.RightToLeft rightToLeft = System.Windows.Forms.RightToLeft.No;

                if (childNodes.Count == 4) // Global font is likely defined
                {
                    if (childNodes[2].Name == "font")
                    {
                        List <XElement> fontElements = childNodes[2].Elements().ToList();

                        globalFont.Style = (System.Drawing.FontStyle)Enum.Parse(typeof(System.Drawing.FontStyle), fontElements[0].Value);
                        globalFont.Size  = Convert.ToDouble(fontElements[1].Value, CultureInfo.InvariantCulture);

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "Global <font/> is defined.\nFamily:{0}\nStyle:{1}\nSize:{2}", globalFont.Name,
                                       globalFont.Style.ToString(),
                                       globalFont.Size);
                    }
                }
                else if (childNodes.Count == 5) // Global right to left is likely defined
                {
                    if (childNodes[3].Name == "rightToLeft")
                    {
                        rightToLeft = (System.Windows.Forms.RightToLeft)Enum.Parse(typeof(System.Windows.Forms.RightToLeft), childNodes[3].Value);

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "Global <rightToLeft/> defined.");
                    }
                }

                // Get the <control/> nodes in the <controls/> elemenent
                childNodes = childNodes[childNodes.Count - 1].Elements().ToList();

                lManager.Enter(Sender.MANAGER, Level.DEBUG, "{0} <control/> nodes found.", childNodes.Count);

                List <ControlConfig> controls = new List <ControlConfig>();
                for (int c = 0; c < childNodes.Count; c++)
                {
                    ControlConfig control = new ControlConfig();

                    if (childNodes[c].HasAttributes)
                    {
                        List <XAttribute> attributes = childNodes[c].Attributes().ToList();
                        if (attributes.Count >= 1)
                        {
                            control.Name = attributes[0].Value;
                        }

                        if (attributes.Count >= 2)
                        {
                            control.Comment = attributes[1].Value;
                        }

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<control/> {0} has expected attributes.", control.Name);
                    }
                    else
                    {
                        string msg = string.Format("<control/> at index: {0} does not have attributes! Ignoring!", c);
                        lManager.Enter(Sender.MANAGER, Level.WARNING, msg);
                        System.Windows.Forms.MessageBox.Show(msg, "XML Exception", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                    }

                    FontConfig controlFont = null;

                    List <XElement> fontElements = childNodes[c].Elements("font").ToList();
                    if (fontElements.Count > 0)
                    {
                        controlFont      = new FontConfig();
                        controlFont.Name = fontElements[0].FirstAttribute.Value;

                        fontElements      = fontElements[0].Elements().ToList();
                        controlFont.Style = (System.Drawing.FontStyle)Enum.Parse(typeof(System.Drawing.FontStyle), fontElements[0].Value);
                        controlFont.Size  = Convert.ToDouble(fontElements[1].Value, CultureInfo.InvariantCulture);

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<font/> detected.\nFamily:{0}\nStyle:{2}\nSize:{1}", controlFont.Name,
                                       controlFont.Style.ToString(),
                                       controlFont.Size);
                    }
                    else
                    {
                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "No <font/> detected for control: {0}", control.Name);
                    }

                    control.Font = (controlFont != null) ? controlFont : globalFont;

                    List <XElement> locationElements = childNodes[c].Elements("location").ToList();
                    if (locationElements.Count == 1)
                    {
                        string[] location = childNodes[c].Elements("location").ToList()[0].Value.Split(',');
                        control.Location = new System.Drawing.Point(int.Parse(location[0]), int.Parse(location[1]));

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<location/> detected.\nx:{0}\ny:{1}", control.Location.X,
                                       control.Location.Y);
                    }
                    else
                    {
                        control.Location = new System.Drawing.Point(0, 0);
                    }

                    List <XElement> sizeElements = childNodes[c].Elements("size").ToList();
                    if (sizeElements.Count == 1)
                    {
                        string[] size = childNodes[c].Elements("size").ToList()[0].Value.Split(',');
                        control.Size = new System.Drawing.Size(int.Parse(size[0]), int.Parse(size[1]));

                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<size/> detected. \nheight:{0}\nwidth:{1}", control.Size.Height,
                                       control.Size.Width);
                    }
                    else
                    {
                        control.Size = new System.Drawing.Size(0, 0);
                    }

                    TextConfig text = new TextConfig();
                    text.Alignment = System.Drawing.ContentAlignment.MiddleLeft;

                    List <XElement> textElements = childNodes[c].Elements("text").ToList();

                    if (textElements.Count > 0)
                    {
                        lManager.Enter(Sender.MANAGER, Level.DEBUG, "<text/> element detected!");

                        if (textElements[0].HasAttributes)
                        {
                            List <XAttribute> attributes = textElements[0].Attributes().ToList();

                            XAttribute attribute = attributes.Find(a => a.Name == "align");
                            if (attribute != null)
                            {
                                text.Alignment = (System.Drawing.ContentAlignment)Enum.Parse(typeof(System.Drawing.ContentAlignment), attribute.Value);
                            }

                            attribute = attributes.Find(a => a.Name == "rightToLeft");
                            if (attribute != null)
                            {
                                text.RightToLeft = (System.Windows.Forms.RightToLeft)Enum.Parse(typeof(System.Windows.Forms.RightToLeft), attribute.Value);
                            }
                        }

                        text.Text = textElements[0].Value;
                    }
                    else
                    {
                        text.Text = string.Empty;
                    }

                    control.Text = text;

                    if (control.Populated)
                    {
                        controls.Add(control);
                    }
                }

                locale.Controls = controls;

                if (locale.Populated)
                {
                    locales.Add(locale);
                }

                lManager.Enter(Sender.MANAGER, Level.DEBUG, string.Format("{0} controls configurations loaded from locale: {1} from\n\t- {2}", locale.Controls.Count, locale.Name, filePath));
            }
        }
Exemplo n.º 16
0
        // ReSharper disable once UnusedMember.Global
        public void ConfigureServices(IServiceCollection services)
        {
            var cache = new CacheConfig();
            var db    = new DatabaseConfig();
            var auth  = new AuthenticationConfig();
            var mail  = new MailConfig();
            var text  = new TextConfig();
            var sys   = new SystemConfig();
            var mqtt  = new MqttConfig();

            this._configuration.GetSection("Cache").Bind(cache);
            this._configuration.GetSection("Authentication").Bind(auth);
            this._configuration.GetSection("Database").Bind(db);
            this._configuration.GetSection("Mail").Bind(mail);
            this._configuration.GetSection("System").Bind(sys);
            this._configuration.GetSection("Text").Bind(text);
            this._configuration.GetSection("Mqtt").Bind(mqtt);

            services.AddCors();
            var privatemqtt = mqtt.InternalBroker;

            services.AddPostgres(db.PgSQL.ConnectionString);
            services.AddDocumentStore(db.MongoDB.ConnectionString, db.MongoDB.DatabaseName, db.MongoDB.MaxConnections);
            services.AddIdentityFramwork(auth);

            if (cache.Enabled)
            {
                services.AddCacheStrategy(cache, db);
            }

            services.AddReverseProxy(sys);

            /* Add repositories */
            services.AddSqlRepositories(cache.Enabled);
            services.AddDocumentRepositories(cache.Enabled);
            services.AddUserService();

            services.AddCommandPublisher(options => {
                options.Ssl           = privatemqtt.Ssl;
                options.Host          = privatemqtt.Host;
                options.Port          = privatemqtt.Port;
                options.Username      = privatemqtt.Username;
                options.Password      = privatemqtt.Password;
                options.CommandsTopic = privatemqtt.InternalCommandsTopic;
            });

            if (mail.Provider == "SendGrid")
            {
                services.AddSingleton <IEmailSender, SendGridMailer>();
                services.Configure <SendGridAuthOptions>(opts => {
                    opts.FromName = mail.FromName;
                    opts.From     = mail.From;
                    opts.Key      = mail.SendGrid.Key;
                    opts.Username = mail.SendGrid.Username;
                });
            }
            else if (mail.Provider == "SMTP")
            {
                services.AddSingleton <IEmailSender, SmtpMailer>();
                services.Configure <SmtpAuthOptions>(opts => {
                    opts.FromName = mail.FromName;
                    opts.From     = mail.From;
                    opts.Password = mail.Smtp.Password;
                    opts.Username = mail.Smtp.Username;
                    opts.Ssl      = mail.Smtp.Ssl;
                    opts.Port     = mail.Smtp.Port;
                    opts.Host     = mail.Smtp.Host;
                });
            }

            if (text.Provider == "Twillio")
            {
                services.AddTwilioTextApi(text);
            }
            else
            {
                Console.WriteLine("Text message provider not configured!");
            }


            services.AddSwaggerGen(c => {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title   = "Sensate IoT Auth API - Version 1",
                    Version = "v1"
                });

                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme {
                    In          = ParameterLocation.Header,
                    Name        = "Authorization",
                    Type        = SecuritySchemeType.ApiKey,
                    Description = "API key needed to access the endpoints."
                });

                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Name      = "Authorization",
                            Type      = SecuritySchemeType.ApiKey,
                            In        = ParameterLocation.Header,
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            },
                        },
                        new string[] {}
                    }
                });
            });

            services.AddRouting();
            services.AddControllers().AddNewtonsoftJson();
        }
Exemplo n.º 17
0
        public static IServiceCollection AddTwilioTextApi(this IServiceCollection services, TextConfig config)
        {
            TwilioClient.Init(config.Twilio.AccountSid, config.Twilio.AuthToken);

            var incoming = IncomingPhoneNumberResource.Fetch(pathSid: config.Twilio.PhoneSid);

            services.Configure <TextServiceSettings>(options => {
                options.AlphaCode   = config.AlphaCode;
                options.PhoneNumber = incoming.PhoneNumber.ToString();
            });

            services.AddScoped <ITextSendService, TwillioTextSendService>();
            return(services);
        }
Exemplo n.º 18
0
        public void ConfigureServices(IServiceCollection services)
        {
            var db       = new DatabaseConfig();
            var mqtt     = new MqttConfig();
            var timeouts = new TimeoutConfig();
            var mail     = new MailConfig();
            var text     = new TextConfig();

            this.Configuration.GetSection("Mail").Bind(mail);
            this.Configuration.GetSection("Database").Bind(db);
            this.Configuration.GetSection("Mqtt").Bind(mqtt);
            this.Configuration.GetSection("Timeouts").Bind(timeouts);
            this.Configuration.GetSection("Text").Bind(text);

            var privatemqtt = mqtt.InternalBroker;

            services.AddConnectionStrings(db.Networking.ConnectionString, db.SensateIoT.ConnectionString);
            services.AddAuthorizationContext();
            services.AddNetworkingContext();
            services.AddDocumentStore(db.MongoDB.ConnectionString, db.MongoDB.DatabaseName, db.MongoDB.MaxConnections);
            services.Configure <TimeoutConfig>(this.Configuration.GetSection("Timeouts"));

            services.Configure <MqttConfig>(this.Configuration.GetSection("Mqtt"));
            services.Configure <MetricsOptions>(this.Configuration.GetSection("HttpServer:Metrics"));
            services.AddHostedService <MetricsService>();

            services.AddInternalMqttService(options => {
                options.Ssl        = privatemqtt.Ssl;
                options.Host       = privatemqtt.Host;
                options.Port       = privatemqtt.Port;
                options.Username   = privatemqtt.Username;
                options.Password   = privatemqtt.Password;
                options.Id         = Guid.NewGuid().ToString();
                options.TopicShare = "$share/triggers/";
            });

            services.Configure <RouterSettings>(s => {
                s.Host   = this.Configuration.GetValue <string>("Router:Host");
                s.Port   = this.Configuration.GetValue <ushort>("Router:Port");
                s.Secure = this.Configuration.GetValue <bool>("Router:Secure");
            });

            if (mail.Provider == "SendGrid")
            {
                services.AddSingleton <IEmailSender, SendGridMailer>();
                services.Configure <SendGridAuthOptions>(opts => {
                    opts.FromName = mail.FromName;
                    opts.From     = mail.From;
                    opts.Key      = mail.SendGrid.Key;
                    opts.Username = mail.SendGrid.Username;
                });
            }
            else if (mail.Provider == "SMTP")
            {
                services.AddSingleton <IEmailSender, SmtpMailer>();
                services.Configure <SmtpAuthOptions>(opts => {
                    opts.FromName = mail.FromName;
                    opts.From     = mail.From;
                    opts.Password = mail.Smtp.Password;
                    opts.Username = mail.Smtp.Username;
                    opts.Ssl      = mail.Smtp.Ssl;
                    opts.Port     = mail.Smtp.Port;
                    opts.Host     = mail.Smtp.Host;
                });
            }

            if (text.Provider == "Twillio")
            {
                TwilioClient.Init(text.Twilio.AccountSid, text.Twilio.AuthToken);

                var incoming = IncomingPhoneNumberResource.Fetch(pathSid: text.Twilio.PhoneSid);
                services.Configure <TextServiceSettings>(options => {
                    options.AlphaCode   = text.AlphaCode;
                    options.PhoneNumber = incoming.PhoneNumber.ToString();
                });

                services.AddScoped <ITextSendService, TwillioTextSendService>();
            }
            else
            {
                throw new InvalidOperationException("Text provider not configured!");
            }

            services.AddScoped <IControlMessageRepository, ControlMessageRepository>();
            services.AddScoped <ITriggerRepository, TriggerRepository>();
            services.AddScoped <IControlMessageRepository, ControlMessageRepository>();
            services.AddScoped <ITriggerActionExecutionService, TriggerActionExecutionService>();

            services.AddSingleton <IDataPointMatchingService, DataPointMatchingService>();
            services.AddSingleton <IRegexMatchingService, RegexMatchingService>();
            services.AddSingleton <IRouterClient, RouterClient>();
            services.AddSingleton <IEmailSender, SmtpMailer>();
            services.AddSingleton <ITriggerActionCache, TriggerActionCache>();

            services.AddHostedService <TriggerActionReloadService>();

            services.AddHttpClient();
            services.AddMqttHandlers();
        }
Exemplo n.º 19
0
 /// <summary>
 /// 从配置读取
 /// </summary>
 public static void readConfig()
 {
     Ok     = TextConfig.getText("ok");
     Cancel = TextConfig.getText("cancel");
 }