private void ValidatePscxPath(string parameterName, PscxPathAttribute pathAttrib, PscxPathInfo pscxPath) { WriteDebug(String.Format("ValidatePscxPath: parameter {0} ; pscxPath {1}", parameterName, pscxPath)); if (pscxPath.IsValid == false) { // todo: localize string description = String.Format( "The path '{0}' supplied for {1} is invalid.", pscxPath, parameterName); // path syntax error OnPscxPathError(parameterName, description, PscxPathState.Invalid, pscxPath); } PscxPathType pathType = PscxPathType.Unknown; // explicit true or unset if (pathAttrib.ShouldExist || (pathAttrib._shouldExist == null)) { if (pathAttrib.ShouldExist) { // explicit true, so check existance ValidateExists(parameterName, pscxPath, ref pathType); } else { // shouldexist not specified, so grab path type via invokeprovider pathType = this.InvokeProvider.Item.IsContainer(pscxPath.ToString()) ? PscxPathType.Container : PscxPathType.Leaf; } PscxPathType expectedPathType = pathAttrib.PathType; // do we have a path type constraint? if (expectedPathType != PscxPathType.None) { ValidatePathType(parameterName, pscxPath, pathType, expectedPathType); } } else // shouldexist explicit false { // NOTE: for Pscx developers Trace.Assert(pathAttrib.PathType == PscxPathType.None, String.Format( "Pscx Developer Error: {0}\n\nIf a PathType constraint is placed on a parameter, " + "ShouldExist cannot be explicitly set to false. Remove " + "the ShouldExist condition from the attribute, or set it " + "explicitly to true.\n\nIf you are seeing this message " + "as a Pscx end-user, please log an issue on " + "http://www.codeplex.com/powershellcx", CmdletName)); } // any provider constraints defined on the PscxPath attribute, // or on a Type-level ProviderConstraint attribute? if ((pathAttrib.ProviderTypes != null) || (_defaultProviderConstraint != null)) { CheckProviderConstraints(pscxPath, pathAttrib, parameterName); } }
public void ProcessPath(PscxPathInfo pscxPath) { _command.WriteVerbose("Add/update " + pscxPath); try { if (_command.InvokeProvider.Item.IsContainer(pscxPath.ToString())) { //_zip.AddDirectory(pscxPath.ProviderPath); } else { string fileName = pscxPath.ProviderPath; if (_command.FlattenPaths.IsPresent) { fileName = Path.GetFileName(pscxPath.ProviderPath); _command.WriteVerbose(String.Format("Flattened '{0}' to '{1}'", pscxPath.ProviderPath, fileName)); //_zip.Add(pscxPath.ProviderPath, fileName); // new overload to SZL 0.86 (fixes -append -flattenpath bug) } else { //_zip.Add(fileName); } } } catch (PipelineStoppedException) { throw; } catch (Exception ex) { var error = new ErrorRecord(ex, "ZipAddOrUpdateFail", ErrorCategory.WriteError, pscxPath); // perhaps allow erroraction to control whether terminating or not _command.ThrowTerminatingError(error); } }