Пример #1
0
        public static IList <T> ExecuteProcedurewithOutParameter <T>(string procedureName, System.Collections.ObjectModel.Collection <DBParameters> parameters, string databaseConnection, out Dictionary <string, string> dic)
        {
            dic = new Dictionary <string, string>();
            List <T> returnValue;

            // Create a suitable command type and add the required parameter
            using (SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(databaseConnection))
            {
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand(procedureName, sqlConnection);
                sqlCommand.CommandType    = CommandType.StoredProcedure;
                sqlCommand.CommandTimeout = _appSetting;
                /*Add different Parameter from Model object Property*/
                AddParameters(ref sqlCommand, parameters);

                /*Execute Procedure from supplied Execution type*/
                returnValue = DataReaderToList <T>(sqlCommand.ExecuteReader());

                if (parameters.Any(a => a.Direction == ParameterDirection.Output))
                {
                    foreach (var db in parameters.Where(w => w.Direction == ParameterDirection.Output))
                    {
                        dic.Add(sqlCommand.Parameters[db.Name].ParameterName, Convert.ToString(sqlCommand.Parameters[db.Name].Value));
                    }
                }
            }
            return(returnValue);
        }
Пример #2
0
        public static object ExecuteProcedurewithOutParameter(string procedureName, ExecuteType executeType, System.Collections.ObjectModel.Collection <DBParameters> parameters, string databaseConnection, out Dictionary <string, string> dictionary)
        {
            dictionary = new Dictionary <string, string>();
            object returnValue;

            //// Create a suitable command type and add the required parameter
            using (SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(databaseConnection))
            {
                sqlConnection.Open();

                SqlCommand sqlCommand = new SqlCommand(procedureName, sqlConnection);
                sqlCommand.CommandType    = CommandType.StoredProcedure;
                sqlCommand.CommandTimeout = _appSetting;
                /*Add different Parameter from Model object Property*/
                AddParameters(ref sqlCommand, parameters);

                /*Execute Procedure from supplied Execution type*/
                if (executeType == ExecuteType.ExecuteScalar)
                {
                    returnValue = sqlCommand.ExecuteScalar();
                }
                else if (executeType == ExecuteType.ExecuteDataSet)
                {
                    DataSet dataSet = new DataSet();
                    dataSet.Locale = System.Globalization.CultureInfo.InvariantCulture;
                    SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCommand);
                    sqlAdapter.Fill(dataSet);
                    returnValue = dataSet;
                }
                else if (executeType == ExecuteType.ExecuteNonQuery)
                {
                    returnValue = sqlCommand.ExecuteNonQuery();
                }
                else if (executeType == ExecuteType.ExecuteReader)
                {
                    returnValue = sqlCommand.ExecuteReader();
                }
                else
                {
                    returnValue = "No Proper execute type provide";
                }

                if (parameters.Any(a => a.Direction == ParameterDirection.Output))
                {
                    foreach (var db in parameters.Where(w => w.Direction == ParameterDirection.Output))
                    {
                        dictionary.Add(sqlCommand.Parameters[db.Name].ParameterName, Convert.ToString(sqlCommand.Parameters[db.Name].Value));
                    }
                }
            }
            return(returnValue);
        }
Пример #3
0
        public static bool CheckForUpdates()
        {
            Properties.GUI.Settings.Default.LastCheckForUpdates = DateTime.UtcNow;
            Properties.GUI.Settings.Default.Save();

            string  teamcityURL = "http://teamcity.labkey.org";
            string  buildType   = Environment.Is64BitProcess ? "Bumbershoot_Windows_X86_64" : "ProteoWizard_Bumbershoot_Windows_X86";
            string  buildsURL   = String.Format("{0}/httpAuth/app/rest/buildTypes/id:{1}/builds?status=SUCCESS&count=1&guest=1", teamcityURL, buildType);
            string  latestArtifactURL;
            Version latestVersion;

            lock (webClient)
            {
                string xml        = webClient.DownloadString(buildsURL);
                int    startIndex = xml.IndexOf("id=");
                if (startIndex < 0)
                {
                    throw new InvalidDataException("build id not found in:\r\n" + xml);
                }
                int endIndex = xml.IndexOfAny("\"'".ToCharArray(), startIndex + 4);
                if (endIndex < 0)
                {
                    throw new InvalidDataException("not well formed xml:\r\n" + xml);
                }
                startIndex += 4; // skip the attribute name, equals, and opening quote
                string buildId = xml.Substring(startIndex, endIndex - startIndex);

                latestArtifactURL = String.Format("{0}/repository/download/{1}/{2}:id", teamcityURL, buildType, buildId);
                latestVersion     = new Version(webClient.DownloadString(latestArtifactURL + "/IDPICKER_VERSION?guest=1"));
            }

            Version currentVersion = new Version(Util.Version);

            if (currentVersion < latestVersion)
            {
                System.Collections.ObjectModel.Collection <SvnLogEventArgs> logItems = null;

                using (var client = new SvnClient())
                {
                    client.Authentication.Clear();
                    client.Authentication.DefaultCredentials = new NetworkCredential("anonsvn", "anonsvn");

                    try
                    {
                        client.GetLog(new Uri("svn://svn.code.sf.net/p/proteowizard/code/trunk/pwiz/pwiz_tools/Bumbershoot/idpicker/"),
                                      new SvnLogArgs(new SvnRevisionRange(currentVersion.Build, latestVersion.Build)),
                                      out logItems);
                    }
                    catch (Exception e)
                    {
                        HandleException(e);
                    }
                }

                IEnumerable <SvnLogEventArgs> filteredLogItems = logItems;

                string changeLog;
                if (logItems.IsNullOrEmpty())
                {
                    changeLog = "<unable to get change log>";
                }
                else
                {
                    // return if no important revisions have happened
                    filteredLogItems = logItems.Where(o => !filterRevisionLog(o.LogMessage).Trim().IsNullOrEmpty());
                    if (!filteredLogItems.IsNullOrEmpty())
                    {
                        var logEntries = filteredLogItems.Select(o => String.Format("Revision {0}:\r\n{1}",
                                                                                    o.Revision,
                                                                                    filterRevisionLog(o.LogMessage)));
                        changeLog = String.Join("\r\n\r\n", logEntries.ToArray());
                    }
                    else
                    {
                        changeLog = "Technical changes and bug fixes.";
                    }
                }

                MainWindow.Invoke(new MethodInvoker(() =>
                {
                    var form = new NewVersionForm(Application.ProductName,
                                                  currentVersion.ToString(),
                                                  latestVersion.ToString(),
                                                  changeLog)
                    {
                        Owner         = MainWindow,
                        StartPosition = FormStartPosition.CenterParent
                    };

                    if (form.ShowDialog() == DialogResult.Yes)
                    {
                        string archSuffix   = Environment.Is64BitProcess ? "x86_64" : "x86";
                        string guestAccess  = Application.ExecutablePath.Contains("build-nt-x86") ? "" : "?guest=1"; // don't log me out of TC session
                        string installerURL = String.Format("{0}/IDPicker-{1}-{2}.msi{3}", latestArtifactURL, latestVersion, archSuffix, guestAccess);
                        System.Diagnostics.Process.Start(installerURL);
                    }
                }));
                return(true);
            }
            return(false);
        }
Пример #4
0
        private static void Restore(DBUtils dbu)
        {
            ICollection <BackupInfo> biColl = new System.Collections.ObjectModel.Collection <BackupInfo>(dbu.GetLocalBackups());
            var toVersion = string.Empty;

            if (ArgsDict.Keys.Contains("ver"))
            {
                toVersion = ArgsDict["ver"];
            }
            var tsFilter = string.Empty;

            if (ArgsDict.Keys.Contains("ts"))
            {
                tsFilter = ArgsDict["ts"];
            }
            while (string.IsNullOrEmpty(toVersion))
            {
                Console.Out.WriteLine("Local versions:");
                foreach (var i in biColl.Select(p => p.Version).Distinct())
                {
                    Console.Out.WriteLine("\t{0}", i);
                }
                Console.Out.Write("Enter version to restore (or \"exit\" to exit):");
                var res = Console.ReadLine();
                if (res == "exit")
                {
                    return;
                }
                var bi = biColl.Where(c => c.Version.Equals(res)).FirstOrDefault();
                if (bi != null)
                {
                    toVersion = bi.Version;
                }
            }
            DateTime ts = DateTime.MinValue;
            Dictionary <int, DateTime> tss = new Dictionary <int, DateTime>();
            int num = 0;

            foreach (var bi in biColl.Where(c => c.Version.Equals(toVersion)).OrderByDescending(p => p.Timestamp))
            {
                if (string.IsNullOrWhiteSpace(tsFilter) || bi.Timestamp.ToString(BaseUtils.TimestampFormatString).StartsWith(tsFilter, StringComparison.InvariantCultureIgnoreCase))
                {
                    tss.Add(num++, bi.Timestamp);
                }
            }
            while (ts == DateTime.MinValue)
            {
                Console.Out.WriteLine("Local backups for version {0}:", toVersion);
                foreach (var k in tss.Keys)
                {
                    Console.Out.WriteLine("{0,3:D}\t{1}", k, tss[k]);
                }
                Console.Out.Write("Enter backup number to restore (or \"exit\" to exit):");
                var res = Console.ReadLine();
                if (res == "exit")
                {
                    return;
                }
                num = -1;
                if (int.TryParse(res, out num) && tss.Keys.Contains(num))
                {
                    ts = tss[num];
                }
            }
            if (!dbu.GetCurrentVersion().Equals("none", StringComparison.InvariantCultureIgnoreCase))
            {
                Console.Out.Write("You are going to replace current version \"{0}\" with version \"{1} ({2})\".\nContinue(Y/N)?", dbu.GetCurrentVersion(), toVersion, ts);
                var ans = Console.ReadLine();
                if (ans != "Y" && ans != "y")
                {
                    return;
                }
                Console.Out.Write("Backup current version \"{0}\" before(Y/N)?", dbu.GetCurrentVersion());
                ans = Console.ReadLine();
                if (ans == "Y" || ans == "y")
                {
                    dbu.BackupDBS();
                }
            }
            dbu.RestoreDBS(toVersion, ts);
        }