public int export() { Console.WriteLine("Export process started, executable dir: " + ExportUtils.getExecutableDir() + ", server URL: " + ExportConstants.SERVER_BASE_URL); // TODO: Check server connection // Upload video files to server bool result = uploader.upload(ExportConstants.SERVER_USER, ExportConstants.SERVER_PWD); // TODO upload files with clips only Console.WriteLine("Uploaded videos to server"); // Get SVX model from database Svx svx = provider.provide(); Console.WriteLine("Retrieved meta-data"); // Convert SVX model into XML and write to stream MemoryStream stream = new MemoryStream(); marshaller.marshal(svx, stream); Console.WriteLine("Created meta-data exchange stream"); // Send XML stream as request to server string status = uploader.sendSvx(stream.ToArray(), ExportConstants.APP_USER, ExportConstants.APP_PWD); Console.WriteLine("Sent meta-data to server - Done"); return(ExportConstants.RESULT_SUCCESS); }
public Svx provide() { Svx svx = new Svx(); CommandWrapper cw = new CommandWrapper().init(); // Loading Events / MatchInfo string eventSql = "select MatchInfo.Date as date_, MatchInfo.Place as location, TC1.TeamCode as homeTeam, TC2.TeamCode as awayTeam " + "from (MatchInfo left join TeamCode TC1 on MatchInfo.HomeTeamNumb=TC1.TeamIndex) " + "left join TeamCode TC2 on MatchInfo.AwayTeamNumb=TC2.TeamIndex"; OleDbDataReader eventReader = cw.getReader(eventSql); while (eventReader.Read()) { Event event_ = new Event(); event_.Date = eventReader["date_"] != DBNull.Value ? Convert.ToDateTime(eventReader["date_"]).ToString(ExportConstants.DATE_FORMAT) : ""; event_.Location = Convert.ToString(eventReader["location"]); event_.HomeTeam = Convert.ToString(eventReader["homeTeam"]); event_.AwayTeam = Convert.ToString(eventReader["awayTeam"]); svx.Event = event_; continue; } // Loading Clips / MatchAnalyse // Using modulus on the values in the variable columns in MatchAnalysis to remove insignificant digits as only the last is relevant string clipSql = "select MatchAnalyse.RecordFrameStart as start, TeamCode.TeamCode as team, MatchAnalyse.VideoFileName as filename, " + "PlayerCode.PlayerCode as person, " + "(select GroupVariablesCode.VariableCode from GroupVariablesCode " + "where GroupVariablesCode.VariableGroup=1 and (MatchAnalyse.PlayStart mod 10)=GroupVariablesCode.VariablePosition) as playStart, " + "(select GroupVariablesCode.VariableCode from GroupVariablesCode " + "where GroupVariablesCode.VariableGroup=2 and (MatchAnalyse.PlayPhase mod 10)=GroupVariablesCode.VariablePosition) as playPhase, " + "(select GroupVariablesCode.VariableCode from GroupVariablesCode " + "where GroupVariablesCode.VariableGroup=3 and (MatchAnalyse.MVar1 mod 10)=GroupVariablesCode.VariablePosition) as freeVar, " + "(select GroupVariablesCode.VariableCode from GroupVariablesCode " + "where GroupVariablesCode.VariableGroup=0 and MatchAnalyse.MVar2=GroupVariablesCode.VariablePosition) as freeVar2, " + "(select GroupVariablesCode.VariableCode from GroupVariablesCode " + "where GroupVariablesCode.VariableGroup=4 and (MatchAnalyse.Chance mod 10)=GroupVariablesCode.VariablePosition) as chance, " + "(select GroupVariablesCode.VariableCode from GroupVariablesCode " + "where GroupVariablesCode.VariableGroup=5 and (MatchAnalyse.Grade mod 10)=GroupVariablesCode.VariablePosition) as grade " + "from (MatchAnalyse left join TeamCode on MatchAnalyse.TeamIndex=TeamCode.TeamIndex) " + "left join PlayerCode on MatchAnalyse.PlayerIndexPosFrom=PlayerCode.PlayerIndex"; OleDbDataReader clipReader = cw.getReader(clipSql); while (clipReader.Read()) { Clip clip = new Clip(); clip.Start = Math.Abs(Convert.ToInt32(clipReader["start"] != null ? clipReader["start"] : 0) / ExportConstants.FRAMES_PER_SEC); clip.Team = Convert.ToString(clipReader["team"]); clip.Filename = Convert.ToString(clipReader["filename"] != null ? clipReader["filename"] : "").Trim(); clip.addCategory(Convert.ToString(clipReader["playStart"])); clip.addCategory(Convert.ToString(clipReader["playPhase"])); clip.addCategory(Convert.ToString(clipReader["freeVar"])); clip.addCategory(Convert.ToString(clipReader["freeVar2"])); clip.addCategory(Convert.ToString(clipReader["chance"])); clip.addCategory(Convert.ToString(clipReader["grade"])); clip.addPerson(Convert.ToString(clipReader["person"])); svx.addClip(clip); } cw.close(); return(svx); }
public void marshal(Svx svx, MemoryStream stream) { //XmlWriter writer = new XmlTextWriter(ExportUtils.getExecutableDir() + ExportConstants.DEBUG_FILENAME, null); // For debugging XmlWriter writer = new XmlTextWriter(stream, null); writer.WriteStartDocument(); writer.WriteStartElement("svx"); writer.WriteAttributeString("xmlns", ExportConstants.XMLNS); writer.WriteAttributeString("xmlns:xsi", ExportConstants.XSI); writer.WriteAttributeString("xsi:schemaLocation", ExportConstants.XSI_LOCATION); // Event Event event_ = svx.Event; writer.WriteStartElement("event"); writer.WriteAttributeString("date", event_.Date); writer.WriteAttributeString("location", event_.Location); writer.WriteAttributeString("homeTeam", event_.HomeTeam); writer.WriteAttributeString("awayTeam", event_.AwayTeam); writer.WriteEndElement(); // Clips writer.WriteStartElement("clips"); foreach (Clip clip in svx.Clips) { writer.WriteStartElement("clip"); writer.WriteAttributeString("start", Convert.ToString(clip.Start)); writer.WriteAttributeString("team", clip.Team); writer.WriteAttributeString("filename", clip.Filename); if (clip.Categories != null && clip.Categories.Count > 0) { writer.WriteStartElement("categories"); foreach (string category in clip.Categories) { writer.WriteStartElement("category"); writer.WriteString(category); writer.WriteEndElement(); } writer.WriteEndElement(); } if (clip.Persons != null && clip.Persons.Count > 0) { writer.WriteStartElement("persons"); foreach (string person in clip.Persons) { writer.WriteStartElement("person"); writer.WriteString(person); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }