예제 #1
0
		public void TestFileCtor_LongDisplayName()
		{
			BinaryData data = new BinaryData(new MemoryStream(new byte[] {79, 5, 15})); //any old byte array
			try
			{
				File file = new File(data, "ShortIsOK");
			}
			catch
			{
				Assert.Fail("Did not expect this ctor to fail");
			}

			try
			{
				StringBuilder tooLong = new StringBuilder();
				string guid = Guid.NewGuid().ToString();
				for( int i = 0; i < 100; i++)
				{
					tooLong.Append(guid);
				}

				//Why do we care about long names?  
				//Because the File code calls a framework class that tells us if the name looks like a file path.
				//That code (Path.GetPathRoot()) can throw on 'long' filenames.  Since there is nothing to stop display names 
				//being longer than the legal limit of file paths, the File code should not blow up in this case.

				File file = new File(data, tooLong.ToString());
			}
			catch
			{
				Assert.Fail("Did not expect this ctor to fail");
			}

		}
예제 #2
0
		public void TestInitialiseRtf_WithoutModifyPassword()
		{
			String filePath = Path.Combine(TESTFILE_DIR, "TestInitialiseRtf_NoModifyPassword.rtf");
			using (File file = new File(filePath, filePath))
			{
                Assert.IsFalse(file.WritePasswordProtected, "Shouldn't have detected write password in " + filePath);
                Assert.IsFalse(file.ReadPasswordProtected, "Shouldn't have detected read password in " + filePath);
				Assert.IsTrue(file.CanOpenContent, "Shouldn't have detected some protection in " + filePath);
			}
		}
예제 #3
0
		public void TestInitialiseRtf_WithModifyPassword()
		{
			String filePath = Path.Combine(TESTFILE_DIR, "TestInitialiseRtf_ModifyPasswordIs_fdsa.rtf");
			using (File file = new File(filePath, filePath))
			{
				Assert.IsTrue(file.WritePasswordProtected, "Should have detected write password in " + filePath );
				Assert.IsFalse(file.ReadPasswordProtected, "Shouldn't have detected read password in " + filePath);

                // Here we expect true, since even if document has Modify Password we still can open it, but cannot modify.
                Assert.IsTrue(file.CanOpenContent, "Shouldn't have detected open protection in " + filePath);
			}
		}
예제 #4
0
		public void TestInitialiseXsl()
		{
			String filePath = Path.Combine(TESTFILE_DIR, "Allriskelementsxls.xls");
			using (File file = new File(filePath, filePath))
			{
				Assert.IsTrue(file.FileType == FileType.ExcelSheet, "Should have detected ExcelSheet in " + filePath);
                Assert.IsFalse(file.WritePasswordProtected, "Shouldn't have detected write password in " + filePath);
                Assert.IsTrue(file.ReadPasswordProtected, "Shouldn't have detected read password in " + filePath);
				Assert.IsFalse(file.CanOpenContent, "Shouldn't have detected some protection in " + filePath);
			}

			filePath = Path.Combine(TESTFILE_DIR, "EncryptedWithDocumentRestriction.xls");
			using (File file = new File(filePath, filePath))
			{
				Assert.IsTrue(file.FileType == FileType.ExcelSheet, "Should have detected ExcelSheet in " + filePath);
                Assert.IsFalse(file.WritePasswordProtected, "Shouldn't have detected write password in " + filePath);
                Assert.IsFalse(file.ReadPasswordProtected, "Shouldn't have detected read password in " + filePath);
				Assert.IsTrue(file.CanOpenContent, "Shouldn't have detected some protection in " + filePath);
			}
		}
예제 #5
0
파일: File.cs 프로젝트: killbug2004/WSProf
 public File(Workshare.FCS.Lite.Interface.File file)
 {
     m_impl = file;
 }
예제 #6
0
파일: File.cs 프로젝트: killbug2004/WSProf
 /// <summary>
 /// Constructor that makes this collection and sets the contentstream
 /// </summary>
 /// <param name="contentstream"></param>
 /// <param name="displayname"></param>
 /// <param name="fileType"></param>
 public File(Stream contentstream, string displayname, FileType fileType)
 {
     m_impl = new Workshare.FCS.Lite.Interface.File(contentstream, displayname, fileType);
 }
예제 #7
0
파일: File.cs 프로젝트: killbug2004/WSProf
 /// <summary>
 /// Constructor that makes this a collection
 /// <param name="displayname"></param>
 /// </summary>
 public File(string displayname, FileType fileType)
 {
     m_impl = new Workshare.FCS.Lite.Interface.File(displayname, fileType);
 }
예제 #8
0
파일: File.cs 프로젝트: killbug2004/WSProf
 /// <summary>
 /// Constructor that takes a filename as a parameter
 /// </summary>
 /// /// <param name="filename"></param>
 /// /// <param name="displayname"></param>
 public File(string filename, string displayname)
 {
     m_impl = new Workshare.FCS.Lite.Interface.File(filename, displayname);
 }
예제 #9
0
파일: File.cs 프로젝트: killbug2004/WSProf
 /// <summary>
 /// Constructor that takes a byte[] as a parameter
 /// </summary>
 /// <param name="memoryfile"></param>
 /// <param name="displayname"></param>
 public File(BinaryData memoryfile, string displayname)
 {
     m_impl = new Workshare.FCS.Lite.Interface.File(memoryfile, displayname);
 }
예제 #10
0
파일: File.cs 프로젝트: killbug2004/WSProf
 /// <summary>
 /// Create a File wrapper around an existing FCS.Lite define file object
 /// </summary>
 /// <param name="implementation"></param>
 internal File(IFile implementation)
 {
     m_impl = (Workshare.FCS.Lite.Interface.File) implementation;
 }
예제 #11
0
		public string Execute(IActionData3 data, ActionPropertySet properties)
		{
			Stream inputStream = null;
			Stream outputStream = null;
			try
			{
				using (Workshare.Policy.Engine.Interfaces.IFile inputFile = new Workshare.FCS.Lite.Interface.File(data.FileName, Path.GetFileName(data.FileName)))
				{
					inputStream = inputFile.Contents;
					Dictionary<string, string> streamProperties = data.Properties;
					outputStream = actionObject.Execute(inputStream, properties, ref streamProperties);
					if (null != inputStream)
					{
						inputStream.Close();
					}
					ThrowIfAbortWasFound(streamProperties);

					string displayName = data.Properties["DisplayName"];
					string outputFile = data.FileName;
					if (String.Compare(Path.GetFileName(data.FileName), displayName, true) != 0)
					{
						outputFile = Path.Combine(Path.GetFullPath(data.FileName), displayName);
						System.IO.File.Delete(data.FileName);
						data.Properties["FileName"] = outputFile;
						data.Properties["DisplayName"] = Path.GetFileName(data.FileName);
					}					

					using (FileStream fileStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.Read))
					{
						StreamUtils.CopyStreamToStream(outputStream, fileStream);
						if (null != outputStream)
						{
							outputStream.Close();
						}
					}

					return outputFile;
				}
			}
			catch (System.Exception ex)
			{
				Logger.LogError(ex);
				throw;
			}
			finally
			{
				if (null != inputStream)
				{
					inputStream.Close();
				}

				if (null != outputStream)
				{
					outputStream.Close();
				}
			}
		}
예제 #12
0
		private OfficeApplication GetOfficeApplicationType(string filename)
		{
			Workshare.FCS.Lite.Interface.File file = new Workshare.FCS.Lite.Interface.File(filename, "");

			switch( file.FileType )
			{
				case FileType.WordDocument:
				case FileType.WordDocumentX:
				case FileType.WordDocumentMacroX:
				case FileType.WordDocumentTemplateX:
				case FileType.WordDocumentMacroTemplateX:
				case FileType.RTFDocument:
				case FileType.TextDocument:
				case FileType.HTMLDocument:
					return OfficeApplication.Word;

				case FileType.ExcelSheet:
				case FileType.ExcelSheetX:
				case FileType.ExcelSheetMacroX:
				case FileType.ExcelSheetTemplateX:
				case FileType.ExcelSheetMacroTemplateX:
					return OfficeApplication.Excel;

				case FileType.PowerPoint:
				case FileType.PowerPointX:
				case FileType.PowerPointMacroX:
				case FileType.PowerPointTemplateX:
				case FileType.PowerPointMacroTemplateX:
				case FileType.PowerPointShowX:
				case FileType.PowerPointMacroShowX:
					return OfficeApplication.PowerPoint;                                              

				case FileType.Email:
					return OfficeApplication.Outlook;
			}           

			throw new System.Exception("Unsupported file type");
		}
예제 #13
0
        protected string GetExtensionForMasqueradingAttachment(OutlookAttachment attachment)
        {
            if (attachment.FileName.Contains('~')) // only interested in 8.3 formated file names.
            {
                var extension = Path.GetExtension(attachment.FileName);

                if (!string.IsNullOrEmpty(extension))
                {
                    using (var tfc = new TempFileController())
                    {
                        var tempfile = tfc.GetTempFilename(extension.TrimStart('.'), true);
                        attachment.SaveAsFile(tempfile);

                        using (IFile file = new Workshare.FCS.Lite.Interface.File(tempfile, attachment.DisplayName))
                        {
                            switch (file.FileType)
                            {
                                case FileType.WordDocumentX:
                                    return "docx";
                                case FileType.ExcelSheetX:
                                    return "xlsx";
                                case FileType.PowerPointX:
                                    return "pptx";
                            }
                        }
                    }
                }
            }
            return string.Empty;
        }
예제 #14
0
        public static FileType GetFileType(string filename)
        {
            Workshare.FCS.Lite.Interface.File file = new Workshare.FCS.Lite.Interface.File(filename, "");

            return file.FileType;
        }
예제 #15
0
		/// <summary>
		/// Sets up this encryption object
		/// </summary>
		/// <param name="attachment">Original attachment</param>
		protected FileEncryption(Attachment attachment, File file)
		{		
			m_Attachment = attachment;
			m_AttachmentFile = file;
		}
예제 #16
0
		private string AddAttachment(Request request, IEmailAttachment attachment)
		{
            string contentType = MimeAttachmentsProxy.GetContentType(attachment);
			string attachmentName = attachment.DisplayName;

            // 14781 - CR:  00180301 Professional 7.00 FP3 - Rodyk -  Illegal Characters in Path error sending MSG attachments
            var invalidFileNameCharacters = Path.GetInvalidFileNameChars();
		    if (attachmentName.IndexOfAny(invalidFileNameCharacters) == -1)
		    {
		        // Hack alert. TFS6626 - customer with 'Lawsoft' which creates dodgy .msg files that have the DisplayName field of the attachment set wrongly
		        // the DisplayName is missing the '.' separating the name and the extension. We work around this for now
		        if (string.IsNullOrEmpty(Path.GetExtension(attachmentName)) &&
		            !string.IsNullOrEmpty(Path.GetExtension(attachment.FileName)))
		        {
		            // do we have a display name with no extension and a file name with an extension
		            // there must be a '.' in the filename, since it has an extension.
		            // now test to see if we remove the '.' separating the extension, does the filename end with the attachment name
		            if (attachment.FileName.Remove(attachment.FileName.LastIndexOf('.'), 1).EndsWith(attachmentName))
		            {
		                // yep, so we have FileName = 'c:\blah\blah\test.docx' and display name = 'testdocx'
		                // which isn't good - as we check for profiles to display based on the extension (which would be blank)
		                // and we re-instate only the displayname of the attachment, not the file name
		                // so we will get the corrected display name from the filename
		                attachmentName = Path.GetFileName(attachment.FileName);
		            }
		        }
		    }
		    string contentId = attachment.ContentId;
			string index = attachment.ContentItemIndex.ToString(CultureInfo.InvariantCulture);

			if (string.IsNullOrEmpty(contentId))
				contentId = Guid.NewGuid().ToString();


			IFile file = new File(attachment.FileName, attachmentName);
			Attachment requestAttachment = new Attachment(file, contentType, contentId, index, false);
		    requestAttachment.IsSignature = attachment.IsSignature;

			if (attachment.IsSignature)
			{
				requestAttachment.IgnoreForWorkshareActions = true;
			}

			CustomProperty prop = new CustomProperty(PropertyNames.LocalFileName, attachment.FileName);

			if (attachment.RecordKey != null)
			{
				string recordkey =  attachment.RecordKey;
				CustomProperty prop2 = new CustomProperty(PropertyNames.RecordKey, recordkey);
				requestAttachment.Properties = new CustomProperty[] { prop, prop2 };
			}
			else
			{
				requestAttachment.Properties = new CustomProperty[] { prop };
			}

			List<Attachment> attachments = new List<Attachment>(request.Attachments);
			attachments.Add(requestAttachment);
			request.Attachments = attachments.ToArray();

			return attachmentName;
		}
예제 #17
0
		private bool CleanFiles(Collection<IContainer> files)
		{
			try
			{
				for (int i = 0; i < files.Count; i++)
				{
					if (_bCancel)
					{
						if (CleanProcessCancelled != null)
							CleanProcessCancelled(this, new EventArgs());

						return false;
					}

					Workshare.Policy.Engine.File file = files[i] as Workshare.Policy.Engine.File;
					if (file != null && file.FileType == FileType.ZIP)
					{
						if (file.ReadOnly)
						{
							Logger.LogError(string.Format("Cannot batch-clean file '{0}' as it is read-only", file.FileName));
							if (FileProcessed != null)
								FileProcessed(this, new FileProcessEventArgs(file, FileProcessEventArgs.Status.ReadOnly));

							file.Properties.Add("Modified", "False");
						}
						else
						{
							CleanFiles(file.Files);
						}
					}
					else
					{
						IFile newFile = ProcessSingleFile(files[i] as IFile);

						if (newFile != null)
						{
							// Keep the old displayname so that we don't loose the zip path information
							files[i] = new Workshare.FCS.Lite.Interface.File(newFile.FileName, files[i].DisplayName);// Can't set Displayname directly.

							// Need to copy the properties to ensure the end report is updated correctly
							foreach (var property in newFile.Properties)
							{
								var file1 = files[i] as IFile;
								if (file1 != null)
								{
									file1.Properties.Add(property.Key, property.Value);
								}
							}
						}
					}
				}
			}
			finally
			{
				GC.Collect();
				GC.WaitForPendingFinalizers();
			}

			return true;
		}