예제 #1
0
/*
	public void CreateGalleriePlayingData (String PictureElementsFileRootDirectory,
					String TableName, DataRow TableTableRow)
		{
		CVM.CommonValues m_CVM = new CVM.CommonValues ();
		XAMLHandling m_XAMLHandling = new XAMLHandling (m_CVM);
		LocalWPMediaRoot = CommonDataBase.DataBase.GetLocalWPMediaRoot ();
		String TableDirectory = Path.Combine (PictureElementsFileRootDirectory, TableName);
		List<FileInfo> ExistingFiles = WMB.Basics.GetFileInfoEntriesFromDirectory
			(TableDirectory, new string [] { ControlFileExtension }, 1);
		return;
		}		
*/		
		
	public void CreateStandbildPlayingData (String WPMediaServerRootDirectory, 
			String PackageFilesRootDirectory, String TableName, DataRow tableDefinitionRow)
		{
		if (WMB.Basics.IsTestRun)
			{
			int NumberOfFiles = WMB.Basics.GetFilesFromDirectory
				(Path.Combine(PackageFilesRootDirectory, TableName), new string[] { "*.pkg" }, 1).Count; 

			WMB.Basics.ReportInformationToEventViewer("WPMediaCentralServices.CreateStandbildPlayingData",
				"PackageFilesRootDirectory =\r\n\"" + PackageFilesRootDirectory + "\" Tabelle =\r\n\""
				+ TableName + "\" " + Convert.ToString(NumberOfFiles) + " Files");
			}
		DateTime DateTimeToHandle = DateTime.Now;
		CVM.CommonValues m_CVM = new CVM.CommonValues();
		XAMLHandling m_XAMLHandling = new XAMLHandling (m_CVM);
		LocalWPMediaRoot = CommonDataBase.DataBase.GetLocalWPMediaRoot ();
		String TableDirectory = Path.Combine (PackageFilesRootDirectory, TableName);
		List<FileInfo> ExistingFiles = WMB.Basics.GetFileInfoEntriesFromDirectory
			(TableDirectory, new string [] { ControlFileExtension }, 1);
		if (ExistingFiles == null)
			return;
		WPMediaStandbildPlayingData Description = new WPMediaStandbildPlayingData();

//ToDo	Checking for IsActive on this day - new Implementation	
		List<MMUnitUsageData> PossibleDataFromDataBase
			= Data.DbServer3.WPMediaAddOnData.GetWPMediaAddOnDataStandBildUsagePerTabelle
				(TableName, Data.DbServer3.WPMediaAddOnData.Timings
					.GetPossiblyInvolvedConnectedIds(DateTimeToHandle)[TableName]);


		Dictionary<DateTime, List<MMUnitUsageData>> AvtiveThisDayParameter 
				= new Dictionary<DateTime, List<MMUnitUsageData>>()
					{
						{ DateTimeToHandle,
						GetDayMMUnitUsageData
							(PossibleDataFromDataBase, DateTimeToHandle)
						}
					};

			//TODO
			//MMUnitUsageTreeEntry Root = MMUnitUsageTreeEntry.GetUsageTree (null, null, null, null);

			//int WeekDay = (int) DateTime.Now.DayOfWeek;
			//List<MMUnitUsageData> DownloadEntriesStandBildUsageData = Root.Childs[MMUnitUsageTreeEntry.ALL_ACTIVE_ENTRIES].ContentList;
			//	MMUnitUsageTreeEntry RootsChilds = Root.Childs [MMUnitUsageTreeEntry.ALL_ACTIVE_ENTRIES];
			//List<MMUnitUsageData> AllDayUsageData = RootsChilds.Childs[MMUnitUsageTreeEntry.ALL_DAY_ENTRIES].ContentList;
			//List<MMUnitUsageData> ThisWeekDayUsageData = RootsChilds.Childs[WMB.Basics.ShortWeekDayNames[WeekDay]].ContentList;

			//Description.NamesOfLocalToDownloadDescriptions = new List<string> ();
			//foreach (MMUnitUsageData UsageData in DownloadEntriesStandBildUsageData)
			//	{
			//	Description.NamesOfLocalToDownloadDescriptions.Add(UsageData.PackageFileNamePart);
			//	}
			//foreach (MMUnitUsageData UsageData in AllDayUsageData)
			//	{
			//	Description.NamesOfTodayActiveDescriptions.Add(UsageData.PackageFileNamePart);
			//	}
			//foreach (MMUnitUsageData UsageData in ThisWeekDayUsageData)
			//	{
			//	Description.NamesOfTodayActiveDescriptions.Add(UsageData.PackageFileNamePart);
			//	}

			Description.NamesOfTodayActiveDescriptions = new List<string>();
			foreach (MMUnitUsageData UsageData in AvtiveThisDayParameter[DateTimeToHandle])
				{
				Description.NamesOfTodayActiveDescriptions.Add(UsageData.PackageFileNamePart);
				}

			foreach (String PackageFileName in Description.NamesOfTodayActiveDescriptions)
			{
			bool Found = false;
			foreach (FileInfo FInfo in ExistingFiles)
				{
				if (FInfo.Name.ToLower () == Path.GetFileName (PackageFileName).ToLower ())
					Found = true;
				}
			if (!Found)
				{
				WMB.Basics.ReportErrorToEventViewer("WPMediaCentralService.CreateStandbildPlayingData",
					"Der PackageFile \"" + PackageFileName + "\" fehlt");
				}
			}
		int SkipLength = PackageFilesRootDirectory.Length + 1 - "Source\\".Length;

		if (WMB.Basics.IsTestRun)
			WMB.Basics.ReportInformationToEventViewer ("WPMediaCentralServices.CreateStandbildPlayingData",
			    "NamesOfLocalToDownloadDescriptions = " + Convert.ToString (Description.NamesOfLocalToDownloadDescriptions.Count)
			    + "\r\nNamesOfTodayActiveDescriptions = " + Convert.ToString (Description.NamesOfTodayActiveDescriptions.Count));
	
		String EntryTimingType = tableDefinitionRow[CVM.CommonValues.WPMEDIA_ENTRY_TIMING_TYPE].ToString();
		String PlayingOrder = tableDefinitionRow [CVM.CommonValues.WPMEDIA_ENTRY_PLAYING_ORDER].ToString ();
		double EntryDuration = 8;
		if (tableDefinitionRow [CVM.CommonValues.WPMEDIA_ENTRY_ENTRY_DURATION] != null)
			{
			if (!String.IsNullOrEmpty (tableDefinitionRow [CVM.CommonValues.WPMEDIA_ENTRY_ENTRY_DURATION].ToString ()))
				EntryDuration = Convert.ToDouble (tableDefinitionRow [CVM.CommonValues.WPMEDIA_ENTRY_ENTRY_DURATION]);
			}
		double OutsideSetDuration = -1;
		if (tableDefinitionRow [CVM.CommonValues.WPMEDIA_OUTSIDE_SET_DURATION] != null)
			{
			if (!String.IsNullOrEmpty (tableDefinitionRow [CVM.CommonValues.WPMEDIA_OUTSIDE_SET_DURATION].ToString ()))
				OutsideSetDuration = Convert.ToDouble (tableDefinitionRow [CVM.CommonValues.WPMEDIA_OUTSIDE_SET_DURATION]);
			}
		String MeaningOfOutsideSetDuration = tableDefinitionRow [CVM.CommonValues.WPMEDIA_MEANING_OF_OUTSIDE_SET_DURATION].ToString ();
		Description.TableName = TableName;
		Description.TableDefinitionTable = tableDefinitionRow.Table.Clone ();
		DataRow TableDefinitionRow = Description.TableDefinitionTable.NewRow ();
		TableDefinitionRow.ItemArray = tableDefinitionRow.ItemArray;
		Description.TableDefinitionTable.Rows.Add (TableDefinitionRow);
		Description.NameOfProcessingModule = tableDefinitionRow ["Type"].ToString ();

		Description.NamesOfActiveDescriptions = new List<string> ();
		Description.SortFields = new List<string> ();
		Description.LastWriteTimesOfNamesOfActiveDescriptions = new List<DateTime> ();
		Description.PlayLengthOfEachDescription = new List<TimeSpan> ();
		Description.NumberOfPagesOfEachDescription = new List<int> ();
		Description.NameOfPlayingDataDescription = TableName;
		Description.OverallPlayLength = 0;
		int OverallNumberOfPictures = 0;
		String TableType = tableDefinitionRow [CVM.CommonValues.WPMEDIA_ENTRY_TYPE_OF_TABLE].ToString ();
		ManagedTimingsControl TimingsCheckerClass = new ManagedTimingsControl ();
		CVM.ITimingsInterface TimingsCheckerInterface = TimingsCheckerClass as ITimingsInterface;
		TimingsCheckerInterface.m_TimingsTypenDataSet = m_DataBase.GetCommonDataSet ("Select * from TimingTypen");
		foreach (String PackageFileName in Description.NamesOfTodayActiveDescriptions)
			{
			FileInfo Entry = new FileInfo(Path.Combine(PackageFilesRootDirectory, PackageFileName));
			String ID = Path.GetFileNameWithoutExtension (Entry.FullName);
			DataTable UsedTimings;
			if (TimingsCheckerInterface.IsActive (ID, out UsedTimings) == false)
				continue;
			int NumberOfPages = 0;
			String SortField = PlayingOrder;
			TimeSpan PlayLengthForThisEntry = TimeSpan.Zero;
			List <double> PageDurations = new List<double> ();

			GraphicsHandling GraphicsHandler = new GraphicsHandling (LocalWPMediaRoot);
			if (GraphicsHandler.GetInstatiatedPackage (Entry.FullName) == null)
				{
				WMB.Basics.ReportErrorToEventViewer("WPMediaCentralServices.CreateStandbildPlayingData",
					"Der File\r\n\"" + Entry.FullName + "\"\r\nkonnte nicht als gültiges Package aufgelöst werden.\r\n"
					+ "In der Folge werden damit Fehler auftreten");
				continue;
				}
			List<TimeSpan> DurationForEachPage = new List<TimeSpan> ();
			foreach (double PageDuration in GraphicsHandler.PageDurations)
				{
				PlayLengthForThisEntry += TimeSpan.FromSeconds(PageDuration);
				DurationForEachPage.Add(TimeSpan.FromSeconds(PageDuration));
				}
			SortField = GraphicsHandler.GetFilledSortField (SortField);
			NumberOfPages = GraphicsHandler.PageDurations.Count;
			GraphicsHandler.Close ();
			Description.StandBildTVVersion = "PKG_Version";
			Description.DurationOfEachPageInEachDescription.Add (DurationForEachPage);
			Description.FillTimingsForEachDescription (ID, UsedTimings);

			if ((NumberOfPages == 0)
				|| (PlayLengthForThisEntry == TimeSpan.Zero))
				{
				WMB.Basics.ReportErrorToEventViewer ("WPMediaCentralServices.CreateStandbildPlayingData",
					Entry.FullName + " in der Table \"" + TableName + "\" hat eine PlayLength von 0");
				continue;
				}
			Description.NamesOfActiveDescriptions.Add (Entry.FullName.Substring (SkipLength));
			if (String.IsNullOrEmpty(Description.SubDirectoryWhereTheDescriptionsAreLocated))
				{
				Description.SubDirectoryWhereTheDescriptionsAreLocated = Path.GetDirectoryName
					(Entry.FullName.Substring (SkipLength));
				}
			
			Description.LastWriteTimesOfNamesOfActiveDescriptions.Add (Entry.LastWriteTime);
			Description.SortFields.Add (SortField);
			Description.NumberOfPagesOfEachDescription.Add (NumberOfPages);
			OverallNumberOfPictures += NumberOfPages;
			Description.OverallPlayLength += PlayLengthForThisEntry.TotalSeconds;
			Description.PlayLengthOfEachDescription.Add (PlayLengthForThisEntry);
			}
		if (OutsideSetDuration > 0)
			{
			if (MeaningOfOutsideSetDuration == CVM.CommonValues.WPMEDIA_MEANING_OF_OUTSIDE_SET_DURATION_MAX)
				if (OutsideSetDuration < Description.OverallPlayLength)
					Description.OverallPlayLength = OutsideSetDuration;
			if (MeaningOfOutsideSetDuration == CVM.CommonValues.WPMEDIA_MEANING_OF_OUTSIDE_SET_DURATION_FIX)
				Description.OverallPlayLength = OutsideSetDuration;
			}
		Description.OverallNumberOfPicturesToShow = OverallNumberOfPictures;
		String ControlFileName = Description.TableName;
		if (tableDefinitionRow ["DefinitionNameToCreate"] != Convert.DBNull)
			if (!String.IsNullOrEmpty (tableDefinitionRow ["DefinitionNameToCreate"].ToString ()))
				ControlFileName = tableDefinitionRow ["DefinitionNameToCreate"].ToString ();
//TODO	String PlayingDataDirectory = Path.Combine(LocalWPMediaRoot, XML_SENDER_AUTO_CONTROL_DIRECTORY);
		String PlayingDataDirectory = Path.Combine(WPMediaServerRootDirectory, XML_SENDER_AUTO_CONTROL_DIRECTORY);
		if (!Directory.Exists (PlayingDataDirectory))
			Directory.CreateDirectory (PlayingDataDirectory);
		String FileName = Path.Combine (PlayingDataDirectory, ControlFileName + AUTO_CONTROL_FILE_EXT_EXTENSION_SHORT);
		Description.FillIndexIndizess ();
		WPMediaStandbildPlayingData EarlierDescription
			= GetWPMediaStandbildPlayingDataFromAssembledFile (FileName);
//		EarlierDescription.ClearAllRandomElements();
		if (PlayingDataObjectsAreEqual(EarlierDescription, Description))
			return;

		MemoryStream ContentOfPlayingData = AssembleContentOfPlayingData(Description,
			Convert.ToString(Description.OverallPlayLength), Description.TableName, "StandbildTV");
		bool CorrectDeleted = true;
		if (File.Exists (FileName))
			{
			CorrectDeleted = CommonDataBase.CommonBasics.SecureFileDelete (FileName, null);
			}
		if (CorrectDeleted)
			{
			FileStream TargetFile = File.Open (FileName, FileMode.Create, FileAccess.Write);
			ContentOfPlayingData.WriteTo(TargetFile);
			TargetFile.Close ();
			}
		ContentOfPlayingData.Close ();
		}