Example #1
0
        public bool TryGet(out object result)
        {
            try
            {
                if (LanguageManager.Instance.Current.LanCode.ToLower() != "zh-cn")
                {
                    result = null;
                    return(false);
                }
                byte[] data = new WebClient().DownloadData(GetUrl());
                object _tmp = null;
                using (var ms = new MemoryStream(data))
                {
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        _tmp = XamlReader.Load(ms, context);
                    });
                }
                result = _tmp;
                return(true);
            }
            catch (Exception e)
            {
                result = null;
                SLogger <RemoteXamlReader> .Warn("Can not parse remote xaml", e);

                return(false);
            }
        }
Example #2
0
 internal static Task <object?> CreateTask(IExtensionInfo info,
                                           Dictionary <string, object> args,
                                           Action <Thread> threadReceiver,
                                           ILake source)
 {
     return(new Task <object?>(() =>
     {
         try
         {
             Thread.CurrentThread.Name = $"Extension Task {info.Id}";
             using var procedure = info.OpenProcedure();
             threadReceiver(Thread.CurrentThread);
             procedure.Source = source;
             procedure.Args = args;
             return procedure.Run();
         }
         catch (Exception e)
         {
             SLogger.Warn("ExtensionTask", "Uncaught error", e);
             var title = string.Format(new T().RxGetClassText("error_title_fmt"), info.Name());
             LakeProvider.Lake.Get <IAppManager>().ShowException(title, e.GetType().Name, e);
             return default;
         }
     }));
 }
        public void Inject()
        {
            var injectables = GetInjectables(instance.GetType());

            foreach (var injectable in injectables)
            {
                try
                {
                    object?value = GetValue(injectable.Attr.Id, injectable.ValueType !);
#pragma warning disable CS8604 // 可能的 null 引用参数。
                    injectable.Set(instance, value);
#pragma warning restore CS8604 // 可能的 null 引用参数。
                }
                catch (IdNotFoundException)
                {
                    SLogger <DependenciesInjector> .Info($"Can not found component: {(injectable.Attr.Id ?? injectable.ValueType?.Name)}. Injecting of {instance.GetType().FullName}.{injectable.Name} is skipped");
                }
                catch (TypeNotFoundException)
                {
                    SLogger <DependenciesInjector> .Info($"Can not found component: {(injectable.Attr.Id ?? injectable.ValueType?.Name)}. Injecting of {instance.GetType().FullName}.{injectable.Name} is skipped");
                }
                catch (Exception e)
                {
                    SLogger <DependenciesInjector>
                    .Warn($"Can't inject proerty:{instance.GetType().FullName}.{injectable.Name}", e);
                }
            }
        }
Example #4
0
        protected virtual void Dispose(bool disposing)
        {
            if (!DisposedValue)
            {
                if (disposing)
                {
                    handleDisposedEvent = false;
                    lock (notDisposedSet)
                    {
                        notDisposedSet.All((p) =>
                        {
                            try
                            {
                                p.Dispose();
                            }
                            catch (Exception e)
                            {
                                SLogger <CommandProcedure> .Warn("can not dispose command procedure", e);
                            }
                            return(true);
                        });
                        this.notDisposedSet.Clear();
                    }
                    // TODO: 释放托管状态(托管对象)。
                }
                // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。
                // TODO: 将大型字段设置为 null。

                DisposedValue = true;
                Disposed?.Invoke(this, new EventArgs());
            }
        }
Example #5
0
        private IEnumerable <ILibrarian> GetLibManagers(IEnumerable <Assembly> assemblies)
        {
            var result = new List <ILibrarian>();

            foreach (var assembly in assemblies)
            {
                try
                {
                    var libManagerTypes = (from type in assembly.GetTypes()
                                           where typeof(ILibrarian).IsAssignableFrom(type)
                                           select type);

                    if (libManagerTypes.Any())
                    {
                        result.Add(BuildLibrarian(libManagerTypes.First()));
                    }
                    else
                    {
                        result.Add(BuildLibrarian(assembly));
                    }
                }
                catch (Exception e)
                {
                    SLogger <DreamLibManager> .Warn($"Could not create the instance of {assembly.GetName().Name}'s librarian", e);
                }
            }
            SLogger <DreamLibManager> .Info($"There are {result.Count()} librarians");

            foreach (var lib in result)
            {
                SLogger <DreamLibManager> .Info($"{lib.Name}");
            }
            return(result);
        }
Example #6
0
        private void Flow()
        {
            try
            {
                isRunning = true;
                instance  = (IExtension)Activator.CreateInstance(extensionType);
                Result    = instance.Main(Args);
            }
            catch (ThreadAbortException)
            {
                Result = null;
            }
            catch (Exception e)
            {
                var appManager = LakeProvider.Lake.Get <IAppManager>();
                Result = e;
                SLogger <ExtensionTask> .Warn($"{extensionType.Name}-extension error", e.InnerException);

                string fmt = appManager.GetPublicResouce <string>("OpenFxExceptionMsgTitleFmt");
                fmt = string.Format(fmt, Wrapper.Info.Name);
                string sketch = appManager.GetPublicResouce <string>("OpenFxExceptionSketch");
                appManager.ShowException(fmt, sketch, e.GetType() == typeof(TargetInvocationException) ? e.InnerException : e);
            }
            finally
            {
                instance.Dispose();
                isRunning = false;
                Finished?.Invoke(this, new TaskFinishedEventArgs(this));
            }
        }
Example #7
0
        private IEnumerable <Assembly> GetAssemblies(IEnumerable <FileInfo> files)
        {
            var result = new List <Assembly>();

            foreach (var file in files)
            {
                try
                {
                    if (file.Extension == PATTERN_OEXT.Substring(1))
                    {
                        SLogger <DreamLibManager> .Info($"{file} is an aoext");

                        result.Add(Assembly.LoadFile(file.FullName));
                    }
                    else
                    {
                        result.Add(Assembly.Load(File.ReadAllBytes(file.FullName)));
                    }
                }
                catch (Exception e)
                {
                    SLogger <DreamLibManager> .Warn($"can not load extension: {file.Name}", e);
                }
            }
            SLogger <DreamLibManager> .Debug($"There are {result.Count()} assemblies");

            return(result);
        }
Example #8
0
 private void InputImpl(object para)
 {
     Task.Run(() =>
     {
         try
         {
             ETapper._app.RunOnUIThread(() =>
             {
                 Input.CanExecuteProp = false;
             });
             AndroidKeyCode code = (AndroidKeyCode)para;
             executor.AdbShell(Device, $"input keyevent {(int)code}");
         }
         catch (Exception e)
         {
             SLogger <ETapper> .Warn($"can not input key {para}", e);
         }
         finally
         {
             ETapper._app.RunOnUIThread(() =>
             {
                 Input.CanExecuteProp = true;
             });
         }
     });
 }
Example #9
0
        private IEnumerable <ILibrarian> GetLibManagers(IEnumerable <Assembly> assemblies)
        {
            var result = new List <ILibrarian>();

            foreach (var assembly in assemblies)
            {
                try
                {
                    var libManagerTypes = (from type in assembly.GetTypes()
                                           where typeof(ILibrarian).IsAssignableFrom(type)
                                           select type);
                    if (libManagerTypes.Any())
                    {
                        result.Add((ILibrarian)Activator.CreateInstance(libManagerTypes.First()));
                    }
                    else
                    {
                        result.Add(new DefaultLibrarian(assembly));
                    }
                }
                catch (Exception e)
                {
                    SLogger <DreamLibManager> .Warn($"Can not create the instance of {assembly.GetName().Name}'s librarian", e);
                }
            }
            return(result);
        }
Example #10
0
        private bool InstallUsePnPUtil(string fileName)
        {
            try
            {
                var startInfo = new ProcessStartInfo("pnputil", $"-i -a {fileName}")
                {
                    Verb                   = "runas",
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                };
                var outputBuilder = new OutputBuilder();
                int exitCode      = 0;
                using (var proc = Process.Start(startInfo))
                {
                    proc.OutputDataReceived += (s, e) => { outputBuilder.AppendOut(e.Data); };
                    proc.ErrorDataReceived  += (s, e) => { outputBuilder.AppendError(e.Data); };
                    proc.Start();
                    proc.BeginOutputReadLine();
                    proc.BeginErrorReadLine();
                    proc.WaitForExit();
                    exitCode = proc.ExitCode;
                    proc.Dispose();
                    return(exitCode == 0);
                }
            }
            catch (Exception ex)
            {
                SLogger <OSImpl> .Warn("failed", ex);

                return(false);
            }
        }
Example #11
0
        private bool SafeCheck(ILibrarian lib)
        {
            try {
                return(lib.Check());
            } catch (Exception e) {
                SLogger <LiYinLoader> .Warn($"An error occurred when checking a librarian", e);

                return(false);
            }
        }
Example #12
0
 public void Reload()
 {
     Librarians = ReloadLibs(Check(GetLibManagers(GetAssemblies(GetFiles()))));
     Librarians.All((lib) =>
     {
         SLogger <DreamLibManager> .Warn($"Call ready method: {lib.Name}");
         SafeReady(lib);
         return(true);
     });
 }
Example #13
0
 public static void Start(string className)
 {
     try
     {
         LakeProvider.Lake.Get <ITaskManager>().CreateNewTaskOf(className)?.Start();
     }
     catch (Exception e)
     {
         SLogger.Warn(nameof(ExtensionBridge), $"Can not run extension : {className}", e);
     }
 }
Example #14
0
 protected void _OpenUrl(object para)
 {
     try
     {
         Process.Start(para as string);
     }
     catch (Exception e)
     {
         SLogger.Warn(this, $"can not open url {para}", e);
     }
 }
Example #15
0
 public static void Start(string className)
 {
     try
     {
         AtmbContext.Instance.NewExtensionThread(className)?.Start();
     }
     catch (Exception e)
     {
         SLogger.Warn(nameof(ExtensionBridge), "extension not found", e);
     }
 }
 private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     try
     {
         Process.Start(App.Current.Resources["urlDonatePage"].ToString());
     }
     catch (Exception ex)
     {
         SLogger.Warn(this, "can not open donate page url", ex);
     }
 }
Example #17
0
 public static void Start(string className)
 {
     try
     {
         LakeProvider.Lake.Get <ITaskManager>().GetNewThread(className)?.Start();
     }
     catch (Exception e)
     {
         SLogger.Warn(nameof(ExtensionBridge), "extension not found", e);
     }
 }
Example #18
0
 protected void _OpenGoUrl(object para)
 {
     try
     {
         var goPre = ctx.App.GetPublicResouce("UrlGoPrefix") as string;
         Process.Start(goPre + para);
     }
     catch (Exception e)
     {
         SLogger.Warn(this, $"can not open url {para}", e);
     }
 }
Example #19
0
 public void SendMessage(string msg_type, object value)
 {
     try
     {
         MessageReceived?.Invoke(this,
                                 new MessageReceivedEventArgs(msg_type, value));
     }
     catch (Exception e)
     {
         SLogger <MessageBusImpl> .Warn($"An error occured when handling message : {msg_type}/{value}", e);
     }
 }
Example #20
0
        protected void _OpenGoUrl(object para)
        {
            var goPre = App.Current.Resources["UrlGoPrefix"] as string;

            try
            {
                Process.Start(goPre + para);
            }
            catch (Exception e)
            {
                SLogger.Warn(this, $"can not open url {para}", e);
            }
        }
Example #21
0
 public async Task DoInteractivate()
 {
     try
     {
         throw new NotImplementedException();
         var index = await new IndexReader().Do();
         _ = new MOTDHandler().Do(index);
     }
     catch (Exception e)
     {
         SLogger <RemoteInteractivator> .Warn("Failed", e);
     }
 }
Example #22
0
 private void DisplayTextAd(IXCardsManager xCardsManager)
 {
     try
     {
         var jsonString = webClient.DownloadString(TEXTAD);
         var card       = JsonSerializer.Deserialize <TextADCard>(jsonString);
         xCardsManager.Register(card);
     }
     catch (Exception e)
     {
         SLogger <EAutumnBoxAdFetcher> .Warn(e);
     }
 }
Example #23
0
 /// <summary>
 ///  初始化UI
 /// </summary>
 static void InitUI(ILeafUI ui)
 {
     ui.EnableHelpBtn(() =>
     {
         try
         {
             System.Diagnostics.Process.Start("http://www.atmb.top/guide/dpm/");
         }
         catch (Exception e)
         {
             SLogger <DeviceOwnerSetter> .Warn("can not open dpm help link", e);
         }
     });
 }
Example #24
0
        private bool SafeReady(ILibrarian lib)
        {
            try
            {
                lib.Ready();
                return(true);
            }
            catch (Exception e)
            {
                SLogger <DreamLibManager> .Warn($"There is an error occurred when calling a librarian's Ready() method", e);

                return(false);
            }
        }
Example #25
0
        private bool InstallUsePnPUtil_SysNative(string fileName)
        {
            try
            {
                var winDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                var result = new ProcessBasedCommand($"{winDir}\\sysnative\\pnputil", $"-i -a {fileName}").Execute();
                return(result.ExitCode == 0);
            }
            catch (Exception ex)
            {
                SLogger <OSImpl> .Warn("failed", ex);

                return(false);
            }
        }
Example #26
0
        public static bool TryGet <T>(this ILake lake, out T value)
        {
            if (lake is null)
            {
                throw new ArgumentNullException(nameof(lake));
            }

            try
            {
                value = lake.Get <T>();
                return(true);
            }
            catch (TypeNotFoundException)
            {
                SLogger.Warn(nameof(LakeExtension), $"Can not get component by type: {typeof(T).FullName}");
                value = default !;
Example #27
0
 public static Task RefreshAsync(Action callback)
 {
     return(Task.Run(() =>
     {
         RemoteVersionInfoGetter getter = new RemoteVersionInfoGetter();
         try
         {
             Result = getter.GetSync();
             callback?.Invoke();
         }
         catch (Exception e)
         {
             SLogger.Warn(nameof(Updater), "cannot refresh update informations", e);
         }
     }));
 }
Example #28
0
 private void RunRoutines <T>()
 {
     Task.Run(() =>
     {
         try
         {
             var instance = new ObjectBuilder(typeof(T), Lake).Build();
             var mProxy   = new MethodProxy(instance, ROUTINE_DO_METHOD_NAME, Lake);
             mProxy.Invoke();
         }
         catch (Exception e)
         {
             SLogger <EssentialsLibrarin> .Warn("Routine is failed", e);
         }
     });
 }
Example #29
0
 public static void SwitchToMainGrid()
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         try
         {
             //SLogger.Info(nameof(MainWindowBus), "Panel creating");
             var panel = new PanelMainV2();
             MainWindow.MainContentContainer.Content = panel;
             //SLogger.Info(nameof(MainWindowBus), "Created panel instance");
         }
         catch (Exception e)
         {
             SLogger.Warn(nameof(MainWindowBus), "Could not create panel", e);
         }
     });
 }
Example #30
0
        private IEnumerable <ILibrarian> ReloadLibs(IEnumerable <ILibrarian> libs)
        {
            List <ILibrarian> reloaded = new List <ILibrarian>();

            foreach (var lib in libs)
            {
                try
                {
                    lib.Reload();
                    reloaded.Add(lib);
                }
                catch (Exception e)
                {
                    SLogger <DreamLibManager> .Warn($"An error occured when reloading lib {lib?.GetType().Name}", e);
                }
            }
            return(reloaded);
        }