public static SearchCondition CreateAndOrCondition(SearchConditionType conditionType, bool simplify, params SearchCondition[] conditionNodes) { ICondition result = null; var nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass(); try { var conditions = new List <ICondition>(); if (conditionNodes != null) { conditions.AddRange(conditionNodes.Select(c => c.SearchConditionNative)); } IEnumUnknown subConditions = new EnumUnknown <ICondition>(conditions); var hr = nativeConditionFactory.MakeAndOr((CONDITION_TYPE)conditionType, subConditions, simplify, out result); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } } finally { Marshal.ReleaseComObject(nativeConditionFactory); } return(new SearchCondition(result)); }
private static SearchCondition CreateLeafCondition(string propertyName, PropVariant propVar, string valueType, SearchConditionOperation operation) { IConditionFactory nativeConditionFactory = null; SearchCondition condition = null; try { if (string.IsNullOrEmpty(propertyName) || propertyName.ToUpperInvariant() == "SYSTEM.NULL") { propertyName = null; } nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass(); ICondition nativeCondition = null; var hr = nativeConditionFactory.MakeLeaf(propertyName, (CONDITION_OPERATION)operation, valueType, propVar, null, null, null, false, out nativeCondition); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } condition = new SearchCondition(nativeCondition); } finally { if (nativeConditionFactory != null) { Marshal.ReleaseComObject(nativeConditionFactory); } } return(condition); }
public IEnumerable <SearchCondition> GetSubConditions() { var result = new List <SearchCondition>(); object subConditionObject; var guid = new Guid(ComIID.IEnumUnknown); var hr = this.SearchConditionNative.GetSubConditions(ref guid, out subConditionObject); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } if (subConditionObject != null) { var enumUnknown = subConditionObject as IEnumUnknown; while (enumUnknown != null && hr == COMErrorCodes.S_OK) { var buffer = IntPtr.Zero; var fetched = 0U; hr = enumUnknown.Next(1, ref buffer, ref fetched); if (HRESULT.Succeeded(hr) && fetched == 1) { result.Add(new SearchCondition((ICondition)Marshal.GetObjectForIUnknown(buffer))); } } } return(result); }
public void Execute(StringScanner s, Env env) { if (s.Scan("false|off").Length > 0 && _writer != null) { env.Display.TextWriters.Remove(_writer); env.Input.OnWrite = null; _writer.Flush(); _writer.Dispose(); _writer = null; } else if (_writer == null) { if (env.Engine == null) { throw ShellException.NoDatabase(); } var path = Path.GetFullPath(string.Format("LiteDB-spool-{0:yyyy-MM-dd-HH-mm}.txt", DateTime.Now)); _writer = File.CreateText(path); env.Display.TextWriters.Add(_writer); env.Input.OnWrite = (t) => _writer.Write(t); } }
public void Execute(StringScanner s, Env env) { if (env.Engine == null) { throw ShellException.NoDatabase(); } var filename = s.Scan(@".+").Trim(); foreach (var line in File.ReadAllLines(filename)) { env.Input.Queue.Enqueue(line); } }
public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env) { if (engine == null) { throw ShellException.NoDatabase(); } var filename = s.Scan(@".+").Trim(); foreach (var line in File.ReadAllLines(filename)) { input.Queue.Enqueue(line); } }
public static ShellPropertyKey FromCanonicalName(string canonicalName) { PROPERTYKEY propertyKey; var hr = PropertySystemNativeMethods.PSGetPropertyKeyFromName(canonicalName, out propertyKey); if (HRESULT.Failed(hr)) { throw new ArgumentException( ErrorMessages.ShellInvalidCanonicalName, ShellException.FromHRESULT(hr)); } return(new ShellPropertyKey(propertyKey, canonicalName)); }
public static PropVariant FromBooleanArray(bool[] values) { Contract.Requires <ArgumentNullException>(values != null); PropVariant result; var hr = InitPropVariantFromBooleanVector(values, (uint)values.Length, out result); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } return(result); }
public static PropVariant FromUInt64Array(UInt64[] value) { Contract.Requires <ArgumentNullException>(value != null); PropVariant result; var hr = InitPropVariantFromUInt64Vector(value, (uint)value.Length, out result); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } return(result); }
/// <summary> /// Create a new instance of the <see cref="PropVariant" /> structure. /// </summary> /// <param name="value"></param> /// <returns><see cref="PropVariant" />(<c>VT_VECTOR</c> | <c>VT_LPWSTR</c>)</returns> public static PropVariant FromStringAs(string value) { Contract.Requires <ArgumentNullException>(value != null); PropVariant result; var hr = InitPropVariantFromStringAsVector(value, out result); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } return(result); }
public static PropVariant FromDateTime(DateTime value) { PropVariant result; FILETIME filetime; DateTimeToFileTime(value, out filetime); var hr = InitPropVariantFromFileTime(ref filetime, out result); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } return(result); }
/// <summary> /// Create a new instance of the <see cref="ShellPropertyStore" /> class /// to the specified <see cref="ShellObject" />. /// </summary> /// <param name="shellObject"></param> /// <returns></returns> public static ShellPropertyStore Create(ShellObject shellObject) { Contract.Requires <ArgumentNullException>(shellObject != null); IPropertyStore propertyStore; var guid = new Guid(PropertySystemIID.IPropertyStore); var hr = shellObject.ShellItem.ShellItemInterface.GetPropertyStore( GETPROPERTYSTOREFLAGS.GPS_BESTEFFORT, ref guid, out propertyStore); if (HRESULT.Failed(hr) || propertyStore == null) { throw ShellException.FromHRESULT(hr); } return(new ShellPropertyStore(propertyStore)); }
public static PropVariant FromDateTimeArray(DateTime[] value) { Contract.Requires <ArgumentNullException>(value != null); PropVariant result; var fileTimeArray = new FILETIME[value.Length]; for (var index = 0; index < value.Length; ++index) { DateTimeToFileTime(value[index], out fileTimeArray[index]); } var hr = InitPropVariantFromFileTimeVector(fileTimeArray, (uint)fileTimeArray.Length, out result); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } return(result); }
public static SearchCondition CreateNotCondition(SearchCondition conditionToBeNegated, bool simplify) { Contract.Requires <ArgumentNullException>(conditionToBeNegated != null); ICondition result; var nativeConditionFactory = (IConditionFactory) new ConditionFactoryCoClass(); try { var hr = nativeConditionFactory.MakeNot(conditionToBeNegated.SearchConditionNative, simplify, out result); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } } finally { Marshal.ReleaseComObject(nativeConditionFactory); } return(new SearchCondition(result)); }
public IntPtr GetImageHandle(double width, double height) { var size = new SIZE(width, height); var flags = GetFlags(); IntPtr result; var hr = this.shllItemImageFactoryInterface.GetImage(size, flags, out result); if (HRESULT.Failed(hr)) { if (hr == 0x8004B200 && this.FormatOption == ShellItemImageFormatOptions.ThumbnailOnly) { throw new InvalidOperationException( ErrorMessages.ShellThumbnailDoesNotHaveThumbnail, Marshal.GetExceptionForHR(hr)); } if (hr == 0x80040154) { throw new NotSupportedException(ErrorMessages.ShellThumbnailNoHandler, Marshal.GetExceptionForHR(hr)); } throw ShellException.FromHRESULT(hr); } return(result); }
public static SearchCondition ParseStructuredQuery(string query, CultureInfo cultureInfo) { Contract.Requires <ArgumentException>(!String.IsNullOrEmpty(query)); ICondition result = null; var nativeQueryParserManager = (IQueryParserManager) new QueryParserManagerCoClass(); IQueryParser queryParser = null; IQuerySolution querySolution = null; IEntity mainType = null; SearchCondition searchCondition = null; try { // IQueryParser作成 var guid = new Guid(SearchIID.IQueryParser); var hr = nativeQueryParserManager.CreateLoadedParser( "SystemIndex", cultureInfo == null ? (ushort)0 : (ushort)cultureInfo.LCID, ref guid, out queryParser); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } if (queryParser != null) { var optionValue = PropVariant.FromObject(true); try { hr = queryParser.SetOption(STRUCTURED_QUERY_SINGLE_OPTION.SQSO_NATURAL_SYNTAX, optionValue); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } } finally { optionValue.Clear(); } hr = queryParser.Parse(query, null, out querySolution); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } if (querySolution != null) { hr = querySolution.GetQuery(out result, out mainType); if (HRESULT.Failed(hr)) { throw ShellException.FromHRESULT(hr); } } } searchCondition = new SearchCondition(result); } catch { searchCondition?.Dispose(); throw; } finally { Marshal.ReleaseComObject(nativeQueryParserManager); if (queryParser != null) { Marshal.ReleaseComObject(queryParser); } if (querySolution != null) { Marshal.ReleaseComObject(querySolution); } if (mainType != null) { Marshal.ReleaseComObject(mainType); } } return(searchCondition); }