internal PersistenceConfiguration(
     IPersistentDataStore persistentDataStore,
     int maxCachedUsers
     )
 {
     PersistentDataStore = persistentDataStore;
     MaxCachedUsers      = maxCachedUsers;
 }
        public EditPostWindowViewModel(Window window, EditPostWindow.Type type, Draft existing = null, Commentable parent = null, FeedItem edit = null)
        {
            this.window = window;
            this.api    = AppManager.Instance.API;
            this.db     = AppManager.Instance.DB;

            this.type     = type;
            this.existing = existing;
            this.parent   = parent;
            this.editing  = edit;

            Cancelled = true;

            if (parent != null)
            {
                mode = Mode.NewComment;

                ViewModels.Comment comment = parent as ViewModels.Comment;
                if (comment != null)
                {
                    if (AppManager.Instance.API.User.LoggedInUser != comment.Username)
                    {
                        Text = "@" + comment.Username + " ";
                    }
                }
            }
            else if (existing != null)
            {
                mode = Mode.EditDraft;

                Text       = existing.Text;
                TagsString = existing.Tags;
                ImagePath  = existing.ImagePath;
            }
            else if (edit != null)
            {
                mode = Mode.EditExisting;

                var r       = edit.AsRant();
                var comment = edit.AsComment();
                if (r != null)
                {
                    Text       = r.Text;
                    TagsString = r.TagsString;
                }
                else if (comment != null)
                {
                    Text = comment.Text;
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
        }
        public PersistentDataStoreWrapper(
            IPersistentDataStore persistentStore,
            string mobileKey,
            Logger log
            )
        {
            _persistentStore = persistentStore;
            _log             = log;

            _globalNamespace      = NamespacePrefix;
            _environmentNamespace = NamespacePrefix + "_" + Base64.UrlSafeSha256Hash(mobileKey);
        }
        internal PersistentStoreWrapper(
            IPersistentDataStore core,
            DataStoreCacheConfig caching,
            IDataStoreUpdates dataStoreUpdates,
            TaskExecutor taskExecutor,
            Logger log
            )
        {
            this._core             = core;
            this._caching          = caching;
            this._dataStoreUpdates = dataStoreUpdates;
            this._log = log;

            _cacheIndefinitely = caching.IsEnabled && caching.IsInfiniteTtl;
            if (caching.IsEnabled)
            {
                var itemCacheBuilder = Caches.KeyValue <CacheKey, ItemDescriptor?>()
                                       .WithLoader(GetInternalForCache)
                                       .WithMaximumEntries(caching.MaximumEntries);
                var allCacheBuilder = Caches.KeyValue <DataKind, ImmutableDictionary <string, ItemDescriptor> >()
                                      .WithLoader(GetAllAndDeserialize);
                var initCacheBuilder = Caches.SingleValue <bool>()
                                       .WithLoader(_core.Initialized);
                if (!caching.IsInfiniteTtl)
                {
                    itemCacheBuilder.WithExpiration(caching.Ttl);
                    allCacheBuilder.WithExpiration(caching.Ttl);
                    initCacheBuilder.WithExpiration(caching.Ttl);
                }
                _itemCache = itemCacheBuilder.Build();
                _allCache  = allCacheBuilder.Build();
                _initCache = initCacheBuilder.Build();
            }
            else
            {
                _itemCache = null;
                _allCache  = null;
                _initCache = null;
            }

            _statusManager = new PersistentDataStoreStatusManager(
                !_cacheIndefinitely,
                true,
                this.PollAvailabilityAfterOutage,
                dataStoreUpdates.UpdateStatus,
                taskExecutor,
                log
                );
        }
Esempio n. 5
0
 public static IPersistentDataStoreFactory AsSingletonFactory(this IPersistentDataStore instance) =>
 new SinglePersistentDataStoreFactory
 {
     Instance = instance
 };
Esempio n. 6
0
 public DraftsManager(IPersistentDataStore db)
 {
     this.db = db;
 }
Esempio n. 7
0
 public void RegisterServices(ILogger logger, IHealthReporter healthReporter, IPersistentDataStore persistentStore)
 {
     ServerLogger          = logger;
     ServerHealthReporter  = healthReporter;
     ServerPersistentStore = persistentStore;
 }
Esempio n. 8
0
 public SpecificPersistentDataStoreFactory(IPersistentDataStore store)
 {
     _store = store;
 }
Esempio n. 9
0
 public FollowedUserChecker(IDataStore ds, IDevRantClient api, IPersistentDataStore history)
 {
     this.ds      = ds;
     this.api     = api;
     this.history = history;
 }
Esempio n. 10
0
        /// <summary>
        /// Casts a vote
        /// </summary>
        /// <param name="args"></param>
        /// <param name="api">API to use to vote</param>
        /// <param name="db">Optional DB to mark as Read</param>
        /// <returns>Throws exception on errors</returns>
        public static async Task Vote(ButtonClickedEventArgs args, IDevRantClient api, IPersistentDataStore db = null)
        {
            Vote vote = null;

            Votable votable = args.SelectedItem as Votable;

            if (votable.Voted == VoteState.Disabled)
            {
                return;
            }

            if (votable != null)
            {
                switch (args.Type)
                {
                case ButtonType.Down:
                    if (votable.Voted == VoteState.Down)
                    {
                        vote = Dtos.Vote.ClearVote();
                    }
                    else
                    {
                        var dlg = new DownvoteReasonWindow();
                        dlg.Topmost = true;
                        dlg.ShowDialog();

                        if (dlg.Reason != null)
                        {
                            vote = Dtos.Vote.DownVote(dlg.Reason.Value);
                        }
                        else
                        {
                            return;
                        }
                    }
                    break;

                case ButtonType.Up:
                    if (votable.Voted == VoteState.Up)
                    {
                        vote = Dtos.Vote.ClearVote();
                    }
                    else
                    {
                        vote = Dtos.Vote.UpVote();
                    }
                    break;
                }

                FeedItem item = args.SelectedItem as FeedItem;

                switch (args.SelectedItem.Type)
                {
                case FeedItem.FeedItemType.Post:
                    var rant = item.AsRant();

                    var r1 = await api.User.VoteRant(rant.ID, vote);

                    rant.Update(r1);
                    rant.Read = true;

                    if (db != null)
                    {
                        db.MarkRead(rant.ID);
                    }

                    break;

                case FeedItem.FeedItemType.Collab:
                    var collab = item.AsCollab();

                    var r2 = await api.User.VoteCollab(collab.ID, vote);

                    collab.Update(r2);
                    break;

                case FeedItem.FeedItemType.Comment:
                    var comment = item.AsComment();
                    var r3      = await api.User.VoteComment(comment.ID, vote);

                    comment.Update(r3);
                    break;
                }

                args.InvokeCallback();
            }
        }