ChlFileSerializer converted to a SerializerBase subclass so it can use the same reference list logic as TV data files

This commit is contained in:
hbeham
2016-05-05 00:12:06 +02:00
parent aaba300f2d
commit 7b7e7bef99
14 changed files with 669 additions and 419 deletions

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A2A5C606-167C-4FC2-87A8-2D67590B283B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ChanSort.Loader.RefList</RootNamespace>
<AssemblyName>ChanSort.Loader.RefList</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RefSerializer.cs" />
<Compile Include="RefSerializerPlugin.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ChanSort.Api\ChanSort.Api.csproj">
<Project>{dccffa08-472b-4d17-bb90-8f513fc01392}</Project>
<Name>ChanSort.Api</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ChanSort.Loader.RefList")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ChanSort.Loader.RefList")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a2a5c606-167c-4fc2-87a8-2d67590b283b")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,147 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using ChanSort.Api;
namespace ChanSort.Loader.RefList
{
public class RefSerializer : SerializerBase
{
private static readonly char[] Separators = { ';' };
private readonly ChannelList allChannels =
new ChannelList(SignalSource.DvbT | SignalSource.DvbC | SignalSource.DvbS | SignalSource.AnalogC | SignalSource.AnalogT | SignalSource.Tv | SignalSource.Radio, "All");
#region ctor()
public RefSerializer(string inputFile) : base(inputFile)
{
this.Features.ChannelNameEdit = ChannelNameEditMode.All;
this.Features.CanSkipChannels = false;
this.Features.CanDeleteChannels = true;
this.Features.CanHaveGaps = true;
this.Features.EncryptedFlagEdit = false;
this.DataRoot.SortedFavorites = false;
this.DataRoot.SupportedFavorites = 0;
this.DataRoot.AddChannelList(this.allChannels);
allChannels.VisibleColumnFieldNames = new List<string>
{
"Position",
"Name",
"OriginalNetworkId",
"TransportStreamId",
"ServiceId"
};
}
#endregion
public override string DisplayName => ".txt Reference List Loader";
#region Load()
public override void Load()
{
this.ReadChannels();
}
#endregion
#region ReadChannels()
private void ReadChannels()
{
var lineNr = 0;
using (var file = new StreamReader(this.FileName))
{
string line;
while ((line = file.ReadLine()) != null)
{
++lineNr;
var parts = line.Split(Separators);
if (parts.Length < 2)
continue;
int progNr;
if (!int.TryParse(parts[0], out progNr))
continue;
var channel = new ChannelInfo(allChannels.SignalSource, lineNr, progNr, parts[1]);
if (parts.Length >= 3)
{
var subParts = parts[2].Split('-');
if (subParts.Length >= 3)
{
int val;
if (int.TryParse(subParts[0], out val))
channel.OriginalNetworkId = val;
if (int.TryParse(subParts[1], out val))
channel.TransportStreamId = val;
if (int.TryParse(subParts[2], out val))
channel.ServiceId = val;
}
}
this.DataRoot.AddChannel(this.allChannels, channel);
lineNr++;
}
}
}
#endregion
#region GetFileInformation()
public override string GetFileInformation()
{
var sb = new StringBuilder();
sb.Append(base.GetFileInformation());
return sb.ToString();
}
#endregion
#region Save()
//public override void Save(string tvOutputFile)
//{
// var writer = new ChlFileSerializer();
// writer.Save(tvOutputFile, this.allChannels);
// this.FileName = tvOutputFile;
//}
public override void Save(string tvOutputFile)
{
Save(tvOutputFile, this.allChannels);
this.FileName = tvOutputFile;
}
public static void Save(string fileName, ChannelList list)
{
var samToolBoxMode = (Path.GetExtension(fileName) ?? "").ToLower() == ".chl";
using (var writer = new StreamWriter(fileName, false, Encoding.UTF8))
{
foreach (var channel in list.GetChannelsByNewOrder())
{
if (channel.NewProgramNr == -1) continue;
writer.Write(channel.NewProgramNr);
writer.Write(Separators[0]);
writer.Write(channel.Name);
if (!samToolBoxMode)
{
writer.Write(Separators[0]);
writer.Write(channel.OriginalNetworkId);
writer.Write("-");
writer.Write(channel.TransportStreamId);
writer.Write("-");
writer.Write(channel.ServiceId);
}
writer.WriteLine();
}
}
}
#endregion
}
}

View File

@@ -0,0 +1,16 @@
using ChanSort.Api;
namespace ChanSort.Loader.RefList
{
public class RefSerializerPlugin : ISerializerPlugin
{
public string PluginName => "ChanSort Reference List";
public string FileFilter => "*.txt;*.chl";
public SerializerBase CreateSerializer(string inputFile)
{
return new RefSerializer(inputFile);
}
}
}