示例#1
0
        public ReadmeViewModel(IApplicationService applicationService, IShareService shareService, IActionMenuService actionMenuService)
        {
            Title = "Readme";

            var nonNullContentModel = this.WhenAnyValue(x => x.ContentModel).Select(x => x != null);

            ShareCommand = ReactiveCommand.Create(nonNullContentModel);
            ShareCommand.Subscribe(_ => shareService.ShareUrl(ContentModel.HtmlUrl));

            GoToGitHubCommand = ReactiveCommand.Create(nonNullContentModel);
            GoToGitHubCommand.Select(_ => ContentModel.HtmlUrl).Subscribe(this.ShowWebBrowser);

            GoToLinkCommand = ReactiveCommand.Create();
            GoToLinkCommand.OfType <string>().Subscribe(this.ShowWebBrowser);

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(nonNullContentModel, _ =>
            {
                var menu = actionMenuService.Create(Title);
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToGitHubCommand);
                return(menu.Show());
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async x =>
            {
                var repository = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName];
                ContentText    = await repository.GetReadmeRendered();
                ContentModel   = (await applicationService.Client.ExecuteAsync(repository.GetReadme())).Data;
            });
        }
示例#2
0
        public ReadmeViewModel(
            ISessionService applicationService,
            IActionMenuFactory actionMenuService)
        {
            Title = "Readme";

            var nonNullContentModel = this.WhenAnyValue(x => x.ContentModel).Select(x => x != null);

            ShareCommand = ReactiveCommand.Create(nonNullContentModel);
            ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, ContentModel.HtmlUrl));

            GoToGitHubCommand = ReactiveCommand.Create(nonNullContentModel);
            GoToGitHubCommand.Select(_ => ContentModel.HtmlUrl).Subscribe(GoToWebBrowser);

            GoToLinkCommand = ReactiveCommand.Create();
            GoToLinkCommand.OfType <string>().Subscribe(x => GoToWebBrowser(new Uri(x)));

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(nonNullContentModel, sender => {
                var menu = actionMenuService.Create();
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToGitHubCommand);
                return(menu.Show(sender));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(x => {
                var contentTask = applicationService.GitHubClient.Repository.Content.GetReadmeHtml(RepositoryOwner, RepositoryName)
                                  .ContinueWith(t => ContentText = t.Result, TaskScheduler.FromCurrentSynchronizationContext());

                var modelTask = applicationService.GitHubClient.Repository.Content.GetReadme(RepositoryOwner, RepositoryName)
                                .ContinueWith(t => ContentModel = t.Result, TaskScheduler.FromCurrentSynchronizationContext());

                return(Task.WhenAll(contentTask, modelTask));
            });
        }
示例#3
0
        public static bool checkOwner(DeployableObject obj, Controllable controllable)
        {
            bool flag;

            Fougerite.Player pl = Fougerite.Server.Cache[controllable.playerClient.userID];
            if (obj.ownerID == pl.UID)
            {
                flag = true;
            }
            else if (obj is SleepingBag)
            {
                flag = false;
            }
            else
            {
                ShareCommand command = ChatCommand.GetCommand("share") as ShareCommand;
                ArrayList    list    = (ArrayList)command.GetSharedDoors()[obj.ownerID];
                if (list == null)
                {
                    flag = false;
                }
                if (list.Contains(pl.UID))
                {
                    flag = true;
                }
                flag = false;
            }
            return(flag);
        }
 public void Dispose()
 {
     _shareLinkSubscription.Dispose();
     ShareCommand.Dispose();
     Text.Dispose();
     KeyPressedCommand.Dispose();
     SelectAllTextTrigger.Dispose();
     IsInProgress.Dispose();
     ErrorMessage.Dispose();
     _textToSpeechSubscription.Dispose();
 }
示例#5
0
        private async void TrackConnectionStatus()
        {
            // bool lastStatus = true;
            bool lastInternetStatus = true;
            var  lastGpsStatus      = LocationStatus.Started;

            _trackConnectionTask = new Task(async() =>
            {
                while (true)
                {
                    await Task.Delay(2000);

                    if (lastInternetStatus != IsInternetEnabled)
                    {
                        Dispatcher.RequestMainThreadAction(async() =>
                        {
                            RaisePropertyChanged(() => IsInternetEnabled);

                            ShareCommand.RaiseCanExecuteChanged();

                            if (!IsInternetEnabled)
                            {
                                await _popupService.OpenBasicPopup(AppResources.NoInternetEnabled);
                            }
                        });
                        lastInternetStatus = IsInternetEnabled;
                    }

                    if (lastGpsStatus != GpsStatus)
                    {
                        Dispatcher.RequestMainThreadAction(async() =>
                        {
                            ShareCommand.RaiseCanExecuteChanged();

                            if (GpsStatus != LocationStatus.Started)
                            {
                                await _popupService.OpenBasicPopup(AppResources.NoGpsEnabled);
                            }
                        });
                        lastGpsStatus = GpsStatus;
                    }

                    ConnectionsStatus = IsInternetEnabled && GpsStatus == LocationStatus.Started;
                    RaisePropertyChanged(() => ConnectionsStatus);
                }
            }, TaskCreationOptions.LongRunning);
            _trackConnectionTask.Start();
        }
示例#6
0
        private async Task PickPhoto()
        {
            StopFade();

            var status = await Permissions.CheckStatusAsync <Permissions.Photos>();

            if (status == PermissionStatus.Unknown)
            {
                status = await Permissions.RequestAsync <Permissions.Photos>();
            }

            if (status == PermissionStatus.Denied)
            {
                ShowFixSettings = true;

                await App.Current.MainPage.DisplayAlert(Title,
                                                        "Photo Pick Denied - fix in settings",
                                                        "Ok");
            }
            else
            {
                ShowFixSettings = false;

                //var sharedPhoto = await DependencyService.Get<IPhotoPickerService>()
                //                          .GetImageStreamAsync();
                var sharedPhotoService = App.ServiceProvider.GetService <IPhotoPickerService>();
                var sharedPhoto        = await sharedPhotoService.GetImageStreamAsync();


                if (sharedPhoto != null)
                {
                    BoxOpacity = 0;

                    // Make a copy of the image stream as ImageSource.FromStream() will
                    // close the source

                    var stream = new MemoryStream();
                    sharedPhoto.ImageData.CopyTo(stream);
                    cachedImage = stream.ToArray();

                    ImageSource = ImageSource.FromStream(() => new MemoryStream(cachedImage));

                    ButtonLabel        = "Pick another picture";
                    _EnableShareButton = true;
                    ShareCommand.ChangeCanExecute();
                }
            }
        }
示例#7
0
        public SectionViewModel(IMvxNavigationService navigationService,
                                GardianAppContext appContext,
                                NavCommand navCommand,
                                ShareCommand shareCommand)
        {
            this.appContext = appContext;
            //Command
            GoToNewsDetailsCommand = new GoToNewsDetailsCommand(navigationService);
            NavMenuTriggerCommand  = new MvxCommand(NavPanelTrigger);
            NavCommand             = navCommand;
            ShareCommand           = shareCommand;

            PageTitle              = appContext.Settings.PageSettings;
            ProgressRingIsActive   = true;
            ProgressRingVisibility = true;
        }
示例#8
0
        public ReleaseViewModel(IApplicationService applicationService, IShareService shareService,
                                IUrlRouterService urlRouterService, IActionMenuService actionMenuService)
        {
            this.WhenAnyValue(x => x.ReleaseModel)
            .Select(x => x == null ? "Release" : x.Name).Subscribe(x => Title = x);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null));
            ShareCommand.Subscribe(_ => shareService.ShareUrl(ReleaseModel.HtmlUrl));

            var gotoUrlCommand = this.CreateUrlCommand();

            GoToGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null));
            GoToGitHubCommand.Select(_ => ReleaseModel.HtmlUrl).Subscribe(gotoUrlCommand.ExecuteIfCan);

            GoToLinkCommand = ReactiveCommand.Create();
            GoToLinkCommand.OfType <string>().Subscribe(x =>
            {
                var handledViewModel = urlRouterService.Handle(x);
                if (handledViewModel != null && applicationService.Account.OpenUrlsInApp)
                {
                    ShowViewModel(handledViewModel);
                }
                else
                {
                    gotoUrlCommand.ExecuteIfCan(x);
                }
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null),
                _ =>
            {
                var menu = actionMenuService.Create(Title);
                menu.AddButton("Share", ShowMenuCommand);
                menu.AddButton("Show in GitHub", GoToGitHubCommand);
                return(menu.Show());
            });

            _contentText = this.WhenAnyValue(x => x.ReleaseModel).IsNotNull()
                           .Select(x => x.BodyHtml).ToProperty(this, x => x.ContentText);

            LoadCommand = ReactiveCommand.CreateAsyncTask(x =>
                                                          this.RequestModel(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetRelease(ReleaseId),
                                                                            x as bool?, r => ReleaseModel = r.Data));
        }
        public DetailsViewModel(IMvxNavigationService navigationService,
                                GardianAppContext appContext,
                                NavCommand navCommand,
                                ShareCommand shareCommand)
        {
            _navigationService = navigationService;

            this.appContext = appContext;

            //Commands
            NavMenuTriggerCommand = new MvxCommand(NavPanelTrigger);
            NavCommand            = navCommand;
            ShareCommand          = shareCommand;
            //Ring
            ProgressRingIsActive   = true;
            ProgressRingVisibility = true;
            PageTitle = "Details";
        }
示例#10
0
文件: Core.cs 项目: balu92/Fougerite
        public static void Init()
        {
            InitializeCommands();
            ShareCommand   command  = ChatCommand.GetCommand("share") as ShareCommand;
            FriendsCommand command2 = ChatCommand.GetCommand("friends") as FriendsCommand;

            if (File.Exists(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp")))
            {
                command.SetSharedDoors(Helper.ObjectFromFile <Hashtable>(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp")));
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp")))
            {
                command2.SetFriendsLists(Helper.ObjectFromFile <Hashtable>(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp")));
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("admins.xml")))
            {
                Administrator.AdminList = Helper.ObjectFromXML <System.Collections.Generic.List <Administrator> >(RustPPModule.GetAbsoluteFilePath("admins.xml"));
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("cache.rpp")))
            {
                userCache = Helper.ObjectFromFile <Dictionary <ulong, string> >(RustPPModule.GetAbsoluteFilePath("cache.rpp"));
            }
            else
            {
                userCache = new Dictionary <ulong, string>();
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("whitelist.xml")))
            {
                whiteList = new PList(Helper.ObjectFromXML <System.Collections.Generic.List <PList.Player> >(RustPPModule.GetAbsoluteFilePath("whitelist.xml")));
            }
            else
            {
                whiteList = new PList();
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("bans.xml")))
            {
                blackList = new PList(Helper.ObjectFromXML <System.Collections.Generic.List <PList.Player> >(RustPPModule.GetAbsoluteFilePath("bans.xml")));
            }
            else
            {
                blackList = new PList();
            }
        }
示例#11
0
 void DoorUse(Fougerite.Player p, DoorEvent de)
 {
     if (Core.IsEnabled() && !de.Open)
     {
         ShareCommand command = ChatCommand.GetCommand("share") as ShareCommand;
         ArrayList    list    = (ArrayList)command.GetSharedDoors()[de.Entity.OwnerID];
         if (list == null)
         {
             de.Open = false;
         }
         else if (list.Contains(p.PlayerClient.userID))
         {
             de.Open = true;
         }
         else
         {
             de.Open = false;
         }
     }
 }
示例#12
0
        public HomeViewModel(IMvxNavigationService navigationService,
                             GardianAppContext appContext,
                             NavCommand navCommand,
                             ShareCommand shareCommand)
        {
            this.appContext     = appContext;
            appContext.Settings = new AppSettings("All News", string.Empty);
            appContext.SaveSettings(appContext.Settings);

            //Command
            GoToNewsDetailsCommand = new GoToNewsDetailsCommand(navigationService);
            NavMenuTriggerCommand  = new MvxCommand(NavPanelTrigger);
            NavCommand             = navCommand;
            ShareCommand           = shareCommand;

            PageTitle      = "All News";
            IsPaneOpen     = true;
            NewsCollection = new ObservableCollection <StoryHeader>();

            ProgressRingIsActive   = true;
            ProgressRingVisibility = true;
            Initialize();
        }
示例#13
0
文件: Hooks.cs 项目: balu92/Fougerite
        public static bool checkOwner(DeployableObject obj, Controllable controllable)
        {
            bool flag;

            if (obj.ownerID == controllable.playerClient.userID)
            {
                return(true);
            }
            try
            {
                SleepingBag bag1 = (SleepingBag)obj;
                flag = false;
            }
            catch
            {
                try
                {
                    ShareCommand command = ChatCommand.GetCommand("share") as ShareCommand;
                    ArrayList    list    = (ArrayList)command.GetSharedDoors()[obj.ownerID];
                    if (list == null)
                    {
                        return(false);
                    }
                    if (list.Contains(controllable.playerClient.userID))
                    {
                        return(true);
                    }
                    flag = false;
                }
                catch (Exception)
                {
                    flag = false;
                }
            }
            return(flag);
        }
示例#14
0
 public static void CreateSaves()
 {
     try
     {
         ShareCommand   command  = (ShareCommand)ChatCommand.GetCommand("share");
         FriendsCommand command2 = (FriendsCommand)ChatCommand.GetCommand("friends");
         if (command.GetSharedDoors().Count != 0)
         {
             ObjectToFile <Hashtable>(command.GetSharedDoors(), RustPPModule.GetAbsoluteFilePath("doorsSave.rpp"));
         }
         else if (File.Exists(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp")))
         {
             File.Delete(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp"));
         }
         if (command2.GetFriendsLists().Count != 0)
         {
             ObjectToFile <Hashtable>(command2.GetFriendsLists(), RustPPModule.GetAbsoluteFilePath("friendsSave.rpp"));
         }
         else if (File.Exists(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp")))
         {
             File.Delete(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp"));
         }
         if (Administrator.AdminList.Count != 0)
         {
             ObjectToXML <List <Administrator> >(Administrator.AdminList, RustPPModule.GetAbsoluteFilePath("admins.xml"));
         }
         else if (File.Exists(RustPPModule.GetAbsoluteFilePath("admins.xml")))
         {
             File.Delete(RustPPModule.GetAbsoluteFilePath("admins.xml"));
         }
         if (Core.userCache.Count != 0)
         {
             ObjectToFile <Dictionary <ulong, string> >(Core.userCache, RustPPModule.GetAbsoluteFilePath("cache.rpp"));
         }
         else if (File.Exists(RustPPModule.GetAbsoluteFilePath("cache.rpp")))
         {
             File.Delete(RustPPModule.GetAbsoluteFilePath("cache.rpp"));
         }
         if (Core.whiteList.Count != 0)
         {
             ObjectToXML <List <PList.Player> >(Core.whiteList.PlayerList, RustPPModule.GetAbsoluteFilePath("whitelist.xml"));
         }
         else if (File.Exists(RustPPModule.GetAbsoluteFilePath("whitelist.xml")))
         {
             File.Delete(RustPPModule.GetAbsoluteFilePath("whitelist.xml"));
         }
         if (Core.blackList.Count != 0)
         {
             ObjectToXML <List <PList.Player> >(Core.blackList.PlayerList, RustPPModule.GetAbsoluteFilePath("bans.xml"));
         }
         else if (File.Exists(RustPPModule.GetAbsoluteFilePath("bans.xml")))
         {
             File.Delete(RustPPModule.GetAbsoluteFilePath("bans.xml"));
         }
     }
     catch (Exception ex)
     {
         Fougerite.Logger.LogException(ex);
         throw;
     }
 }
示例#15
0
        public static void Init()
        {
            InitializeCommands();
            ShareCommand   command  = ChatCommand.GetCommand("share") as ShareCommand;
            FriendsCommand command2 = ChatCommand.GetCommand("friends") as FriendsCommand;
            bool           success  = false;

            if (File.Exists(RustPPModule.GetAbsoluteFilePath("doorsSave.xml")))
            {
                SerializableDictionary <ulong, List <ulong> > doorsDict;
                doorsDict = Helper.ObjectFromXML <SerializableDictionary <ulong, List <ulong> > >(RustPPModule.GetAbsoluteFilePath("doorsSave.xml"));
                Hashtable doorsSave = new Hashtable();
                foreach (KeyValuePair <ulong, List <ulong> > kvp in doorsDict)
                {
                    ArrayList arr = new ArrayList(kvp.Value);
                    doorsSave.Add(kvp.Key, arr);
                }
                command.SetSharedDoors(doorsSave);
                success = true;
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp")) && !success)
            {
                command.SetSharedDoors(Helper.ObjectFromFile <Hashtable>(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp")));
            }

            if (!File.Exists(RustPPModule.GetAbsoluteFilePath("doorsSave.xml")))
            {
                SerializableDictionary <ulong, List <ulong> > doorsSave = new SerializableDictionary <ulong, List <ulong> >();
                foreach (DictionaryEntry entry in command.GetSharedDoors())
                {
                    ulong        key   = (ulong)entry.Key;
                    ArrayList    value = (ArrayList)entry.Value;
                    List <ulong> list  = new List <ulong>(value.OfType <ulong>());
                    doorsSave.Add(key, list);
                }
                Helper.ObjectToXML <SerializableDictionary <ulong, List <ulong> > >(doorsSave, RustPPModule.GetAbsoluteFilePath("doorsSave.xml"));
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp")))
            {
                command2.SetFriendsLists(Helper.ObjectFromFile <Hashtable>(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp")));
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("admins.xml")))
            {
                Administrator.AdminList = Helper.ObjectFromXML <List <Administrator> >(RustPPModule.GetAbsoluteFilePath("admins.xml"));
            }
            success = false;
            bool clearer = false;

            if (File.Exists(RustPPModule.GetAbsoluteFilePath("userCache.xml")))
            {
                FileInfo fi   = new FileInfo(RustPPModule.GetAbsoluteFilePath("userCache.xml"));
                float    mega = (fi.Length / 1024f) / 1024f;
                if (mega > 0.65)
                {
                    try
                    {
                        //string n = Path.Combine(RustPPModule.ConfigsFolder, "userCache-OLD-" + DateTime.Now.ToShortDateString() + ".xml");
                        System.IO.File.Move(RustPPModule.GetAbsoluteFilePath("userCache.xml"),
                                            Path.Combine(RustPPModule.ConfigsFolder,
                                                         "userCache-OLD-" + DateTime.Now.ToShortDateString() + ".xml"));
                        clearer = true;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError("Rust++ failed to copy the usercache file.");
                    }
                }
                else
                {
                    SerializableDictionary <ulong, string> userDict = Helper.ObjectFromXML <SerializableDictionary <ulong, string> >(RustPPModule.GetAbsoluteFilePath("userCache.xml"));
                    userCache = new Dictionary <ulong, string>(userDict);
                    success   = true;
                }
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("cache.rpp")) && !success)
            {
                if (clearer)
                {
                    File.WriteAllText(RustPPModule.GetAbsoluteFilePath("cache.rpp"), string.Empty);
                }
                userCache = Helper.ObjectFromFile <Dictionary <ulong, string> >(RustPPModule.GetAbsoluteFilePath("cache.rpp"));
                if (!File.Exists(RustPPModule.GetAbsoluteFilePath("userCache.xml")))
                {
                    Helper.ObjectToXML <SerializableDictionary <ulong, string> >(new SerializableDictionary <ulong, string>(userCache), RustPPModule.GetAbsoluteFilePath("userCache.xml"));
                }
            }
            else if (!success)
            {
                userCache = new Dictionary <ulong, string>();
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("whitelist.xml")))
            {
                whiteList = new PList(Helper.ObjectFromXML <List <PList.Player> >(RustPPModule.GetAbsoluteFilePath("whitelist.xml")));
            }
            else
            {
                whiteList = new PList();
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("mutelist.xml")))
            {
                muteList = new PList(Helper.ObjectFromXML <List <PList.Player> >(RustPPModule.GetAbsoluteFilePath("mutelist.xml")));
            }
            else
            {
                muteList = new PList();
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("bans.xml")))
            {
                blackList = new PList(Helper.ObjectFromXML <List <PList.Player> >(RustPPModule.GetAbsoluteFilePath("bans.xml")));
            }
            else
            {
                blackList = new PList();
            }
        }
示例#16
0
        public static void CreateSaves()
        {
            Logger.Log("Guardando clanes");
            RustPP.Data.Globals.GuardarClanes();
            Logger.Log("Guardando cuentas");
            RustPP.Data.Globals.GuardarCuentas();
            ShareCommand   command  = (ShareCommand)ChatCommand.GetCommand("share");
            FriendsCommand command2 = (FriendsCommand)ChatCommand.GetCommand("amigos");

            if (command.GetSharedDoors().Count != 0)
            {
                Logger.Log("Guardando puertas");
                ObjectToFile <Hashtable>(command.GetSharedDoors(), RustPPModule.GetAbsoluteFilePath("doorsSave.rpp"));
                SerializableDictionary <ulong, List <ulong> > doorsSave = new SerializableDictionary <ulong, List <ulong> >();
                foreach (DictionaryEntry entry in command.GetSharedDoors())
                {
                    ulong        key   = (ulong)entry.Key;
                    ArrayList    value = (ArrayList)entry.Value;
                    List <ulong> list  = new List <ulong>(value.OfType <ulong>());
                    doorsSave.Add(key, list);
                }
                ObjectToXML <SerializableDictionary <ulong, List <ulong> > >(doorsSave, RustPPModule.GetAbsoluteFilePath("doorsSave.xml"));
            }
            else if (File.Exists(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp")))
            {
                File.Delete(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp"));
            }
            if (command2.GetFriendsLists().Count != 0)
            {
                Logger.Log("Saving friends lists.");
                ObjectToFile <Hashtable>(command2.GetFriendsLists(), RustPPModule.GetAbsoluteFilePath("friendsSave.rpp"));
            }
            else if (File.Exists(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp")))
            {
                File.Delete(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp"));
            }
            if (Administrator.AdminList.Count != 0)
            {
                Logger.Log("Saving administrator list.");
                ObjectToXML <List <Administrator> >(Administrator.AdminList, RustPPModule.GetAbsoluteFilePath("admins.xml"));
            }
            else if (File.Exists(RustPPModule.GetAbsoluteFilePath("admins.xml")))
            {
                File.Delete(RustPPModule.GetAbsoluteFilePath("admins.xml"));
            }
            if (Core.userCache.Count != 0)
            {
                Logger.Log("Saving user cache.");
                ObjectToXML <SerializableDictionary <ulong, string> >(new SerializableDictionary <ulong, string>(Core.userCache), RustPPModule.GetAbsoluteFilePath("userCache.xml"));
                ObjectToFile <Dictionary <ulong, string> >(Core.userCache, RustPPModule.GetAbsoluteFilePath("cache.rpp"));
            }
            else if (File.Exists(RustPPModule.GetAbsoluteFilePath("cache.rpp")))
            {
                File.Delete(RustPPModule.GetAbsoluteFilePath("cache.rpp"));
            }
            if (Core.structureCache.Count != 0)
            {
                Logger.Log("Saving structure cache.");
                ObjectToXML <SerializableDictionary <int, string> >(new SerializableDictionary <int, string>(Core.structureCache), RustPPModule.GetAbsoluteFilePath("structureCache.xml"));
                ObjectToFile <Dictionary <int, string> >(Core.structureCache, RustPPModule.GetAbsoluteFilePath("structureCache.rpp"));
            }
            else if (File.Exists(RustPPModule.GetAbsoluteFilePath("structureCache.rpp")))
            {
                File.Delete(RustPPModule.GetAbsoluteFilePath("structureCache.rpp"));
            }
            if (Core.userLang.Count != 0)
            {
                Logger.Log("Guardando preferencias de lenguaje.");
                ObjectToXML <SerializableDictionary <ulong, string> >(new SerializableDictionary <ulong, string>(Core.userLang), RustPPModule.GetAbsoluteFilePath("userLang.xml"));
                ObjectToFile <Dictionary <ulong, string> >(Core.userLang, RustPPModule.GetAbsoluteFilePath("userLang.rpp"));
            }
            else if (File.Exists(RustPPModule.GetAbsoluteFilePath("userLang.rpp")))
            {
                File.Delete(RustPPModule.GetAbsoluteFilePath("userLang.rpp"));
            }
            if (Core.whiteList.Count != 0)
            {
                Logger.Log("Saving whitelist.");
                ObjectToXML <List <PList.Player> >(Core.whiteList.PlayerList, RustPPModule.GetAbsoluteFilePath("whitelist.xml"));
            }
            else if (File.Exists(RustPPModule.GetAbsoluteFilePath("whitelist.xml")))
            {
                File.Delete(RustPPModule.GetAbsoluteFilePath("whitelist.xml"));
            }
            if (Core.muteList.Count != 0)
            {
                Logger.Log("Saving mutelist.");
                ObjectToXML <List <PList.Player> >(Core.muteList.PlayerList, RustPPModule.GetAbsoluteFilePath("mutelist.xml"));
            }
            else if (File.Exists(RustPPModule.GetAbsoluteFilePath("mutelist.xml")))
            {
                File.Delete(RustPPModule.GetAbsoluteFilePath("mutelist.xml"));
            }
            if (Core.blackList.Count != 0)
            {
                Logger.Log("Saving blacklist.");
                ObjectToXML <List <PList.Player> >(Core.blackList.PlayerList, RustPPModule.GetAbsoluteFilePath("bans.xml"));
            }
            else if (File.Exists(RustPPModule.GetAbsoluteFilePath("bans.xml")))
            {
                File.Delete(RustPPModule.GetAbsoluteFilePath("bans.xml"));
            }
        }
示例#17
0
        protected BaseIssueViewModel(
            ISessionService applicationService,
            IMarkdownService markdownService,
            IActionMenuFactory actionMenuFactory,
            IAlertDialogFactory alertDialogFactory)
        {
            _applicationService = applicationService;
            _markdownService    = markdownService;
            _alertDialogFactory = alertDialogFactory;

            _assigneesCache = new Lazy <Task <IReadOnlyList <Octokit.User> > >(() =>
                                                                               _applicationService.GitHubClient.Issue.Assignee.GetAllForRepository(RepositoryOwner, RepositoryName));
            _milestonesCache = new Lazy <Task <IReadOnlyList <Octokit.Milestone> > >(() =>
                                                                                     _applicationService.GitHubClient.Issue.Milestone.GetAllForRepository(RepositoryOwner, RepositoryName));
            _labelsCache = new Lazy <Task <IReadOnlyList <Octokit.Label> > >(() =>
                                                                             _applicationService.GitHubClient.Issue.Labels.GetAllForRepository(RepositoryOwner, RepositoryName));

            IssueUpdated.Subscribe(x => Issue = x);

            _avatar = this.WhenAnyValue(x => x.Issue.User.AvatarUrl)
                      .Select(x => new GitHubAvatar(x))
                      .ToProperty(this, x => x.Avatar);

            var issuePresenceObservable = this.WhenAnyValue(x => x.Issue, x => x.CanModify)
                                          .Select(x => x.Item1 != null && x.Item2);

            Events = InternalEvents.CreateDerivedCollection(x => x);

            this.WhenAnyValue(x => x.Issue.Comments)
            .ToProperty(this, x => x.CommentCount, out _commentsCount);

            _participants = Events.Changed
                            .Select(_ => Events.Select(y => y.Actor).Distinct().Count())
                            .Select(x => x == 0 ? 1 : x)
                            .ToProperty(this, x => x.Participants);

            GoToAssigneesCommand  = ReactiveCommand.Create(issuePresenceObservable);
            GoToLabelsCommand     = ReactiveCommand.Create(issuePresenceObservable);
            GoToMilestonesCommand = ReactiveCommand.Create(issuePresenceObservable);

            _assignedUser = this.WhenAnyValue(x => x.Issue.Assignee)
                            .ToProperty(this, x => x.AssignedUser);

            _assignedMilestone = this.WhenAnyValue(x => x.Issue.Milestone)
                                 .ToProperty(this, x => x.AssignedMilestone);

            _assignedLabels = this.WhenAnyValue(x => x.Issue.Labels)
                              .ToProperty(this, x => x.AssignedLabels);

            _isClosed = this.WhenAnyValue(x => x.Issue.State)
                        .Select(x => x == Octokit.ItemState.Closed)
                        .ToProperty(this, x => x.IsClosed);

            _markdownDescription = this.WhenAnyValue(x => x.Issue)
                                   .Select(x => ((x == null || string.IsNullOrEmpty(x.Body)) ? null : x.Body))
                                   .Where(x => x != null)
                                   .Select(x => GetMarkdownDescription().ToObservable())
                                   .Switch()
                                   .ToProperty(this, x => x.MarkdownDescription, null, RxApp.MainThreadScheduler);

            LoadCommand = ReactiveCommand.CreateAsyncTask(t => Load(applicationService));

            GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null));
            GoToOwnerCommand
            .Select(_ => this.CreateViewModel <UserViewModel>())
            .Select(x => x.Init(Issue.User.Login))
            .Subscribe(NavigateTo);

            ToggleStateCommand = ReactiveCommand.CreateAsyncTask(issuePresenceObservable, async t => {
                try
                {
                    var updatedIssue = await applicationService.GitHubClient.Issue.Update(RepositoryOwner, RepositoryName, Id, new Octokit.IssueUpdate {
                        State = (Issue.State == Octokit.ItemState.Open) ? Octokit.ItemState.Closed : Octokit.ItemState.Open
                    });
                    _issueUpdatedObservable.OnNext(updatedIssue);
                }
                catch (Exception e)
                {
                    var close = (Issue.State == Octokit.ItemState.Open) ? "close" : "open";
                    throw new Exception("Unable to " + close + " the item. " + e.Message, e);
                }

                RetrieveEvents().ToBackground(x => InternalEvents.Reset(x));
            });

            AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => {
                var vm = new ComposerViewModel(async s => {
                    var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[Id].CreateComment(s);
                    var comment = (await applicationService.Client.ExecuteAsync(request)).Data;
                    InternalEvents.Add(new IssueCommentItemViewModel(comment));
                    _commentAddedSubject.OnNext(comment);
                }, alertDialogFactory);
                NavigateTo(vm);
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Issue).Select(x => x != null),
                sender => {
                var menu = actionMenuFactory.Create();
                menu.AddButton("Edit", GoToEditCommand);
                menu.AddButton(Issue.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand);
                menu.AddButton("Comment", AddCommentCommand);
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                return(menu.Show(sender));
            });

            GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => {
                var vm             = this.CreateViewModel <IssueEditViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.Id    = Id;
                vm.Issue = Issue;
                vm.SaveCommand.Subscribe(_issueUpdatedObservable.OnNext);
                NavigateTo(vm);
            });

            GoToUrlCommand = ReactiveCommand.Create();
            GoToUrlCommand.OfType <string>().Subscribe(GoToUrl);
            GoToUrlCommand.OfType <Uri>().Subscribe(x => GoToUrl(x.AbsoluteUri));

            var hasHtmlObservable = this.WhenAnyValue(x => x.HtmlUrl).Select(x => x != null);

            ShareCommand = ReactiveCommand.Create(hasHtmlObservable);
            ShareCommand.Subscribe(sender => actionMenuFactory.ShareUrl(sender, HtmlUrl));

            GoToHtmlUrlCommand = ReactiveCommand.Create(hasHtmlObservable);
            GoToHtmlUrlCommand.Subscribe(_ => GoToUrl(HtmlUrl.AbsoluteUri));
        }
示例#18
0
        public static void Init()
        {
            InitializeCommands();
            ShareCommand   command  = ChatCommand.GetCommand("share") as ShareCommand;
            FriendsCommand command2 = ChatCommand.GetCommand("friends") as FriendsCommand;
            bool           success  = false;

            if (File.Exists(RustPPModule.GetAbsoluteFilePath("doorsSave.xml")))
            {
                SerializableDictionary <ulong, List <ulong> > doorsDict;
                doorsDict = Helper.ObjectFromXML <SerializableDictionary <ulong, List <ulong> > >(RustPPModule.GetAbsoluteFilePath("doorsSave.xml"));
                Hashtable doorsSave = new Hashtable();
                foreach (KeyValuePair <ulong, List <ulong> > kvp in doorsDict)
                {
                    ArrayList arr = new ArrayList(kvp.Value);
                    doorsSave.Add(kvp.Key, arr);
                }
                command.SetSharedDoors(doorsSave);
                success = true;
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp")) && !success)
            {
                command.SetSharedDoors(Helper.ObjectFromFile <Hashtable>(RustPPModule.GetAbsoluteFilePath("doorsSave.rpp")));
            }

            if (!File.Exists(RustPPModule.GetAbsoluteFilePath("doorsSave.xml")))
            {
                SerializableDictionary <ulong, List <ulong> > doorsSave = new SerializableDictionary <ulong, List <ulong> >();
                foreach (DictionaryEntry entry in command.GetSharedDoors())
                {
                    ulong        key   = (ulong)entry.Key;
                    ArrayList    value = (ArrayList)entry.Value;
                    List <ulong> list  = new List <ulong>(value.OfType <ulong>());
                    doorsSave.Add(key, list);
                }
                Helper.ObjectToXML <SerializableDictionary <ulong, List <ulong> > >(doorsSave, RustPPModule.GetAbsoluteFilePath("doorsSave.xml"));
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp")))
            {
                command2.SetFriendsLists(Helper.ObjectFromFile <Hashtable>(RustPPModule.GetAbsoluteFilePath("friendsSave.rpp")));
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("admins.xml")))
            {
                Administrator.AdminList = Helper.ObjectFromXML <List <Administrator> >(RustPPModule.GetAbsoluteFilePath("admins.xml"));
            }
            success = false;
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("userCache.xml")))
            {
                FileInfo fi   = new FileInfo(RustPPModule.GetAbsoluteFilePath("userCache.xml"));
                float    mega = (fi.Length / 1024f) / 1024f;
                if (mega > 0.70)
                {
                    Logger.LogWarning("Rust++ Cache.xml and Cache.rpp are getting big. Deletion is suggested.");
                }
                SerializableDictionary <ulong, string> userDict = Helper.ObjectFromXML <SerializableDictionary <ulong, string> >(RustPPModule.GetAbsoluteFilePath("userCache.xml"));
                userCache = new Dictionary <ulong, string>(userDict);
                success   = true;
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("cache.rpp")) && !success)
            {
                userCache = Helper.ObjectFromFile <Dictionary <ulong, string> >(RustPPModule.GetAbsoluteFilePath("cache.rpp"));
                if (!File.Exists(RustPPModule.GetAbsoluteFilePath("userCache.xml")))
                {
                    Helper.ObjectToXML <SerializableDictionary <ulong, string> >(new SerializableDictionary <ulong, string>(userCache), RustPPModule.GetAbsoluteFilePath("userCache.xml"));
                }
            }
            else if (!success)
            {
                userCache = new Dictionary <ulong, string>();
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("whitelist.xml")))
            {
                whiteList = new PList(Helper.ObjectFromXML <List <PList.Player> >(RustPPModule.GetAbsoluteFilePath("whitelist.xml")));
            }
            else
            {
                whiteList = new PList();
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("mutelist.xml")))
            {
                muteList = new PList(Helper.ObjectFromXML <List <PList.Player> >(RustPPModule.GetAbsoluteFilePath("mutelist.xml")));
            }
            else
            {
                muteList = new PList();
            }
            if (File.Exists(RustPPModule.GetAbsoluteFilePath("bans.xml")))
            {
                blackList = new PList(Helper.ObjectFromXML <List <PList.Player> >(RustPPModule.GetAbsoluteFilePath("bans.xml")));
            }
            else
            {
                blackList = new PList();
            }
        }
示例#19
0
        public IssueViewModel(IApplicationService applicationService, IShareService shareService)
        {
            _applicationService = applicationService;
            Comments            = new ReactiveList <IssueCommentModel>();
            Events = new ReactiveList <IssueEventModel>();
            var issuePresenceObservable = this.WhenAnyValue(x => x.Issue).Select(x => x != null);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue, x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)));
            ShareCommand.Subscribe(_ => shareService.ShareUrl(Issue.HtmlUrl));

            AddCommentCommand = ReactiveCommand.Create();
            AddCommentCommand.Subscribe(_ =>
            {
                var vm = CreateViewModel <CommentViewModel>();
                ReactiveUI.Legacy.ReactiveCommandMixins.RegisterAsyncTask(vm.SaveCommand, async t =>
                {
                    var issue   = _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[IssueId];
                    var comment = await _applicationService.Client.ExecuteAsync(issue.CreateComment(vm.Comment));
                    Comments.Add(comment.Data);
                    vm.DismissCommand.ExecuteIfCan();
                });
                ShowViewModel(vm);
            });

            ToggleStateCommand = ReactiveCommand.CreateAsyncTask(issuePresenceObservable, async t =>
            {
                var close = string.Equals(Issue.State, "open", StringComparison.OrdinalIgnoreCase);
                try
                {
                    var issue = _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[Issue.Number];
                    var data  = await _applicationService.Client.ExecuteAsync(issue.UpdateState(close ? "closed" : "open"));
                    Issue     = data.Data;
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to " + (close ? "close" : "open") + " the item. " + e.Message, e);
                }
            });

            GoToEditCommand = ReactiveCommand.Create(issuePresenceObservable);
            GoToEditCommand.Subscribe(_ =>
            {
                var vm             = CreateViewModel <IssueEditViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.Id    = IssueId;
                vm.Issue = Issue;
                vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x);
                ShowViewModel(vm);
            });

            GoToAssigneeCommand = ReactiveCommand.Create(issuePresenceObservable);
            GoToAssigneeCommand.Subscribe(_ =>
            {
                var vm             = CreateViewModel <IssueAssignedToViewModel>();
                vm.SaveOnSelect    = true;
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.IssueId         = IssueId;
                vm.SelectedUser    = Issue.Assignee;
                vm.WhenAnyValue(x => x.SelectedUser).Subscribe(x =>
                {
                    Issue.Assignee = x;
                    this.RaisePropertyChanged("Issue");
                });
                ShowViewModel(vm);
            });

            GoToLabelsCommand = ReactiveCommand.Create(issuePresenceObservable);
            GoToLabelsCommand.Subscribe(_ =>
            {
                var vm             = CreateViewModel <IssueLabelsViewModel>();
                vm.SaveOnSelect    = true;
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.IssueId         = IssueId;
                vm.SelectedLabels.Reset(Issue.Labels);
                vm.WhenAnyValue(x => x.SelectedLabels).Subscribe(x =>
                {
                    Issue.Labels = x.ToList();
                    this.RaisePropertyChanged("Issue");
                });
                ShowViewModel(vm);
            });

            GoToMilestoneCommand = ReactiveCommand.Create(issuePresenceObservable);
            GoToMilestoneCommand.Subscribe(_ =>
            {
                var vm               = CreateViewModel <IssueMilestonesViewModel>();
                vm.SaveOnSelect      = true;
                vm.RepositoryOwner   = RepositoryOwner;
                vm.RepositoryName    = RepositoryName;
                vm.IssueId           = IssueId;
                vm.SelectedMilestone = Issue.Milestone;
                vm.WhenAnyValue(x => x.SelectedMilestone).Subscribe(x =>
                {
                    Issue.Milestone = x;
                    this.RaisePropertyChanged("Issue");
                });
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var forceCacheInvalidation = t as bool?;
                var issue = _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[IssueId];
                var t1    = this.RequestModel(issue.Get(), forceCacheInvalidation, response => Issue = response.Data);
                Comments.SimpleCollectionLoad(issue.GetComments(), forceCacheInvalidation).FireAndForget();
                Events.SimpleCollectionLoad(issue.GetEvents(), forceCacheInvalidation).FireAndForget();
                return(t1);
            });
        }
示例#20
0
        public GistViewModel(
            ISessionService sessionService,
            IActionMenuFactory actionMenuService,
            IAlertDialogFactory alertDialogFactory)
        {
            Comments = new ReactiveList <GistCommentModel>();

            Title = "Gist";

            this.WhenAnyValue(x => x.Gist).Where(x => x != null && x.Files != null && x.Files.Count > 0)
            .Select(x => x.Files.First().Key).Subscribe(x =>
                                                        Title = x);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null));
            ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, new Uri(Gist.HtmlUrl)));

            this.WhenAnyValue(x => x.Gist.Owner.AvatarUrl)
            .Select(x => new GitHubAvatar(x))
            .ToProperty(this, x => x.Avatar, out _avatar);

            ToggleStarCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue),
                async t =>
            {
                try
                {
                    if (!IsStarred.HasValue)
                    {
                        return;
                    }
                    var request = IsStarred.Value ? sessionService.Client.Gists[Id].Unstar() : sessionService.Client.Gists[Id].Star();
                    await sessionService.Client.ExecuteAsync(request);
                    IsStarred = !IsStarred.Value;
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to start gist. Please try again.", e);
                }
            });

            ForkCommand = ReactiveCommand.CreateAsyncTask(async t => {
                var gist = await sessionService.GitHubClient.Gist.Fork(Id);
                var vm   = this.CreateViewModel <GistViewModel>();
                vm.Id    = gist.Id;
                vm.Gist  = gist;
                NavigateTo(vm);
            });

            ForkCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    alertDialogFactory.Show("Forking...");
                }
                else
                {
                    alertDialogFactory.Hide();
                }
            });

            GoToEditCommand = ReactiveCommand.Create();
            GoToEditCommand.Subscribe(_ =>
            {
                var vm  = this.CreateViewModel <GistEditViewModel>();
                vm.Gist = Gist;
                vm.SaveCommand.Subscribe(x => Gist = x);
                NavigateTo(vm);
            });

            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)));
            GoToHtmlUrlCommand
            .Select(_ => this.CreateViewModel <WebBrowserViewModel>())
            .Select(x => x.Init(Gist.HtmlUrl))
            .Subscribe(NavigateTo);

            GoToFileSourceCommand = ReactiveCommand.Create();
            GoToFileSourceCommand.OfType <GistFile>().Subscribe(x =>
            {
                var vm      = this.CreateViewModel <GistFileViewModel>();
                vm.Id       = Id;
                vm.GistFile = x;
                vm.Filename = x.Filename;
                NavigateTo(vm);
            });

            GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist.Owner).Select(x => x != null));
            GoToOwnerCommand
            .Select(_ => this.CreateViewModel <UserViewModel>())
            .Select(x => x.Init(Gist.Owner.Login))
            .Subscribe(NavigateTo);

            AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ =>
                                                                          NavigateTo(new ComposerViewModel("Add Comment", async x => {
                var request = sessionService.Client.Gists[Id].CreateGistComment(x);
                Comments.Add((await sessionService.Client.ExecuteAsync(request)).Data);
            }, alertDialogFactory)));

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Gist).Select(x => x != null),
                sender => {
                var menu = actionMenuService.Create();
                if (Gist.Owner != null && string.Equals(sessionService.Account.Username, Gist.Owner.Login, StringComparison.OrdinalIgnoreCase))
                {
                    menu.AddButton("Edit", GoToEditCommand);
                }
                else
                {
                    menu.AddButton("Fork", ForkCommand);
                }
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                return(menu.Show(sender));
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                sessionService.GitHubClient.Gist.IsStarred(Id).ToBackground(x => IsStarred = x);
                Comments.SimpleCollectionLoad(sessionService.Client.Gists[Id].GetComments());
                Gist = await sessionService.GitHubClient.Gist.Get(Id);
            });
        }
示例#21
0
        public GistViewModel(IApplicationService applicationService, IShareService shareService,
                             IActionMenuService actionMenuService, IStatusIndicatorService statusIndicatorService)
        {
            Comments = new ReactiveList <GistCommentModel>();

            Title = "Gist";

            GoToUrlCommand = this.CreateUrlCommand();

            this.WhenAnyValue(x => x.Gist).Where(x => x != null && x.Files != null && x.Files.Count > 0)
            .Select(x => x.Files.First().Key).Subscribe(x =>
                                                        Title = x);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null));
            ShareCommand.Subscribe(_ => shareService.ShareUrl(Gist.HtmlUrl));

            ToggleStarCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue),
                async t =>
            {
                try
                {
                    if (!IsStarred.HasValue)
                    {
                        return;
                    }
                    var request = IsStarred.Value ? applicationService.Client.Gists[Id].Unstar() : applicationService.Client.Gists[Id].Star();
                    await applicationService.Client.ExecuteAsync(request);
                    IsStarred = !IsStarred.Value;
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to start gist. Please try again.", e);
                }
            });

            ForkCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                var data       = await applicationService.Client.ExecuteAsync(applicationService.Client.Gists[Id].ForkGist());
                var forkedGist = data.Data;
                var vm         = CreateViewModel <GistViewModel>();
                vm.Id          = forkedGist.Id;
                vm.Gist        = forkedGist;
                ShowViewModel(vm);
            });

            ForkCommand.IsExecuting.Subscribe(x =>
            {
                if (x)
                {
                    statusIndicatorService.Show("Forking...");
                }
                else
                {
                    statusIndicatorService.Hide();
                }
            });

            GoToEditCommand = ReactiveCommand.Create();

            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)));
            GoToHtmlUrlCommand.Select(_ => Gist.HtmlUrl).Subscribe(this.ShowWebBrowser);

            GoToFileSourceCommand = ReactiveCommand.Create();
            GoToFileSourceCommand.OfType <GistFileModel>().Subscribe(x =>
            {
                var vm      = CreateViewModel <GistFileViewModel>();
                vm.Id       = Id;
                vm.GistFile = x;
                vm.Filename = x.Filename;
                ShowViewModel(vm);
            });

            GoToUserCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && x.Owner != null));
            GoToUserCommand.Subscribe(x =>
            {
                var vm      = CreateViewModel <UserViewModel>();
                vm.Username = Gist.Owner.Login;
                ShowViewModel(vm);
            });

            AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm = CreateViewModel <GistCommentViewModel>();
                vm.Id  = Id;
                vm.CommentAdded.Subscribe(Comments.Add);
                ShowViewModel(vm);
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Gist).Select(x => x != null),
                _ =>
            {
                var menu = actionMenuService.Create(Title);
                if (Gist.Owner != null && string.Equals(applicationService.Account.Username, Gist.Owner.Login, StringComparison.OrdinalIgnoreCase))
                {
                    menu.AddButton("Edit", GoToEditCommand);
                }
                else
                {
                    menu.AddButton("Fork", ForkCommand);
                }
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                return(menu.Show());
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var forceCacheInvalidation = t as bool?;
                var t1 = this.RequestModel(applicationService.Client.Gists[Id].Get(), forceCacheInvalidation, response => Gist = response.Data);
                this.RequestModel(applicationService.Client.Gists[Id].IsGistStarred(), forceCacheInvalidation, response => IsStarred = response.Data).FireAndForget();
                Comments.SimpleCollectionLoad(applicationService.Client.Gists[Id].GetComments(), forceCacheInvalidation).FireAndForget();
                return(t1);
            });
        }
示例#22
0
        public async Task <ActionResult <bool> > ShareAsync([FromBody] ShareCommand sharePostCommand)
        {
            var result = await _mediator.Send(sharePostCommand);

            return(Ok(ResponseWrapper.CreateOkResponseWrapper(result)));
        }
示例#23
0
        public PullRequestViewModel(
            IApplicationService applicationService,
            IMarkdownService markdownService,
            IActionMenuFactory actionMenuService)
            : base(applicationService, markdownService)
        {
            this.WhenAnyValue(x => x.Id)
            .Subscribe(x => Title = "Pull Request #" + x);

            _canMerge = this.WhenAnyValue(x => x.PullRequest)
                        .Select(x => x != null && !x.Merged)
                        .ToProperty(this, x => x.CanMerge);

            var canMergeObservable = this.WhenAnyValue(x => x.PullRequest).Select(x =>
                                                                                  x != null && !x.Merged && x.Mergeable.HasValue && x.Mergeable.Value);

            MergeCommand = ReactiveCommand.CreateAsyncTask(canMergeObservable, async t =>
            {
                var req      = new Octokit.MergePullRequest(null);
                var response = await applicationService.GitHubClient.PullRequest.Merge(RepositoryOwner, RepositoryName, Id, req);
                if (!response.Merged)
                {
                    throw new Exception(string.Format("Unable to merge pull request: {0}", response.Message));
                }
                LoadCommand.ExecuteIfCan();
            });

//            ToggleStateCommand = ReactiveCommand.CreateAsyncTask(
//                this.WhenAnyValue(x => x.PullRequest).Select(x => x != null),
//                async t =>
//            {
//                var newState = PullRequest.State == Octokit.ItemState.Open ? Octokit.ItemState.Closed : Octokit.ItemState.Open;
//
//                try
//                {
//                    var req = new Octokit.PullRequestUpdate { State = newState };
//                    PullRequest = await applicationService.GitHubClient.PullRequest.Update(RepositoryOwner, RepositoryName, Id, req);
//                }
//                catch (Exception e)
//                {
//                    throw new Exception("Unable to " + (newState == Octokit.ItemState.Closed ? "close" : "open") + " the item. " + e.Message, e);
//                }
//            });


            GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null));
            GoToHtmlUrlCommand.Select(_ => PullRequest.HtmlUrl).Subscribe(GoToUrlCommand.ExecuteIfCan);

            GoToCommitsCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm             = this.CreateViewModel <PullRequestCommitsViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.PullRequestId   = Id;
                NavigateTo(vm);
            });

            GoToFilesCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm             = this.CreateViewModel <PullRequestFilesViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.PullRequestId   = Id;
                NavigateTo(vm);
            });

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null));
            ShareCommand.Subscribe(_ => actionMenuService.ShareUrl(PullRequest.HtmlUrl));

            GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm             = this.CreateViewModel <IssueEditViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.Id = Id;
                //vm.Issue = Issue;
//                vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x);
                NavigateTo(vm);
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.PullRequest).Select(x => x != null),
                _ =>
            {
                var menu = actionMenuService.Create(Title);
                menu.AddButton("Edit", GoToEditCommand);
                menu.AddButton(PullRequest.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand);
                menu.AddButton("Comment", GoToAddCommentCommand);
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToHtmlUrlCommand);
                return(menu.Show());
            });
        }
示例#24
0
        public IssueViewModel(IApplicationService applicationService, IActionMenuFactory actionMenuFactory,
                              IMarkdownService markdownService, IGraphicService graphicsService)
        {
            _applicationService = applicationService;

            var issuePresenceObservable = this.WhenAnyValue(x => x.Issue).Select(x => x != null);

            GoToAssigneesCommand = ReactiveCommand.Create(issuePresenceObservable)
                                   .WithSubscription(_ => Assignees.LoadCommand.ExecuteIfCan());

            GoToLabelsCommand = ReactiveCommand.Create(issuePresenceObservable)
                                .WithSubscription(_ => Labels.LoadCommand.ExecuteIfCan());

            GoToMilestonesCommand = ReactiveCommand.Create(issuePresenceObservable)
                                    .WithSubscription(_ => Milestones.LoadCommand.ExecuteIfCan());

            this.WhenAnyValue(x => x.Id)
            .Subscribe(x => Title = "Issue #" + x);

            _assignedUser = this.WhenAnyValue(x => x.Issue.Assignee)
                            .ToProperty(this, x => x.AssignedUser);

            _assignedMilestone = this.WhenAnyValue(x => x.Issue.Milestone)
                                 .ToProperty(this, x => x.AssignedMilestone);

            _assignedLabels = this.WhenAnyValue(x => x.Issue.Labels)
                              .ToProperty(this, x => x.AssignedLabels);

            _markdownDescription = this.WhenAnyValue(x => x.Issue)
                                   .Select(x => ((x == null || string.IsNullOrEmpty(x.Body)) ? null : markdownService.Convert(x.Body)))
                                   .ToProperty(this, x => x.MarkdownDescription);

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null));
            ShareCommand.Subscribe(_ => actionMenuFactory.ShareUrl(Issue.HtmlUrl));

            var events = new ReactiveList <IIssueEventItemViewModel>();

            Events = events.CreateDerivedCollection(x => x);

            AddCommentCommand = ReactiveCommand.Create();
            AddCommentCommand.Subscribe(_ =>
            {
                var vm             = this.CreateViewModel <IssueCommentViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.Id = Id;
                vm.SaveCommand.Subscribe(x => events.Add(new IssueCommentItemViewModel(x)));
                NavigateTo(vm);
            });

            ToggleStateCommand = ReactiveCommand.CreateAsyncTask(issuePresenceObservable, async t =>
            {
                try
                {
                    Issue = await applicationService.GitHubClient.Issue.Update(RepositoryOwner, RepositoryName, Id, new Octokit.IssueUpdate {
                        State = (Issue.State == Octokit.ItemState.Open) ? Octokit.ItemState.Closed : Octokit.ItemState.Open
                    });
                }
                catch (Exception e)
                {
                    var close = (Issue.State == Octokit.ItemState.Open) ? "close" : "open";
                    throw new Exception("Unable to " + close + " the item. " + e.Message, e);
                }
            });

            GoToEditCommand = ReactiveCommand.Create(issuePresenceObservable);
            GoToEditCommand.Subscribe(_ =>
            {
                var vm             = this.CreateViewModel <IssueEditViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.Id = Id;
//                vm.Issue = Issue;
//                vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x);
                NavigateTo(vm);
            });

            Assignees = new IssueAssigneeViewModel(
                () => applicationService.GitHubClient.Issue.Assignee.GetForRepository(RepositoryOwner, RepositoryName),
                () => Task.FromResult(Issue),
                UpdateIssue);

            Milestones = new IssueMilestonesViewModel(
                () => applicationService.GitHubClient.Issue.Milestone.GetForRepository(RepositoryOwner, RepositoryName),
                () => Task.FromResult(Issue),
                UpdateIssue);

            Labels = new IssueLabelsViewModel(
                () => applicationService.GitHubClient.Issue.Labels.GetForRepository(RepositoryOwner, RepositoryName),
                () => Task.FromResult(Issue),
                UpdateIssue,
                graphicsService);

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                var issueRequest = applicationService.GitHubClient.Issue.Get(RepositoryOwner, RepositoryName, Id)
                                   .ContinueWith(x => Issue = x.Result, new CancellationToken(), TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext());
                var eventsRequest   = applicationService.GitHubClient.Issue.Events.GetForIssue(RepositoryOwner, RepositoryName, Id);
                var commentsRequest = applicationService.GitHubClient.Issue.Comment.GetForIssue(RepositoryOwner, RepositoryName, Id);
                await Task.WhenAll(issueRequest, eventsRequest, commentsRequest);

                var tempList = new List <IIssueEventItemViewModel>(eventsRequest.Result.Count + commentsRequest.Result.Count);
                tempList.AddRange(eventsRequest.Result.Select(x => new IssueEventItemViewModel(x)));
                tempList.AddRange(commentsRequest.Result.Select(x => new IssueCommentItemViewModel(x)));
                events.Reset(tempList.OrderBy(x => x.CreatedAt));
            });

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Issue).Select(x => x != null),
                _ =>
            {
                var menu = actionMenuFactory.Create(Title);
                menu.AddButton(Issue.State == Octokit.ItemState.Open ? "Close" : "Open", ToggleStateCommand);
//
//
//                var editButton = _actionSheet.AddButton("Edit");
//                var commentButton = _actionSheet.AddButton("Comment");
//                var shareButton = _actionSheet.AddButton("Share");
//                var showButton = _actionSheet.AddButton("Show in GitHub");

                return(menu.Show());
            });
        }
        public PullRequestViewModel(IApplicationService applicationService, IMarkdownService markdownService, IShareService shareService)
        {
            _applicationService = applicationService;
            _markdownService    = markdownService;

            Comments = new ReactiveList <IssueCommentModel>();
            Events   = new ReactiveList <IssueEventModel>();

            MergeCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.PullRequest).Select(x =>
                                                             x != null && x.Merged.HasValue && !x.Merged.Value && x.Mergable.HasValue && x.Mergable.Value),
                async t =>
            {
                try
                {
                    var response = await _applicationService.Client.ExecuteAsync(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests[PullRequestId].Merge());
                    if (!response.Data.Merged)
                    {
                        throw new Exception(response.Data.Message);
                    }
                    var pullRequest = _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests[PullRequestId].Get();
                    await this.RequestModel(pullRequest, true, r => PullRequest = r.Data);
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to Merge: " + e.Message, e);
                }
            });

            ToggleStateCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), async t =>
            {
                var close = string.Equals(PullRequest.State, "open", StringComparison.OrdinalIgnoreCase);

                try
                {
                    var data = await _applicationService.Client.ExecuteAsync(
                        _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests[PullRequestId].UpdateState(close ? "closed" : "open"));
                    PullRequest = data.Data;
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to " + (close ? "close" : "open") + " the item. " + e.Message, e);
                }
            });

            GoToCommitsCommand = ReactiveCommand.Create();
            GoToCommitsCommand.Subscribe(_ =>
            {
                var vm             = CreateViewModel <PullRequestCommitsViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.PullRequestId   = PullRequestId;
                ShowViewModel(vm);
            });

            GoToFilesCommand = ReactiveCommand.Create();
            GoToFilesCommand.Subscribe(_ =>
            {
                var vm           = CreateViewModel <PullRequestFilesViewModel>();
                vm.Username      = RepositoryOwner;
                vm.Repository    = RepositoryName;
                vm.PullRequestId = PullRequestId;
                ShowViewModel(vm);
            });

            ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl)));
            ShareCommand.Subscribe(_ => shareService.ShareUrl(PullRequest.HtmlUrl));

            GoToEditCommand = ReactiveCommand.Create();
            GoToEditCommand.Subscribe(_ =>
            {
                var vm             = CreateViewModel <IssueEditViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.Id    = PullRequestId;
                vm.Issue = Issue;
                vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x);
                ShowViewModel(vm);
            });

            GoToLabelsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null));
            GoToLabelsCommand.Subscribe(_ =>
            {
                var vm             = CreateViewModel <IssueLabelsViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.IssueId         = PullRequestId;
                vm.SaveOnSelect    = true;
                vm.SelectedLabels.Reset(Issue.Labels);
                vm.WhenAnyValue(x => x.Labels).Skip(1).Subscribe(x =>
                {
                    Issue.Labels = x.ToList();
                    this.RaisePropertyChanged("Issue");
                });
                ShowViewModel(vm);
            });

            GoToMilestoneCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null));
            GoToMilestoneCommand.Subscribe(_ =>
            {
                var vm               = CreateViewModel <IssueMilestonesViewModel>();
                vm.RepositoryOwner   = RepositoryOwner;
                vm.RepositoryName    = RepositoryName;
                vm.IssueId           = PullRequestId;
                vm.SaveOnSelect      = true;
                vm.SelectedMilestone = Issue.Milestone;
                vm.WhenAnyValue(x => x.SelectedMilestone).Skip(1).Subscribe(x =>
                {
                    Issue.Milestone = x;
                    this.RaisePropertyChanged("Issue");
                });
                ShowViewModel(vm);
            });

            GoToAssigneeCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null));
            GoToAssigneeCommand.Subscribe(_ =>
            {
                var vm             = CreateViewModel <IssueAssignedToViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.IssueId         = PullRequestId;
                vm.SaveOnSelect    = true;
                vm.SelectedUser    = Issue.Assignee;
                vm.WhenAnyValue(x => x.SelectedUser).Skip(1).Subscribe(x =>
                {
                    Issue.Assignee = x;
                    this.RaisePropertyChanged("Issue");
                });
                ShowViewModel(vm);
            });

            GoToAddCommentCommand = ReactiveCommand.Create();
            GoToAddCommentCommand.Subscribe(_ =>
            {
                var vm = CreateViewModel <CommentViewModel>();
                ReactiveUI.Legacy.ReactiveCommandMixins.RegisterAsyncTask(vm.SaveCommand, async t =>
                {
                    var req =
                        _applicationService.Client.Users[RepositoryOwner]
                        .Repositories[RepositoryName].Issues[PullRequestId].CreateComment(vm.Comment);
                    var comment = await _applicationService.Client.ExecuteAsync(req);
                    Comments.Add(comment.Data);
                    vm.DismissCommand.ExecuteIfCan();
                });
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var forceCacheInvalidation = t as bool?;
                var pullRequest            = _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests[PullRequestId].Get();
                var t1 = this.RequestModel(pullRequest, forceCacheInvalidation, response => PullRequest = response.Data);
                Events.SimpleCollectionLoad(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[PullRequestId].GetEvents(), forceCacheInvalidation).FireAndForget();
                Comments.SimpleCollectionLoad(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[PullRequestId].GetComments(), forceCacheInvalidation).FireAndForget();
                this.RequestModel(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[PullRequestId].Get(), forceCacheInvalidation, response => Issue = response.Data).FireAndForget();
                return(t1);
            });
        }