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


C# PSCmdletBase.WriteError方法代码示例

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


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

示例1: runSQLCommand

        private static void runSQLCommand(PSCmdletBase cmdlet, IDatabase database, string SQLCode)
        {
            if (null == database) {
                cmdlet.WriteError(
                    cmdlet,
                    "Could not find the database with name '" +
                    database.Name +
                    "' among registered databases",
                    "CouldNotFindDB",
                    ErrorCategory.InvalidArgument,
                    true);
            }

            if (null == database.Connection) {

                database.Connection =
                    new SQLiteConnection(database.ConnectionString);

            }
            if (database.Connection.State == ConnectionState.Closed) {
                database.Connection.Open();
            }

            using (SQLiteCommand cmd =
                   new SQLiteCommand(SQLCode)) {

                cmd.Connection = database.Connection;
                //cmdlet.WriteVerbose(cmdlet, cmd.ExecuteNonQuery().ToString());

                int result = cmd.ExecuteNonQuery();

                cmdlet.WriteVerbose(
                    cmdlet,
                    SQLCode +
                    ": " +
                    result.ToString());
            }
        }
开发者ID:uiatester,项目名称:STUPS,代码行数:38,代码来源:SQLiteHelper.cs

示例2: runTwoScriptBlockCollections

        protected internal void runTwoScriptBlockCollections(
            ScriptBlock[] scriptblocksSet1,
            ScriptBlock[] scriptblocksSet2,
            // 20130318
            //PSCmdletBase cmdlet)
            PSCmdletBase cmdlet,
            object[] parameters)
        {
            cmdlet.WriteVerbose(cmdlet, "preparing scriptblocks");

            System.Collections.Generic.List<ScriptBlock> scriptblocks =
                new System.Collections.Generic.List<ScriptBlock>();

            try {
                if (scriptblocksSet1 != null &&
                    scriptblocksSet1.Length > 0) {

                    foreach (ScriptBlock sb in scriptblocksSet1) {

                        scriptblocks.Add(sb);
                    }
                }

                if (scriptblocksSet2 != null &&
                    scriptblocksSet2.Length > 0) {

                    foreach (ScriptBlock sb in scriptblocksSet2) {

                        scriptblocks.Add(sb);
                    }
                }

            //                if (null == scriptblocks || 0 == scriptblocks.Count) {
            //
            //                    cmdlet.WriteVerbose(cmdlet, "there is no any StopAction scriptblock");
            //
            //                    //throw new Exception("There are no StopAction scriptblocks, define at least one");
            //                    cmdlet.WriteError(
            //                        cmdlet,
            //                        "There are no StopAction scriptblocks, define at least one",
            //                        "NoStopActionScriptblocks",
            //                        ErrorCategory.InvalidArgument,
            //                        true);
            //                }

                cmdlet.WriteVerbose(cmdlet, "scriptblocks were prepared");
            }
            catch (Exception eScriptblocksPreparation) {

                cmdlet.WriteVerbose(cmdlet, "Scriptblocks are not going to be run");

                cmdlet.WriteVerbose(cmdlet, eScriptblocksPreparation.Message);

                cmdlet.WriteError(
                    cmdlet,
                    eScriptblocksPreparation.Message,
                    "ScriptblocksNotPrepared",
                    ErrorCategory.InvalidOperation,
                    true);
            }

            // 20130318
            //runScriptBlocks(scriptblocks, cmdlet, false);
            // 20130319
            try {

                cmdlet.WriteVerbose(cmdlet, "running scriptblocks");

                runScriptBlocks(scriptblocks, cmdlet, false, parameters);

                cmdlet.WriteVerbose(cmdlet, "Scriptblocks finished successfully");
            }
            catch (Exception eScriptBlocks) {

                cmdlet.WriteVerbose(cmdlet, "Scriptblocks failed");

                cmdlet.WriteVerbose(cmdlet, eScriptBlocks.Message);

                cmdlet.WriteError(
                    cmdlet,
                    eScriptBlocks.Message,
                    "ScriptblocksFailed",
                    ErrorCategory.InvalidResult,
                    true);
            }
        }
开发者ID:krukovskiy,项目名称:STUPS,代码行数:86,代码来源:PSCmdletBase.cs

示例3: ConnectionMakeAlive

        internal static SQLiteConnection ConnectionMakeAlive(PSCmdletBase cmdlet, string databaseName)
        {
            SQLiteConnection connection = null;

            IDatabase database = GetDatabase(cmdlet, databaseName);
            if (null == database) {
                cmdlet.WriteError(
                    cmdlet,
                    "Could not find the database with name '" +
                    database.Name +
                    "' among registered databases.",
                    "CouldNotFindDB",
                    ErrorCategory.InvalidArgument,
                    true);
                return connection;
            }

            if (null == database.ConnectionString ||
                string.Empty == database.ConnectionString) {

                cmdlet.WriteError(
                    cmdlet,
                    "Could not find the connectionString to the database with name '" +
                    database.Name +
                    "'.",
                    "CouldNotFindConnString",
                    ErrorCategory.InvalidArgument,
                    true);
                return connection;
            }

            try {
                if (null == database.Connection) {

                    database.Connection =
                        new SQLiteConnection(database.ConnectionString);

                    database.Connection.Open();

                }

                try {
                if (database.Connection.State != ConnectionState.Open) {

                    database.Connection.ConnectionString = database.ConnectionString;

                    database.Connection.Open();
                }
                }
                catch {
                    database.Connection =
                        new SQLiteConnection(database.ConnectionString);
                    database.Connection.Open();
                }

                connection = database.Connection;
            }
            catch (Exception eCheckConnection) {

                cmdlet.WriteError(
                    cmdlet,
                    "Could not open a connection to the database with name '" +
                    database.Name +
                    "'. " +
                    eCheckConnection.Message,
                    "CouldNotCheckConnection",
                    ErrorCategory.InvalidOperation,
                    true);
            }
            //SQLiteConnection connection = ConnectionMakeAlive(

            return connection;
        }
开发者ID:uiatester,项目名称:STUPS,代码行数:73,代码来源:SQLiteHelper.cs

示例4: OpenDatabase

        public static void OpenDatabase(
            PSCmdletBase cmdlet, 
            string fileName,
            bool structureDB,
            bool repositoryDB,
            bool resultsDB)
        {
            // check input

            try {
                string absolutePath =
                    System.IO.Path.GetFullPath(fileName);
                cmdlet.WriteVerbose(cmdlet, absolutePath);

                if (System.IO.File.Exists(absolutePath)) {
                    string connectionString =
                        "Data Source='" +
                        absolutePath +
                        "';Version=3;Max Pool Size=100;UseUTF16Encoding=True;";
                    cmdlet.WriteVerbose(cmdlet, connectionString);

                    using (SQLiteConnection conn = new SQLiteConnection(connectionString)) {

                        conn.Open();

                        IDatabase database =
                            new Database(
                                ((DatabaseFileCmdletBase)cmdlet).Name,
                                fileName,
                                conn);

                        // check structure DB

                        // check repository DB

                        // check data DB

                        conn.Close();

                        if (structureDB) {
                            TestData.CurrentStructureDB = database;
                        }
                        if (repositoryDB) {
                            TestData.CurrentRepositoryDB = database;
                        }
                        if (resultsDB) {
                            TestData.CurrentResultsDB = database;
                        }

                        SQLiteData.Databases.Add(database);

                        cmdlet.WriteObject(cmdlet, database);
                    }
                }
            }
            catch (Exception eOpenDB) {
                cmdlet.WriteError(
                    cmdlet,
                    "Unable to open the database. " +
                    eOpenDB.Message,
                    "OpenDBFailed",
                    ErrorCategory.InvalidOperation,
                    true);
            }
        }
开发者ID:uiatester,项目名称:STUPS,代码行数:65,代码来源:SQLiteHelper.cs

示例5: CreateConstant

        public static void CreateConstant(
            PSCmdletBase cmdlet,
            //int testBucketId,
            ITestBucket bucket,
            string[] constantNames, 
            object[] constantValues,
            System.Type[] constantTypes)
        {
            try {
                checkConnection(TestData.CurrentStructureDB.Connection);

                DbProviderFactory factory = new SQLiteFactory();

                cmdlet.WriteVerbose(cmdlet, "begin transaction");
                using (DbTransaction dbTrans =
                       TestData.CurrentStructureDB.Connection.BeginTransaction()) {

                    cmdlet.WriteVerbose(cmdlet, "creating a data adapter");
                    using (DbDataAdapter adpConstant = factory.CreateDataAdapter()) {

                        cmdlet.WriteVerbose(cmdlet, "creating a command");
                        using (DbCommand cmd1 = TestData.CurrentStructureDB.Connection.CreateCommand()) {

                            cmd1.Transaction = dbTrans;
                            cmd1.CommandText = "SELECT * FROM TestConstants WHERE 1 = 2";
                            adpConstant.SelectCommand = cmd1;

                            using (DbCommandBuilder bldConstant = factory.CreateCommandBuilder()) {

                                bldConstant.DataAdapter = adpConstant;

                                using (DataTable tblConstant = new DataTable()) {

                                    adpConstant.Fill(tblConstant);

                                    for (int i = 0; i < constantNames.Length; i++) {
                                        DataRow rowConstant = tblConstant.NewRow();
                                        rowConstant["ConstantName"] = constantNames[i];
                                        //rowConstant["ConstantTag"] = constantTags[i];
                                        //rowConstant["Description"] = constantDescriptions[i];
                                        rowConstant["ConstantValue"] = constantValues[i];
                                        rowConstant["ConstantType"] = constantTypes[i];
                                        rowConstant["BucketId"] = bucket.BucketId;
                                        tblConstant.Rows.Add(rowConstant);

                                        ITestConstant constant =
                                            new TestConstant(
                                                constantNames[i],
                                                constantValues[i],
                                                constantTypes[i]);
                                        constant.BucketId = bucket.BucketId;
                                    }
                                    cmdlet.WriteVerbose(cmdlet, "12");
                                    cmdlet.WriteVerbose(cmdlet, tblConstant.Rows.Count.ToString() + " rows");
                                    adpConstant.Update(tblConstant);
                                    cmdlet.WriteVerbose(cmdlet, tblConstant.Rows.Count.ToString() + " rows");
                                    cmdlet.WriteVerbose(cmdlet, "14");
                                }
                            }
                        }
                    }
                    dbTrans.Commit();
                }
            }
            catch (Exception eCreateConstant) {
                cmdlet.WriteError(cmdlet,
                                  "Failed to create test constant(s). " +
                                  eCreateConstant.Message,
                                  "CreateConstantFailed",
                                  ErrorCategory.InvalidOperation,
                                  true);
            }
        }
开发者ID:uiatester,项目名称:STUPS,代码行数:73,代码来源:SQLiteHelper.cs

示例6: CloseDatabase

        public static void CloseDatabase(
            PSCmdletBase cmdlet, 
            string databaseName)
        {
            // check input

            try {

                cmdlet.WriteVerbose(cmdlet, "enumerating registered databases");

                for (int i = 0; i < SQLiteData.Databases.Count; i++) {

                    cmdlet.WriteVerbose(cmdlet, "check the database name");

                    if (databaseName == SQLiteData.Databases[i].Name) {

                        cmdlet.WriteVerbose(cmdlet, "close the database");

                        try {
                            if (null != SQLiteData.Databases[i].Connection &&
                                SQLiteData.Databases[i].Connection.State == ConnectionState.Open) {
                                SQLiteData.Databases[i].Connection.Close();
                            }
                        }
                        catch {}

                        if (SQLiteData.Databases[i].IsResultsDB) {
                            TestData.CurrentResultsDB = null;
                        }
                        if (SQLiteData.Databases[i].IsRepositoryDB) {
                            TestData.CurrentRepositoryDB = null;
                        }
                        if (SQLiteData.Databases[i].IsStructureDB) {
                            TestData.CurrentStructureDB = null;
                        }
                        //SQLiteData.Databases[i].Connection.Close();

                        SQLiteData.Databases.RemoveAt(i);

                        break;
                    }
                }

            }
            catch (Exception eOpenDB) {
                cmdlet.WriteError(
                    cmdlet,
                    "Unable to open the database. " +
                    eOpenDB.Message,
                    "OpenDBFailed",
                    ErrorCategory.InvalidOperation,
                    true);
            }
        }
开发者ID:uiatester,项目名称:STUPS,代码行数:54,代码来源:SQLiteHelper.cs

示例7: runTwoScriptBlockCollections

        protected void runTwoScriptBlockCollections(
            ScriptBlock[] scriptblocksSet1,
            ScriptBlock[] scriptblocksSet2,
            // 20130318
            //PSCmdletBase cmdlet)
            PSCmdletBase cmdlet,
            object[] parameters)
        {
            cmdlet.WriteVerbose(cmdlet, "preparing scriptblocks");

            System.Collections.Generic.List<ScriptBlock> scriptblocks =
                new System.Collections.Generic.List<ScriptBlock>();

            try {
                if (scriptblocksSet1 != null &&
                    scriptblocksSet1.Length > 0) {

                    foreach (ScriptBlock sb in scriptblocksSet1) {

                        scriptblocks.Add(sb);
                    }
                }

                if (scriptblocksSet2 != null &&
                    scriptblocksSet2.Length > 0) {

                    foreach (ScriptBlock sb in scriptblocksSet2) {

                        scriptblocks.Add(sb);
                    }
                }

                cmdlet.WriteVerbose(cmdlet, "scriptblocks were prepared");
            }
            catch (Exception eScriptblocksPreparation) {

                cmdlet.WriteVerbose(cmdlet, "Scriptblocks are not going to be run");

                cmdlet.WriteVerbose(cmdlet, eScriptblocksPreparation.Message);

                cmdlet.WriteError(
                    cmdlet,
                    eScriptblocksPreparation.Message,
                    "ScriptblocksNotPrepared",
                    ErrorCategory.InvalidOperation,
                    true);
            }

            // 20130318
            //runScriptBlocks(scriptblocks, cmdlet, false);
            // 20130319
            try {

                cmdlet.WriteVerbose(cmdlet, "running scriptblocks");

                runScriptBlocks(scriptblocks, cmdlet, false, parameters);

                cmdlet.WriteVerbose(cmdlet, "Scriptblocks finished successfully");
            }
            catch (Exception eScriptBlocks) {

                cmdlet.WriteVerbose(cmdlet, "Scriptblocks failed");

                cmdlet.WriteVerbose(cmdlet, eScriptBlocks.Message);

                cmdlet.WriteError(
                    cmdlet,
                    eScriptBlocks.Message,
                    "ScriptblocksFailed",
                    ErrorCategory.InvalidResult,
                    true);
            }
        }
开发者ID:JosefNemec,项目名称:STUPS,代码行数:73,代码来源:PSCmdletBase.cs


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