Esempio n. 1
0
        public static async void UploadSimulationInstant()
        {
            // Finding the current tick
            Tick tick = TimeManager.CurrentSimulation.ticks.Last();

            if (tick is null)
            {
                return;
            }

            // Finding the metadata to save
            string userId = "defaultUserId";

            if (!(MetadataManager.Instance is null))
            {
                userId = MetadataManager.Instance.UserId;
            }

            Metadata metadata = new Metadata(userId, tick);

            // Saving the simulation instance and preparing it to receive further data
            // regarding the elements contained within the petri dish
            SimulationInstanceViewModel simulationInstanceViewModel = metadata.ToSimulationInstance();

            int id = await SaveSimulationInstance(simulationInstanceViewModel);

            // Saving the elements data
            List <SimulationDetailViewModel> simulationDetailViewModelList = metadata.ToSimulationDetailList(id);

            SaveSimulationDetails(simulationDetailViewModelList);
        }
Esempio n. 2
0
        public SimulationInstanceViewModel ToSimulationInstance()
        {
            string userId       = MetadataManager.Instance.UserId;
            string simulationId = Tick.SimulationId;
            int    day          = Tick.Day;

            SimulationInstanceViewModel simulationInstanceViewModel = new SimulationInstanceViewModel(
                userId,
                simulationId,
                day);

            return(simulationInstanceViewModel);
        }
Esempio n. 3
0
        private static async Task <int> SaveSimulationInstance(SimulationInstanceViewModel simulationInstanceViewModel)
        {
            string json = JsonConvert.SerializeObject(simulationInstanceViewModel, Formatting.None);

            json = HttpUtility.UrlEncode(json);

            string result = await client.GetStringAsync(Config.URL_SAVE_SIMINSTANCE + json);

            int intResult;

            int.TryParse(result, out intResult);

            return(intResult);
        }