Exemple #1
0
        private static int Strip(StripOptions opts)
        {
            Console.WriteLine($"Read WRP from '{opts.Source}'");
            var source = StreamHelper.Read <AnyWrp>(opts.Source);

            Console.WriteLine("Convert");
            var editable = source.GetEditableWrp();

            editable.Objects = new List <EditableWrpObject>()
            {
                EditableWrpObject.Dummy
            };

            Console.WriteLine($"Write to '{opts.Target}'");
            editable.Write(opts.Target);

            Console.WriteLine("Done");
            return(0);
        }
Exemple #2
0
        private async Task <Tuple <MemoryActivity, MemoryActivity> > StripAsync(StripOptions options, bool log = false)
        {
            var strippedFileName = GetStrippedFileName(FileName);

            using (var input = await TestFileHelper.OpenForReadAsync(FileName))
            {
                var stripper = new FitStripper {
                    LogEnabled = log
                };
                using (var output = await TestFileHelper.OpenForWriteAsync(strippedFileName))
                {
                    stripper.Strip(input, output, options);
                }
            }
            var activity = await LoadAsync(FileName);

            var strippedActivity = await LoadAsync(strippedFileName);

            return(new Tuple <MemoryActivity, MemoryActivity>(activity, strippedActivity));
        }
Exemple #3
0
        public void Strip(Stream input, Stream output, StripOptions options)
        {
            int time = Environment.TickCount;

            _options = options;

            // Create file encode object
            _encoder = new Encode(output);

            Decode decoder = new Decode();

            //MesgBroadcaster mesgBroadcaster = new MesgBroadcaster();

            // Connect the Broadcaster to our event (message) source (in this case the Decoder)
            decoder.MesgEvent           += OnMesg;
            decoder.MesgDefinitionEvent += OnMesgDefn;

            // Subscribe to message events of interest by connecting to the Broadcaster
            //mesgBroadcaster.MesgEvent += OnMesg;
            //mesgBroadcaster.MesgDefinitionEvent += OnMesgDefn;

            _mesgCounts.Clear();

            bool status = decoder.IsFIT(input);

            status &= decoder.CheckIntegrity(input);
            // Process the file
            if (status)
            {
                Log("Decoding...");
                decoder.Read(input);
                Log("Decoded FIT file");
            }
            else
            {
                try
                {
                    Log("Integrity Check Failed.");
                    Log("Attempting to decode...");
                    decoder.Read(input);
                }
                catch (FitException ex)
                {
                    Log("DecodeDemo caught FitException: " + ex.Message);
                }
            }

            _encoder.Close();

            Log("Summary:");
            int totalMesgs = 0;

            foreach (KeyValuePair <ushort, int> pair in _mesgCounts)
            {
                Log("MesgID {0,3} Count {1}", pair.Key, pair.Value);
                totalMesgs += pair.Value;
            }

            Log("{0} Message Types {1} Total Messages", _mesgCounts.Count, totalMesgs);

            time = Environment.TickCount - time;
            Log("Time elapsed: {0:0.#}s", time / 1000.0f);// stopwatch.Elapsed.TotalSeconds);
        }
Exemple #4
0
        public void Strip(System.IO.Stream input, System.IO.Stream output, StripOptions options)
        {
            bool writeEnabled = true; // controls whether the active readed element has to be written to the result

            using (XmlReader reader = XmlReader.Create(input))
            {
                var writerSettings = new XmlWriterSettings
                {
                    Encoding = new UTF8Encoding(false) // don't write BOM in the first byte
                };
                using (XmlWriter writer = XmlWriter.Create(output, writerSettings))
                {
                    while (reader.Read())
                    {
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            if (!writeEnabled)
                            {
                                break;
                            }
                            if (((options & StripOptions.Power) != StripOptions.None && reader.Name == "Watts") ||
                                ((options & StripOptions.HeartRate) != StripOptions.None && reader.Name == "HeartRateBpm") ||
                                ((options & StripOptions.Cadence) != StripOptions.None && reader.Name == "Cadence"))
                            {
                                // skip elements we want to strip
                                writeEnabled = false;
                                break;
                            }
                            writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                            writer.WriteAttributes(reader, true);
                            if (reader.IsEmptyElement)
                            {
                                writer.WriteEndElement();
                            }
                            break;

                        case XmlNodeType.Text:
                            if (!writeEnabled)
                            {
                                break;
                            }
                            writer.WriteString(reader.Value);
                            break;

                        case XmlNodeType.Whitespace:
                        case XmlNodeType.SignificantWhitespace:
                            writer.WriteWhitespace(reader.Value);
                            break;

                        case XmlNodeType.CDATA:
                            writer.WriteCData(reader.Value);
                            break;

                        case XmlNodeType.EntityReference:
                            writer.WriteEntityRef(reader.Name);
                            break;

                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.ProcessingInstruction:
                            writer.WriteProcessingInstruction(reader.Name, reader.Value);
                            break;

                        case XmlNodeType.DocumentType:
                            writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                            break;

                        case XmlNodeType.Comment:
                            writer.WriteComment(reader.Value);
                            break;

                        case XmlNodeType.EndElement:
                            if (writeEnabled)
                            {
                                writer.WriteFullEndElement();
                            }
                            if (((options & StripOptions.Power) != StripOptions.None && reader.Name == "Watts") ||
                                ((options & StripOptions.HeartRate) != StripOptions.None && reader.Name == "HeartRateBpm") ||
                                ((options & StripOptions.Cadence) != StripOptions.None && reader.Name == "Cadence"))
                            {
                                writeEnabled = true;     // nem kell a következőket kihagyni
                            }
                            break;
                        }
                    }
                }
            }
        }