Esempio n. 1
0
		public bool InsertDefaultPackageMaterials (WCFStandardsNS.WCFStandards DataBase, Object Package)
			{
			
			DataSet FrameDataDataSet = (Package as Paketieren.PackagingHandler).GetDataSetFromDataSetName ("FrameDefinitions");
			String TableNameParameter = FrameDataDataSet.Tables["TableDefinitions"].Rows[0]["TableName"].ToString();
			String ID = FrameDataDataSet.Tables[TableNameParameter].Rows[0]["ID"].ToString();
			String NameID = FrameDataDataSet.Tables[TableNameParameter].Rows[0]["NameID"].ToString();
			String DefaultDirectoryName = String.Empty;
			DefaultDirectoryName = NameID;
			if (NameID.IndexOf (':') != -1)
				{
				DefaultDirectoryName = NameID.Split (':') [0];
				}
			//else
			//    {
			//    DefaultDirectoryName = NameID.TrimEnd (new char [] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' });
			//    }
			if (Basics.CheckForValidPersistentName (DefaultDirectoryName) == false)
				return false;
			if (Basics.CheckForValidPersistentName(TableNameParameter) == false)
				return false;
			String RemotePackageDirectory = Path.Combine(Path.Combine(RemoteWPMediaRoot, "Source"), TableNameParameter);
			//			String RemoteDefaultDirectory = Path.Combine (RemotePackageDirectory, Basics.XML_AUTO_DEFAULT_DIRECTORY_NAME);
			String PackageDirectory = Path.Combine(Path.Combine(LocalWPMediaRoot, "Source"), TableNameParameter);
			String DefaultDirectory = Path.Combine (PackageDirectory, Basics.XML_AUTO_DEFAULT_DIRECTORY_NAME);
			String LocalizedDirectory = Path.Combine (PackageDirectory, DefaultDirectoryName);
			DataSet RemoteDefaultPictures = DataBase.GetRemoteFileData (RemotePackageDirectory,
					 Basics.AUTO_GRAPHICS_EXTENSIONS, 2);
			List<String> AvailableRemoteFiles = new List<string> ();
			List<String> AllAvailableFiles = new List<string> ();
			foreach (DataRow RemoteDataRow in RemoteDefaultPictures.Tables [0].Rows)
				{
				if (((!String.IsNullOrEmpty (DefaultDirectoryName))
					&& (Path.GetFileName (Path.GetDirectoryName (RemoteDataRow ["FileName"].ToString ())) == DefaultDirectoryName))
						|| (Path.GetFileName (Path.GetDirectoryName (RemoteDataRow ["FileName"].ToString ())) == "_Default"))
					{
					AvailableRemoteFiles.Add (RemoteDataRow ["FileName"].ToString ());
					if (!AllAvailableFiles.Contains (Path.GetFileNameWithoutExtension (RemoteDataRow ["FileName"].ToString ().ToUpper ())))
						AllAvailableFiles.Add (Path.GetFileNameWithoutExtension (RemoteDataRow ["FileName"].ToString ().ToUpper ()));
					}
				}

			List<String> DefaultPictures = new List<string> ();
			if (Directory.Exists (DefaultDirectory))
				DefaultPictures = Basics.GetFilesFromDirectory (DefaultDirectory, Basics.AUTO_GRAPHICS_EXTENSIONS, 1);
			List<String> LocalizedPictures = new List<string> ();
			if (Directory.Exists (LocalizedDirectory))
				LocalizedPictures = Basics.GetFilesFromDirectory (LocalizedDirectory, Basics.AUTO_GRAPHICS_EXTENSIONS, 1);
			foreach (String FileName in DefaultPictures)
				if (!AllAvailableFiles.Contains (Path.GetFileNameWithoutExtension (FileName.ToUpper ())))
					AllAvailableFiles.Add (Path.GetFileNameWithoutExtension (FileName.ToUpper ()));
			foreach (String FileName in LocalizedPictures)
				if (!AllAvailableFiles.Contains (Path.GetFileNameWithoutExtension (FileName.ToUpper ())))
					AllAvailableFiles.Add (Path.GetFileNameWithoutExtension (FileName.ToUpper ()));



			foreach (String CoreFileName in AllAvailableFiles)
				{
				String SourceFileNameToTransfer = String.Empty;
				String ElementName = String.Empty;
				bool SourceIsRemote = false;
				bool FoundInLocalized = false;
				foreach (String LocalizedFileName in LocalizedPictures)
					{
					if (LocalizedFileName.IndexOf ("\\" + DefaultDirectoryName + "\\" + CoreFileName + ".", StringComparison.OrdinalIgnoreCase) != -1)
						{
						ElementName = Path.GetFileName (LocalizedFileName);
						SourceFileNameToTransfer = LocalizedFileName;
						SourceIsRemote = false;
						break;
						}
					}
				if (String.IsNullOrEmpty (ElementName))
					{
					foreach (String DefaultFileName in DefaultPictures)
						{
						if (DefaultFileName.IndexOf ("\\_Default\\" + CoreFileName + ".", StringComparison.OrdinalIgnoreCase) != -1)
							{
							ElementName = Path.GetFileName (DefaultFileName);
							SourceFileNameToTransfer = DefaultFileName;
							SourceIsRemote = false;
							break;
							}
						}
					}
				if (String.IsNullOrEmpty (ElementName))
					{
					foreach (String LocalizedRemoteFileName in AvailableRemoteFiles)
						{
						if (LocalizedRemoteFileName.IndexOf ("\\" + DefaultDirectoryName + "\\" + CoreFileName + ".", StringComparison.OrdinalIgnoreCase) != -1)
							{
							ElementName = Path.GetFileName (LocalizedRemoteFileName);
							SourceFileNameToTransfer = LocalizedRemoteFileName;
							SourceIsRemote = true;
							break;
							}
						}
					}
				if (String.IsNullOrEmpty (ElementName))
					{
					foreach (String LocalizedRemoteFileName in AvailableRemoteFiles)
						{
						if (LocalizedRemoteFileName.IndexOf ("\\_Default\\" + CoreFileName + ".", StringComparison.OrdinalIgnoreCase) != -1)
							{
							ElementName = Path.GetFileName (LocalizedRemoteFileName);
							SourceFileNameToTransfer = LocalizedRemoteFileName;
							SourceIsRemote = true;
							break;
							}
						}
					}

				if (SourceIsRemote)
					{
					DateTime SourceFileLastWriteTime = DateTime.MinValue;
					MemoryStream RemoteFileStream = GetRemoteFileStream (SourceFileNameToTransfer, ref SourceFileLastWriteTime);
					if (RemoteFileStream != null)
						(Package as Paketieren.PackagingHandler).AddStreamElement (RemoteFileStream,
							ElementName);
					}
				else
					{
					(Package as Paketieren.PackagingHandler).AddFileElement
							(SourceFileNameToTransfer, ElementName);
					}
				}
			return true;
			}