当前位置: 首页>>代码示例>>C#>>正文


C# PSCmdlet.WriteWarning方法代码示例

本文整理汇总了C#中System.Management.Automation.PSCmdlet.WriteWarning方法的典型用法代码示例。如果您正苦于以下问题:C# PSCmdlet.WriteWarning方法的具体用法?C# PSCmdlet.WriteWarning怎么用?C# PSCmdlet.WriteWarning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.PSCmdlet的用法示例。


在下文中一共展示了PSCmdlet.WriteWarning方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OldHtmlDescriptionUpdater

        public OldHtmlDescriptionUpdater(string description, PSCmdlet callingCmdlet)
        {
            try
            {
                var settings = new XmlReaderSettings();
                settings.ProhibitDtd = false;
                callingCmdlet.WriteWarning("Reading HTML descrption");
                using (XmlReader reader = XmlReader.Create(new StringReader(XmlDeclaration + description), settings))
                {
                    reader.ReadToFollowing("div");
                    var id = reader.GetAttribute("id");
                    if (id == "GlymaNodeDescriptionDiv")
                    {
                        callingCmdlet.WriteWarning("GlymaNodeDescriptionDiv div tag found");

                        var widthString = reader.GetAttribute("width");
                        int width;
                        if (widthString != null && int.TryParse(widthString, out width) && width > 0)
                        {
                            Width = width;
                        }

                        var heightString = reader.GetAttribute("height");
                        int height;
                        if (heightString != null && int.TryParse(heightString, out height) && height > 0)
                        {
                            Height = height;
                        }

                        Description = reader.ReadInnerXml();
                    }
                    else
                    {
                        Description = description;
                    }
                }
            }
            catch
            {
                Description = description;
            }
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:42,代码来源:OldHtmlDescriptionUpdater.cs

示例2: PopulateCmdletBase

        public bool PopulateCmdletBase(PSCmdlet cmdlet, ref Get_GLDomainBase cmdletBase)
        {
            bool isSuccessful = false;

            object identityAsObject = Identity;

            if (Identity is PSObject)
            {
                PSObject identityAsPSObject = Identity as PSObject;

                identityAsObject = identityAsPSObject.BaseObject;
            }

            if (identityAsObject is SPSite)
            {
                SPSite site = identityAsObject as SPSite;

                using (SPWeb web = site.RootWeb)
                {
                    isSuccessful = GetDatabaseDetails(web, ref cmdletBase);
                }
            }
            else if (identityAsObject is SPWeb)
            {
                SPWeb web = identityAsObject as SPWeb;

                isSuccessful = GetDatabaseDetails(web, ref cmdletBase);
            }
            else if (identityAsObject is string)
            {
                string siteUrl = identityAsObject as string;

                using (SPSite site = new SPSite(siteUrl))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        isSuccessful = GetDatabaseDetails(web, ref cmdletBase);
                    }
                }
            }
            else if (identityAsObject is Guid)
            {
                Guid siteId = (Guid)identityAsObject;

                using (SPSite site = new SPSite(siteId))
                {
                    using (SPWeb web = site.RootWeb)
                    {
                        isSuccessful = GetDatabaseDetails(web, ref cmdletBase);
                    }
                }
            }
            else
            {
                cmdlet.WriteWarning("No valid 'Identity' specified. Identity must be a SPSite, SPWeb, site/web URL, or site colleciton ID.");

                return isSuccessful;
            }

            if (!isSuccessful)
            {
                cmdlet.WriteWarning("Provided 'Identity' has no Glyma Server details declared for it. Try a parent if it's a sub-site.");

                return isSuccessful;
            }

            return isSuccessful;
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:68,代码来源:IdentityLoader.cs

示例3: UpdateMappingToolDatabase

        private void UpdateMappingToolDatabase(PSCmdlet callingCmdlet)
        {
            using (var mapDatabaseContext = new MappingTool.MappingToolDatabaseDataContext(MapDatabaseConnectionString))
            {
                var glymaDbVersion = mapDatabaseContext.GetGlymaDbVersion();

                foreach (var row in glymaDbVersion)
                {
                    if (row.Column1 != "v1.5.0r3")
                    {
                        callingCmdlet.WriteWarning(string.Format("This update can only update the v1.5.0r3 database to v1.5.0r4 database. The version of this database is {0}.", row.Column1));

                        return;
                    }
                }
            }

            using (var mapDbConnection = new SqlConnection(MapDatabaseConnectionString))
            {
                mapDbConnection.Open();
                var transaction = mapDbConnection.BeginTransaction();
                try
                {
                    callingCmdlet.WriteWarning("Database update started, please wait...");
                    new UpdateAllMetadata().Execute(mapDbConnection, transaction);
                    callingCmdlet.WriteWarning("Updated to new description metadata name");

                    var descriptionTypeMetadataList = new QueryMetadata("Description.Type").GetItems(mapDbConnection, transaction);
                    callingCmdlet.WriteWarning(string.Format("{0} description type records found.", descriptionTypeMetadataList.Count()));

                    var descriptionMetadataList = new QueryMetadata("Description.Content").GetItems(mapDbConnection, transaction);
                    callingCmdlet.WriteWarning(string.Format("{0} description records found.", descriptionMetadataList.Count()));

                    foreach (var updatableNode in descriptionTypeMetadataList)
                    {
                        var found = descriptionMetadataList.FirstOrDefault(q => q.NodeUid == updatableNode.NodeUid);
                        if (found != null)
                        {
                            if (string.IsNullOrEmpty(found.MetadataValue))
                            {
                                new DeleteMetadata(updatableNode.MetadataId).Execute(mapDbConnection, transaction);
                                new DeleteMetadata(found.MetadataId).Execute(mapDbConnection, transaction);
                                callingCmdlet.WriteWarning(string.Format("Node Id {0} description deleted",
                                    updatableNode.NodeUid));
                            }
                            else if (found.MetadataValue.StartsWith("http://") || found.MetadataValue.StartsWith("https://") || updatableNode.MetadataValue == "Iframe")
                            {
                                var parts = found.MetadataValue.Split(',');
                                if (parts.Count() == 3)
                                {
                                    new UpdateMetadata(found.MetadataId, "Description.Url", parts[0])
                                        .Execute(mapDbConnection, transaction);
                                    new InsertMetadata("Description.Width", parts[1].Replace("px", ""),
                                        found.NodeUid, found.RootMapUid, found.DomainUid,
                                        found.Created, found.Modified, found.CreatedBy, found.ModifiedBy)
                                        .Execute(mapDbConnection, transaction);
                                    new InsertMetadata("Description.Height", parts[2].Replace("px", ""),
                                        found.NodeUid, found.RootMapUid, found.DomainUid,
                                        found.Created, found.Modified, found.CreatedBy, found.ModifiedBy)
                                        .Execute(mapDbConnection, transaction);
                                    new UpdateMetadata(updatableNode.MetadataId, "Description.Type", "Iframe")
                                        .Execute(mapDbConnection, transaction);
                                    callingCmdlet.WriteWarning(
                                        string.Format("Node Id {0} description has updated to Iframe",
                                            updatableNode.NodeUid));
                                }
                                else
                                {
                                    new UpdateMetadata(updatableNode.MetadataId, "Description.Type", "Html").Execute(mapDbConnection, transaction);
                                }
                            }
                            else
                            {
                                var descriptionUpdater = new OldHtmlDescriptionUpdater(found.MetadataValue, callingCmdlet);
                                new UpdateMetadata(updatableNode.MetadataId, "Description.Type", "Html")
                                    .Execute(mapDbConnection, transaction);
                                new UpdateMetadata(found.MetadataId, "Description.Content", descriptionUpdater.Description)
                                    .Execute(mapDbConnection, transaction);
                                if (descriptionUpdater.Width > 0)
                                {
                                    new InsertMetadata("Description.Width", descriptionUpdater.Width.ToString(CultureInfo.InvariantCulture), found.NodeUid, found.RootMapUid, found.DomainUid, found.Created, found.Modified, found.CreatedBy, found.ModifiedBy)
                                    .Execute(mapDbConnection, transaction);
                                }

                                if (descriptionUpdater.Height > 0)
                                {
                                    new InsertMetadata("Description.Height", descriptionUpdater.Height.ToString(CultureInfo.InvariantCulture), found.NodeUid, found.RootMapUid, found.DomainUid, found.Created, found.Modified, found.CreatedBy, found.ModifiedBy)
                                    .Execute(mapDbConnection, transaction);
                                }
                                callingCmdlet.WriteWarning(string.Format("Node Id {0} description has updated to Html", updatableNode.NodeUid));
                            }
                        }
                        else
                        {
                            new DeleteMetadata(updatableNode.MetadataId).Execute(mapDbConnection, transaction);
                            callingCmdlet.WriteWarning(string.Format("Node Id {0} description deleted",
                                    updatableNode.NodeUid));
                        }
                    }

//.........这里部分代码省略.........
开发者ID:chris-tomich,项目名称:Glyma,代码行数:101,代码来源:Update_v1_5_0_r4Base.cs

示例4: ExecuteCmdletBase

        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            SqlAssemblies sqlAssemblies = new SqlAssemblies();

            if (!sqlAssemblies.LoadedSuccessfully)
            {
                callingCmdlet.WriteWarning(sqlAssemblies.ErrorMessage);
                return;
            }

            try
            {
                SmoServer server = new SmoServer(sqlAssemblies, DatabaseServer);
                server.SetApplicationName("GlymaNewMapDbInstaller");

                SmoDatabase database = new SmoDatabase(sqlAssemblies, server, DatabaseName);

                SmoFileGroup fileGroup = new SmoFileGroup(sqlAssemblies, database, "PRIMARY");
                database.AddFileGroup(fileGroup);

                SmoDataFile dataFile = new SmoDataFile(sqlAssemblies, fileGroup, DatabaseName);
                fileGroup.AddDataFile(dataFile);
                dataFile.SetFileName(server.GetMasterDbPath() + "\\" + DatabaseName + ".mdf");
                dataFile.SetSize(50.0 * 1024.0);
                dataFile.SetGrowthType("KB");
                dataFile.SetGrowth(1024.0);
                dataFile.SetIsPrimaryFile(true);

                SmoLogFile logFile = new SmoLogFile(sqlAssemblies, database, DatabaseName + "_Log");
                database.AddLogFile(logFile);
                logFile.SetFileName(server.GetMasterDbPath() + "\\" + DatabaseName + "_Log.ldf");
                logFile.SetSize(164.0 * 1024.0);
                logFile.SetGrowthType("Percent");
                logFile.SetGrowth(10.0);

                database.Create();

                fileGroup = database.GetFileGroup("PRIMARY");
                fileGroup.SetIsDefault(true);
                fileGroup.Alter();
                database.Alter();

                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    connection.Open();

                    if (!string.IsNullOrEmpty(WebApplicationPoolAccount))
                    {
                        if (!IsWebApplicationPoolAccountDbo)
                        {
                            EmbeddedSqlScript createWebUserScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.CreateUser.sql");
                            createWebUserScript.AddToken("[ACCOUNT_NAME]", WebApplicationPoolAccount);
                            createWebUserScript.ExecuteNonQuery(connection);

                            EmbeddedSqlScript grantWebUserRoleScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.GrantUserRole.sql");
                            grantWebUserRoleScript.AddToken("[ACCOUNT_NAME]", WebApplicationPoolAccount);
                            grantWebUserRoleScript.AddToken("[ROLE]", "db_owner");
                            grantWebUserRoleScript.ExecuteNonQuery(connection);
                        }
                    }
                    else
                    {
                        callingCmdlet.WriteWarning("There was no web application pool account provided. As we are skipping this step, the web application pool account will need to be manually given db_owner rights to this Glyma Map DB.");
                    }

                    if (!string.IsNullOrEmpty(GlymaServiceApplicationPoolAccount))
                    {
                        if (!IsGlymaServiceApplicationPoolAccountDbo)
                        {
                            EmbeddedSqlScript createGlymaServiceUserScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.CreateUser.sql");
                            createGlymaServiceUserScript.AddToken("[ACCOUNT_NAME]", GlymaServiceApplicationPoolAccount);
                            createGlymaServiceUserScript.ExecuteNonQuery(connection);

                            EmbeddedSqlScript grantGlymaServiceUserRoleScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.GrantUserRole.sql");
                            grantGlymaServiceUserRoleScript.AddToken("[ACCOUNT_NAME]", GlymaServiceApplicationPoolAccount);
                            grantGlymaServiceUserRoleScript.AddToken("[ROLE]", "db_owner");
                            grantGlymaServiceUserRoleScript.ExecuteNonQuery(connection);
                        }
                    }
                    else
                    {
                        callingCmdlet.WriteWarning("There was no Glyma service application pool account provided. As we are skipping this step, the Glyma application pool account will need to be manually given db_owner rights to this Glyma Map DB.");
                    }

                    EmbeddedSqlScript createTablesScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.CreateTables.sql");
                    createTablesScript.ExecuteNonQuery(connection);

                    EmbeddedSqlScript createConstraintsScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.CreateConstraints.sql");
                    createConstraintsScript.ExecuteNonQuery(connection);

                    EmbeddedSqlScript insertTypesDataScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.InsertTypesData.sql");
                    insertTypesDataScript.ExecuteNonQuery(connection);

                    EmbeddedSqlScript createFullTextCatalogScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.CreateFullTextCatalog.sql");
                    createFullTextCatalogScript.ExecuteNonQuery(connection);

                    EmbeddedSqlScript createStoredProceduresScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.CreateStoredProcedures.sql");
                    createStoredProceduresScript.ExecuteNonQuery(connection);

                    EmbeddedSqlScript createQueryMapSPScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapDB.CreateQueryMapSP.sql");
//.........这里部分代码省略.........
开发者ID:chris-tomich,项目名称:Glyma,代码行数:101,代码来源:New_GLMapDatabaseBase.cs

示例5: GetContext

        /// <summary>
        /// Gets a sql auth connection context.
        /// </summary>
        /// <param name="cmdlet">The cmdlet requesting the context</param>
        /// <param name="serverName">The name of the server to connect to</param>
        /// <param name="manageUrl">The manage url of the server</param>
        /// <param name="credentials">The credentials to connect to the server</param>
        /// <param name="sessionActivityId">The session activity ID</param>
        /// <param name="managementServiceUri">The URI for management service</param>
        /// <returns>The connection context</returns>
        public static IServerDataServiceContext GetContext(
            PSCmdlet cmdlet,
            string serverName,
            Uri manageUrl,
            SqlAuthenticationCredentials credentials,
            Guid sessionActivityId,
            Uri managementServiceUri)
        {
            Version version;
            
            // If a version was specified (by tests) us it.
            if (sqlVersion == SqlVersion.v2)
            {
                version = new Version(11, 0);
            }
            else if (sqlVersion == SqlVersion.v12)
            {
                version = new Version(12, 0);
            }
            else // If no version specified, determine the version by querying the server.
            {
                version = GetVersion(manageUrl, credentials);
            }
            sqlVersion = SqlVersion.None;

            IServerDataServiceContext context = null;

            if (version.Major >= 12)
            {
                context = new TSqlConnectionContext(
                    sessionActivityId,
                    manageUrl.Host,
                    credentials,
                    serverName);
            }
            else
            {
                context = ServerDataServiceSqlAuth.Create(
                    managementServiceUri,
                    sessionActivityId,
                    credentials,
                    serverName);

                // Retrieve $metadata to verify model version compatibility
                XDocument metadata = ((ServerDataServiceSqlAuth)context).RetrieveMetadata();
                XDocument filteredMetadata = DataConnectionUtility.FilterMetadataDocument(metadata);
                string metadataHash = DataConnectionUtility.GetDocumentHash(filteredMetadata);
                if (!((ServerDataServiceSqlAuth)context).metadataHashes.Any(knownHash => metadataHash == knownHash))
                {
                    cmdlet.WriteWarning(Resources.WarningModelOutOfDate);
                }

                ((ServerDataServiceSqlAuth)context).MergeOption = MergeOption.PreserveChanges;
            }

            return context;
        }
开发者ID:FrankSiegemund,项目名称:azure-powershell,代码行数:67,代码来源:SqlAuthContextFactory.cs

示例6: ExecuteCmdletBase

        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            SqlAssemblies sqlAssemblies = new SqlAssemblies();

            if (!sqlAssemblies.LoadedSuccessfully)
            {
                callingCmdlet.WriteWarning(sqlAssemblies.ErrorMessage);
                return;
            }

            SmoServer server = new SmoServer(sqlAssemblies, DatabaseServer);
            server.SetApplicationName("GlymaNewMapSecurityDbInstaller");

            SmoDatabase database = new SmoDatabase(sqlAssemblies, server, DatabaseName);

            SmoFileGroup fileGroup = new SmoFileGroup(sqlAssemblies, database, "PRIMARY");
            database.AddFileGroup(fileGroup);

            SmoDataFile dataFile = new SmoDataFile(sqlAssemblies, fileGroup, DatabaseName);
            fileGroup.AddDataFile(dataFile);
            dataFile.SetFileName(server.GetMasterDbPath() + "\\" + DatabaseName + ".mdf");
            dataFile.SetSize(50.0 * 1024.0);
            dataFile.SetGrowthType("KB");
            dataFile.SetGrowth(1024.0);
            dataFile.SetIsPrimaryFile(true);

            SmoLogFile logFile = new SmoLogFile(sqlAssemblies, database, DatabaseName + "_Log");
            database.AddLogFile(logFile);
            logFile.SetFileName(server.GetMasterDbPath() + "\\" + DatabaseName + "_Log.ldf");
            logFile.SetSize(164.0 * 1024.0);
            logFile.SetGrowthType("Percent");
            logFile.SetGrowth(10.0);

            database.Create();

            fileGroup = database.GetFileGroup("PRIMARY");
            fileGroup.SetIsDefault(true);
            fileGroup.Alter();
            database.Alter();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                EmbeddedSqlScript createUserScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapSecurityDB.CreateUser.sql");
                createUserScript.AddToken("[ACCOUNT_NAME]", ApplicationPoolAccount);
                createUserScript.ExecuteNonQuery(connection);

                EmbeddedSqlScript grantUserRoleScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapSecurityDB.GrantUserRole.sql");
                grantUserRoleScript.AddToken("[ACCOUNT_NAME]", ApplicationPoolAccount);
                grantUserRoleScript.AddToken("[ROLE]", "db_owner");
                grantUserRoleScript.ExecuteNonQuery(connection);

                // TODO Create security database.

                EmbeddedSqlScript createGetRootMapsSPScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapSecurityDB.CreateGetRootMapsSP.sql");
                createGetRootMapsSPScript.ExecuteNonQuery(connection);

                EmbeddedSqlScript createSearchUserScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapSecurityDB.CreateUser.sql");
                createSearchUserScript.AddToken("[ACCOUNT_NAME]", SearchCrawlAccount);
                createSearchUserScript.ExecuteNonQuery(connection);

                EmbeddedSqlScript grantSearchPermissionsScript = new EmbeddedSqlScript("Glyma.Powershell.Resources.New_GLMapSecurityDB.GrantSearchPermissions.sql");
                grantSearchPermissionsScript.AddToken("[ACCOUNT_NAME]", SearchCrawlAccount);
                grantSearchPermissionsScript.ExecuteNonQuery(connection);

                connection.Close();
            }
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:69,代码来源:New_GLMapSecurityDatabaseBase.cs

示例7: ExecuteCmdletBase

        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            if (Domain == null)
            {
                callingCmdlet.WriteWarning("No valid domain has been provided.");

                return;
            }

            if (!Domain.CheckIsValid())
            {
                callingCmdlet.WriteWarning("An invalid domain object has been provided.");

                return;
            }

            Model.IDatabaseInfo dbInfo = Domain;

            using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(dbInfo.ConnectionString))
            {
                dataContext.CommandTimeout = 180;
                if (MapId != Guid.Empty)
                {
                    /// Find maps by ID.
                    /// 

                    Model.Map map = GetMapById(dataContext, MapId);

                    callingCmdlet.WriteObject(map);
                }
                else if (!string.IsNullOrEmpty(MapName))
                {
                    /// Find maps by name.
                    /// 

                    List<Model.Map> maps = GetMapsByName(dataContext, MapName);

                    callingCmdlet.WriteObject(maps, true);
                }
                else
                {
                    /// Fine all maps.
                    /// 

                    List<Model.Map> maps = GetAllMaps(dataContext);

                    callingCmdlet.WriteObject(maps, true);
                }
            }
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:50,代码来源:Get_GLMapBase.cs

示例8: ExecuteCmdletBase

        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            HashSet<Guid> validMaps = new HashSet<Guid>();
            HashSet<Guid> orphanedNodes = new HashSet<Guid>();
            HashSet<Guid> orphanedRelationships = new HashSet<Guid>();

            if (RootMap == null || !RootMap.CheckIsValid())
            {
                callingCmdlet.WriteWarning("An invalid source map has been provided.");

                return;
            }

            Model.IDatabaseInfo mapDbInfo = RootMap.Domain;

            using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(mapDbInfo.ConnectionString))
            {
                dataContext.CommandTimeout = 180;

                var dbRootMapNodes = from dbNode in dataContext.Nodes
                                     where dbNode.NodeUid == RootMap.NodeId
                                     select dbNode;

                var dbRootMapNode = dbRootMapNodes.FirstOrDefault();

                if (dbRootMapNode == null)
                {
                    throw new KeyNotFoundException("The specified root map doesn't exist.");
                }

                if (dbRootMapNode.NodeUid != dbRootMapNode.RootMapUid)
                {
                    throw new NotSupportedException("The provided root map isn't a root map.");
                }

                /// We need to find all the valid children maps, starting at the root map. We'll do this recursively.
                #region Find valid maps
                validMaps.Add(dbRootMapNode.NodeUid);

                RecusivelyFindValidMaps(ref validMaps, dbRootMapNode);
                #endregion

                #region Find all nodes that aren't part of a valid map
                var allNodesInMap = from dbNode in dataContext.Nodes
                                    where dbNode.RootMapUid == RootMap.NodeId
                                    select dbNode;

                foreach (var node in allNodesInMap)
                {
                    if (validMaps.Contains(node.NodeUid))
                    {
                        continue;
                    }

                    bool isNodeValid = CheckIsValid(ref validMaps, node);

                    if (!isNodeValid)
                    {
                        /// If the orphaned nodes list doesn't contain the node, then add the node to the list.
                        if (!orphanedNodes.Contains(node.NodeUid))
                        {
                            orphanedNodes.Add(node.NodeUid);
                        }

                        /// Find all the orphaned relationships.
                        FindOrphanedRelationships(ref orphanedRelationships, node);
                    }
                }
                #endregion

                int orphanedNodesCount = 0;
                int orphanedMetadataCount = 0;
                int orphanedDescriptorsCount = 0;
                int orphanedRelationshipsCount = 0;

                foreach (Guid nodeId in orphanedNodes)
                {
                    var orphanedDescriptors = from dbDescriptor in dataContext.Descriptors
                                              where dbDescriptor.NodeUid == nodeId
                                              select dbDescriptor;

                    foreach (var orphanedDescriptor in orphanedDescriptors)
                    {
                        dataContext.Descriptors.DeleteOnSubmit(orphanedDescriptor);
                        orphanedDescriptorsCount++;
                    }

                    var orphanedMetadata = from dbMetadata in dataContext.Metadatas
                                           where dbMetadata.NodeUid == nodeId
                                           select dbMetadata;

                    foreach (var orphanedMetadatum in orphanedMetadata)
                    {
                        dataContext.Metadatas.DeleteOnSubmit(orphanedMetadatum);
                        orphanedMetadataCount++;
                    }
                }

                dataContext.SubmitChanges();

//.........这里部分代码省略.........
开发者ID:chris-tomich,项目名称:Glyma,代码行数:101,代码来源:Repair_GLDatabaseIntegrityBase.cs

示例9: UpdateMappingToolDatabase

        private bool UpdateMappingToolDatabase(PSCmdlet callingCmdlet)
        {
            using (MappingTool.MappingToolDatabaseDataContext mapDatabaseContext = new MappingTool.MappingToolDatabaseDataContext(MapDatabaseConnectionString))
            {
                var glymaDbVersion = mapDatabaseContext.GetGlymaDbVersion();

                foreach (var row in glymaDbVersion)
                {
                    if (row.Column1 != "v1.5.0r2")
                    {
                        callingCmdlet.WriteWarning(string.Format("This update can only update the v1.5.0r2 database to v1.5.0r3 database. The version of this database is {0}.", row.Column1));

                        return false;
                    }
                }
            }

            using (SqlConnection mapDbConnection = new SqlConnection(MapDatabaseConnectionString))
            {
                mapDbConnection.Open();

                try
                {
                    EmbeddedSqlScript updateGlymaDbVersion = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r3.UpdateGlymaDbVersion.sql");
                    updateGlymaDbVersion.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                    return false;
                }

                mapDbConnection.Close();
            }

            return true;
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:36,代码来源:Update_v1_5_0_r3Base.cs

示例10: UpdateTransactionDatabase

        private bool UpdateTransactionDatabase(PSCmdlet callingCmdlet)
        {
            using (Transaction.TransactionDatabaseDataContext transactionDatabaseContext = new Transaction.TransactionDatabaseDataContext(TransactionDatabaseConnectionString))
            {
                var glymaDbVersion = transactionDatabaseContext.GetGlymaDbVersion();

                foreach (var row in glymaDbVersion)
                {
                    if (row.Column1 != "v1.5.0r2")
                    {
                        callingCmdlet.WriteWarning(string.Format("This update can only update the v1.5.0r2 database to v1.5.0r3 database. The version of this database is {0}.", row.Column1));

                        return false;
                    }
                }
            }

            using (SqlConnection transactionDbConnection = new SqlConnection(TransactionDatabaseConnectionString))
            {
                transactionDbConnection.Open();

                try
                {
                    EmbeddedSqlScript updateGlymaDbVersion = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r3.UpdateGlymaDbVersion.sql");
                    updateGlymaDbVersion.ExecuteNonQuery(transactionDbConnection);
                }
                catch
                {
                    return false;
                }

                try
                {
                    EmbeddedSqlScript insertNewTransactionOperations = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r3.InsertTransactionOperations.sql");
                    insertNewTransactionOperations.ExecuteNonQuery(transactionDbConnection);
                }
                catch
                {
                    return false;
                }

                transactionDbConnection.Close();
            }

            return true;
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:46,代码来源:Update_v1_5_0_r3Base.cs

示例11: ExecuteCmdletBase

        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            Dictionary<Guid, QueryMapNode> originalNodes = new Dictionary<Guid, QueryMapNode>();
            List<QueryMapRelationship> originalRelationships = new List<QueryMapRelationship>();
            List<QueryMapDescriptor> originalDescriptors = new List<QueryMapDescriptor>();
            List<QueryMapMetadata> originalMetadata = new List<QueryMapMetadata>();

            if (DestinationDomain == null || !DestinationDomain.CheckIsValid())
            {
                callingCmdlet.WriteWarning("An invalid destination domain has been provided.");

                return;
            }

            if (SourceMap == null || !SourceMap.CheckIsValid())
            {
                callingCmdlet.WriteWarning("An invalid source map has been provided.");

                return;
            }

            Model.IDatabaseInfo sourceMapDbInfo = SourceMap.Domain;

            using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(sourceMapDbInfo.ConnectionString))
            {
                dataContext.CommandTimeout = 180;
                var queryMapResultSets = dataContext.QueryMapMultiDepth(SourceMap.Domain.DomainId, SourceMap.NodeId, -1, false);

                var queryMapResultSet = queryMapResultSets.GetResult<QueryMapMultiDepthResult>();

                while (queryMapResultSet != null)
                {
                    foreach (var queryMapResult in queryMapResultSet)
                    {
                        if (queryMapResult.Level != null)
                        {
                            if (queryMapResult.NodeUid.HasValue && queryMapResult.NodeUid != Guid.Empty)
                            {
                                /// Make sure that we aren't copying across a domain node.
                                if (queryMapResult.NodeTypeUid.HasValue && queryMapResult.NodeTypeUid != new Guid("263754C2-2F31-4D21-B9C4-6509E00A5E94"))
                                {
                                    /// The QueryMap procedure returns ALL nodes by following relationships to max depth meaning some nodes are repeated in some of the levels multiple nodes may connect to them.
                                    if (!originalNodes.ContainsKey(queryMapResult.NodeUid.Value))
                                    {
                                        /// TODO: Need to consider copying the NodeOriginalId.
                                        QueryMapNode node = new QueryMapNode();
                                        node.NodeUid = queryMapResult.NodeUid.Value;
                                        node.DomainUid = DestinationDomain.DomainId;
                                        node.NodeTypeUid = queryMapResult.NodeTypeUid;
                                        node.RootMapUid = queryMapResult.RootMapUid;
                                        node.Created = queryMapResult.Created;
                                        node.Modified = queryMapResult.Modified;
                                        node.CreatedBy = queryMapResult.CreatedBy;
                                        node.ModifiedBy = queryMapResult.ModifiedBy;

                                        originalNodes[queryMapResult.NodeUid.Value] = node;
                                    }
                                }
                            }
                        }
                        else if (queryMapResult.MetadataId != null)
                        {
                            if (queryMapResult.MetadataId.HasValue && queryMapResult.MetadataId != Guid.Empty)
                            {
                                QueryMapMetadata metadatum = new QueryMapMetadata();
                                metadatum.MetadataId = queryMapResult.MetadataId.Value;
                                metadatum.NodeUid = queryMapResult.NodeUid;
                                metadatum.RelationshipUid = queryMapResult.RelationshipUid;
                                metadatum.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;
                                metadatum.MetadataTypeUid = queryMapResult.MetadataTypeUid;
                                metadatum.MetadataName = queryMapResult.MetadataName;
                                metadatum.MetadataValue = queryMapResult.MetadataValue;
                                metadatum.DomainUid = queryMapResult.DomainUid;
                                metadatum.RootMapUid = queryMapResult.RootMapUid;
                                metadatum.Created = queryMapResult.Created;
                                metadatum.Modified = queryMapResult.Modified;
                                metadatum.CreatedBy = queryMapResult.CreatedBy;
                                metadatum.ModifiedBy = queryMapResult.ModifiedBy;

                                originalMetadata.Add(metadatum);
                            }
                        }
                        else if (queryMapResult.DescriptorUid != null)
                        {
                            if (queryMapResult.DescriptorUid.HasValue && queryMapResult.DescriptorUid != Guid.Empty)
                            {
                                QueryMapDescriptor descriptor = new QueryMapDescriptor();
                                descriptor.DescriptorUid = queryMapResult.DescriptorUid.Value;
                                descriptor.NodeUid = queryMapResult.NodeUid;
                                descriptor.RelationshipUid = queryMapResult.RelationshipUid;
                                descriptor.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;

                                originalDescriptors.Add(descriptor);
                            }
                        }
                        else
                        {
                            if (queryMapResult.RelationshipUid.HasValue && queryMapResult.RelationshipUid != Guid.Empty)
                            {
                                /// TODO: Need to consider copying the RelationshipOriginalId.
//.........这里部分代码省略.........
开发者ID:chris-tomich,项目名称:Glyma,代码行数:101,代码来源:Copy_GLMapBase.cs


注:本文中的System.Management.Automation.PSCmdlet.WriteWarning方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。