public override bool NotifyOfItemSend(object mailItemObject) { MailClientHookBase.PreCacheEventWaitForCompletion(); PerformanceCounters.Instance.StartTimer(PerformanceCounters.CounterType.SendToDialogShow); BeginTimingDiagnostics(); ProcessResult processResult = ProcessResult.UNDEFINED; bool cancelEmailSend = true; try { IProxy mailItem = mailItemObject as IProxy; if (mailItem == null) { ErrorMessage errorMessage = new ErrorMessage( "NOTESITEM_UNAVAILABLE", "Workshare.PolicyMarshaller.Properties.Resources", Assembly.GetExecutingAssembly()); Interop.Logging.Logger.LogError(errorMessage.LogString); throw new Exception(errorMessage.DisplayString); } OnItemSend(mailItem, ref cancelEmailSend, ref processResult); mailItem.SetProcessResultCode((int) processResult); return !cancelEmailSend; } catch (Exception ex) { return ShouldContinueAfterException(ex); } finally { EndTimingDiagnostics(); } }
public string Execute(IActionData3 input, ActionPropertySet aProperties) { PDFCleanActionPropertySet cleanProperties = new PDFCleanActionPropertySet(aProperties); Dictionary<string, string> streamProperties = input.Properties; PDFCleanPropertiesDisplayTranslator strings = PDFCleanPropertiesDisplayTranslator.Instance; if (!streamProperties.ContainsKey(strings.StrmProp_DisplayName)) { ErrorMessage errorMessage = new ErrorMessage("UNABLE_TO_GET_FILE_IN_STREAM", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new Exception(errorMessage.DisplayString); } if (aProperties.SystemProperties.ContainsKey(strings.SysProp_FileType)) { if (!m_supportedFiles.Supports(aProperties.SystemProperties[strings.SysProp_FileType].Value as string)) { Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage("UNABLE_TO_CLEAN_NON_SUPPORTED_FILETYPE", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); return null; } } return CallCleanThread(cleanProperties, input.FileName, ref streamProperties, strings); }
public void TestDisplayString2() { int i = 3; string expected = string.Format("This is a formated string where i = {0}!", i); ErrorMessage errorMessage = new ErrorMessage("TestString3", "Workshare.Test.Utilities.Properties.UtilitiesResources", Assembly.GetExecutingAssembly(), i); Assert.AreEqual(expected, errorMessage.DisplayString, "Strings should be the same "); }
public void TestDisplayString3() { double d = 5.9; string s = "Added string"; string expected = string.Format("Test string with double {0} and {1}!", d, s); ErrorMessage errorMessage = new ErrorMessage("TestString4", "Workshare.Test.Utilities.Properties.UtilitiesResources", Assembly.GetExecutingAssembly(), new object[] { d, s }); Assert.AreEqual(expected, errorMessage.DisplayString, "Strings should be the same "); }
public IPolicySet ConvertPolicySet(AddPolicyLoadConversionMessageDelegate AddConversionMessage) { const decimal currentVersion = 2.1M; PolicyConverterBase converter = null; decimal version = decimal.Parse(GetPolicySetVersion(), CultureInfo.InvariantCulture); if (0 < decimal.Compare(currentVersion, version)) { PolicySetVersionStatus status = LatestVersion.Status; converter = new PolicySetVersionConverter_2_1(m_policySetCache, AddConversionMessage); converter.CreateCopyOfLatestVersion(); SetVersionStatus(LatestVersion, PolicySetVersionStatus.Disabled); converter.Convert(); converter.ConvertCompiledPolicySets(); // Restore status in the latest version SetVersionStatus(LatestVersion, status); } else if (0 == decimal.Compare(currentVersion, version)) { converter = new PolicyConverterBase(m_policySetCache, AddConversionMessage); } else { ErrorMessage errorMessage = new ErrorMessage("POLICY_VERSION_NOT_SUPPORTED", "Workshare.Policy.Properties.Resources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new Exceptions.PolicyException(errorMessage.DisplayString); } IPolicySet result = converter.LatestPolicySet; if (result.PolicyType != m_policySetCache.LatestPolicyType) { string error = string.Format(CultureInfo.CurrentCulture, Properties.Resources.POLICY_TYPES_DISAGREE, m_policySetCache.LatestPolicyType, result.PolicyType); Logger.LogError(error); throw new Exceptions.PolicyException(error); } return result; }
public static DataItem CreateDataItemWithCultureInfo(IPolicyLanguageItem name, DataType dataType, object data, CultureInfo ci) { switch (dataType) { case DataType.StringArray: case DataType.String: return new DataItem(name, Convert.ToString(data, ci)); case DataType.LongArray: case DataType.Long: return new DataItem(name, Convert.ToInt64(data, ci)); case DataType.DoubleArray: case DataType.Double: return new DataItem(name, Convert.ToDouble(data, ci)); case DataType.BooleanArray: case DataType.Boolean: return new DataItem(name, Convert.ToBoolean(data, ci)); case DataType.DateArray: case DataType.Date: case DataType.DateTimeArray: case DataType.DateTime: return new DataItem(name, Convert.ToDateTime(data, ci)); case DataType.Object: { DataSource dataSource = data as DataSource; return new DataItem(name, dataSource.DeepCopy(dataSource.ReadOnly, false)); } default: { ErrorMessage errorMessage = new ErrorMessage( "OUT_OF_RANGE", "Workshare.Policy.Properties.Resources", Assembly.GetExecutingAssembly(), dataType); Logger.LogError(errorMessage.LogString); throw new PolicyException(errorMessage.DisplayString); } } }
/// <summary> /// Builds a list of RoutingItem objects from the items in the Device Types checked list box /// </summary> /// <returns>The list of RoutingItem objects</returns> private List<IRoutingItem> GetRoutingItemsFromDeviceTypes() { List<IRoutingItem> routingItems = new List<IRoutingItem>(); DeviceTypeDisplayTranslator displayTranslator = DeviceTypeDisplayTranslator.Instance; //get device types int index = 0; foreach (string deviceType in m_ui.CheckedDeviceTypes) { try { string deviceTypeData = displayTranslator.GetDataType(deviceType); IRoutingItem routingItem = new RoutingItem(deviceTypeData, deviceTypeData); CustomAttributes.SetContentType(routingItem, Workshare.Policy.Routing.RemovableDeviceItemContentTypes.DeviceType); routingItems.Add(routingItem); } catch (ArgumentException ex) { ErrorMessage errorMessage = new ErrorMessage( "DEVICETYPE_UNKNOWN", "Workshare.PolicyDesigner.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); Logger.LogError(ex); } index++; } //Remember that the ItemCheck event was rasied *before* the state changes. //So, do extra processing for the item that changed. We may need to add it to, //or remove it from, our list if (m_changedDeviceTypeIndex >= 0) { string changedDeviceType = m_ui.DeviceTypes[m_changedDeviceTypeIndex] as string; string changedDeviceTypeData = displayTranslator.GetDataType(changedDeviceType); if (m_changedDeviceTypeNewCheckState == CheckState.Checked) { //item should be in our list IRoutingItem changedRoutingItem = null; foreach(IRoutingItem routingItem in routingItems) { if (routingItem.Content == changedDeviceTypeData) { changedRoutingItem = routingItem; } } if (null == changedRoutingItem) { IRoutingItem routingItem = new RoutingItem(changedDeviceTypeData, changedDeviceTypeData); CustomAttributes.SetContentType(routingItem, Workshare.Policy.Routing.RemovableDeviceItemContentTypes.DeviceType); routingItems.Add(routingItem); } } else if (m_changedDeviceTypeNewCheckState == CheckState.Unchecked) { //item shouldn't be in our list. IRoutingItem changedRoutingItem = null; foreach (IRoutingItem routingItem in routingItems) { if (routingItem.Content == changedDeviceTypeData) { changedRoutingItem = routingItem; } } if (null != changedRoutingItem) { routingItems.Remove(changedRoutingItem); } } else { //don't currently support intermediate state System.Diagnostics.Debug.Assert(false); } } return routingItems; }
/// <summary> /// Converts a localised displayable representation of a RunAt enumeration into the enumeration value /// </summary> /// <param name="runAt">The localised displayable representation of the RunAt enuemration to evaluate</param> /// <returns>The RunAt enumeration</returns> private RunAt ConvertRunAt(string runAt) { if (runAt == Properties.Resources.RUNAT_CLIENT) return RunAt.Client; if (runAt == Properties.Resources.RUNAT_SERVER) return RunAt.Server; if (runAt == Properties.Resources.RUNAT_BOTH) return RunAt.Both; ErrorMessage errorMessage = new ErrorMessage( "RUNAT_INVALID", "Workshare.PolicyDesigner.Properties.Resources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new Exception(errorMessage.DisplayString); }
/// <summary> /// Converts a RunAt enumeration to a localised displayable value /// </summary> /// <param name="runAt">The RunAt enumeration to evaluate</param> /// <returns>The localised displayable representation of the RunAt enumeration</returns> private string ConvertRunAt(RunAt runAt) { switch (runAt) { case RunAt.Client: return Properties.Resources.RUNAT_CLIENT; case RunAt.Server: return Properties.Resources.RUNAT_SERVER; case RunAt.Both: return Properties.Resources.RUNAT_BOTH; default: ErrorMessage errorMessage = new ErrorMessage( "RUNAT_INVALID", "Workshare.PolicyDesigner.Properties.Resources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new Exception(errorMessage.DisplayString); } }
private void AddFileTypeRow(ActionFileTypeObject fileType) { //TODO: we shouldn't have our own file type enumeration in the policy designer! try { ListViewItem item = new ListViewItem(FileTypeBridge.GetFileType(fileType.Filetype)); item.Tag = fileType.Identifier; fileTypesListView.Items.Add(item); } catch(ArgumentException ex) { ErrorMessage errorMessage = new ErrorMessage( "FILETYPE_UNSUPPORTED", "Workshare.PolicyDesigner.Properties.Resources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new PolicyDesignerException(errorMessage.DisplayString, ex); } }
/// <summary> /// Gets an FileContextType from its display name /// </summary> /// <param name="fileContextString">The display name of an FileContextType</param> /// <returns>A FileContextType</returns> public static ConditionUnitFactory.FileContextType GetFileContextType(string fileContextString) { if (fileContextString.CompareTo(FileContextTypeParagraph) == 0) return ConditionUnitFactory.FileContextType.Paragraph; if (fileContextString.CompareTo(FileContextTypeHeader) == 0) return ConditionUnitFactory.FileContextType.Header; if (fileContextString.CompareTo(FileContextTypeFooter) == 0) return ConditionUnitFactory.FileContextType.Footer; if (fileContextString.CompareTo(FileContextTypeFootnote) == 0) return ConditionUnitFactory.FileContextType.Footnote; if (fileContextString.CompareTo(FileContextTypeEndnote) == 0) return ConditionUnitFactory.FileContextType.Endnote; if (fileContextString.CompareTo(FileContextTypeTextBox) == 0) return ConditionUnitFactory.FileContextType.TextBox; if (fileContextString.CompareTo(FileContextTypeCellText) == 0) return ConditionUnitFactory.FileContextType.CellText; if (fileContextString.CompareTo(FileContextTypeCustomProperty) == 0) return ConditionUnitFactory.FileContextType.CustomProperty; if (fileContextString.CompareTo(FileContextTypeSubject) == 0) return ConditionUnitFactory.FileContextType.Subject; if (fileContextString.CompareTo(FileContextTypeBody) == 0) return ConditionUnitFactory.FileContextType.Body; if (fileContextString.CompareTo(FileContextTypeHttpContent) == 0) return ConditionUnitFactory.FileContextType.HTTPContent; ErrorMessage errorMessage = new ErrorMessage( "FILECONTEXTTYPE_UNSUPPORTED", "Workshare.PolicyDesigner.Properties.Resources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new ArgumentException(errorMessage.DisplayString); }
/// <summary> /// Gets an OperatorType from its display name /// </summary> /// <param name="op">The display name of an OperatorType</param> /// <returns>An OperatorType</returns> public static OperatorType GetOperatorType(string op) { if (op.CompareTo(OperatorTypeEquals) == 0) return OperatorType.Equals; if (op.CompareTo(OperatorTypeGreaterThan) == 0) return OperatorType.GreaterThan; if (op.CompareTo(OperatorTypeGreaterThanOrEqualTo) == 0) return OperatorType.GreaterThanOrEqualTo; if (op.CompareTo(OperatorTypeLessThan) == 0) return OperatorType.LessThan; if (op.CompareTo(OperatorTypeLessThanOrEqualTo) == 0) return OperatorType.LessThanOrEqualTo; if (op.CompareTo(OperatorTypeNotEqualTo) == 0) return OperatorType.NotEqual; ErrorMessage errorMessage = new ErrorMessage( "OPERATORTYPE_UNSUPPORTED", "Workshare.PolicyDesigner.Properties.Resources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new ArgumentException(errorMessage.DisplayString); }
private Stream ExecuteStream(Stream input, Dictionary<string, string> sProperties, ActionPropertySet aProperties) { m_fallbackTried = null; if (aProperties == null) throw new ArgumentNullException("aProperties"); Dictionary<string, string> streamProperties = sProperties; CleanActionPropertySet cleanProperties = new CleanActionPropertySet(aProperties); cleanProperties[Workshare.ApplicationControllers.PropertyNames.REQUIRES_APPCONTROLLER].Value = false; CleanPropertiesDisplayTranslator strings = CleanPropertiesDisplayTranslator.Instance; if (!streamProperties.ContainsKey(strings.StrmProp_DisplayName)) { ErrorMessage errorMessage = new ErrorMessage("UNABLE_TO_GET_FILE_IN_STREAM", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new CleanUserActionException(errorMessage.DisplayString); } if (aProperties.SystemProperties.ContainsKey(strings.SysProp_FileType)) { if (!m_supportedFiles.Supports(aProperties.SystemProperties[strings.SysProp_FileType].Value as string)) { Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage("UNABLE_TO_CLEAN_NON_SUPPORTED_FILETYPE", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); return null; } } return CallCleanThread(cleanProperties, input, ref streamProperties, strings, false, false); }
private bool Init(object application) { try { m_application = application as _Application; if (m_application == null) { ErrorMessage errorMessage = new ErrorMessage("APPLICATION_NOT_INIT", "Workshare.PolicyMarshaller.Properties.Resources", Assembly.GetExecutingAssembly()); Interop.Logging.Logger.LogError(errorMessage.LogString); throw new Exception(errorMessage.DisplayString); } m_parentWnd = NativeMethods.GetForegroundWindow(); return true; } catch (Exception ex) { return ShouldContinueAfterException(ex); } }
private void AddPropertyToRatedLists(string key, RiskRating rating, TargetApplication target) { if (m_list.ContainsKey(key)) { switch (rating) { case RiskRating.Low: case RiskRating.Medium: case RiskRating.High: case RiskRating.Rated: m_RatedRisk.Add(key, target); m_riskRatedProperties.Add(key, rating); break; case RiskRating.None: break; default: { ErrorMessage errorMessage = new ErrorMessage("UNEXPECTED_RISK_RATING", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new Exception(errorMessage.DisplayString); } } } else { ErrorMessage errorMessage = new ErrorMessage("PDFCLEANUSERACTIONPROPERTY", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); } }
private void SetRoutingItemCollection(IRoutingItemCollection routingItemCollection) { //reset the our internal record of the last checked item, else things will screw up when we //next call GetRoutingItemCollection m_changedDeviceTypeIndex = -1; m_changedDeviceTypeNewCheckState = CheckState.Unchecked; Dictionary<string, bool> deviceTypesDictionary = new Dictionary<string, bool>(); DeviceTypeDisplayTranslator displayTranslator = DeviceTypeDisplayTranslator.Instance; StringBuilder volumeNames = new StringBuilder(); StringBuilder volumeIDs = new StringBuilder(); //set all device types supported by us foreach (string deviceType in displayTranslator.DataTypes) { deviceTypesDictionary.Add(displayTranslator.GetDisplayType(deviceType), false); } //ASSUMPTION: if the members input panel is disabled, assume that this is the default group and //check all the checkboxes. This is purely cosmetic. if (!m_ui.MembersInputPanelEnabled) { Dictionary<string, bool> copyOfDictionary = new Dictionary<string, bool>(deviceTypesDictionary); foreach (string deviceType in copyOfDictionary.Keys) { deviceTypesDictionary[deviceType] = true; } } else { //now, check those that are currently members foreach (IRoutingItem routingItem in routingItemCollection) { string contentType = CustomAttributes.GetContentType(routingItem); if (0 == String.Compare(contentType, Workshare.Policy.Routing.RemovableDeviceItemContentTypes.DeviceType, false, CultureInfo.InvariantCulture)) { try { string displayableSelectedDeviceType = displayTranslator.GetDisplayType(routingItem.Content); if (deviceTypesDictionary.ContainsKey(displayableSelectedDeviceType)) { deviceTypesDictionary[displayableSelectedDeviceType] = true; } } catch (ArgumentException ex) { ErrorMessage errorMessage = new ErrorMessage( "DEVICETYPE_UNKNOWN", "Workshare.PolicyDesigner.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); Logger.LogError(ex); } catch (KeyNotFoundException ex) { ErrorMessage errorMessage = new ErrorMessage( "DEVICETYPE_UNKNOWN", "Workshare.PolicyDesigner.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); Logger.LogError(ex); } } else if (0 == String.Compare(contentType, Workshare.Policy.Routing.RemovableDeviceItemContentTypes.VolumeName, false, CultureInfo.InvariantCulture)) { if (volumeNames.Length == 0) { volumeNames.AppendFormat(routingItem.Content); } else { volumeNames.AppendFormat("; {0}", routingItem.Content); } } else if (0 == String.Compare(contentType, Workshare.Policy.Routing.RemovableDeviceItemContentTypes.VolumeID, false, CultureInfo.InvariantCulture)) { if (volumeIDs.Length == 0) { volumeIDs.AppendFormat(routingItem.Content); } else { volumeIDs.AppendFormat("; {0}", routingItem.Content); } } else { string message = String.Format(CultureInfo.InvariantCulture, Properties.Resources.ROUTINGITEMTYPE_UNKNOWN, routingItem.Content); Logger.LogError(message); } } } //finally, update the ui CheckedListBox.ObjectCollection deviceTypes = m_ui.DeviceTypes; deviceTypes.Clear(); foreach (string key in deviceTypesDictionary.Keys) { deviceTypes.Add(key, deviceTypesDictionary[key]); } m_ui.VolumeName = volumeNames.ToString(); m_ui.VolumeID = volumeIDs.ToString(); }
private void SetVersionStatus(SaveOption option) { LocalPolicySetVersionCache ver = (LocalPolicySetVersionCache)LatestVersion; switch (option) { case SaveOption.Delete: ver.Status = PolicySetVersionStatus.Deleted; break; case SaveOption.Disable: { DisableOldVersions(); if (ver.Status == PolicySetVersionStatus.Enabled) ver.Status = PolicySetVersionStatus.Disabled; } break; case SaveOption.SaveOnly: { if (PolicySetVersionStatus.Enabled != ver.Status) ver.Status = PolicySetVersionStatus.InProgress; } break; case SaveOption.SaveNew: { if (ver.Status == PolicySetVersionStatus.Enabled) ver = NewVersionFromLatest(PolicySetVersionStatus.InProgress); else ver.Status = PolicySetVersionStatus.InProgress; } break; case SaveOption.Publish: { if (ver.Status == PolicySetVersionStatus.InProgress || ver.Status == PolicySetVersionStatus.Disabled) ver.Status = PolicySetVersionStatus.Enabled; else if (ver.Status == PolicySetVersionStatus.Enabled) ver = NewVersionFromLatest(PolicySetVersionStatus.Enabled); DisableOldVersions(); } break; default: { ErrorMessage errorMessage = new ErrorMessage( "STATUS_NOT_IMPL", "Workshare.Policy.ClientCache.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new Exception(errorMessage.DisplayString); } } }
private void AddPropertyToRatedLists(string key, RiskRating rating, TargetApplication target) { if (m_list.ContainsKey(key)) { switch (rating) { case RiskRating.Low: case RiskRating.Medium: case RiskRating.High: case RiskRating.Rated: m_RatedRisk.Add(key, target); m_riskRatedProperties.Add(key, rating); break; case RiskRating.Exclusion: m_ExclusionRatedRisk.Add(key, target); break; case RiskRating.None: break; default: { ErrorMessage errorMessage = new ErrorMessage("UNEXPECTED_RISK_RATING", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new CleanUserActionException(errorMessage.DisplayString); } } } else { ErrorMessage errorMessage = new ErrorMessage("CLEANUSERACTIONPROPERTY", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); // Don't throw an exception currently because binary clean doesn't have all properties? //str = Utilities.CultureSpecificString.CurrentResourceString("CLEANUSERACTIONPROPERTY", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly()); //str = string.Format(CultureInfo.CurrentCulture, str, key); //throw new CleanUserActionException(str); } }
/// <summary> /// Returns the display name of an FileContextType /// </summary> /// <param name="fileContextType">The FileContextType to be displayed</param> /// <returns>The display name of the FileContextType</returns> public static string GetFileContextString(ConditionUnitFactory.FileContextType fileContextType) { switch (fileContextType) { case ConditionUnitFactory.FileContextType.Paragraph: return FileContextTypeParagraph; case ConditionUnitFactory.FileContextType.Header: return FileContextTypeHeader; case ConditionUnitFactory.FileContextType.Footer: return FileContextTypeFooter; case ConditionUnitFactory.FileContextType.Footnote: return FileContextTypeFootnote; case ConditionUnitFactory.FileContextType.Endnote: return FileContextTypeEndnote; case ConditionUnitFactory.FileContextType.TextBox: return FileContextTypeTextBox; case ConditionUnitFactory.FileContextType.CellText: return FileContextTypeCellText; case ConditionUnitFactory.FileContextType.CustomProperty: return FileContextTypeCustomProperty; case ConditionUnitFactory.FileContextType.Subject: return FileContextTypeSubject; case ConditionUnitFactory.FileContextType.Body: return FileContextTypeBody; case ConditionUnitFactory.FileContextType.HTTPContent: return FileContextTypeHttpContent; default: { ErrorMessage errorMessage = new ErrorMessage( "FILECONTEXTTYPE_UNSUPPORTED", "Workshare.PolicyDesigner.Properties.Resources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new ArgumentException(errorMessage.DisplayString); } } }
private IStream GetStream(out StructuredStorageInterface.IStorage iStorage, string streamname) { if (m_bNotAStreamFile) { iStorage = null; return null; } if (!HasStructuredStorageHeader()) { m_bNotAStreamFile = false; iStorage = null; return null; } uint iRet = 0; if (Workshare.Interop.Options.OptionApi.GetBool("UseDiskBasedFiles") && !string.IsNullOrEmpty(m_fileData.Filename) && m_fileData.BinaryFileData is DiskBinaryData) { iRet = StructuredStorageInterface.StgOpenStorage(m_fileData.Filename, null, StructuredStorageInterface.ReadOnlyModeTransacted, System.IntPtr.Zero, 0, out iStorage); } else { if (m_lockbyteswrapper == null) { m_lockbyteswrapper = new LockBytesWrapper(m_fileData.BinaryFileData); } else { if (!m_lockbyteswrapper.Represents(m_fileData.BinaryFileData)) { throw new InvalidOperationException("Invalid use of lockbyteswrapper in FileTypeIdentifiers"); } } if (null == m_lockbyteswrapper.ILockBytesInterface) { ErrorMessage errorMessage = new ErrorMessage( "EXPECTED_VALID", "Workshare.Policy.Engine.Properties", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new NullReferenceException(errorMessage.DisplayString + " - " + "ILockBytes"); } iRet = StructuredStorageInterface.StgOpenStorageOnILockBytes(m_lockbyteswrapper.ILockBytesInterface, null, StructuredStorageInterface.ReadOnlyMode, System.IntPtr.Zero, 0, out iStorage); } if (0 != iRet) { ComObjectGovernor.ReleaseObject(iStorage); if (StructuredStorageInterface.STG_E_SHAREVIOLATION != iRet) { m_bNotAStreamFile = true; return null; } ErrorMessage errorMessage = new ErrorMessage( "FAILED_OPEN_STORAGE", "Workshare.Policy.Engine.Properties", Assembly.GetExecutingAssembly(), iRet.ToString("x", CultureInfo.InvariantCulture)); Logger.LogError(errorMessage.LogString); throw new FileLoadException(errorMessage.DisplayString, m_fileData.Filename); } IStream iStream; try { iStream = iStorage.OpenStream(streamname, IntPtr.Zero, Convert.ToInt32(StructuredStorageInterface.ReadOnlyMode), 0); } catch (System.Runtime.InteropServices.COMException) { ComObjectGovernor.ReleaseObject(iStorage); // iStorage.OpenStream no longer throws STG_E_FILENOTFOUND for some reason, and instead throws an RPC error // which is quite generic anyway ... so we no longer check for error code. //if (StructuredStorageInterface.STG_E_FILENOTFOUND != (uint) e.ErrorCode) //throw e; return null; } return iStream; }
/// <summary> /// Returns the display name of an OperatorType /// </summary> /// <param name="op">The OperatorType to be displayed</param> /// <returns>The display name of the OperatorType</returns> public static string GetOperatorString(OperatorType op) { switch (op) { case OperatorType.Equals: return OperatorTypeEquals; case OperatorType.GreaterThan: return OperatorTypeGreaterThan; case OperatorType.GreaterThanOrEqualTo: return OperatorTypeGreaterThanOrEqualTo; case OperatorType.LessThan: return OperatorTypeLessThan; case OperatorType.LessThanOrEqualTo: return OperatorTypeLessThanOrEqualTo; case OperatorType.NotEqual: return OperatorTypeNotEqualTo; default: { ErrorMessage errorMessage = new ErrorMessage( "OPERATORTYPE_UNSUPPORTED", "Workshare.PolicyDesigner.Properties.Resources", Assembly.GetExecutingAssembly()); Logger.LogError(errorMessage.LogString); throw new ArgumentException(errorMessage.DisplayString); } } }
public void TestDisplayString1() { ErrorMessage errorMessage = new ErrorMessage("TestString1", "Workshare.Test.Utilities.Properties.UtilitiesResources", Assembly.GetExecutingAssembly()); Assert.AreEqual("This is test string one!", errorMessage.DisplayString, "Strings should be the same "); }