Example #1
0
        protected void WriteObject(IshSession ishSession, Enumerations.ISHType[] ishType, IshBaseObject ishBaseObject, bool enumerateCollection)
        {
            List <IshBaseObject> ishBaseObjectList = new List <IshBaseObject>();

            ishBaseObjectList.Add(ishBaseObject);
            WriteObject(ishSession, ishType, ishBaseObjectList, enumerateCollection);
        }
Example #2
0
        protected override void ProcessRecord()
        {
            try
            {
                int ishPasswordLength = _ishPassword == null ? 0 : _ishPassword.Length;
                if (PSCredential != null)
                {
                    _ishUserName       = PSCredential.UserName;
                    _ishSecurePassword = PSCredential.Password;
                }
                else if (!String.IsNullOrWhiteSpace(_ishPassword))
                {
                    _ishSecurePassword = SecureStringConversions.StringToSecureString(_ishPassword);
                }
                else
                {
                    _ishSecurePassword = null;
                }
                WriteVerbose($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + "]");
                WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + $"] Timeout[{_timeout}] TimeoutIssue[{_timeoutIssue}] TimeoutService[{_timeoutService}] IgnoreSslPolicyErrors[{_ignoreSslPolicyErrors}]");

                IshSession ishSession = null;

                /* If the PSCmdlet is not accepted switch the condition to
                 * if (!String.IsNullOrWhiteSpace(WsTrustIssuerMexUrl) && !String.IsNullOrWhiteSpace(WsTrustIssuerMexUrl))
                 */
                if (this.ParameterSetName.EndsWith("-ExplicitIssuer"))
                {
                    WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] WsTrustIssuerUrl[{WsTrustIssuerUrl}] WsTrustIssuerMexUrl[{WsTrustIssuerMexUrl}]");
                    ishSession = new IshSession(Logger, WsBaseUrl, WsTrustIssuerUrl, WsTrustIssuerMexUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors);
                }
                else
                {
                    ishSession = new IshSession(Logger, WsBaseUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors);
                }

                // Keep the IshSession initialization as minimal as possible
                // Do early load of IshTypeFieldSetup (either <13-TriDKXmlSetup-based or >=13-RetrieveFieldSetupByIshType-API-based) for
                // usage by ToIshMetadataFields/.../ToIshRequestedMetadataFields and Expand-ISHParameter.ps1 parameter autocompletion
                //var ishTypeFieldSetup = ishSession.IshTypeFieldSetup;

                WriteObject(true);
            }
            catch (TrisoftAutomationException trisoftAutomationException)
            {
                WriteVerbose(trisoftAutomationException.Message);
                WriteObject(false);
            }
            catch (AggregateException aggregateException)
            {
                var flattenedAggregateException = aggregateException.Flatten();
                WriteVerbose(flattenedAggregateException.ToString());
                WriteObject(false);
            }
            catch (Exception exception)
            {
                WriteVerbose(exception.Message);
                WriteObject(false);
            }
        }
Example #3
0
        protected override void ProcessRecord()
        {
            try
            {
                int ishPasswordLength = _ishPassword == null ? 0 : _ishPassword.Length;
                if (PSCredential != null)
                {
                    _ishUserName       = PSCredential.UserName;
                    _ishSecurePassword = PSCredential.Password;
                }
                else if (!String.IsNullOrWhiteSpace(_ishPassword))
                {
                    _ishSecurePassword = SecureStringConversions.StringToSecureString(_ishPassword);
                }
                else
                {
                    _ishSecurePassword = null;
                }

                WriteVerbose($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + "]");
                WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + $"] Timeout[{_timeout}] TimeoutIssue[{_timeoutIssue}] TimeoutService[{_timeoutService}] IgnoreSslPolicyErrors[{_ignoreSslPolicyErrors}]");
                IshSession ishSession = null;
                if (this.ParameterSetName.EndsWith("-ExplicitIssuer"))
                {
                    WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] WsTrustIssuerUrl[{WsTrustIssuerUrl}] WsTrustIssuerMexUrl[{WsTrustIssuerMexUrl}]");
                    ishSession = new IshSession(Logger, WsBaseUrl, WsTrustIssuerUrl, WsTrustIssuerMexUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors);
                }
                else
                {
                    ishSession = new IshSession(Logger, WsBaseUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors);
                }

                // Do early load of IshTypeFieldSetup (either <13-TriDKXmlSetup-based or >=13-RetrieveFieldSetupByIshType-API-based) for
                // usage by ToIshMetadataFields/.../ToIshRequestedMetadataFields and Expand-ISHParameter.ps1 parameter autocompletion
                var ishTypeFieldSetup = ishSession.IshTypeFieldSetup;

                WriteObject(ishSession);
            }
            catch (NotSupportedException notSupportedException)
            {
                WriteError(new ErrorRecord(notSupportedException, "-1", ErrorCategory.InvalidOperation, null));
            }
            catch (TrisoftAutomationException trisoftAutomationException)
            {
                ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
            }
            catch (AggregateException aggregateException)
            {
                var flattenedAggregateException = aggregateException.Flatten();
                WriteVerbose(flattenedAggregateException.ToString());
                ThrowTerminatingError(new ErrorRecord(flattenedAggregateException, base.GetType().Name, ErrorCategory.NotSpecified, null));
            }
            catch (Exception exception)
            {
                ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
            }
        }
Example #4
0
 protected override void BeginProcessing()
 {
     if (IshSession == null)
     {
         IshSession = (IshSession)SessionState.PSVariable.GetValue(ISHRemoteSessionStateIshSession);
     }
     if (IshSession == null)
     {
         throw new ArgumentException(ISHRemoteSessionStateIshSessionException);
     }
     WriteDebug($"Using IshSession[{IshSession.Name}] from SessionState.{ISHRemoteSessionStateIshSession}");
     base.BeginProcessing();
 }
Example #5
0
        /// <summary>
        /// Convert a BaseFolder enumeration value into a base folder label
        /// </summary>
        /// <param name="ishSession">Client session object to the InfoShare server instance. Keeps track of your security tokens and provide you clients to the various API end points. Holds matching contract parameters like separators, batch and chunk sizes.</param>
        /// <param name="baseFolder">BaseFolder enumeration value</param>
        /// <returns>base folder label</returns>
        internal virtual string BaseFolderEnumToLabel(IshSession ishSession, Folder25ServiceReference.BaseFolder baseFolder)
        {
            IshFields requestedMetadata = new IshFields();

            requestedMetadata.AddField(new IshRequestedMetadataField("FNAME", Enumerations.Level.None, Enumerations.ValueType.All));
            string xmlIshFolder = ishSession.Folder25.GetMetadata(
                baseFolder,
                new string[] { },  // Use empty folder path so we can just get the basefolder name
                requestedMetadata.ToXml());
            XmlDocument result = new XmlDocument();

            result.LoadXml(xmlIshFolder);
            XmlElement xmlIshFolderElement = (XmlElement)result.SelectSingleNode("ishfolder");
            IshFolder  ishFolder           = new IshFolder(xmlIshFolderElement);

            return(((IshMetadataField)ishFolder.IshFields.RetrieveFirst("FNAME", Enumerations.Level.None, Enumerations.ValueType.Value)).Value);
        }
Example #6
0
        /// <summary>
        /// Convert base folder label into a BaseFolder enumeration value
        /// </summary>
        /// <param name="ishSession">The <see cref="IshSession"/>.</param>
        /// <param name="baseFolderLabel">Label of the base folder</param>
        /// <returns>The BaseFolder enumeration value</returns>
        internal virtual Folder25ServiceReference.BaseFolder BaseFolderLabelToEnum(IshSession ishSession, string baseFolderLabel)
        {
            foreach (Folder25ServiceReference.BaseFolder baseFolder in System.Enum.GetValues(typeof(Folder25ServiceReference.BaseFolder)))
            {
                var folderLabel = BaseFolderEnumToLabel(ishSession, baseFolder);
                if (String.CompareOrdinal(folderLabel, baseFolderLabel) == 0)
                {
                    return(baseFolder);
                }
            }

            // The baseFolder is wrong
            // EL: DIRTY WORKAROUND BELOW TO THROW AN EXCEPTION WITH ERROR CODE 102001
            string xmlIshFolder = ishSession.Folder25.GetMetadata(
                BaseFolder.System,
                new string[] { "'" + baseFolderLabel + "'" },  // Use faulty folder path with quotes added, so we can throw the expected exception with errorcode=102001
                "");

            return(BaseFolder.Data);
        }
Example #7
0
        protected void WriteObject(IshSession ishSession, Enumerations.ISHType[] ishType, List <IshBaseObject> ishBaseObjects, bool enumerateCollection)
        {
            switch (ishSession.PipelineObjectPreference)
            {
            case Enumerations.PipelineObjectPreference.PSObjectNoteProperty:
                List <PSObject> psObjects = new List <PSObject>();
                foreach (var IshBaseObject in ishBaseObjects)
                {
                    PSObject psObject = PSObject.AsPSObject(IshBaseObject);      // returning a PSObject object that inherits from ishObject
                    foreach (IshField ishField in IshBaseObject.IshFields.Fields())
                    {
                        psObject.Properties.Add(ishSession.NameHelper.GetPSNoteProperty(ishType, (IshMetadataField)ishField));
                    }
                    psObjects.Add(psObject);
                }
                WriteObject(psObjects, enumerateCollection);
                break;

            case Enumerations.PipelineObjectPreference.Off:
                WriteObject(ishBaseObjects, true);
                break;
            }
        }
Example #8
0
        private readonly string _levelNameValueTypeSeparator = "_";  // Not that many special characters allowed in Properties, e.g. '=' is assignment
        // TODO [Could] NameHelper PSNoteProperty generator could benefit of fast-lookup dictionary to store DataType and PropertyName as almost all IshObjects start from the same requested metadata request...

        public NameHelper(IshSession ishSession)
        {
            _ishSession = ishSession;
        }
Example #9
0
        protected override void ProcessRecord()
        {
            try
            {
                if ((this.ParameterSetName.StartsWith("UserNamePassword")) && string.IsNullOrEmpty(_ishUserName))
                {
                    // We came in with an empty username but with -IshUserName/-IshPassword;
                    // so fallback to NetworkCredential/ActiveDirectory
                    WriteWarning("Empty -IshUserName so fall back to NetworkCredential/ActiveDirectory, ignoring -IshPassword.");
                    _ishUserName = null;
                    _ishPassword = null;
                }
                int ishPasswordLength = _ishPassword == null ? 0 : _ishPassword.Length;
                if (PSCredential != null)
                {
                    _ishUserName       = PSCredential.UserName;
                    _ishSecurePassword = PSCredential.Password;
                }
                else if (!String.IsNullOrWhiteSpace(_ishPassword))
                {
                    _ishSecurePassword = SecureStringConversions.StringToSecureString(_ishPassword);
                }
                else
                {
                    _ishSecurePassword = null;
                }

                WriteVerbose($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + "]");
                WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] IshUserName[{_ishUserName}] IshPassword[" + new string('*', ishPasswordLength) + $"] Timeout[{_timeout}] TimeoutIssue[{_timeoutIssue}] TimeoutService[{_timeoutService}] IgnoreSslPolicyErrors[{_ignoreSslPolicyErrors}]");
                IshSession ishSession = null;
                if (this.ParameterSetName.EndsWith("-ExplicitIssuer"))
                {
                    WriteDebug($"Connecting to WsBaseUrl[{WsBaseUrl}] WsTrustIssuerUrl[{WsTrustIssuerUrl}] WsTrustIssuerMexUrl[{WsTrustIssuerMexUrl}]");
                    ishSession = new IshSession(Logger, WsBaseUrl, WsTrustIssuerUrl, WsTrustIssuerMexUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors);
                }
                else
                {
                    ishSession = new IshSession(Logger, WsBaseUrl, _ishUserName, _ishSecurePassword, _timeout, _timeoutIssue, _timeoutService, _ignoreSslPolicyErrors);
                }

                // Do early load of IshTypeFieldSetup (either <13-TriDKXmlSetup-based or >=13-RetrieveFieldSetupByIshType-API-based) for
                // usage by ToIshMetadataFields/.../ToIshRequestedMetadataFields and Expand-ISHParameter.ps1 parameter autocompletion
                var ishTypeFieldSetup = ishSession.IshTypeFieldSetup;

                // Submit the PSVariable so you don't have to specify '-IshSession $ishSession' all the time, can be retrieved in every cmdlet, preferably in BeginProcessing()
                WriteVerbose($"Storing IshSession[{ishSession.Name}] under SessionState.{ISHRemoteSessionStateIshSession}");
                this.SessionState.PSVariable.Set(ISHRemoteSessionStateIshSession, ishSession);

                WriteObject(ishSession);
            }
            catch (NotSupportedException notSupportedException)
            {
                WriteError(new ErrorRecord(notSupportedException, "-1", ErrorCategory.InvalidOperation, null));
            }
            catch (TrisoftAutomationException trisoftAutomationException)
            {
                ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
            }
            catch (AggregateException aggregateException)
            {
                var flattenedAggregateException = aggregateException.Flatten();
                WriteWarning(flattenedAggregateException.ToString());
                ThrowTerminatingError(new ErrorRecord(flattenedAggregateException, base.GetType().Name, ErrorCategory.NotSpecified, null));
            }
            catch (Exception exception)
            {
                if (exception.InnerException != null)
                {
                    WriteWarning(exception.InnerException.ToString());
                }
                ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
            }
        }