/// <summary>
        /// Checks if an item of the specified type exists at path.
        /// </summary>
        /// <param name="reportingService">The reporting service.</param>
        /// <param name="path">The path.</param>
        /// <param name="itemType">Type of the item.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">reportingService</exception>
        private static bool ItemExists(ReportingService2010 reportingService, string path, string itemType)
        {
            if (reportingService == null)
                throw new ArgumentNullException("reportingService");

            if (string.IsNullOrEmpty(itemType))
                throw new ArgumentException("itemType");

            string actualItemType = reportingService.GetItemType(path);

            if (itemType == actualItemType)
                return true;
            else
                return false;
        }
        private static void CreateReports(ReportingService2010 reportingService, string path)
        {
            if (reportingService == null)
                throw new ArgumentNullException("reportingService");

            if (string.IsNullOrEmpty(path))
                throw new ArgumentException("path");

            foreach (ReportItem report in SetupReportItems)
            {
                string fullPath = string.Format(report.Path, path);
                string parent = TesterUtility.GetParentPath(fullPath);

                Warning[] warnings;
                reportingService.CreateCatalogItem("Report",
                    report.Name,
                    parent,
                    true,
                    report.Definition,
                    null,
                    out warnings);
            }
        }
        /// <summary>
        /// Gets the reporting service object.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="credentials">The credentials.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">url</exception>
        private static ReportingService2010 GetReportingService(string url, ICredentials credentials)
        {
            if (string.IsNullOrEmpty(url))
                throw new ArgumentException("url");

            if (credentials == null)
                credentials = CredentialCache.DefaultNetworkCredentials;

            if (!url.EndsWith("reportservice2010.asmx"))
            {
                if (url.EndsWith("/"))
                    url = url.Substring(0, url.Length - 1);

                url = string.Format("{0}/reportservice2010.asmx", url);
            }

            ReportingService2010 service = new ReportingService2010();
            service.Url = url;

            service.Credentials = credentials;
            service.PreAuthenticate = true;
            service.UseDefaultCredentials = true;

            return service;
        }
        private static void CreateReport(ReportingService2010 reportingService, ReportItem report)
        {
            if (reportingService == null)
                throw new ArgumentNullException("reportingService");

            if (report == null)
                throw new ArgumentNullException("report");

            string parent = TesterUtility.GetParentPath(report.Path);

            ReportingService2010TestEnvironment.CreateFolderFromPath(reportingService, parent);

            Warning[] warnings;

            reportingService.CreateCatalogItem("Report",
                report.Name,
                parent,
                true,
                report.Definition,
                null,
                out warnings);
        }
        private static void CreateFolders(ReportingService2010 reportingService, string path)
        {
            foreach (FolderItem folder in SetupFolderItems)
            {
                string fullPath = string.Format(folder.Path, path);

                ReportingService2010TestEnvironment.CreateFolderFromPath(reportingService, fullPath);
            }
        }
        /// <summary>
        /// Creates the folder structure of a given path. This will go through each folder in the path and create it.
        /// </summary>
        /// <param name="reportingService">The reporting service.</param>
        /// <param name="path">The path.</param>
        /// <exception cref="System.ArgumentNullException">reportingService</exception>
        private static void CreateFolderFromPath(ReportingService2010 reportingService, string path)
        {
            if (reportingService == null)
                throw new ArgumentNullException("reportingService");

            string [] folders = path.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);

            string parentPath = "/";

            foreach (string folder in folders)
            {
                string folderPath;

                if (parentPath != "/" && parentPath.EndsWith("/"))
                    parentPath = parentPath.Substring(0, parentPath.LastIndexOf("/"));

                if (parentPath == "/")
                    folderPath = parentPath + folder;
                else
                    folderPath = parentPath + "/" + folder;

                if (!ReportingService2010TestEnvironment.ItemExists(reportingService, folderPath, "Folder"))
                {
                    reportingService.CreateFolder(folder, parentPath, null);
                }

                if (parentPath != "/")
                    parentPath += "/" + folder;
                else
                    parentPath += folder;
            }
        }
        private static void CreateDataSources(ReportingService2010 reportingService, string path)
        {
            if (reportingService == null)
                throw new ArgumentNullException("reportingService");

            if (string.IsNullOrEmpty(path))
                throw new ArgumentException("path");

            foreach (DataSourceItem dataSource in SetupDataSourceItems)
            {
                DataSourceDefinition def = new DataSourceDefinition();
                def.ConnectString = dataSource.ConnectString;

                switch (dataSource.CredentialsRetrieval)
                {
                    case "Integrated":
                        def.CredentialRetrieval = CredentialRetrievalEnum.Integrated; break;
                    case "None":
                        def.CredentialRetrieval = CredentialRetrievalEnum.None; break;
                    case "Prompt":
                        def.CredentialRetrieval = CredentialRetrievalEnum.Prompt; break;
                    case "Store":
                        def.CredentialRetrieval = CredentialRetrievalEnum.Store; break;
                }

                def.Enabled = dataSource.Enabled;
                def.EnabledSpecified = dataSource.EnabledSpecified;
                def.Extension = dataSource.Extension;
                def.ImpersonateUser = dataSource.ImpersonateUser;
                def.ImpersonateUserSpecified = dataSource.ImpersonateUserSpecified;
                def.OriginalConnectStringExpressionBased = dataSource.OriginalConnectStringExpressionBased;
                def.Password = dataSource.Password;
                def.Prompt = dataSource.Prompt;
                def.UseOriginalConnectString = dataSource.UseOriginalConnectString;
                def.UserName = dataSource.UserName;
                def.WindowsCredentials = dataSource.WindowsCredentials;

                string fullPath = string.Format(dataSource.Path, path);
                string parent = TesterUtility.GetParentPath(fullPath);

                reportingService.CreateDataSource(dataSource.Name, parent, true, def, null);
            }
        }
        private static void CreateDataSource(ReportingService2010 reportingService, DataSourceItem dataSource)
        {
            if (reportingService == null)
                throw new ArgumentNullException("reportingService");

            if (dataSource == null)
                throw new ArgumentNullException("dataSource");

            DataSourceDefinition def = new DataSourceDefinition();
            def.ConnectString = dataSource.ConnectString;

            switch (dataSource.CredentialsRetrieval)
            {
                case "Integrated":
                    def.CredentialRetrieval = CredentialRetrievalEnum.Integrated; break;
                case "None":
                    def.CredentialRetrieval = CredentialRetrievalEnum.None; break;
                case "Prompt":
                    def.CredentialRetrieval = CredentialRetrievalEnum.Prompt; break;
                case "Store":
                    def.CredentialRetrieval = CredentialRetrievalEnum.Store; break;
            }

            def.Enabled = dataSource.Enabled;
            def.EnabledSpecified = dataSource.EnabledSpecified;
            def.Extension = dataSource.Extension;
            def.ImpersonateUser = dataSource.ImpersonateUser;
            def.ImpersonateUserSpecified = dataSource.ImpersonateUserSpecified;
            def.OriginalConnectStringExpressionBased = dataSource.OriginalConnectStringExpressionBased;
            def.Password = dataSource.Password;
            def.Prompt = dataSource.Prompt;
            def.UseOriginalConnectString = dataSource.UseOriginalConnectString;
            def.UserName = dataSource.UserName;
            def.WindowsCredentials = dataSource.WindowsCredentials;

            string parent = TesterUtility.GetParentPath(dataSource.Path);

            ReportingService2010TestEnvironment.CreateFolderFromPath(reportingService, parent);

            reportingService.CreateDataSource(dataSource.Name, parent, true, def, null);
        }