Esempio n. 1
0
        protected override async void OnMessage(MessageEventArgs e)
        {
            var rawString = e.Data;
            var request   = JsonConvert.DeserializeObject <Request <Object> >(rawString);

            switch (request.action)
            {
            case ACTION_SET_ID:
                id    = JsonConvert.DeserializeObject <Request <string> >(rawString).payload;
                Story = await Task.Factory.StartNew(() => Story.Read(GetTargetFile(id)));

                break;

            case ACTION_UPDATE_LAYOUT:

                if (Story == null)
                {
                    // fail
//                                Send();
                }
                else
                {
                    var updateRequest = JsonConvert.DeserializeObject <Request <UpdateRequest> >(rawString)
                                        .payload;
                    var storylineApp = new StorylineApp();
                    LayoutHandler.ApplyUpdateConfig(updateRequest, storylineApp);
                    await Task.Factory.StartNew(() => storylineApp.SolveStory(Story));

                    var result = await LayoutHandler.postProcess(storylineApp._relaxedPos, Story, storylineApp);

                    Send(JsonConvert.SerializeObject(result));
                }
                break;
            }
        }
Esempio n. 2
0
        public async Task <LayoutResult> handleLayout(string id)
        {
            string filePath = GetTargetFile(id);

            if (File.Exists(filePath))
            {
                var story = await Task.Factory.StartNew(() => Story.Read(filePath));

                var storylineApp = new StorylineApp();
                await Task.Factory.StartNew(() => storylineApp.SolveStory(story));

                var result = await postProcess(storylineApp._relaxedPos, story, storylineApp);

                return(result);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        public async Task <LayoutResult> updateLayout(UpdateRequest updateRequest)
        {
            string filePath = GetTargetFile(updateRequest.id);

            if (File.Exists(filePath))
            {
                var story = await Task.Factory.StartNew(() => Story.Read(filePath));

                var storylineApp = new StorylineApp();

                ApplyUpdateConfig(updateRequest, storylineApp);

                await Task.Factory.StartNew(() => storylineApp.SolveStory(story));

                var result = await postProcess(storylineApp._relaxedPos, story, storylineApp);

                return(result);
            }
            else
            {
                return(null);
            }
        }