public async Task InvokeAsync(
            HttpContext context,
            IContentStorage contentStore,
            ISchemaStorage schemaStorage,
            JsonService jsonService)
        {
            string schema = (string)context.GetRouteValue("schema");

            QueryParameters queryParameters = await jsonService.Deserialize <QueryParameters>(context.Request.Body);

            ContentSchema schemaModel = await schemaStorage.GetContentSchemaAsync(schema);

            QueryResult <ContentItem> contentItems = await contentStore.Query(schema, queryParameters);

            foreach (ContentItem contentItem in contentItems.Items)
            {
                contentItem.ApplySchema(schemaModel);
            }

            QueryResult <RestContentItem> resultQuery = new QueryResult <RestContentItem>()
            {
                Offset     = contentItems.Offset,
                Count      = contentItems.Count,
                TotalCount = contentItems.TotalCount,
                Items      = contentItems.Items.Select(x => x.ToRest()).ToList()
            };

            string json = jsonService.Serialize(resultQuery);

            await context.Response.WriteAsync(json);
        }
Beispiel #2
0
        private static Profile Load(IContentStorage storage, string profileFolder, Guid id, string file)
        {
            Profile profile = null;
            var     path    = storage.CombinePath(profileFolder, file);

            if (storage.IsFileExist(path))
            {
                var document = new XmlDocument();
                using (var stream = storage.OpenForRead(path))
                {
                    document.Load(stream);
                }

                var rootElement  = document.DocumentElement;
                var name         = rootElement.GetChildElementText(NameElementName) ?? file;
                var passwordHash = rootElement.GetChildElementText(PasswordHashElementName);
                profile           = new Profile(id, name, passwordHash);
                profile.WorldName = rootElement.GetChildElementText(WorldElemenName);

                var      activeData = rootElement.GetChildElementText(LastActiveElementName);
                DateTime lastActive;
                if (!string.IsNullOrEmpty(activeData) &&
                    DateTime.TryParse(activeData, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out lastActive))
                {
                    profile.LastActive = lastActive;
                }
                else
                {
                    profile.LastActive = DateTime.MinValue;
                }
            }

            return(profile);
        }
 /// <summary>
 /// Public constructor used for dependencies injection
 /// </summary>
 /// <param name="rssSourcesProvider">RSS Sources prodiver instance</param>
 /// <param name="newsProvider">New provider instance</param>
 /// <param name="storage">Storage provider instance</param>
 /// <param name="parser">Parser provider instance</param>
 public SourcesController(IRssSourcesProvider rssSourcesProvider, INewsProvider newsProvider,
     IContentStorage storage, IParserProvider parser)
 {
     _rssSourcesProvider = rssSourcesProvider;
     _newsProvider = newsProvider;
     _contentStorage = storage;
     _newsParser = parser;
 }
        protected BaseCloudProvider(IContentStorage storage, AzureStorageConfiguration configuration)
        {
            Ensure.That(storage).IsNotNull();
            Ensure.That(configuration).IsNotNull();

            Storage       = storage;
            Configuration = configuration;
        }
Beispiel #5
0
 public TempContentStorage(
     IOptions <TempContentStorageOptions> options,
     IContentStorage contentStorage,
     ILogger <TempContentStorage> logger)
 {
     this.contentStorage = contentStorage ?? throw new ArgumentNullException(nameof(contentStorage));
     this.logger         = logger ?? throw new ArgumentNullException(nameof(logger));
     this.options        = options?.Value ?? throw new ArgumentNullException(nameof(options));
 }
        public async Task InvokeAsync(
            HttpContext context,
            IContentStorage contentStore)
        {
            Guid   contentId = Guid.Parse((string)context.GetRouteValue("id"));
            string schema    = (string)context.GetRouteValue("schema");

            await contentStore.PublishAsync(schema, contentId);
        }
 public MessageService(
     IUnitOfWork unitOfWork,
     IContentStorage contentStorage,
     CloudStorageConfiguration cloudStorageConfiguration,
     AttachmentConfiguration attachmentConfiguration) : base(unitOfWork)
 {
     _contentStorage            = contentStorage;
     _cloudStorageConfiguration = cloudStorageConfiguration;
     _attachmentConfiguration   = attachmentConfiguration;
 }
 private async Task RemoveExpiredContent(IContentStorage contentStorage, CancellationToken cancellationToken)
 {
     await foreach (var page in contentStorage.GetAll(options.ContentCategory, cancellationToken))
     {
         foreach (var item in page.Where(x => x.Timestamp.Add(options.ContentSavePeriod) < DateTimeOffset.UtcNow))
         {
             await contentStorage.Delete(item.Id, options.ContentCategory, cancellationToken);
         }
     }
 }
 public ChannelService(IUnitOfWork unitOfWork,
                       IChannelMemberService channelMemberService,
                       IMemberService memberService,
                       CloudStorageConfiguration configuration,
                       IContentStorage contentStorage) : base(unitOfWork)
 {
     _channelMemberService = channelMemberService;
     _memberService        = memberService;
     _configuration        = configuration;
     _contentStorage       = contentStorage;
 }
Beispiel #10
0
 public DocumentStorage(
     IElasticClient elasticClient,
     IOptions <DocumentStorageOptions> options,
     IContentStorage contentStorage,
     ITextHighlighter textHighlighter)
 {
     this.elasticClient   = elasticClient ?? throw new ArgumentNullException(nameof(elasticClient));
     this.contentStorage  = contentStorage ?? throw new ArgumentNullException(nameof(contentStorage));
     this.textHighlighter = textHighlighter ?? throw new ArgumentNullException(nameof(textHighlighter));
     this.options         = options?.Value ?? throw new ArgumentNullException(nameof(options));
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaControllerHelper" /> class.
 /// </summary>
 /// <param name="mediaService">The media service.</param>
 /// <param name="contentStorage">The content storage.</param>
 /// <param name="tagsService">The tags service.</param>
 /// <param name="tagsSearchCacheHelper">The tags search cache helper.</param>
 public MediaControllerHelper(
     IMediaService mediaService,
     IContentStorage contentStorage,
     ITagsService tagsService,
     ITagsSearchCacheHelper tagsSearchCacheHelper
     )
 {
     this.mediaService          = mediaService;
     this.contentStorage        = contentStorage;
     this.tagsService           = tagsService;
     this.tagsSearchCacheHelper = tagsSearchCacheHelper;
 }
Beispiel #12
0
        public static XmlElement LoadXml(this IContentStorage storage, string path)
        {
            XmlElement element = null;

            if (storage.IsFileExist(path))
            {
                using (var stream = storage.OpenForRead(path))
                {
                    var document = new XmlDocument();
                    document.Load(stream);
                    element = document.DocumentElement;
                }
            }

            return(element);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectionAnswerSetsControllerHelper" /> class.
 /// </summary>
 /// <param name="selectionAnswerSetService">The selection answer set service.</param>
 /// <param name="careElementContext">The care element context.</param>
 /// <param name="contentStorage">The content storage.</param>
 /// <param name="globalSearchCacheHelper">The global search cache helper.</param>
 /// <param name="tagsSearchCacheHelper">The tags search cache helper.</param>
 /// <param name="tagsService">The tags service.</param>
 /// <param name="mediaFileHelper">The audio file helper.</param>
 public SelectionAnswerSetsControllerHelper(
     ISelectionAnswerSetService selectionAnswerSetService,
     ICareElementContext careElementContext,
     IContentStorage contentStorage,
     IGlobalSearchCacheHelper globalSearchCacheHelper,
     ITagsSearchCacheHelper tagsSearchCacheHelper,
     ITagsService tagsService,
     IMediaFileHelper mediaFileHelper
     )
 {
     this.selectionAnswerSetService = selectionAnswerSetService;
     this.careElementContext        = careElementContext;
     this.contentStorage            = contentStorage;
     this.globalSearchCacheHelper   = globalSearchCacheHelper;
     this.tagsSearchCacheHelper     = tagsSearchCacheHelper;
     this.tagsService     = tagsService;
     this.mediaFileHelper = mediaFileHelper;
 }
Beispiel #14
0
        public virtual void Start(
            IContentStorage contentStorage = null,
            IProfileStorage profileStorage = null,
            ILog log = null)
        {
            if (contentStorage == null)
            {
                contentStorage = new ContentFileStorage();
            }

            if (profileStorage == null)
            {
                profileStorage = new ProfileFileStorage(contentStorage);
            }

            var context = new GameContext();

            this.Context = context;

            context.Log            = log ?? new ConsoleLogger();
            context.ContentStorage = contentStorage;
            context.ProfileStorage = profileStorage;
            context.Settings       = new GameSettings(contentStorage, log);
            context.ColorManager   = new ColorManager();
            context.LocaleManager  = new LocaleManager(this.Context.Settings.DefaultLocale);
            context.TypeManager    = new TypeManager(contentStorage);

            // Load resource collection
            ResourceCollection.LoadResources(context);

            context.RoomManager = new RoomManager(context);
            var worldManager = new WorldManager(context.Settings.LoginWorldName, context.Settings.StartWorldName);

            this.RegisterWorlds(worldManager, context);
            context.WorldManager          = worldManager;
            context.ActionableItemManager = new ActionableObjectManager();

            profileStorage.Init(context);
            this.StopEvent = new ManualResetEventSlim(false);
            this.thread    = new Thread(RunGame);
            this.thread.Start(this);
        }
        public async Task InvokeAsync(
            HttpContext context,
            IContentStorage contentStore,
            JsonService jsonService)
        {
            RestContentItem input = await jsonService.Deserialize <RestContentItem>(context.Request.Body);

            ContentItem model = input.ToModel();

            await contentStore.UpdateAsync(model);

            ResourceCreated result = new ResourceCreated()
            {
                Id = input.Id
            };

            string json = jsonService.Serialize(result);

            await context.Response.WriteAsync(json);
        }
        public async Task InvokeAsync(
            HttpContext context,
            IContentStorage contentStore,
            ISchemaStorage schemaStorage,
            JsonService jsonService)
        {
            Guid   contentId = Guid.Parse((string)context.GetRouteValue("id"));
            string schema    = (string)context.GetRouteValue("schema");

            ContentItem result = await contentStore.GetContentItemAsync(schema, contentId);

            ContentSchema schemaModel = await schemaStorage.GetContentSchemaAsync(schema);

            result.ApplySchema(schemaModel);

            RestContentItem restModel = result.ToRest();

            string json = jsonService.Serialize(restModel);

            await context.Response.WriteAsync(json);
        }
Beispiel #17
0
        private void LoadRoomsFromMapFolder(
            IContentStorage storage,
            string folder,
            IGameContext context,
            bool inDesign,
            object syncObject,
            IList <RoomData> dataToProcess)
        {
            var files = storage.GetFiles(folder);

            if ((files != null) && (files.Count > 0))
            {
                Parallel.For(
                    0,
                    files.Count,
                    index =>
                {
                    var path = storage.CombinePath(folder, files[index]);
                    LoadRoomsFromMapFile(storage, path, syncObject, context, inDesign, dataToProcess);
                });
            }
        }
Beispiel #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameSettingsData" /> class.
        /// </summary>
        public GameSettings(IContentStorage storage, ILog log, string filename = DefaultSettingsFilename)
        {
            if (!storage.IsFileExist(filename))
            {
                // TODO: Write error. Settings file does not exist
                return;
            }

            var rootElement = storage.LoadXml(filename);

            this.DefaultLocale  = rootElement.GetChildElementText(LocaleElementName);
            this.HeartBeat      = rootElement.GetChildElementValue <int>(HeartBeatElementName, 500);
            this.LineSpace      = Math.Max(1, rootElement.GetChildElementValue <int>(LineSpaceElementName, 1));
            this.LoginWorldName = rootElement.GetChildElementText(LoginWorldElementName);
            this.StartWorldName = rootElement.GetChildElementText(StartWorldElementName);

            this.PlayerProfileFolder = DefaultPlayerProfileFolder;
            this.PlayerDataFolder    = DefaultPlayerDataFolder;
            this.MapDataFolder       = DefaultMapDataFolder;
            this.MapDesignFolder     = DefaultMapDesignFolder;
            this.WorldDataFolder     = DefaultWorldDataFolder;
            this.SetFolders(rootElement.SelectSingleNode(FolderRootElementName) as XmlElement, log);
            this.LoadWorldConfigurations(rootElement.SelectSingleNode(WorldRootElementName) as XmlElement, log);
        }
Beispiel #19
0
 public FileController(ILogger logger, CloudStorageConfiguration storageConfiguration, IContentStorage contentStorage) : base(logger)
 {
     _storageConfiguration = storageConfiguration;
     _contentStorage       = contentStorage;
 }
Beispiel #20
0
        public static XmlElement LoadXml(this IContentStorage storage, string folder, string file)
        {
            var path = string.IsNullOrEmpty(folder) ? file : storage.CombinePath(folder, file);

            return(storage.LoadXml(path));
        }
 public ContentCacheLoader(IContentStorage storage, IWebLoader webLoader)
 {
     Storage   = storage;
     WebLoader = webLoader;
 }
Beispiel #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TypeManager" /> class.
 /// </summary>
 /// <param name="storage">content storage</param>
 /// <param name="typeFilename">type XML file path</param>
 public TypeManager(IContentStorage storage, string typeFilename = DefaultTypeFilename)
     : this(storage.LoadXml(typeFilename))
 {
 }
Beispiel #23
0
 public QuestionAdminService(IUnitOfWork unitOfWork, IAnswerAdminService answerAdminService, IContentStorage contentStorage) : base(unitOfWork)
 {
     _answerAdminService = answerAdminService;
     _contentStorage     = contentStorage;
 }
Beispiel #24
0
        private void LoadRoomsFromMapFile(
            IContentStorage storage,
            string path,
            object syncObject,
            IGameContext context,
            bool inDesign,
            IList <RoomData> dataToProcess)
        {
            XmlElement rootElement = storage.LoadXml(path);
            string     areaName    = rootElement.GetAttribute(AreaNameAttributeName);

            if (string.IsNullOrWhiteSpace(areaName))
            {
                // TODO: write log. area name is required
                return;
            }

            Area area;

            lock (syncObject)
            {
                if (!this.areas.TryGetValue(areaName, out area))
                {
                    area = new Area(areaName);
                    this.areas.Add(areaName, area);
                }
            }

            foreach (XmlElement roomElement in rootElement.SelectNodes(RoomElementName))
            {
                string roomName = roomElement.GetAttribute(RoomNameAttributeName);
                if (string.IsNullOrWhiteSpace(roomName))
                {
                    // TODO: write error. room name is required
                    continue;
                }

                roomName = roomName.Trim();

                IRoom room        = null;
                var   typeElement = roomElement.SelectSingleNode(TypeElementName) as XmlElement;
                if (typeElement != null)
                {
                    room = RuntimeUtility.CreateInstance <IRoom>(typeElement, context.TypeManager, context.Log);
                }

                if (room == null)
                {
                    room = new Room();
                }

                var fullName = GetRoomFullName(areaName, roomName);
                var roomData = new RoomData
                {
                    Name     = roomName,
                    Area     = area,
                    InDesign = inDesign,
                    Data     = roomElement
                };

                lock (syncObject)
                {
                    if (area.Rooms.ContainsKey(roomName))
                    {
                        // TODO: write error
                    }
                    else
                    {
                        area.Rooms.Add(roomName, room);
                        rooms.Add(fullName, room);
                        dataToProcess.Add(roomData);
                    }
                }
            }
        }
Beispiel #25
0
 public static async Task UnpublishAsync <TContentType>(this IContentStorage storage, Guid id)
     where TContentType : class
 {
 }
Beispiel #26
0
 /// <summary>
 ///     Public constructor used for dependency injection
 /// </summary>
 /// <param name="storage"></param>
 public ParserProvider(IContentStorage storage)
 {
     _storage = storage;
 }
 public CloudAttachmentProvider(IContentStorage storage, AzureStorageConfiguration configuration)
     : base(storage, configuration)
 {
 }
Beispiel #28
0
 public DbStoryRunner(IContentProvider contentProvider, IContentStorage contentStorage, ISourceControl versioning)
 {
     this.contentProvider = contentProvider;
     this.contentStorage = contentStorage;
     this.versioning = versioning;
 }
Beispiel #29
0
 public EntitiesStorage(IContentStorage contentStorage)
 {
     this._contentStorage = contentStorage;
 }
 public CloudTokenProvider(IContentStorage contentStorage, AzureStorageConfiguration storageConfiguration)
     : base(contentStorage, storageConfiguration)
 {
 }
Beispiel #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaFileHelper" /> class.
 /// </summary>
 /// <param name="contentStorage">The content storage.</param>
 /// <param name="tagsService">The tags service.</param>
 public MediaFileHelper(IContentStorage contentStorage, ITagsService tagsService)
 {
     this.contentStorage = contentStorage;
     this.tagsService    = tagsService;
 }
 public AzureCloudStorageIntegrationTest()
 {
     _contentStorage = new AzureCloudStorage(_cloudStorageConnectionString);
 }
Beispiel #33
0
 public static async Task UpdateAsync <TContentType>(this IContentStorage storage, TContentType entity)
     where TContentType : class
 {
 }
Beispiel #34
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public RssProvider()
 {
     _httpClient = new HttpClient();
     var kernel = NinjectWebCommon.Kernel;
     _contentStorage = kernel.Get<IContentStorage>(); // direct ise of dependency injection
 }