Esempio n. 1
0
        public void PostProcessingFile()
        {
            TvBusinessLayer layer = new TvBusinessLayer();
            Setting setting;

            try
            {
                POSTPROCESSING = true;  //set busy postprocessing status

                setting = layer.GetSetting("Backup_SettingsSetup_debug", "false");
                DEBUG = Convert.ToBoolean(setting.Value);

                setting = layer.GetSetting("Backup_SettingsSetup_TV_USER_FOLDER", ".");
                TV_USER_FOLDER = setting.Value;

                //if ((TV_PROGRAM_FOLDER=="NOT_FOUND")||(TV_PROGRAM_FOLDER=="NOT_DEFINED"))
                 //   TV_PROGRAM_FOLDER = ".";
            }
            catch (Exception ee)
            {
                textoutput("<RED>BackupSettingsServer: Error when waiting for SetupTv exit - aborting postprocessing");
                if (DEBUG==true)
                    textoutput("<RED>BackupSettingsServer: Exception message is " + ee.Message);
            }

            //read postprocessing file
            string fileName = TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + @"\" + POSTPROCESSING_FILE;
            string fileText = "";

            try
            {
                if (System.IO.File.Exists(fileName) == true)
                {
                    System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
                    fileText = sr.ReadToEnd();
                    sr.Close();
                    string[] lines = fileText.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    //process data

                    foreach (String line in lines)
                    {

                        //postprocessing goes here

                        if (line.StartsWith("SETTING") == true)
                        {
                            //"SETTING\t" + attribute + "\t" + setting + "\n";
                            string[] tokens = line.Split("\t".ToCharArray());
                            if (tokens.Length != 3)
                            {
                                textoutput("<RED>BackupSetting Postprocessing Error: SETTING line " + line + " has " + tokens.Length.ToString() + " tokens - skipping entry");
                            }
                            else
                            {
                                if (tokens[2] != "BACKUPSETTINGS_NOTFOUND")
                                {
                                    setting = layer.GetSetting(tokens[1], "");
                                    setting.Value = tokens[2];
                                    setting.Value = setting.Value.Replace("__RETURN__", "\n");
                                    setting.Persist();
                                    if (DEBUG)
                                    {
                                        textoutput("Processed SETTING with attribute=" + tokens[1] + ", value=" + tokens[2]);
                                    }
                                }
                            }

                        }
                        else if (line.StartsWith("CARDGROUPMAP") == true)
                        {
                            //"CARDGROUPMAP\t" + newIdCard + "\t" + newIdCardGroup + "\t" + HybridGroupName + "\n";

                            string[] tokens = line.Split("\t".ToCharArray());
                            if (tokens.Length != 4)
                            {
                                textoutput("<RED>BackupSetting Postprocessing Error: CARDGROUPMAP line " + line + " has " + tokens.Length.ToString() + " tokens - skipping entry");
                            }
                            else
                            {
                                try
                                {
                                    //get cardgroup id from name
                                    int cardid = Convert.ToInt32(tokens[1]);
                                    int cardgroupid = Convert.ToInt32(tokens[2]);

            #if(MP100)
                                    IList hybridcardgroups = CardGroup.ListAll();
            #elif(MP101)
                                    IList<CardGroup> hybridcardgroups = CardGroup.ListAll();
            #else //MP11BETA or SVN
                                    IList<CardGroup> hybridcardgroups = CardGroup.ListAll();
            #endif

                                    foreach (CardGroup hybridcardgroup in hybridcardgroups)
                                    {
                                        if (hybridcardgroup.Name == tokens[3])
                                        {
                                            cardgroupid=hybridcardgroup.IdCardGroup;
                                            if (DEBUG == true)
                                                textoutput("Identified card group " + hybridcardgroup.Name + " with id " + cardgroupid);

                                            break;
                                        }

                                    }

                                    CardGroupMap newcardgroupmap = new CardGroupMap(cardid, cardgroupid);
                                    newcardgroupmap.Persist();
                                    if (DEBUG)
                                    {
                                        textoutput("Processed CARDGROUPMAP with card id=" + cardid.ToString() + ", cardgroup id=" + cardgroupid.ToString() + " HybridGroupName=" + tokens[3].ToString());
                                    }
                                }
                                catch
                                {
                                    textoutput("<RED>Error: Could not create new cardgroup map for card id " + tokens[1].ToString() + " and cardgroup id " + tokens[2].ToString() + " - skipping entry");
                                }

                            }
                        }
                        else if (line.StartsWith("TVMOVIE") == true)
                        {
                            //"TVMOVIE\t" + idChannel + "\t" + stationName + "\t" + timeSharingStart + "\t" + timeSharingEnd + "\n";

                            string[] tokens = line.Split("\t".ToCharArray());
                            if (tokens.Length != 5)
                            {
                                textoutput("<RED>BackupSetting Postprocessing Error: TVMOVIE line " + line + " has " + tokens.Length.ToString() + " tokens - skipping entry");
                            }
                            else
                            {
                                try
                                {
                                    TvMovieMapping tvmapping = new TvMovieMapping(Convert.ToInt32(tokens[1]), tokens[2],tokens[3],tokens[4]);
                                    tvmapping.Persist();
                                }
                                catch
                                {
                                    textoutput("<RED>Error: Could not create new Tv Movie map for channel id=" + tokens[1] + ", station name=" + tokens[2] + " time sharing start=" + tokens[3] + " time sharing end=" + tokens[4] + " - skipping entry");
                                }
                                if (DEBUG)
                                {
                                    textoutput("Processed TVMOVIE with channel id=" + tokens[1] + ", station name=" + tokens[2] + " time sharing start=" + tokens[3] + " time sharing end=" + tokens[4]);
                                }
                            }

                        }

                    }

                    CalculateNextBackupTime(); //calculate next automated export time after import

                }
            }
            catch (Exception ee)
            {
                textoutput("<RED>Server error in processing the file " + fileName);
                if (DEBUG == true)
                {
                    textoutput("<RED>File text was:");
                    textoutput(fileText);
                    textoutput("<RED>Exception message is " + ee.Message);
                }
            }

            textoutput("TV server import postprocessing completed\n\n");
        }
Esempio n. 2
0
 private void placeInHybridCardToolStripMenuItem_Click(object sender, EventArgs e)
 {
   ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
   CardGroup group;
   if (menuItem.Tag == null)
   {
     GroupNameForm dlg = new GroupNameForm();
     if (dlg.ShowDialog(this) != DialogResult.OK)
     {
       return;
     }
     group = new CardGroup(dlg.GroupName);
     group.Persist();
     UpdateMenu();
   }
   else
   {
     group = (CardGroup)menuItem.Tag;
   }
   ListView.SelectedIndexCollection indexes = mpListView1.SelectedIndices;
   if (indexes.Count == 0)
     return;
   for (int i = 0; i < indexes.Count; ++i)
   {
     ListViewItem item = mpListView1.Items[indexes[i]];
     Card card = (Card)item.Tag;
     CardGroupMap map = new CardGroupMap(card.IdCard, group.IdCardGroup);
     map.Persist();
     card.PreloadCard = false;
     card.Persist();
   }
   UpdateHybrids();
   RemoteControl.Instance.Restart();
 }