Exemple #1
0
        public async Task <IActionResult> Create(CreateSessionFolderDTO model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var sessionMainExists = await _sessionContext.SessionMains.AnyAsync(sm => sm.Id == model.SessionMainId);

            if (!sessionMainExists)
            {
                return(BadRequest("Session main does not exist"));
            }

            var sessionFolder = new SessionFolder()
            {
                FolderName   = model.FolderName,
                FSessionMain = model.SessionMainId
            };

            try
            {
                await _sessionContext.SessionFolders.AddAsync(sessionFolder);

                await _sessionContext.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
        // ====================================================================================================
        #region Sessions Disk & Menu

        void GetSessionDataFromDisk()
        {
            mainLogFolder   = SettingsManager.Values.logSettings.mainLogFolder;
            sessionFilename = SettingsManager.Values.logSettings.sessionJsonFilename;
            // Folders with available sessions
            string[] dirs = Directory.GetDirectories(mainLogFolder);

            // Temp variables for string processing
            int    rootLength = mainLogFolder.Length;
            string dirName    = ""; // Variable to store the dirname without full path.

            string[] dirNameParts;  // Separate between date and sessionId
            string[] sessionFiles;

            // Copy predefined sessioncolor options
            sessionColors.AddRange(VisualStyle.SessionsColorTable);
            int sessionCounter = -1;

            foreach (string dir in dirs)
            {
                // Extract folder name without whole path
                dirName = dir.Substring(rootLength);

                // Check if the folder has a valid file with a sessionFilename
                sessionFiles = Directory.GetFiles(dir, sessionFilename, SearchOption.TopDirectoryOnly);

                if (sessionFiles.Length == 1) // There should be only one session file per folder
                {
                    // Process the folder
                    dirNameParts = dirName.Split('_');

                    // Every session data gets a unique key
                    sessionCounter++;

                    // Make a session and define a color for it
                    int         sessionColorIndex = UnityEngine.Random.Range(0, sessionColors.Count);
                    SessionData newSession        = new SessionData(sessionColors[sessionColorIndex], sessionCounter);
                    sessionColors.RemoveAt(sessionColorIndex);
                    if (sessionColors.Count == 0)
                    {
                        sessionColors.AddRange(VisualStyle.SessionsColorTable);
                    }

                    // Add folder info
                    SessionFolder newSessionFolder = new SessionFolder();
                    newSessionFolder.sessionFilepath = sessionFiles[0];         // Full path to json file
                    newSessionFolder.folderPath      = dir;                     // Full path to session folder
                    newSessionFolder.datetime        = DateTime.ParseExact(dirNameParts[0], ExciteOMeterManager.GetFormatTimestampDateTime(), System.Globalization.CultureInfo.InvariantCulture);
                    newSessionFolder.sessionId       = dirName.Substring(dirNameParts[0].Length + 1);
                    newSession.sessionFolder         = newSessionFolder;

                    // Add to list of sessions
                    sessions.Add(newSession);
                }
                else
                {
                    // Move to the next folder and avoid processing this folder
                    Debug.Log("Skipping folder " + dirName + " because session filename " + sessionFilename + " was not found.");
                }
            }
        }