/// <summary> /// 返回根目录 /// </summary> /// <param name="u"></param> public static void root(User u) { string tpath = ConstValue.userpath + u.GetName() + @"\file\home"; u.SetPath(LogicalParser.parse(tpath, u)); u.SetSinglePath(LogicalParser.singleParse(u)); }
// Shamelessly copy pasted from the XDAWaveFormDataParser // Thanks other Stephen private void ParsePQDIF() { try { List <ObservationRecord> observationRecords; using (OpenFileDialog dialog = new OpenFileDialog()) { // Parse PQDif File Data using (LogicalParser logicalParser = new LogicalParser(m_currentFilePath)) { observationRecords = new List <ObservationRecord>(); logicalParser.Open(); while (logicalParser.HasNextObservationRecord()) { observationRecords.Add(logicalParser.NextObservationRecord()); } } // Convert to common channel format m_channels = observationRecords .SelectMany(observation => observation.ChannelInstances) .Where(channel => channel.Definition.QuantityTypeID == QuantityType.WaveForm) .Select(MakeParsedChannel) .ToList(); } } catch (Exception e) { e.Source = m_currentFileRootName; ExceptionList.Add(e); } }
public static User GetInstance(string name) { User newUser = new User(name); newUser.SetPath(LogicalParser.parse(newUser.GetPath(), newUser)); newUser.nowSinglePath = LogicalParser.singleParse(newUser); return(newUser); }
/// <summary> /// 返回上一级目录 /// </summary> /// <param name="u"></param> public static void back(User u) { string tpath = TruepathParser.parse(u); int point = tpath.LastIndexOf(@"\"); tpath = tpath.Substring(0, point); u.SetPath(LogicalParser.parse(tpath, u)); u.SetSinglePath(LogicalParser.singleParse(u)); }
private void PQDIFButton_Click(object sender, EventArgs e) { List <ObservationRecord> observationRecords; using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = "PQDIF Files|*.pqd|All Files|*.*"; dialog.Title = "Browse PQDIF Files"; if (dialog.ShowDialog() == DialogResult.Cancel) { return; } if (!File.Exists(dialog.FileName)) { return; } // Parse PQDif File Data using (LogicalParser logicalParser = new LogicalParser(dialog.FileName)) { observationRecords = new List <ObservationRecord>(); logicalParser.Open(); while (logicalParser.HasNextObservationRecord()) { observationRecords.Add(logicalParser.NextObservationRecord()); } } // Convert to common channel format m_channels = observationRecords .SelectMany(observation => observation.ChannelInstances) .Where(channel => channel.Definition.QuantityTypeID == QuantityType.WaveForm) .Select(MakeParsedChannel) .ToList(); // 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("PQDIF - [{0}]", dialog.SafeFileName); } }
/// <summary> /// 更新索引表. /// </summary> /// <param name="u"></param> public static void Update(User u) { string[] fds = FDfiner.find(TruepathParser.parse(u)).Split('\n'); StringBuilder sb = new StringBuilder(); foreach (string fd in fds) { sb.AppendLine(LogicalParser.parse(fd, u)); } IndexTableWriter.Write(u, sb.ToString(), false); }
public IHttpActionResult Post([FromUri] string meterKey) { //string file = Request.Content.ReadAsStringAsync().Result; //byte[] bytes = System.Text.Encoding.UTF8.GetBytes(file); byte[] bytes = Request.Content.ReadAsByteArrayAsync().Result; ContainerRecord containerRecord; using (Stream stream = new MemoryStream(bytes)) using (LogicalParser parser = new LogicalParser(stream)) { containerRecord = parser.ContainerRecord; while (parser.HasNextObservationRecord()) { parser.NextObservationRecord(); } if (parser.DataSourceRecords.Count == 0) { return(BadRequest("File contained no useable channel definitions")); } IEnumerable <ChannelDefinition> channelDefinitions = parser.DataSourceRecords.First().ChannelDefinitions.Where(cd => cd.QuantityTypeID == QuantityType.WaveForm && cd.SeriesDefinitions.Where(ser => ser.QuantityCharacteristicID == QuantityCharacteristic.Instantaneous && ser.QuantityUnits != QuantityUnits.Seconds).Any() && (cd.QuantityMeasured == QuantityMeasured.Voltage || cd.QuantityMeasured == QuantityMeasured.Current)); var channels = channelDefinitions.Select((cd, index) => new { ID = index + 1, Meter = meterKey, Asset = "", MeasurementType = cd.QuantityMeasured.ToString(), MeasurementCharacteristic = "Instantaneous", Phase = cd.Phase.ToString(), Name = cd.ChannelName, SamplesPerHour = 0, PerUnitValue = 1, HarmonicGroup = 0, Description = cd.DataSource.DataSourceLocation + " - " + cd.ChannelName, Enabled = true, Adder = 0, Multiplier = 1, Series = new [] { new { ID = 0, ChannelID = 0, SeriesType = "Values", SourceIndexes = "" } } }); return(Ok(channels)); } }
/// <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_parser = new LogicalParser(filePath); m_parser.Open(); return(true); } catch (IOException) { return(false); } }
/// <summary> /// Populate known voltage and current data from PQDIF file. /// </summary> /// <param name="faultDataSet">Fault data set to be populated.</param> /// <param name="settings">Source parameters.</param> public static void PopulateDataSet(FaultLocationDataSet faultDataSet, Dictionary <string, string> settings) { string fileName; List <ObservationRecord> observationRecords; ObservationRecord faultObservation; ChannelInstance[] anChannels; ChannelInstance[] bnChannels; ChannelInstance[] cnChannels; if (!settings.TryGetValue("fileName", out fileName) || !File.Exists(fileName)) { throw new ArgumentException("Parameters must define a valid \"fileName\" setting."); } // Parse PQDif File Data using (LogicalParser logicalParser = new LogicalParser(fileName)) { observationRecords = new List <ObservationRecord>(); logicalParser.Open(); while (logicalParser.HasNextObservationRecord()) { observationRecords.Add(logicalParser.NextObservationRecord()); } } // Get the first observation record that contains six wave forms. // Assume that this observation record will has both voltage and // current wave forms for each of the three phases faultObservation = observationRecords.FirstOrDefault(observation => observation.ChannelInstances.Count(channel => channel.Definition.QuantityTypeID == QuantityType.WaveForm) >= 6); if ((object)faultObservation != null) { // Get the voltage and current wave forms for each of the six phase types IEnumerable <ChannelInstance> waveForms = faultObservation.ChannelInstances.Where(channel => channel.Definition.QuantityTypeID == QuantityType.WaveForm).ToList(); anChannels = waveForms.Where(channel => channel.Definition.Phase == Phase.AN).ToArray(); bnChannels = waveForms.Where(channel => channel.Definition.Phase == Phase.BN).ToArray(); cnChannels = waveForms.Where(channel => channel.Definition.Phase == Phase.CN).ToArray(); // Attempt to fill in fault data for each of the three phase types FillFaultData(faultDataSet.Voltages.AN, faultDataSet.Currents.AN, anChannels); FillFaultData(faultDataSet.Voltages.BN, faultDataSet.Currents.BN, bnChannels); FillFaultData(faultDataSet.Voltages.CN, faultDataSet.Currents.CN, cnChannels); // Set the frequency in the data set to the nominal frequency of the system faultDataSet.Frequency = faultObservation.Settings.NominalFrequency; } }
public static Formule parse(String str) { formule_str = str; Node n = null; LogicalParser parser = new LogicalParser(new StringReader(str)); try { n = parser.Parse(); } catch(ParserLogException) { throw; } if (n == null) return null; return parseNode(n); }
public void Dispose() { if (!m_disposed) { try { if ((object)m_parser != null) { m_parser.Dispose(); m_parser = null; } } finally { m_disposed = true; } } }
public static Formule parse(String str) { formule_str = str; Node n = null; LogicalParser parser = new LogicalParser(new StringReader(str)); try { n = parser.Parse(); } catch (ParserLogException) { throw; } if (n == null) { return(null); } return(parseNode(n)); }
private void Parse(string filename) { List <ObservationRecord> observationRecords; List <DataSourceRecord> dataSourceRecords; using (LogicalParser logicalParser = new LogicalParser(filename)) { observationRecords = new List <ObservationRecord>(); logicalParser.Open(); while (logicalParser.HasNextObservationRecord()) { observationRecords.Add(logicalParser.NextObservationRecord()); } dataSourceRecords = logicalParser.DataSourceRecords; } this.m_previousProgress = this.m_previousProgress + 50; this.mProgress.Report(this.m_previousProgress); if (observationRecords.Count == 0) { return; } if (dataSourceRecords.Count != 1) { return; } //create Meter Definition //For now assume a single meter Meter meter = new Meter(); meter.DeviceName = dataSourceRecords[0].DataSourceName; meter.Owner = dataSourceRecords[0].DataSourceOwner; meter.DeviceAlias = GSF.PQDIF.Logical.Equipment.ToString(dataSourceRecords[0].EquipmentID); meter.DeviceLocation = dataSourceRecords[0].DataSourceLocation; if (dataSourceRecords[0].Latitude < uint.MaxValue) { meter.Latitude = dataSourceRecords[0].Latitude; } if (dataSourceRecords[0].Longitude < uint.MaxValue) { meter.Longitude = dataSourceRecords[0].Longitude; } meter.AccountName = GSF.PQDIF.Logical.Vendor.ToString(dataSourceRecords[0].VendorID); using (TransactionScope scope = new TransactionScope()) { AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider); GSF.Data.Model.TableOperations <Meter> meterTable = new GSF.Data.Model.TableOperations <Meter>(connection); meterTable.AddNewRecord(meter); meter.ID = ModelID.GetID <Meter>(connection); //create Channel Definitions List <PQio.Model.Channel> channels = dataSourceRecords[0].ChannelDefinitions.Select(channel => ParseChannel(meter, channel, connection)).ToList(); List <PQio.Model.Event> events = new List <Event>(); //create Event Definitions foreach (ObservationRecord record in observationRecords) { //Create Event Event evt = ParseObservationRecord(record, connection); //create DataSeries objects foreach (ChannelInstance channelInstance in record.ChannelInstances) { ParseSeries(channelInstance, channels[(int)channelInstance.ChannelDefinitionIndex], evt, connection); } events.Add(evt); } // Remove Channels whithout data channels = channels.FindAll(item => RemoveEmptyChannel(item, connection)).ToList(); events = events.FindAll(item => RemoveEmptyEvents(item, connection)).ToList(); // Remove Channels whithout data channels = channels.FindAll(item => RemoveEmptyChannel(item, connection)).ToList(); // If only one set of data it's easy to keep only single line int nVa = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.VoltageA); int nVb = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.VoltageB); int nVc = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.VoltageC); int nIa = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.CurrentA); int nIb = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.CurrentB); int nIc = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.CurrentC); if (nVa == 1 && nVb == 1 && nVc == 1) { //Create new asset Asset asset = new Asset() { AssetKey = String.Format("Asset 1 ({0})", meter.AccountName) }; GSF.Data.Model.TableOperations <Asset> assetTable = new GSF.Data.Model.TableOperations <Asset>(connection); assetTable.AddNewRecord(asset); asset.ID = ModelID.GetID <Asset>(connection); GSF.Data.Model.TableOperations <Channel> channelTable = new GSF.Data.Model.TableOperations <Channel>(connection); Channel Va = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.VoltageA); Channel Vb = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.VoltageB); Channel Vc = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.VoltageC); Va.AssetID = asset.ID; Vb.AssetID = asset.ID; Vc.AssetID = asset.ID; channelTable.UpdateRecord(Va); channelTable.UpdateRecord(Vb); channelTable.UpdateRecord(Vc); if (nIa == 1 && nIb == 1 && nIc == 1) { Channel Ia = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.CurrentA); Channel Ib = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.CurrentB); Channel Ic = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.CurrentC); Ia.AssetID = asset.ID; Ib.AssetID = asset.ID; Ic.AssetID = asset.ID; channelTable.UpdateRecord(Ia); channelTable.UpdateRecord(Ib); channelTable.UpdateRecord(Ic); } } scope.Complete(); } this.m_previousProgress = this.m_previousProgress + 50; this.mProgress.Report(this.m_previousProgress); }