internal static bool IsShowComputerNameMarkerPresent(CimInstance cimInstance) { PSObject pso = PSObject.AsPSObject(cimInstance); PSPropertyInfo psShowComputerNameProperty = pso.InstanceMembers[RemotingConstants.ShowComputerNameNoteProperty] as PSPropertyInfo; if (psShowComputerNameProperty == null) { return(false); } return(true.Equals(psShowComputerNameProperty.Value)); }
/// <summary> /// Safely get property value. /// </summary> private static T SafelyGetPropertyValue <T>(PSObject psObject, string key) { PSPropertyInfo propertyInfo = psObject.Properties[key]; if (propertyInfo is null || propertyInfo.Value is null || !(propertyInfo.Value is T)) { throw RemoteHostExceptions.NewDecodingFailedException(); } return((T)propertyInfo.Value); }
internal static bool IsWriteWarningStream(PSObject so) { try { PSPropertyInfo info = so.Properties["WriteWarningStream"]; return(((info != null) && (info.Value is bool)) && ((bool)info.Value)); } catch (ExtendedTypeSystemException) { return(false); } }
private PSObject Find(string nameOrId, bool findById) { foreach (PSObject obj2 in this) { PSPropertyInfo info = obj2.Properties[findById ? "id" : "name"]; if ((info != null) && (((string)info.Value) == nameOrId)) { return(obj2); } } return(null); }
private void CreateDynamicMemberProperty(ref PSPropertyInfo plotMember, string name, string proxyPropertyName) { if (String.IsNullOrEmpty(proxyPropertyName)) { return; } var pm = plotMember as PSScriptProperty; var script = String.Format("$this.'{0}' | foreach-object {{ {1} }}", proxyPropertyName, pm.GetterScript); plotMember = new PSScriptProperty(name, System.Management.Automation.ScriptBlock.Create(script)); }
// This function is a clone of PopulateFromDictionary using JObject as an input. private static PSObject PopulateFromJDictionary(JObject entries, out ErrorRecord error) { error = null; PSObject result = new PSObject(); foreach (var entry in entries) { PSPropertyInfo property = result.Properties[entry.Key]; if (property != null) { string errorMsg = string.Format(CultureInfo.InvariantCulture, WebCmdletStrings.DuplicateKeysInJsonString, property.Name, entry.Key); error = new ErrorRecord( new InvalidOperationException(errorMsg), "DuplicateKeysInJsonString", ErrorCategory.InvalidOperation, null); return(null); } // Array else if (entry.Value is JArray) { JArray list = entry.Value as JArray; ICollection <object> listResult = PopulateFromJArray(list, out error); if (error != null) { return(null); } result.Properties.Add(new PSNoteProperty(entry.Key, listResult)); } // Dictionary else if (entry.Value is JObject) { JObject dic = entry.Value as JObject; PSObject dicResult = PopulateFromJDictionary(dic, out error); if (error != null) { return(null); } result.Properties.Add(new PSNoteProperty(entry.Key, dicResult)); } // Value else // (entry.Value is JValue) { JValue theValue = entry.Value as JValue; result.Properties.Add(new PSNoteProperty(entry.Key, theValue.Value)); } } return(result); }
internal override void SetUserValue(PSPropertyInfo info, string value) { try { A.SetPropertyValue(Explorer.ItemPath, info.Name, Converter.Parse(info, value)); WhenPropertyChanged(Explorer.ItemPath); } catch (RuntimeException ex) { A.Message(ex.Message); } }
private object GetProperty(string path, string property) { PSObject obj = GetProperty(path); PSPropertyInfo prop = obj.Properties[property]; if (prop != null) { return(prop.Value); } return(null); }
/// <summary> /// Gets a meta value. /// </summary> /// <param name="value">The input object.</param> public object GetValue(object value) { if (_Script != null) { //! _100410_051915 Use module session state otherwise $_ is not visible, only $global:_ is visible var session = _Script.Module == null ? A.Psf.Engine.SessionState : _Script.Module.SessionState; session.PSVariable.Set("_", value); //??? suppress for now // ps: .{ls; ps} | op // -- this with fail on processes with file scripts try { object result = _Script.InvokeReturnAsIs(); if (result == null) { return(null); } else { return(((PSObject)result).BaseObject); } } catch (RuntimeException) { return(null); } finally { //! Null $_ to avoid a leak session.PSVariable.Set("_", null); } } PSObject pso = PSObject.AsPSObject(value); PSPropertyInfo pi = pso.Properties[_Property]; if (pi == null) { return(null); } // Exception case: cert provider, search all try { return(pi.Value); } catch (RuntimeException e) { FarNet.Log.TraceException(e); return(null); } }
internal static JobStateEventArgs RehydrateJobStateEventArgs(PSObject pso) { JobStateInfo jobStateInfo = RehydrateJobStateInfo(PSObject.AsPSObject(pso.Properties["JobStateInfo"].Value)); JobStateInfo previousJobStateInfo = null; PSPropertyInfo info3 = pso.Properties["PreviousJobStateInfo"]; if ((info3 != null) && (info3.Value != null)) { previousJobStateInfo = RehydrateJobStateInfo(PSObject.AsPSObject(info3.Value)); } return(new JobStateEventArgs(jobStateInfo, previousJobStateInfo)); }
// Token: 0x06000DBD RID: 3517 RVA: 0x00029088 File Offset: 0x00027288 private static string GetRemovedMailboxName(PSObject removedMailbox) { if (removedMailbox != null && removedMailbox.Properties != null) { PSPropertyInfo pspropertyInfo = removedMailbox.Properties["Name"]; if (pspropertyInfo != null) { return(pspropertyInfo.Value as string); } } return(""); }
internal static object SafePropertyValue(PSPropertyInfo pi) { //! exceptions, e.g. exit code of running process try { return(pi.Value); } catch (GetValueException e) { return(string.Format(null, "<ERROR: {0}>", e.Message)); } }
protected string RenderPropertyValue(PSObject inputObject, string propertyName, ColorString formatString, bool dontGroupMultipleResults, bool allowMultipleLines) { PSPropertyInfo pi = inputObject.Properties[propertyName]; if (null == pi) { var val = sm_PropNotFoundFmt.ToString(DbgProvider.HostSupportsColor); val = Util.Sprintf(val, propertyName); var e = new PropertyNotFoundException(Util.Sprintf("Property not found: {0}", propertyName)); try { throw e; } catch (Exception) { }; // give it a stack ErrorRecord er = new ErrorRecord(e, "MissingProperty", ErrorCategory.InvalidData, inputObject); AddToError(er); return(val); } try { var obj = pi.Value; IEnumerable enumerable = obj as IEnumerable; if ((null != enumerable) && _ShouldUnroll(enumerable)) { return(ObjectsToMarkedUpString(enumerable, formatString, null, dontGroupMultipleResults).ToString()); } // If a formatString was specified, let /it/ control the display, instead of FormatSingleLine. if (null == formatString) { return(ObjectToMarkedUpString(FormatSingleLine(pi.Value, allowMultipleLines), formatString).ToString()); } else { return(ObjectToMarkedUpString(pi.Value, formatString).ToString()); } } catch (RuntimeException rte) { AddToError(Util.FixErrorRecord(rte.ErrorRecord, rte)); return(new ColorString(ConsoleColor.Red, Util.Sprintf("<Error: {0}>", Util.GetExceptionMessages(rte))) .ToString(DbgProvider.HostSupportsColor)); } } // end RenderPropertyValue()
/// <summary> /// Puts a value into the command line or opens a lookup panel or member panel. /// </summary> /// <param name="file">The file to process.</param> public override void OpenFile(FarFile file) { if (file == null) { throw new ArgumentNullException("file"); } PSPropertyInfo pi = file.Data as PSPropertyInfo; // e.g. visible mode: sender is MemberDefinition if (pi == null) { return; } // lookup opener? if (_LookupOpeners != null) { ScriptHandler <OpenFileEventArgs> handler; if (_LookupOpeners.TryGetValue(file.Name, out handler)) { handler.Invoke(this, new OpenFileEventArgs(file)); return; } } // case: can show value in the command line string s = Converter.InfoToLine(pi); if (s != null) { // set command line ILine cl = Far.Api.CommandLine; cl.Text = "=" + s; cl.SelectText(1, s.Length + 1); return; } // case: enumerable IEnumerable ie = Cast <IEnumerable> .From(pi.Value); if (ie != null) { ObjectPanel op = new ObjectPanel(); op.AddObjects(ie); op.OpenChild(this); return; } // open members OpenFileMembers(file); }
internal static string TranslatePSObjectToString(PSObject pso, string format) { if (string.Equals(format, "xml", StringComparison.OrdinalIgnoreCase)) { PSMemberInfoCollection <PSPropertyInfo> properties = pso.Properties; PSPropertyInfo pSPropertyInfo = properties.FirstOrDefault <PSPropertyInfo>((PSPropertyInfo item) => string.Equals(item.Name, "InnerXml", StringComparison.OrdinalIgnoreCase)); if (pSPropertyInfo != null) { return(pSPropertyInfo.Value.ToString()); } } return(pso.ToString()); }
private void SetSingleValuedAttribute(PSPropertyInfo property, object value) { RmaObject resourceValue = property.Value as RmaObject; if (resourceValue != null) { this.InternalObject.Attributes[property.Name].SetValue(resourceValue.InternalObject.ObjectID); } else { this.InternalObject.Attributes[property.Name].SetValue(this.UnwrapPSObject(property.Value)); } }
private void SetSingleValuedAttribute(PSPropertyInfo property, object value) { AcmaPSObject resourceValue = property.Value as AcmaPSObject; if (resourceValue != null) { this.Hologram.SetAttributeValue(ActiveConfig.DB.GetAttribute(property.Name), resourceValue.Hologram.ObjectID); } else { this.Hologram.SetAttributeValue(ActiveConfig.DB.GetAttribute(property.Name), value); } }
public InvalidChartValueMemberException(ChartSeriesType seriesType, PSPropertyInfo prop, string valueMemberPath, string viewModelMemberName) : base(String.Format( "The value member [{0}] for the [{2}] of series type [{1}] is of an invalid type [{3}].", valueMemberPath, seriesType, viewModelMemberName, null != prop ? prop.TypeNameOfValue : "null" )) { SeriesType = seriesType; Property = prop; ValueMemberPath = valueMemberPath; }
/// <inheritdoc/> public override void DeleteFiles(DeleteFilesEventArgs args) { if (args == null) { return; } // skip not default modes if (MemberMode != 0) { args.Result = JobResult.Ignore; return; } // ask if (args.UI && 0 != (long)Far.Api.GetSetting(FarSetting.Confirmations, "Delete")) { if (Far.Api.Message("Delete selected members", Res.Delete, MessageOptions.None, new string[] { Res.Delete, Res.Cancel }) != 0) { args.Result = JobResult.Ignore; return; } } try { int count1 = Value.Properties.Count(); foreach (FarFile file in args.Files) { PSPropertyInfo pi = file.Data as PSPropertyInfo; if (pi == null) { continue; } Value.Properties.Remove(pi.Name); } int count2 = Value.Properties.Count(); if (count1 - args.Files.Count != count2) { args.Result = JobResult.Incomplete; } } finally { // update always, some members can be deleted, don't leave them MemberPanel.WhenMemberChanged(Value); //????? will it be 2 times for THIS panel? } }
internal void SetPropertyValueOnHost(string propertyName, object value) { PSPropertyInfo property = PrivateData.Properties [propertyName]; if (property == null) { property = new PSNoteProperty(propertyName, value); PrivateData.Properties.Add(property); } else { property.Value = value; } }
private static string GetModuleName(object moduleObject) { if (moduleObject == null) { return(null); } PSPropertyInfo info = PSObject.AsPSObject(moduleObject).Properties["Name"]; if (info == null) { return(null); } return(info.Value as string); }
internal static void AddShowComputerNameMarker(PSObject pso) { PSPropertyInfo psShowComputerNameProperty = pso.InstanceMembers[RemotingConstants.ShowComputerNameNoteProperty] as PSPropertyInfo; if (psShowComputerNameProperty != null) { psShowComputerNameProperty.Value = true; } else { psShowComputerNameProperty = new PSNoteProperty(RemotingConstants.ShowComputerNameNoteProperty, true); pso.InstanceMembers.Add(psShowComputerNameProperty); } }
public string GetAllProperties() { string text = ""; this.propertySet = new List <DscResourcePropertyNode>(); PSPropertyInfo prop = _dscResourceItem.Properties[Constants.DscResourceProperties]; var collectionProperties = (ICollection)prop.Value; int count = 0; foreach (object dscProperty in collectionProperties) { string lhs = ""; ArrayList valueSet = new ArrayList(); var dscPropertyName = dscProperty.GetType().GetProperty(Constants.DscPropertyHeaderName).GetValue(dscProperty, null).ToString(); var dscPropertyType = dscProperty.GetType().GetProperty(Constants.DscPropertyHeaderPropertyType).GetValue(dscProperty, null); var dscIsMandatory = Convert.ToBoolean(dscProperty.GetType().GetProperty(Constants.DscPropertyHeaderIsMandatory).GetValue(dscProperty, null)); var dscValueSet = dscProperty.GetType().GetProperty(Constants.DscPropertyHeaderValues).GetValue(dscProperty, null); if (dscValueSet.GetType().IsGenericType&& dscValueSet is IEnumerable) { if (((List <String>)dscValueSet).Count > 0) { foreach (var item in ((List <String>)dscValueSet)) { valueSet.Add(item); } } } // var dscPossibleValues =dscProperty.GetType().GetProperty(Constants.DscPropertyHeaderValues).GetValue(dscProperty, null); var textInsertIsMandatory = ""; if (dscIsMandatory) { textInsertIsMandatory = " # IsMandatory"; lhs = dscPropertyName; } string descriptionOfProperty = GetPropertyDescriptionFromFile(dscPropertyName); DscResourcePropertyNode propertyNode = new DscResourcePropertyNode(dscPropertyType.ToString(), valueSet, dscPropertyName, descriptionOfProperty) { propertyType = dscPropertyType.ToString(), StringComment = textInsertIsMandatory, IsMandatory = dscIsMandatory, IsChosen = dscIsMandatory, propertyValueSet = valueSet }; count++; this.propertySet.Add(propertyNode); } return(text); }
internal static bool IsShowComputerNameMarkerPresent(CimInstance cimInstance) { PSObject pSObject = PSObject.AsPSObject(cimInstance); PSPropertyInfo item = pSObject.InstanceMembers[RemotingConstants.ShowComputerNameNoteProperty] as PSPropertyInfo; if (item != null) { bool flag = true; return(flag.Equals(item.Value)); } else { return(false); } }
internal static bool ShouldShowComputerNameProperty(PSObject so) { bool result = false; if (so != null) { PSPropertyInfo property1 = so.Properties[RemotingConstants.ComputerNameNoteProperty]; PSPropertyInfo property2 = so.Properties[RemotingConstants.ShowComputerNameNoteProperty]; if (property1 != null && property2 != null) { LanguagePrimitives.TryConvertTo <bool>(property2.Value, out result); } } return(result); }
private bool IsExcludableProperty(PSPropertyInfo psPropertyInfo) { if (null == _excludePropertyNames || !_excludePropertyNames.Any()) { return(false); } var props = from s in _excludePropertyNames where ( IsWildcardMatch(s, psPropertyInfo) || StringComparer.InvariantCultureIgnoreCase.Equals(s, psPropertyInfo.Name) ) select s; return(props.Any()); }
private static T GetPropertyValue <T>( PSObject pso, string propertyName, DeserializingTypeConverter.RehydrationFlags flags) { PSPropertyInfo property = pso.Properties[propertyName]; if (property == null && DeserializingTypeConverter.RehydrationFlags.MissingPropertyOk == (flags & DeserializingTypeConverter.RehydrationFlags.MissingPropertyOk)) { return(default(T)); } object valueToConvert = property.Value; return(valueToConvert == null && DeserializingTypeConverter.RehydrationFlags.NullValueOk == (flags & DeserializingTypeConverter.RehydrationFlags.NullValueOk) ? default(T) : (T)LanguagePrimitives.ConvertTo(valueToConvert, typeof(T), (IFormatProvider)CultureInfo.InvariantCulture)); }
private static PSObject PopulateFromDictionary(IDictionary <string, object> entries, out ErrorRecord error) { error = null; PSObject result = new PSObject(); foreach (KeyValuePair <string, object> entry in entries) { PSPropertyInfo property = result.Properties[entry.Key]; if (property != null) { string errorMsg = string.Format(CultureInfo.InvariantCulture, WebCmdletStrings.DuplicateKeysInJsonString, property.Name, entry.Key); error = new ErrorRecord( new InvalidOperationException(errorMsg), "DuplicateKeysInJsonString", ErrorCategory.InvalidOperation, null); return(null); } if (entry.Value is IDictionary <string, object> ) { IDictionary <string, object> subEntries = entry.Value as IDictionary <string, object>; PSObject dicResult = PopulateFromDictionary(subEntries, out error); if (error != null) { return(null); } result.Properties.Add(new PSNoteProperty(entry.Key, dicResult)); } else if (entry.Value is ICollection <object> ) { ICollection <object> list = entry.Value as ICollection <object>; ICollection <object> listResult = PopulateFromList(list, out error); if (error != null) { return(null); } result.Properties.Add(new PSNoteProperty(entry.Key, listResult)); } else { result.Properties.Add(new PSNoteProperty(entry.Key, entry.Value)); } } return(result); }
internal override object GetValue(PSObject liveObject) { try { PSPropertyInfo propertyInfo = liveObject.Properties[_liveObjectPropertyName]; if (propertyInfo == null) { return(null); } // The live object has the liveObjectPropertyName property. object liveObjectValue = propertyInfo.Value; ICollection collectionValue = liveObjectValue as ICollection; if (collectionValue != null) { liveObjectValue = _parentCmdlet.ConvertToString(PSObjectHelper.AsPSObject(propertyInfo.Value)); } else { PSObject psObjectValue = liveObjectValue as PSObject; if (psObjectValue != null) { // Since PSObject implements IComparable there is a need to verify if its BaseObject actually implements IComparable. if (psObjectValue.BaseObject is IComparable) { liveObjectValue = psObjectValue; } else { // Use the String type as default. liveObjectValue = _parentCmdlet.ConvertToString(psObjectValue); } } } return(ColumnInfo.LimitString(liveObjectValue)); } catch (GetValueException) { // ignore } catch (ExtendedTypeSystemException) { // ignore } return(null); }
private bool IsSupportedSession(CimSession cimSession, TerminatingErrorTracker terminatingErrorTracker) { bool confirmSwitchSpecified = this.CmdletInvocationInfo.BoundParameters.ContainsKey("Confirm"); bool whatIfSwitchSpecified = this.CmdletInvocationInfo.BoundParameters.ContainsKey("WhatIf"); if (confirmSwitchSpecified || whatIfSwitchSpecified) { if (cimSession.ComputerName != null && (!cimSession.ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase))) { PSPropertyInfo protocolProperty = PSObject.AsPSObject(cimSession).Properties["Protocol"]; if ((protocolProperty != null) && (protocolProperty.Value != null) && (protocolProperty.Value.ToString().Equals("DCOM", StringComparison.OrdinalIgnoreCase))) { bool sessionWasAlreadyTerminated; terminatingErrorTracker.MarkSessionAsTerminated(cimSession, out sessionWasAlreadyTerminated); if (!sessionWasAlreadyTerminated) { string nameOfUnsupportedSwitch; if (confirmSwitchSpecified) { nameOfUnsupportedSwitch = "-Confirm"; } else { Dbg.Assert(whatIfSwitchSpecified, "Confirm and WhatIf are the only detected settings"); nameOfUnsupportedSwitch = "-WhatIf"; } string errorMessage = string.Format( CultureInfo.InvariantCulture, CmdletizationResources.CimCmdletAdapter_RemoteDcomDoesntSupportExtendedSemantics, cimSession.ComputerName, nameOfUnsupportedSwitch); Exception exception = new NotSupportedException(errorMessage); ErrorRecord errorRecord = new( exception, "NoExtendedSemanticsSupportInRemoteDcomProtocol", ErrorCategory.NotImplemented, cimSession); this.Cmdlet.WriteError(errorRecord); } } } } return(true); }