Adding channel name clean up.
Adding card mapping support but it's not working.
2 using System.Collections.Generic;
3 using System.Diagnostics;
6 using System.Threading.Tasks;
14 public static string Polarisation(Channel aChannel)
16 switch (aChannel.Polarisation)
22 case "L": //Check that on KingOfSat
24 case "R": //Check that on KingOfSat
29 Debug.Write("WARNING: Unknown Polarisation " + aChannel.Polarisation + " for " + aChannel.Name + "\n");
44 public static string Modulation(Channel aChannel)
46 //Those can be worked out from TvLibrary FormDVBSTuningDetail.Designer.cs
48 switch (aChannel.Modulation)
56 Debug.Write("WARNING: Unknown modulation " + aChannel.Modulation + " for " + aChannel.Name + "\n");
102 public static string FEC(Channel aChannel)
104 //Those can be worked out from TvLibrary FormDVBSTuningDetail.Designer.cs
106 switch (aChannel.FEC)
139 Debug.Write("WARNING: Unknown FEC " + aChannel.FEC + " for " + aChannel.Name + "\n");
147 public static void Export(List<Channel> aChannels, List<string> aTunerCards, string aFileName, bool aAddMapping)
149 XmlDocument xmlDoc = new XmlDocument();
150 XmlNode rootElement = xmlDoc.CreateElement("tvserver");
151 AddAttribute(rootElement, "version", "1.0");
152 xmlDoc.AppendChild(rootElement);
153 //Create our channel element
154 XmlNode nodechannels = xmlDoc.CreateElement("channels");
155 rootElement.AppendChild(nodechannels);
158 int channelMapId = 0;
159 foreach (Channel channel in aChannels)
162 XmlNode nodechannel = xmlDoc.CreateElement("channel");
163 AddAttribute(nodechannel, "GrabEpg", "True");
164 AddAttribute(nodechannel, "IdChannel", channelId);
165 AddAttribute(nodechannel, "IsRadio", "False");
166 AddAttribute(nodechannel, "IsTv", "True");
167 AddAttribute(nodechannel, "LastGrabTime", "2000-1-1 0:0:0");
168 //AddAttribute(nodechannel, "SortOrder", channel.SortOrder);
169 //sAddAttribute(nodechannel, "TimesWatched", "0");
170 AddAttribute(nodechannel, "TotalTimeWatched", "2000-1-1 0:0:0");
171 AddAttribute(nodechannel, "VisibleInGuide", "True");
172 AddAttribute(nodechannel, "DisplayName", channel.Name);
173 AddAttribute(nodechannel, "ChannelNumber", channelId);
177 //I don't think we can get mapping to work without having corresponding server and card definition elements
178 XmlNode nodeMaps = xmlDoc.CreateElement("mappings");
179 foreach (string tuner in aTunerCards)
182 XmlNode nodeMap = xmlDoc.CreateElement("map");
183 AddAttribute(nodeMap, "IdCard", tuner);
184 AddAttribute(nodeMap, "IdChannel", channelId);
185 AddAttribute(nodeMap, "IdChannelMap", channelMapId);
186 nodeMaps.AppendChild(nodeMap);
188 nodechannel.AppendChild(nodeMaps);
191 XmlNode nodeTuningDetails = xmlDoc.CreateElement("TuningDetails");
192 XmlNode nodeTune = xmlDoc.CreateElement("tune");
193 AddAttribute(nodeTune, "IdChannel", channelId);
194 AddAttribute(nodeTune, "IdTuning", channelId);
195 AddAttribute(nodeTune, "Bandwidth", "8"); //Weird
196 AddAttribute(nodeTune, "ChannelNumber", "10000");
197 AddAttribute(nodeTune, "ChannelType", "3"); //Bad hard coding, does it means DVB-S
198 AddAttribute(nodeTune, "CountryId", "31"); //Is that Germany?
199 AddAttribute(nodeTune, "Diseqc", "0"); //Disabled
200 AddAttribute(nodeTune, "FreeToAir", "False"); //Can we get that from KingOfSat? Does it matter?
201 AddAttribute(nodeTune, "Frequency", ((Int32)(Convert.ToDouble(channel.Frequency)*1000)).ToString());
202 AddAttribute(nodeTune, "MajorChannel", "-1");
203 AddAttribute(nodeTune, "MinorChannel", "-1");
204 AddAttribute(nodeTune, "Modulation", Modulation(channel));
205 AddAttribute(nodeTune, "Name", channel.Name);
206 AddAttribute(nodeTune, "NetworkId", channel.NetworkID);
207 AddAttribute(nodeTune, "PmtPid", channel.PMT);
208 AddAttribute(nodeTune, "Polarisation", Polarisation(channel));
209 AddAttribute(nodeTune, "Provider", channel.Provider); //Does that matter? Should really be SKY or CSAT
210 AddAttribute(nodeTune, "ServiceId", channel.SID);
211 AddAttribute(nodeTune, "SwitchingFrequency", "11700000"); //Does it matter?
212 AddAttribute(nodeTune, "Symbolrate", channel.SymbolRate);
213 AddAttribute(nodeTune, "TransportId", channel.TransponderID);
214 AddAttribute(nodeTune, "TuningSource", "0"); //Is that needed?
215 AddAttribute(nodeTune, "VideoSource", "0"); //Is that needed?
216 AddAttribute(nodeTune, "AudioSource", "0"); //Is that needed?
217 AddAttribute(nodeTune, "IsVCRSignal", "False");
218 AddAttribute(nodeTune, "SatIndex", "-1");
219 AddAttribute(nodeTune, "InnerFecRate", FEC(channel));
220 AddAttribute(nodeTune, "Band", "0"); //Needed?
221 AddAttribute(nodeTune, "Pilot", "-1");
222 AddAttribute(nodeTune, "RollOff", "-1");
223 AddAttribute(nodeTune, "Url", "");
224 AddAttribute(nodeTune, "Bitrate", "0"); //Should we bother putting it in there?
225 nodeTuningDetails.AppendChild(nodeTune);
227 nodechannel.AppendChild(nodeTuningDetails);
229 nodechannels.AppendChild(nodechannel);
234 xmlDoc.Save(aFileName);
237 private static void AddAttribute(XmlNode node, string tagName, string tagValue)
239 XmlAttribute attr = node.OwnerDocument.CreateAttribute(tagName);
240 attr.InnerText = tagValue;
241 node.Attributes.Append(attr);
244 private static void AddAttribute(XmlNode node, string tagName, int tagValue)
246 AddAttribute(node, tagName, tagValue.ToString());
249 // store DateTime Values as strings. Improves readability
250 private static void AddAttribute(XmlNode node, string tagName, DateTime tagValue)
252 AddAttribute(node, tagName,
253 String.Format("{0}-{1}-{2} {3}:{4}:{5}", tagValue.Year, tagValue.Month, tagValue.Day, tagValue.Hour,
254 tagValue.Minute, tagValue.Second));
257 private static void AddAttribute(XmlNode node, string tagName, bool tagValue)
259 AddAttribute(node, tagName, tagValue.ToString());