// Shamelessly copy pasted from the XDAWaveFormDataParser // Thanks other Stephen private void ParseSELEVE() { try { // Parse event file EventFile parsedFile = EventFile.Parse(m_currentFilePath); // Convert to common channel format if (parsedFile.EventReports.Count > 0) { m_channels = parsedFile.EventReports .SelectMany(report => report.AnalogSection.AnalogChannels.Select(channel => MakeParsedChannel(report, channel))) .ToList(); } else if (parsedFile.CommaSeparatedEventReports.Count > 0) { m_channels = parsedFile.CommaSeparatedEventReports .SelectMany(report => report.AnalogSection.AnalogChannels.Select(channel => MakeParsedChannel(report, channel))) .ToList(); } } catch (Exception e) { e.Source = m_currentFileRootName; ExceptionList.Add(e); } }
public IHttpActionResult Post([FromBody] CreateEventAgendaModel model) { var agenda = new EventAgenda { AgendaTitle = model.AgendaTitle, AgendaDescription = model.AgendaDescription, Tentative = model.Tentative, Time = model.Time, EventId = model.EventId, PersonInChargeId = model.PersonInChargeId, CreatedBy = null, Display = true, CreatedDate = DateTime.Now, }; db.EventAgenda.Add(agenda); db.SaveChanges(); //files foreach (var fileid in model.FilesId) { var eventfile = new EventFile { FileCategory = EventFileCategory.EventAgenda, FileId = fileid, ParentId = agenda.Id }; db.EventFile.Add(eventfile); } return(Ok(agenda.Id)); }
public IHttpActionResult Post([FromBody] CreateEventSpeakerModel model) { var speaker = new EventSpeaker { UserId = model.UserId, SpeakerType = model.SpeakerType, Experience = model.Experience, SpeakerStatus = model.SpeakerStatus, CreatedBy = null, Display = true, CreatedDate = DateTime.Now, Thumbnail = model.ThumbnailUrl, }; db.EventSpeaker.Add(speaker); db.SaveChanges(); //files foreach (var fileid in model.FilesId) { var eventfile = new EventFile { FileCategory = EventFileCategory.EventSpeaker, FileId = fileid, ParentId = speaker.Id }; db.EventFile.Add(eventfile); } db.SaveChanges(); return(Ok(speaker.Id)); }
private void SELEVEButton_Click(object sender, EventArgs e) { EventFile parsedFile; using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = "SEL Event Files|*.eve;*.sel;*.cev;|Text Files|*.txt|All Files|*.*"; dialog.Title = "Browse SEL Event Files"; if (dialog.ShowDialog() == DialogResult.Cancel) { return; } if (!File.Exists(dialog.FileName)) { return; } // Parse event file parsedFile = EventFile.Parse(dialog.FileName); // Convert to common channel format if (parsedFile.EventReports.Count > 0) { m_channels = parsedFile.EventReports .SelectMany(report => report.AnalogSection.AnalogChannels.Select(channel => MakeParsedChannel(report, channel))) .ToList(); } else if (parsedFile.CommaSeparatedEventReports.Count > 0) { m_channels = parsedFile.CommaSeparatedEventReports .SelectMany(report => report.AnalogSection.AnalogChannels.Select(channel => MakeParsedChannel(report, channel))) .ToList(); } else { m_channels = null; } // Clear the list box and data chart ChannelListBox.Items.Clear(); DataChart.Series.Clear(); // Populate the list box with channel names ChannelListBox.Items.AddRange(m_channels .Select((channel, index) => string.Format("[{0}] {1}", index, channel.Name)) .Cast <object>() .ToArray()); // Select the first channel in the list ChannelListBox.SelectedIndex = 0; // Change the title text of the window to show what file the user has open m_fileName = dialog.SafeFileName; Text = string.Format("SEL EVE - [{0}]", dialog.SafeFileName); } }
/// <summary> /// Parses the file into a meter data set per meter contained in the file. /// </summary> /// <param name="filePath">The path to the file to be parsed.</param> /// <returns>List of meter data sets, one per meter.</returns> public void Parse(string filePath) { Channel channel; DataSeries series; List <DateTime> timeSamples; List <double> valueSamples; if ((object)m_eventFile == null) { m_eventFile = EventFile.Parse(filePath); } if (!m_eventFile.EventReports.Any()) { return; } m_meterDataSet.Meter = new Meter(); m_meterDataSet.Meter.AssetKey = m_eventFile.EventReports[0].Header.RelayID; m_meterDataSet.Meter.Name = m_eventFile.EventReports[0].Header.RelayID; m_meterDataSet.Meter.ShortName = new string(m_eventFile.EventReports[0].Header.RelayID.ToNonNullString().Take(50).ToArray()); m_meterDataSet.Meter.MeterLocation = new MeterLocation(); m_meterDataSet.Meter.MeterLocation.AssetKey = m_eventFile.EventReports[0].Header.StationID; m_meterDataSet.Meter.MeterLocation.Name = m_eventFile.EventReports[0].Header.StationID; m_meterDataSet.Meter.MeterLocation.ShortName = new string(m_eventFile.EventReports[0].Header.StationID.ToNonNullString().Take(50).ToArray()); m_meterDataSet.Meter.MeterLocation.Description = m_eventFile.EventReports[0].Header.StationID; foreach (EventReport report in m_eventFile.EventReports) { for (int i = 0; i < report.AnalogSection.AnalogChannels.Count; i++) { channel = MakeParsedChannel(report, i); series = new DataSeries(); timeSamples = report.AnalogSection.TimeChannel.Samples; valueSamples = report.AnalogSection.AnalogChannels[i].Samples; series.SeriesInfo = channel.Series[0]; series.DataPoints = timeSamples .Zip(valueSamples, (time, value) => new DataPoint() { Time = time, Value = value }) .ToList(); if (new string[] { "VA", "VB", "VC" }.Contains(report.AnalogSection.AnalogChannels[i].Name)) { m_meterDataSet.DataSeries.Add(series.Multiply(1000.0)); } else { m_meterDataSet.DataSeries.Add(series); } } } }
/// <summary> /// Determines whether the file can be parsed at this time. /// </summary> /// <param name="filePath">The path to the file to be parsed.</param> /// <param name="fileCreationTime">The time the file was created.</param> /// <returns>True if the file can be parsed; false otherwise.</returns> public bool CanParse(string filePath, DateTime fileCreationTime) { try { m_eventFile = EventFile.Parse(filePath, SystemFrequency, MaxFileDuration); return(true); } catch (IOException) { return(false); } }
public static EventFileDto ToDto(this EventFile sourc) { return(new EventFileDto { CountDownload = sourc.CountDownload, FileName = sourc.FileName, Id = sourc.Id, Length = sourc.Length, Title = sourc.Title, Type = sourc.Type }); }
/// <summary> /// Parses the file into a meter data set per meter contained in the file. /// </summary> /// <param name="filePath">The path to the file to be parsed.</param> /// <returns>List of meter data sets, one per meter.</returns> public void Parse(string filePath) { if ((object)m_eventFile == null) { m_eventFile = EventFile.Parse(filePath, SystemFrequency, MaxFileDuration); } if (!m_eventFile.EventReports.Any() && !m_eventFile.CommaSeparatedEventReports.Any()) { return; } Header header = m_eventFile.EventReports.FirstOrDefault()?.Header ?? m_eventFile.CommaSeparatedEventReports[0].Header; Meter meter = new Meter(); meter.MeterLocation = new MeterLocation(); meter.Channels = new List <Channel>(); meter.AssetKey = header.RelayID; meter.Name = header.RelayID; meter.ShortName = new string(header.RelayID.ToNonNullString().Take(50).ToArray()); MeterLocation meterLocation = meter.MeterLocation; meterLocation.Meters = new List <Meter>() { meter }; meterLocation.AssetKey = header.StationID; meterLocation.Name = header.StationID; meterLocation.ShortName = new string(header.StationID.ToNonNullString().Take(50).ToArray()); meterLocation.Description = header.StationID; foreach (EventReport report in m_eventFile.EventReports) { for (int i = 0; i < report.AnalogSection.AnalogChannels.Count; i++) { Channel channel = MakeParsedAnalog(report, i); channel.Meter = meter; meter.Channels.Add(channel); List <DateTime> timeSamples = report.AnalogSection.TimeChannel.Samples; List <double> valueSamples = report.AnalogSection.AnalogChannels[i].Samples; DataSeries dataSeries = new DataSeries(); dataSeries.DataPoints = timeSamples .Zip(valueSamples, (time, value) => new DataPoint() { Time = time, Value = value }) .ToList(); if (new string[] { "VA", "VB", "VC", "VS" }.Contains(report.AnalogSection.AnalogChannels[i].Name)) { dataSeries = dataSeries.Multiply(1000.0D); } dataSeries.SeriesInfo = channel.Series[0]; m_meterDataSet.DataSeries.Add(dataSeries); } for (int i = 0; i < report.AnalogSection.DigitalChannels.Count; i++) { Channel channel = MakeParsedDigital(report, i); if (channel.Name == "*") { continue; } channel.Meter = meter; meter.Channels.Add(channel); List <DateTime> timeSamples = report.AnalogSection.TimeChannel.Samples; List <bool?> digitalSamples = report.AnalogSection.DigitalChannels[i].Samples; DataSeries dataSeries = new DataSeries(); dataSeries.SeriesInfo = channel.Series[0]; dataSeries.DataPoints = timeSamples .Zip(digitalSamples, (time, value) => new { Time = time, Value = value }) .Where(x => x.Value != null) .Select(x => new DataPoint { Time = x.Time, Value = Convert.ToDouble(x.Value) }) .ToList(); m_meterDataSet.Digitals.Add(dataSeries); } ComplexNumber z1 = new ComplexNumber(0.0D, 0.0D); ComplexNumber z0 = new ComplexNumber(0.0D, 0.0D); double groupSetting; if (double.TryParse(report.GetGroupSettings("Z1MAG"), out groupSetting)) { z1.Magnitude = groupSetting; } if (double.TryParse(report.GetGroupSettings("Z1ANG"), out groupSetting)) { z1.Angle = Angle.FromDegrees(groupSetting); } if (double.TryParse(report.GetGroupSettings("Z0MAG"), out groupSetting)) { z0.Magnitude = groupSetting; } if (double.TryParse(report.GetGroupSettings("Z0ANG"), out groupSetting)) { z0.Angle = Angle.FromDegrees(groupSetting); } if (z1 != z0) { m_meterDataSet.Configuration.R1 = z1.Real; m_meterDataSet.Configuration.X1 = z1.Imaginary; m_meterDataSet.Configuration.R0 = z0.Real; m_meterDataSet.Configuration.X0 = z0.Imaginary; if (double.TryParse(report.GetGroupSettings("LL"), out groupSetting)) { m_meterDataSet.Configuration.LineLength = groupSetting; } } } foreach (CommaSeparatedEventReport report in m_eventFile.CommaSeparatedEventReports) { for (int i = 0; i < report.AnalogSection.AnalogChannels.Count; i++) { Channel channel = MakeParsedAnalog(report, i); channel.Meter = meter; meter.Channels.Add(channel); List <DateTime> timeSamples = report.AnalogSection.TimeChannel.Samples; List <double> valueSamples = report.AnalogSection.AnalogChannels[i].Samples; DataSeries dataSeries = new DataSeries(); dataSeries.DataPoints = timeSamples .Zip(valueSamples, (time, value) => new DataPoint() { Time = time, Value = value }) .ToList(); dataSeries.SeriesInfo = channel.Series[0]; m_meterDataSet.DataSeries.Add(dataSeries); } for (int i = 0; i < report.AnalogSection.DigitalChannels.Count; i++) { Channel channel = MakeParsedDigital(report, i); if (channel.Name == "*") { continue; } channel.Meter = meter; meter.Channels.Add(channel); List <DateTime> timeSamples = report.AnalogSection.TimeChannel.Samples; List <bool?> digitalSamples = report.AnalogSection.DigitalChannels[i].Samples; DataSeries dataSeries = new DataSeries(); dataSeries.SeriesInfo = channel.Series[0]; dataSeries.DataPoints = timeSamples .Zip(digitalSamples, (time, value) => new { Time = time, Value = value }) .Where(x => x.Value != null) .Select(x => new DataPoint { Time = x.Time, Value = Convert.ToDouble(x.Value) }) .ToList(); m_meterDataSet.Digitals.Add(dataSeries); } } m_meterDataSet.Meter = meter; }
//Edit public IHttpActionResult Put(int id, [FromBody] EditEventAgendaModel model) { var agenda = db.EventAgenda.Where(u => u.Id == id).FirstOrDefault(); if (agenda == null) { return(NotFound()); } agenda.AgendaTitle = model.AgendaTitle; agenda.AgendaDescription = model.AgendaDescription; agenda.Tentative = model.Tentative; agenda.Time = model.Time; agenda.EventId = model.EventId; agenda.PersonInChargeId = model.PersonInChargeId; db.Entry(agenda).State = EntityState.Modified; db.Entry(agenda).Property(x => x.Display).IsModified = false; //remove file var attachments = db.EventFile.Where(s => s.FileCategory == EventFileCategory.EventAgenda && s.ParentId == model.Id).ToList(); if (attachments != null) { //delete all if (model.Attachments == null) { foreach (var attachment in attachments) { attachment.FileDocument.Display = false; db.FileDocument.Attach(attachment.FileDocument); db.Entry(attachment.FileDocument).Property(m => m.Display).IsModified = true; db.EventFile.Remove(attachment); } } else { foreach (var attachment in attachments) { if (!model.Attachments.Any(u => u.Id == attachment.FileDocument.Id)) //delete if not exist anymore { attachment.FileDocument.Display = false; db.FileDocument.Attach(attachment.FileDocument); db.Entry(attachment.FileDocument).Property(m => m.Display).IsModified = true; db.EventFile.Remove(attachment); } } } } //add new file //files foreach (var fileid in model.FilesId) { var eventfile = new EventFile { FileCategory = EventFileCategory.EventAgenda, FileId = fileid, ParentId = agenda.Id }; db.EventFile.Add(eventfile); } db.Configuration.ValidateOnSaveEnabled = true; db.SaveChanges(); return(Ok(true)); }
public IHttpActionResult Put(int id, [FromBody] EditEventSpeakerModel model) { var speaker = db.EventSpeaker.Where(u => u.Id == id).FirstOrDefault(); if (speaker == null) { return(NotFound()); } speaker.UserId = model.UserId; speaker.SpeakerType = model.SpeakerType; speaker.Experience = model.Experience; speaker.SpeakerStatus = model.SpeakerStatus; db.EventSpeaker.Attach(speaker); db.Entry(speaker).Property(x => x.UserId).IsModified = true; db.Entry(speaker).Property(x => x.SpeakerType).IsModified = true; db.Entry(speaker).Property(x => x.Experience).IsModified = true; db.Entry(speaker).Property(x => x.SpeakerStatus).IsModified = true; db.Entry(speaker).Property(x => x.Display).IsModified = false; db.Entry(speaker).Property(x => x.Id).IsModified = false; //remove file var attachments = db.EventFile.Where(s => s.FileCategory == EventFileCategory.EventSpeaker && s.ParentId == model.Id).ToList(); if (attachments != null) { //delete all if (model.Attachments == null) { foreach (var attachment in attachments) { attachment.FileDocument.Display = false; db.FileDocument.Attach(attachment.FileDocument); db.Entry(attachment.FileDocument).Property(m => m.Display).IsModified = true; db.EventFile.Remove(attachment); } } else { foreach (var attachment in attachments) { if (!model.Attachments.Any(u => u.Id == attachment.FileDocument.Id)) //delete if not exist anymore { attachment.FileDocument.Display = false; db.FileDocument.Attach(attachment.FileDocument); db.Entry(attachment.FileDocument).Property(m => m.Display).IsModified = true; db.EventFile.Remove(attachment); } } } } //add files foreach (var fileid in model.FilesId) { var eventfile = new EventFile { FileCategory = EventFileCategory.EventSpeaker, FileId = fileid, ParentId = speaker.Id }; db.EventFile.Add(eventfile); } db.Configuration.ValidateOnSaveEnabled = true; db.SaveChanges(); return(Ok(true)); }
//Edit public IHttpActionResult Put(int id, [FromBody] EditMediaInterviewRequestApiModel model) { var media = db.EventMediaInterviewRequest.Where(u => u.Id == id).FirstOrDefault(); if (media == null) { return(NotFound()); } media.MediaName = model.MediaName; media.MediaType = model.MediaType; media.ContactPerson = model.ContactPerson; media.ContactNo = model.ContactNo; media.AddressStreet1 = model.AddressStreet1; media.AddressStreet2 = model.AddressStreet2; media.AddressPoscode = model.AddressPoscode; media.AddressCity = model.AddressCity; media.State = model.State; media.Email = model.Email; media.DateStart = model.DateStart; media.DateEnd = model.DateEnd; media.Time = model.Time; media.Language = model.Language; media.Topic = model.Topic; media.MediaStatus = model.MediaStatus; media.RefNo = model.RefNo; media.BranchId = model.BranchId; db.Entry(media).State = EntityState.Modified; db.Entry(media).Property(x => x.CreatedDate).IsModified = false; db.Entry(media).Property(x => x.Display).IsModified = false; db.MediaRepresentative.RemoveRange(db.MediaRepresentative.Where(u => u.MediaId == id)); //remove all foreach (var repid in model.RepUserId) { var mediarep = new MediaRepresentative { UserId = repid, MediaInterview = media, }; db.MediaRepresentative.Add(mediarep); } //remove file var attachments = db.EventFile.Where(s => s.FileCategory == EventFileCategory.MediaInterview && s.ParentId == model.Id).ToList(); if (attachments != null) { //delete all if (model.Attachments == null) { foreach (var attachment in attachments) { attachment.FileDocument.Display = false; db.FileDocument.Attach(attachment.FileDocument); db.Entry(attachment.FileDocument).Property(m => m.Display).IsModified = true; db.EventFile.Remove(attachment); } } else { foreach (var attachment in attachments) { if (!model.Attachments.Any(u => u.Id == attachment.FileDocument.Id)) //delete if not exist anymore { attachment.FileDocument.Display = false; db.FileDocument.Attach(attachment.FileDocument); db.Entry(attachment.FileDocument).Property(m => m.Display).IsModified = true; db.EventFile.Remove(attachment); } } } } //add new file //files foreach (var fileid in model.FilesId) { var eventfile = new EventFile { FileCategory = EventFileCategory.MediaInterview, FileId = fileid, ParentId = media.Id }; db.EventFile.Add(eventfile); } db.Configuration.ValidateOnSaveEnabled = true; db.SaveChanges(); return(Ok(true)); }
public IHttpActionResult Post([FromBody] CreateMediaInterviewRequestApiModel model) { var media = new EventMediaInterviewRequest { MediaName = model.MediaName, MediaType = model.MediaType, ContactPerson = model.ContactPerson, ContactNo = model.ContactNo, AddressStreet1 = model.AddressStreet1, AddressStreet2 = model.AddressStreet2, AddressPoscode = model.AddressPoscode, AddressCity = model.AddressCity, State = model.State, Email = model.Email, DateStart = model.DateStart, DateEnd = model.DateEnd, Time = model.Time, Language = model.Language, Topic = model.Topic, CreatedBy = model.CreatedBy, CreatedDate = DateTime.Now, Display = true, MediaStatus = MediaStatus.New, BranchId = model.BranchId, }; db.EventMediaInterviewRequest.Add(media); db.SaveChanges(); foreach (var repid in model.RepUserId) { var mediarep = new MediaRepresentative { UserId = repid, MediaInterview = media, }; db.MediaRepresentative.Add(mediarep); } //files foreach (var fileid in model.FilesId) { var eventfile = new EventFile { FileCategory = EventFileCategory.MediaInterview, FileId = fileid, ParentId = media.Id }; db.EventFile.Add(eventfile); } db.SaveChanges(); if (media != null) { var approval = new EventMediaInterviewApproval { MediaId = media.Id, Level = EventApprovalLevel.Verifier, ApproverId = 0, Status = EventApprovalStatus.None, ApprovedDate = DateTime.Now, Remark = "", RequireNext = false }; db.EventMediaInterviewApproval.Add(approval); } var refno = "EVT/" + DateTime.Now.ToString("yyMM"); refno += "/" + media.Id.ToString("D4"); media.RefNo = refno; db.Entry(media).State = EntityState.Modified; db.SaveChanges(); return(Ok(media.Id)); }
public void Update(EventFile EventFile) { _EventFileRepository.Update(EventFile); }
public EventFile Add(EventFile EventFile) { return(_EventFileRepository.Add(EventFile)); }