PersistentContext CreatePersistentContext(string contextId, PersistentContextOptions options)
        {
            ISerializer defaultJsonSerializer = options.SerializerOverride ?? new DefaultJsonSerializer();

            var          dataStorePath = Path.Combine(wurmAssistantDataDirectory.DirectoryPath, "DataV2", contextId);
            IDataStorage dataStorage   = options.DataStorageOverride ?? new SqLiteDataStorage(dataStorePath);

            return(new PersistentContext(defaultJsonSerializer, dataStorage));
        }
        public IPersistentContext GetPersistentContext(string contextId, PersistentContextOptions options)
        {
            if (!Validate(contextId))
            {
                throw new InvalidOperationException($"Format of contextId is not valid. " +
                                                    $"Format must match regex \"{ContextIdValidationPattern}\" " +
                                                    $"(only letters, numbers and dashes, no whitespaces).");
            }

            contextId = contextId.ToLowerInvariant();

            lock (locker)
            {
                if (activeContexts.ContainsKey(contextId))
                {
                    throw new InvalidOperationException("Context with this contextId has already been provided. " +
                                                        "Context for each contextId can only be retrieved once.");
                }
                var context = CreatePersistentContext(contextId, options);
                activeContexts.Add(contextId, new PersistentContextContainer(context, options));
                return(context);
            }
        }
 public PersistentContextContainer(PersistentContext persistentContext, PersistentContextOptions persistentContextOptions)
 {
     PersistentContext        = persistentContext;
     PersistentContextOptions = persistentContextOptions;
 }