Пример #1
0
        async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            //viewModel.Items.Clear();
            var item = args.SelectedItem as Models.Character;

            if (item == null)
            {
                return;
            }
            BuilderContext Context = new BuilderContext(item.Player);
            PluginManager  manager = new PluginManager();

            manager.Add(new SpellPoints());
            manager.Add(new SingleLanguage());
            Context.Plugins = manager;

            //Task.Run(async () =>
            //     {
            //         if (Context.Player.FilePath is IFile file)
            //         {
            //             string name = file.Name;
            //             IFile target = await (await App.Storage.CreateFolderAsync("Backups", CreationCollisionOption.OpenIfExists).ConfigureAwait(false)).CreateFileAsync(name, CreationCollisionOption.ReplaceExisting).ConfigureAwait(false);
            //             using (Stream fout = await target.OpenAsync(FileAccess.ReadAndWrite))
            //             {
            //                 using (Stream fin = await file.OpenAsync(FileAccess.Read))
            //                 {
            //                     await fin.CopyToAsync(fout);
            //                 }
            //             };
            //         }
            //     }).Forget();
            Context.UndoBuffer         = new LinkedList <Player>();
            Context.RedoBuffer         = new LinkedList <Player>();
            Context.UnsavedChanges     = 0;
            ItemsListView.SelectedItem = null;
            LoadingProgress loader = new LoadingProgress(Context);
            LoadingPage     l      = new LoadingPage(loader);
            await Navigation.PushModalAsync(l);

            var t = l.Cancel.Token;

            try
            {
                await loader.Load(t).ConfigureAwait(false);

                t.ThrowIfCancellationRequested();
                PlayerBuildModel model = new PlayerBuildModel(Context);
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopModalAsync(false);
                    await Navigation.PushModalAsync(new NavigationPage(new FlowPage(model)));
                });
            }
            catch (OperationCanceledException)
            {
            }
            finally
            {
                IsBusy = false;
                (sender as ListView).SelectedItem = null;
            }
            // Manually deselect item
        }
Пример #2
0
        public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
        {
            Task.Run(async() =>
            {
                if ("Inbox".Equals(Path.GetDirectoryName(url.Path)))
                {
                    IFolder incoming = await App.Storage.CreateFolderAsync("Inbox", CreationCollisionOption.OpenIfExists);
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(incoming));
                    });
                }
                else if (url.Path?.EndsWith(".cb5") ?? false)
                {
                    try {
                        using (Stream f = File.OpenRead(url.Path)) {
                            Player player          = Player.Serializer.Deserialize(f) as Player;
                            BuilderContext Context = new BuilderContext(player);
                            PluginManager manager  = new PluginManager();
                            manager.Add(new SpellPoints());
                            manager.Add(new SingleLanguage());
                            manager.Add(new CustomBackground());
                            manager.Add(new NoFreeEquipment());
                            Context.Plugins = manager;


                            Context.UndoBuffer     = new LinkedList <Player>();
                            Context.RedoBuffer     = new LinkedList <Player>();
                            Context.UnsavedChanges = 0;

                            Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                            {
                                LoadingProgress loader   = new LoadingProgress(Context);
                                LoadingPage l            = new LoadingPage(loader, false);
                                App.MainTab.SelectedItem = App.MainTab.Children[2];
                                await App.MainTab.Children[2].Navigation.PushModalAsync(l);
                                var t = l.Cancel.Token;
                                try
                                {
                                    await loader.Load(t).ConfigureAwait(false);
                                    t.ThrowIfCancellationRequested();
                                    PlayerBuildModel model = new PlayerBuildModel(Context);
                                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                                    {
                                        await App.MainTab.Children[2].Navigation.PopModalAsync(false);
                                        await App.MainTab.Children[2].Navigation.PushModalAsync(new NavigationPage(new FlowPage(model)));
                                    });
                                } catch (Exception e) {
                                    ConfigManager.LogError(e);
                                }
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        ConfigManager.LogError(e);
                    }
                }
                else
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        if (url.Path.StartsWith(App.Storage.Path, System.StringComparison.Ordinal))
                        {
                            await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(await FileSystem.Current.GetFolderFromPathAsync(Path.GetDirectoryName(url.Path))));
                        }
                    });
                }
            }).Forget();
            return(true);
        }
        public static void LoadPluginManager(this BuilderContext context, string path)
        {
            PluginManager plug = new PluginManager();

            plug.Add(new NoFreeEquipment());
            plug.Add(new CustomBackground());
            string[] dllFileNames = null;
            if (Directory.Exists(path))
            {
                try
                {
                    dllFileNames = Directory.GetFiles(path, "*.dll");
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error loading Plugins", e);
                }
            }
            else
            {
                context.Plugins = plug;
                return;
            }

            ICollection <Assembly> assemblies = new List <Assembly>(dllFileNames.Length);

            foreach (string dllFile in dllFileNames)
            {
                try
                {
                    Assembly assembly = Assembly.LoadFrom(dllFile);
                    assemblies.Add(assembly);
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error loading Plugin " + dllFile, e);
                }
            }
            Type pluginType = typeof(IPlugin);
            ICollection <Type> pluginTypes = new List <Type>();

            foreach (Assembly assembly in assemblies)
            {
                if (assembly != null)
                {
                    try
                    {
                        Type[] types = assembly.GetTypes();
                        foreach (Type type in types)
                        {
                            if (type.IsInterface || type.IsAbstract)
                            {
                                continue;
                            }
                            else
                            {
                                if (type.GetInterface(pluginType.FullName) != null)
                                {
                                    pluginTypes.Add(type);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ConfigManager.LogError("Error loading Plugin Assembly " + assembly, e);
                    }
                }
            }
            foreach (Type type in pluginTypes)
            {
                try
                {
                    IPlugin plugin = (IPlugin)Activator.CreateInstance(type);
                    plug.available.Add(plugin.Name, plugin);
                }
                catch (Exception e)
                {
                    ConfigManager.LogError("Error loading Plugin Type " + type, e);
                }
            }
            context.Plugins = plug;
        }
Пример #4
0
        public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
        {
            Task.Run(async() =>
            {
                if ("Inbox".Equals(Path.GetFileName(Path.GetDirectoryName(url.Path))))
                {
                    IFolder incoming = await App.Storage.CreateFolderAsync("Incoming", CreationCollisionOption.OpenIfExists);
                    IFile f          = await FileSystem.Current.GetFileFromPathAsync(url.Path);
                    await f.MoveAsync(Path.Combine(incoming.Path, f.Name), NameCollisionOption.GenerateUniqueName);
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(incoming));
                    });
                }
                else if (url.Path?.EndsWith(".cb5") ?? false)
                {
                    url.StartAccessingSecurityScopedResource();
                    try {
                        //using (MemoryStream s = new MemoryStream()) {
                        //    NSInputStream stream = NSInputStream.FromUrl(url);
                        //    byte[] buffer = new byte[1024];
                        //    while (stream.HasBytesAvailable()) {
                        //        int read = (int)stream.Read(buffer, 1024);
                        //        s.Write(buffer, 0, read);
                        //    }
                        //    s.Seek(0, SeekOrigin.Begin);
                        //NSFileHandle fs = NSFileHandle.OpenReadUrl(url, out NSError err);
                        //NSData data = fs.ReadDataToEndOfFile();
                        //fs.CloseFile();
                        //using (Stream f = data.AsStream()) {AsStream
                        //new MyInputStream(NSInputStream.FromUrl(url))) {
                        //NSData d = await url.LoadDataAsync("text/xml");
                        //File.OpenRead(url.Path)
                        using (Stream s = File.OpenRead(url.Path)) {
                            Player player          = Player.Serializer.Deserialize(s) as Player;
                            BuilderContext Context = new BuilderContext(player);
                            PluginManager manager  = new PluginManager();
                            manager.Add(new SpellPoints());
                            manager.Add(new SingleLanguage());
                            manager.Add(new CustomBackground());
                            manager.Add(new NoFreeEquipment());
                            Context.Plugins = manager;


                            Context.UndoBuffer     = new LinkedList <Player>();
                            Context.RedoBuffer     = new LinkedList <Player>();
                            Context.UnsavedChanges = 0;

                            Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                            {
                                LoadingProgress loader   = new LoadingProgress(Context);
                                LoadingPage l            = new LoadingPage(loader, false);
                                App.MainTab.SelectedItem = App.MainTab.Children[1];
                                await App.MainTab.Children[2].Navigation.PushModalAsync(l);
                                var t = l.Cancel.Token;
                                try
                                {
                                    await loader.Load(t).ConfigureAwait(false);
                                    t.ThrowIfCancellationRequested();
                                    PlayerBuildModel model = new PlayerBuildModel(Context);
                                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                                    {
                                        await App.MainTab.Children[1].Navigation.PopModalAsync(false);
                                        await App.MainTab.Children[1].Navigation.PushModalAsync(new NavigationPage(new FlowPage(model)));
                                    });
                                } catch (Exception e) {
                                    ConfigManager.LogError(e);
                                }
                            });
                        }
                        url.StopAccessingSecurityScopedResource();
                    }
                    catch (Exception e)
                    {
                        ConfigManager.LogError(e);
                    }
                }
                else if (url.Path.StartsWith(App.Storage.Path, System.StringComparison.Ordinal))
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(await FileSystem.Current.GetFolderFromPathAsync(Path.GetDirectoryName(url.Path))));
                    });
                }
                else
                {
                    url.StartAccessingSecurityScopedResource();
                    IFolder incoming = await App.Storage.CreateFolderAsync("Incoming", CreationCollisionOption.OpenIfExists);
                    IFile target     = await incoming.CreateFileAsync(url.LastPathComponent, CreationCollisionOption.GenerateUniqueName);
                    using (Stream f = File.OpenRead(url.Path))
                    {
                        using (Stream o = await target.OpenAsync(PCLStorage.FileAccess.ReadAndWrite))
                        {
                            await f.CopyToAsync(o);
                        }
                    }
                    url.StopAccessingSecurityScopedResource();
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        App.MainTab.SelectedItem = App.MainTab.Children[3];
                        await App.MainTab.Children[3].Navigation.PopToRootAsync();
                        await App.MainTab.Children[3].Navigation.PushAsync(new FileBrowser(incoming));
                    });
                }
            }).Forget();
            return(true);
        }
Пример #5
0
 public void AddPlugin(IPlugin plugin) //Adds plugins to server
 {
     pluginManager.Add(plugin);
 }