示例#1
0
        protected override void BeginProcessing()
        {
            if (Query.Equals(string.Empty) && InputFile.Equals(string.Empty))
            {
                throw new Exception("Invoke the command with argument Query|InputFile");
            }
            if (Query != string.Empty && InputFile != string.Empty)
            {
                throw new Exception("The Query and the InputFile options are mutually exclusive");
            }
            string       dbName   = string.Empty;
            NodeDetail   thisNode = null;
            SessionState s1       = this.SessionState;

            string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current);
            if (s1.Drive.Current is NosDBPSDriveInfo)
            {
                if (ConfigurationConnection.ConfigCluster == null)
                {
                    throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION);
                }
                new NoSDbDetail(pathChunks, (PSDriveInfo)s1.Drive.Current).TryGetNodeDetail(out thisNode);

                if (thisNode is IDatabaseContext)
                {
                    dbName           = ((IDatabaseContext)thisNode).DatabaseName;
                    _databaseContext = true;
                }
                else
                {
                    dbName = "$sysdb";
                }
                //conString = "nosdb://" + ConfigurationConnection.Current.ConfigServerIP + ":" +
                //            ConfigurationConnection.Current.Port + "/" +
                //            ConfigurationConnection.ClusterConfiguration.Name + "/" + dbName;
                bool localInstance;
                if (ConfigurationConnection.ClusterConfiguration.Name.Equals("local",
                                                                             StringComparison.InvariantCultureIgnoreCase))
                {
                    localInstance = true;
                }
                else
                {
                    localInstance = false;
                }
                conString = ProviderUtil.GetConnectionString(dbName);
                //conString = "Data Source=" + ConfigurationConnection.Current.ConfigServerIP + ";" + "Port=" +
                //            ConfigurationConnection.Current.Port + ";" + "Database=" + dbName + ";" + "Local Instance="+localInstance+";";
            }

            if (InputFile != string.Empty)
            {
                if (!File.Exists(InputFile))
                {
                    throw new Exception("Input file does't exist");
                }
                string text = File.ReadAllText(InputFile);
                text     = text.Replace("\r\n", "");
                queryArr = text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            }
        }