Exemple #1
0
 public object GetByType(Type type)
 {
     if (type == typeof(ILeafUI))
     {
         return(OpenFxLoader.BaseApi.NewLeafUI());
     }
     else if (type.Name.StartsWith(nameof(ILogger)))
     {
         return(LoggerFactory.Auto(leafInstance.GetType().Name));
     }
     else if (type == typeof(IDevice))
     {
         return(OpenFxLoader.BaseApi.SelectedDevice);
     }
     else if (type == typeof(Dictionary <string, object>))
     {
         return(ExtData);
     }
     else if (type == typeof(IEmbeddedFileManager))
     {
         return(new LeafEmb(leafInstance.GetType().Assembly));
     }
     else if (type == typeof(ICommandExecutor))
     {
         return(new HestExecutor());
     }
     else
     {
         return(OpenApiFactory.Get(type, leafInstance));
     }
 }
Exemple #2
0
        public override void Destory()
        {
            base.Destory();
            IStorageManager storageManager = OpenApiFactory.Get <IStorageManager>(this);

            storageManager.ClearCache();
        }
Exemple #3
0
 /// <summary>
 /// 初始化各种懒加载工厂方法
 /// </summary>
 private void InitFactory()
 {
     _lazyApp = new Lazy <IAppManager>(() =>
     {
         return(OpenApiFactory.Get <IAppManager>(this));
     });
     _lazyUX = new Lazy <IUx>(() =>
     {
         return(OpenApiFactory.Get <IUx>(this));
     });
     _lazyLogger = new Lazy <ILogger>(() =>
     {
         return(LoggerFactory.Auto(LoggingTag));
     });
     _lazyTmp = new Lazy <ITemporaryFloder>(() =>
     {
         return(OpenApiFactory.Get <ITemporaryFloder>(this));
     });
     _lazyEmb = new Lazy <IEmbeddedFileManager>(() =>
     {
         return(OpenApiFactory.Get <IEmbeddedFileManager>(this));
     });
 }
Exemple #4
0
 static LeafUIHelper()
 {
     text = OpenApiFactory.SGet <IClassTextManager>(typeof(LeafUIHelper));
     SLogger.Debug(nameof(LeafUIHelper), $"{typeof(LeafUIHelper)}'s IClassTextManager created");
 }
Exemple #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Apollo!");

            var portalUrl = "http://10.111.211.17:8070/";               // "http://106.54.227.205:8070"; // portal url
            var token     = "f3ab791f808063530553bd5492f52c66489dc021"; // "4c6fa0d0b51458325dee10a2dd03f57a1e89606f"; // 申请的token
            var appId     = "apollo-demo";
            var env       = "PRO";
            var user      = "******";

            var opt = new OpenApiOptions();

            opt.PortalUrl = new Uri(portalUrl);
            opt.Token     = token;
            IOpenApiFactory oaf = new OpenApiFactory(opt);
            var             nsc = oaf.CreateNamespaceClient(appId, env);

            Console.WriteLine("Apollo OpenApi Demo. Input quit to exit.");
            Console.WriteLine("1.Please input 'create key,value' to create item.");
            Console.WriteLine("2.Please input 'update key,value' to update item.");
            Console.WriteLine("3.Please input 'remove key' to remove item.");
            Console.WriteLine("4.Please input 'get key' to get item.");
            Console.WriteLine("5.Please input 'publish xxx' to publish.");
            while (true)
            {
                Console.Write("> ");
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }
                input = input.Trim();
                if (input.Equals("quit", StringComparison.CurrentCultureIgnoreCase))
                {
                    Environment.Exit(0);
                }
                if (input.ToLower().StartsWith("publish "))
                {
                    var nsr = new NamespaceRelease();
                    nsr.ReleasedBy     = user;
                    nsr.ReleaseTitle   = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}-release";
                    nsr.ReleaseComment = input.Substring(8);
                    nsc.Publish(nsr);
                    consoleWriteLine("发布成功!");
                }
                else if (input.ToLower().StartsWith("create "))
                {
                    var kv  = input.Substring(7);
                    var arr = kv.Split(new string[] { ",", "," }, StringSplitOptions.None);
                    if (arr.Length == 2)
                    {
                        var item = new Item();
                        item.Key   = arr[0];
                        item.Value = arr[1];
                        item.DataChangeCreatedBy   = user;
                        item.DataChangeCreatedTime = DateTime.Now;
                        var r     = nsc.CreateItem(item).Result;
                        var color = Console.ForegroundColor;
                        Console.ForegroundColor = ConsoleColor.Red;
                        consoleWriteLine("设置成功!");
                        Console.ForegroundColor = color;
                    }
                    else
                    {
                        consoleWriteLine("格式错误!");
                    }
                }
                else if (input.ToLower().StartsWith("update "))
                {
                    var kv  = input.Substring(7);
                    var arr = kv.Split(new string[] { ",", "," }, StringSplitOptions.None);
                    if (arr.Length == 2)
                    {
                        var item = new Item();
                        item.Key   = arr[0];
                        item.Value = arr[1];
                        item.DataChangeLastModifiedBy   = user;
                        item.DataChangeLastModifiedTime = DateTime.Now;
                        var r = nsc.UpdateItem(item);
                        consoleWriteLine("更新成功!");
                    }
                    else
                    {
                        consoleWriteLine("格式错误!");
                    }
                }
                else if (input.ToLower().StartsWith("remove "))
                {
                    var key = input.Substring(7);
                    var r   = nsc.RemoveItem(key, user).Result;
                    if (r)
                    {
                        consoleWriteLine("删除成功!");
                    }
                    else
                    {
                        consoleWriteLine("删除失败!");
                    }
                }
                else if (input.ToLower().StartsWith("get "))
                {
                    var key  = input.Substring(4);
                    var item = nsc.GetItem(key).Result;
                    if (item != null)
                    {
                        consoleWriteLine($"key:{key},value:{item.Value}");
                    }
                    else
                    {
                        consoleWriteLine("获取失败!");
                    }
                }
                else
                {
                    consoleWriteLine("无效指令!");
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// 平凡的,常见的API获取方法
 /// </summary>
 /// <param name="apiType"></param>
 /// <param name="requester"></param>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static object Get(Type apiType, object requester, object arg = null)
 {
     return(OpenApiFactory.Get(apiType, requester, arg));
 }
Exemple #7
0
 /// <summary>
 /// 泛型的API获取方法
 /// </summary>
 /// <typeparam name="TApi"></typeparam>
 /// <param name="requester"></param>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static TApi Get <TApi>(object requester = null, object arg = null)
 {
     return(OpenApiFactory.Get <TApi>(requester, arg));
 }
Exemple #8
0
 /// <summary>
 /// 供静态类使用的API获取
 /// </summary>
 /// <param name="apiType"></param>
 /// <param name="staticClassType"></param>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static object SGet(Type apiType, Type staticClassType = null, object arg = null)
 {
     return(OpenApiFactory.SGet(apiType, staticClassType, arg));
 }
Exemple #9
0
 /// <summary>
 /// 供静态类使用的API获取
 /// </summary>
 /// <typeparam name="TApi"></typeparam>
 /// <param name="staticClassType"></param>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static TApi SGet <TApi>(Type staticClassType, object arg = null)
 {
     return(OpenApiFactory.SGet <TApi>(staticClassType, arg));
 }