/// <summary> /// Find user config file and load it /// if user config file is not found : /// Find reference config file in a subfolder ("\Config") and copy it to assembly dir /// This process is useful in case of InSitu update. User preferences are kept if any were saved /// But in the same time default preferences are set at the begining for very first use /// </summary> private void InitConfig() { string myselfPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string myselfName = System.IO.Path.GetFileName(myselfPath); string configFileName = System.IO.Path.ChangeExtension(myselfName, "dll.config"); string myselfDir = System.IO.Path.GetDirectoryName(myselfPath); string userConfigPath = System.IO.Path.Combine(myselfDir, configFileName); string refConfigPath = System.IO.Path.Combine(myselfDir, @"Config\" + configFileName); if (!System.IO.File.Exists(userConfigPath)) { if (!System.IO.File.Exists(refConfigPath)) { throw new System.Exception(refConfigPath + ". Config file does not exists. Plugin can't work w<ithout its config file"); } System.IO.File.Copy(refConfigPath, userConfigPath); } // System.Configuration.ConfigurationManager.AppSettings["HasDialog"] work only from an exe // so we use another way by loading the config file from executing path // http://www.sep.com/sep-blog/2010/09/05/configuration-settings-for-net-class-libraries-dlls/ this.ConfigurationFile = System.Configuration.ConfigurationManager.OpenExeConfiguration(myselfPath); keyValueConfigurationCollection = this.ConfigurationFile.AppSettings.Settings; }
public void Run(string[] args) { try { this.privArgs = new CommandLineArgs(args); } catch (System.ArgumentException ex) { ReportError(ex); CommandLineArgs.ShowUsage(); return; } var cfg = System.Configuration.ConfigurationManager.OpenExeConfiguration( System.Configuration.ConfigurationUserLevel.None); this.privConfig = ((System.Configuration.AppSettingsSection)cfg.GetSection("appSettings")).Settings; // Get a TFS instance and connect with the server //var tpc = new Client.TfsTeamProjectCollection(this.GetTFSWorkspaceFromPath(null).ServerUri); string default_server = this.privConfig[".DefaultServer"].Value; System.Diagnostics.Debug.WriteLine(default_server); var default_uri = new System.Uri(default_server); System.Diagnostics.Debug.WriteLine(default_uri); using (var tpc = new Client.TfsTeamProjectCollection(new System.Uri(this.privConfig[".DefaultServer"].Value))) { this.privStore = (WorkItemTracking.Client.WorkItemStore)tpc.GetService( typeof(WorkItemTracking.Client.WorkItemStore)); this.privServer = tpc.GetService <VersionControl.Client.VersionControlServer>(); } this.ProcessBugs(); }
static void Main(string[] args) { new CrashHandler(); string exeFile = System.Reflection.Assembly.GetEntryAssembly().Location; string exePath = Path.GetDirectoryName(exeFile); var tmp = System.Configuration.ConfigurationManager.OpenExeConfiguration(exePath + @"\HockeyUpload.exe"); System.Configuration.KeyValueConfigurationCollection col = tmp.AppSettings.Settings; HockeyApp.AppLoader.Model.Configuration c = HockeyApp.AppLoader.Model.Configuration.Instance; if (Environment.CommandLine.ToUpper().Contains("/HELP")) { HockeyApp.AppLoader.Model.CommandLineArgs.WriteHelp(Console.Out, "HOCH"); } else if (Environment.GetCommandLineArgs().Count() > 1) { try { _args = Args.Configuration.Configure <HockeyApp.AppLoader.Model.CommandLineArgs>().CreateAndBind(Environment.GetCommandLineArgs()); } catch { HockeyApp.AppLoader.Model.CommandLineArgs.WriteHelp(Console.Out, "HOCH"); return; } string errMsg = ""; if (!_args.IsValid(out errMsg)) { LogToConsole("Wrong parameter: " + errMsg); return; } try { AppInfoMatcher matcher = new AppInfoMatcher(); Task <List <AppInfo> > t = matcher.GetMatchingApps(_args); t.Wait(); List <AppInfo> list = t.Result; if (list.Count == 0) { LogToConsole("No matching application found. Please check the configuration information!"); return; } else if (list.Count > 1) { LogToConsole("More than one apps are matching. Please change parameter!"); LogToConsole("Matching apps: " + list.Select(p => p.Title).Aggregate((a, b) => a + "," + b)); return; } UploadStrategy uploader = UploadStrategy.GetStrategy(list.First()); LogToConsole(""); DateTime start = DateTime.Now; Task task = uploader.Upload(_args.Package, matcher.ActiveUserConfiguration, ProgressHandler, CancellationToken.None); task.Wait(); DateTime end = DateTime.Now; TimeSpan sp = end.Subtract(start); FileInfo fi = new FileInfo(_args.Package); long length = fi.Length; length = length / 8; LogToConsole(""); LogToConsole(string.Format("Uploaded {0}KB in {1}sec", length.ToString("###,###,###"), sp.Seconds.ToString("d"))); } catch (Exception ex) { LogToConsole("Error: " + ex.Message); } } else { HockeyApp.AppLoader.Model.CommandLineArgs.WriteHelp(Console.Out, "HOCH"); } }