protected override void ProcessRecord() { if (_dictionary.ContainsKey(PARAM_Name)) { string Name = _dictionary[PARAM_Name].Value as string; if (string.IsNullOrEmpty(Name)) { if (Json) { WriteObject(DataSerializer.Serialize <List <NetworkProfile> >(_networkProfileList, DataType.Json), true); } else { WriteObject(_networkProfileList, true); } } else { NetworkProfile profile = _networkProfileList.First(x => x.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)); if (Json) { WriteObject(DataSerializer.Serialize <NetworkProfile>(profile, DataType.Json), true); } else { WriteObject(profile, true); } } } }
protected static bool AddDynamicParameter(Type type, string name, ref RuntimeDefinedParameterDictionary dic, bool valueFromPipeline) { bool paramAdded = false; if (dic == null || !dic.ContainsKey(name)) { var attrib = new ParameterAttribute { Mandatory = false, ValueFromPipeline = valueFromPipeline, }; var param = new RuntimeDefinedParameter { IsSet = false, Name = name, ParameterType = type }; param.Attributes.Add(attrib); if (dic == null) { dic = new RuntimeDefinedParameterDictionary(); } dic.Add(name, param); paramAdded = true; } return paramAdded; }
protected override void ProcessRecord() { if (_dictionary.ContainsKey(PARAM_Name)) { string Name = _dictionary[PARAM_Name].Value as string; if (!string.IsNullOrEmpty(Name)) { NetworkProfile profile = _networkProfileList.First(x => x.Name == Name); if (Interfaces != null) { profile.Interfaces = Interfaces; } if (Proxy != null) { profile.Proxy = Proxy; } if (StaticRoutes != null) { profile.StaticRoutes = StaticRoutes; } DataSerializer.Serialize <NetworkProfile>( profile, Path.Combine(Item.WorkDirectory, Name + ".json")); } } }
/// <summary> /// Returns the appropriate role of the member. /// </summary> protected string GetRole() { if (_dynamicParameters == null || !_dynamicParameters.ContainsKey("Role") || string.IsNullOrWhiteSpace(_dynamicParameters["Role"].Value?.ToString())) { throw new PSArgumentNullException("Role"); } return(_dynamicParameters["Role"].Value.ToString()); }
protected T GetDynamicParameterValue <T>(string parameterName) { if (DynamicParameterDictionary.ContainsKey(parameterName)) { var p = DynamicParameterDictionary[parameterName]; if (p.IsSet) { if (typeof(T) == typeof(string[])) { if (p.Value == null) { return(default(T)); } if (p.Value is string[]) { return((T)p.Value); } if (p.Value is string) { return((T)(object)new string[1] { p.Value.ToString() }); } if (p.Value is IEnumerable) { return((T)(object)((IEnumerable)p.Value).Cast <object>().Select(each => each.ToString()).ToArray()); } // weird, can't get a collection from whatever is here. return((T)(object)new string[1] { p.Value.ToString() }); } if (typeof(T) == typeof(string)) { if (p.Value == null) { return(default(T)); } return((T)(object)p.Value.ToString()); } return((T)p.Value); } } return(default(T)); }
internal static bool GetValue <T>(this RuntimeDefinedParameterDictionary dict, string name, out T?value) where T : struct { value = default; if (!dict.ContainsKey(name)) { return(false); } if (dict[name].Value is T result) { value = result; return(true); } return(false); }
void Parameterize(SqliteParameterCollection command, RuntimeDefinedParameterDictionary parameterDictionary) { if (null != parameterDictionary) { foreach (SqliteParameter parameter in command) { string name = parameter.ParameterName.TrimStart('@', '$'); if (!(parameterDictionary.ContainsKey(name) && parameterDictionary[name].IsSet)) { continue; } SpecifyParameter(command, parameter.ParameterName, parameterDictionary[name].Value); } } }
protected override void ProcessRecord() { if (!_dictionary.ContainsKey(PARAM_Name)) { return; } string Name = _dictionary[PARAM_Name].Value as string; NetworkProfile networkProfile = _networkProfileList.FirstOrDefault(x => x.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)); if (networkProfile != null) { foreach (InterfaceConfig ic in networkProfile.Interfaces) { ic.ChangeNetworkAddresses(); } } _networkProfileList = null; }
protected static bool AddDynamicParameter(Type type, string name, ref RuntimeDefinedParameterDictionary dic, bool valueFromPipeline, bool valueFromPipelineByPropertyName, string paramSetName, bool mandatory = false) { var paramAdded = false; if (dic == null || !dic.ContainsKey(name)) { var attrib = new ParameterAttribute { Mandatory = mandatory, ValueFromPipeline = valueFromPipeline, ValueFromPipelineByPropertyName = valueFromPipelineByPropertyName }; if (!string.IsNullOrEmpty(paramSetName)) { attrib.ParameterSetName = paramSetName; } var param = new RuntimeDefinedParameter { IsSet = false, Name = name, ParameterType = type }; param.Attributes.Add(attrib); if (dic == null) { dic = new RuntimeDefinedParameterDictionary(); } dic.Add(name, param); paramAdded = true; } return(paramAdded); }
protected override void GetChildNames(string path, ReturnContainers returnContainers) { path = NormalizePath(path); WriteDebug("Listing names in " + path); bool unreadOnly = false; RuntimeDefinedParameterDictionary dic = DynamicParameters as RuntimeDefinedParameterDictionary; if (dic != null && dic.ContainsKey("Unread")) { RuntimeDefinedParameter rdp = dic["Unread"]; unreadOnly = rdp.IsSet; } WriteDebug(unreadOnly ? "Unread items only" : "All items"); // Checks if the path represented is a drive. This means that the // children of the path are folders and feeds if (PathIsDrive(path)) { WriteDebug("Listing root folder folder names"); IFeedFolder folder = FeedsManager.RootFolder as IFeedFolder; IFeedsEnum subFolders = folder.Subfolders as IFeedsEnum; foreach (IFeedFolder subFolder in subFolders) { if (!unreadOnly || subFolder.TotalUnreadItemCount > 0) { WriteItemObject(subFolder.Name, subFolder.Path, true); } } WriteDebug("Listing root folder feed names"); IFeedsEnum feeds = folder.Feeds as IFeedsEnum; foreach (IFeed feed in feeds) { if (!unreadOnly || feed.UnreadItemCount > 0) { WriteItemObject(feed.Name, feed.Path, true); } } return; } if (FeedsManager.ExistsFolder(path)) { WriteDebug("Listing folder names in " + path); IFeedFolder folder = FeedsManager.GetFolder(path) as IFeedFolder; IFeedsEnum subFolders = folder.Subfolders as IFeedsEnum; foreach (IFeedFolder subFolder in subFolders) { if (!unreadOnly || subFolder.TotalUnreadItemCount > 0) { WriteItemObject(subFolder.Name, subFolder.Path, true); } } WriteDebug("Listing feed names in " + path); IFeedsEnum feeds = folder.Feeds as IFeedsEnum; foreach (IFeed feed in feeds) { if (!unreadOnly || feed.UnreadItemCount > 0) { WriteItemObject(feed.Name, feed.Path, true); } } return; } if (FeedsManager.ExistsFeed(path)) { WriteDebug("Listing names in " + path); IFeed feed = FeedsManager.GetFeed(path) as IFeed; IFeedsEnum feedItems = feed.Items as IFeedsEnum; foreach (IFeedItem feedItem in feedItems) { if (!unreadOnly || !feedItem.IsRead) { WriteItemObject(feedItem.LocalId.ToString(), feed.Path + _pathSeparator + feedItem.LocalId, false); } } return; } } // GetChildNames
void Parameterize(SqliteParameterCollection command, RuntimeDefinedParameterDictionary parameterDictionary) { if (null != parameterDictionary) { foreach (SqliteParameter parameter in command) { string name = parameter.ParameterName.TrimStart('@', '$'); if (! (parameterDictionary.ContainsKey(name) && parameterDictionary[name].IsSet) ) { continue; } SpecifyParameter(command, parameter.ParameterName, parameterDictionary[name].Value); } } }