public static int Main(String[] args) { PhysicalApplicationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); /*Servers = new ServerCollection("Servers.xml"); * Sessions = new Dictionary<string, string>(); * Sessions.Add("", "127.0.0.1"); * * WebServer ws = new WebServer(SendResponse, "http://127.0.0.1:90/"); * ws.Run(); * Console.WriteLine("A simple webserver. Press a key to quit."); * Console.ReadKey(); * ws.Stop(); * return 1;*/ //Servers = new ServerCollection("Servers.xml"); PreferedServer = ConfigurationManager.AppSettings["PreferedServer"]; Servers = new ServerCollection(); Sessions = new Dictionary <string, string>(); timer = new System.Timers.Timer(60000); timer.Elapsed += Timer_Elapsed; timer.Start(); Listener = new Listener(); Listener.OnRequest += Listener_OnRequest; Listener.Start(); Console.ReadLine(); return(0); }
private void CreateOrCloseServerMpAlarm(bool isHaveOldAlarm, ServerCollection currentState) { if (currentState.Health != Health.OK) { if (!isHaveOldAlarm) { OnLog("Insert Event:Server ManagementPack Missing"); var alarm = new ApplianceAlarm { OptType = "1", AlarmName = "Server ManagementPack Missing", AlarmType = EnumAlarmType.ServerMpMissing, PossibleCause = "The Management Pack of the plug-in is uninstalled.", Suggstion = "import the Huawei.FusionDirector.Server.Library.mpb", Additional = currentState.ErrorMsg }; var applianceEvent = new ApplianceEvent(alarm); ApplianceConnector.Instance.InsertEvent(applianceEvent); } } else { if (isHaveOldAlarm) { OnLog("Close Event:Server ManagementPack Missing"); var alarm = new ApplianceAlarm { OptType = "2", AlarmType = EnumAlarmType.ServerMpMissing, }; var applianceEvent = new ApplianceEvent(alarm); ApplianceConnector.Instance.InsertEvent(applianceEvent); } } }
private void Form1_Closed(object sender, System.EventArgs e) { this.Channels.AskAccountInfo -= new AskAccountInfoEventHandle(this.Servers.OnAskAccountInfo); // 如果缺了此句,则Servers.Save会出现问题 this.Servers.ServerChanged -= new ServerChangedEventHandle(Servers_ServerChanged); // 保存到文件 // parameters: // strFileName 文件名。如果==null,表示使用装载时保存的那个文件名 Servers.Save(null); Servers = null; LinkInfos.Save(null); LinkInfos = null; // 保存窗口尺寸状态 if (AppInfo != null) { AppInfo.SaveFormStates(this, "mainformstate"); } //记住save,保存信息XML文件 AppInfo.Save(); AppInfo = null; // 避免后面再用这个对象 }
private void WhoAmI(HttpContext context) { string ip; if (context.Request.Params["IP"] != null) { ip = context.Request.Params["IP"]; } else { ip = context.Request.ServerVariables["REMOTE_HOST"]; } ServerCollection servers = new ServerCollection(Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "App_Data", "Servers.xml" )); foreach (string server in servers.Items.Keys) { if (server != ip) { continue; } context.Response.Write(servers.Items[server].Description); break; } }
/// <summary> /// 初始化服务器 /// </summary> /// <param name="col"></param> private static string InitServer(ServerCollection col) { StringBuilder sb = new StringBuilder(); bool hasRegisterLocalServer = false; if (col != null && col.Count > 0) { IList <IServerInfo> serverList = ConfigHelper.GetServerInfoList(col); foreach (IServerInfo s in serverList) { sb.Append(s); ServerManager.Register(s); //服务器如果是自己才注册通道和服务 if (IPHelper.IsLocalIP(s.Address)) { if (s.IsProvideService) { ServerManager.RegisterServerChannel(s); ServerManager.RegisterService(s); } else { ServerManager.RegisterClientChannel(s); } hasRegisterLocalServer = true; } } } //如果没有注册本地服务,则在此注册 if (!hasRegisterLocalServer) { ServerManager.RegisterClientChannel("tcp"); } return(sb.ToString()); }
/// <summary> /// Updates the server collection. /// </summary> /// <param name="model">The model.</param> /// <param name="existObj">The exist object.</param> private void UpdateServerCollection(ServerCollection model, MonitoringObject existObj) { var propertys = this.ServerCollectionClass.PropertyCollection; existObj[propertys["ResourceName"]].Value = model.ResourceName; existObj[propertys["Health"]].Value = model.Health.ToString(); existObj[this.DisplayNameField].Value = model.ResourceName; }
public void SetServerCollectionShouldSet() { var target = new ServerCollection(); ServerCollection.SetServerCollection(target); Assert.That(ServerCollection.Instance, Is.EqualTo(target)); }
public UISection() { _serverCollection = new ServerCollection(); _fontCollection = new FontCollection(); _windowsDesktopSettingsCollection = new WindowsDesktopSettingsCollection(); ConnectTimeout = 5; ReceiveTimeout = 10; SendTimeout = 5; RetryCount = 2; }
public ServerList() { InitializeComponent(); communicator = ServiceController.Communicator; serverCollection = ServiceController.Communicator.ServerCollection; registeredServersListView.ItemsSource = serverCollection; if (serverCollection.Count > 0) SetRegisteredServersListVeiewSelectedItemToDefault(); }
/// <summary> /// Creates the server collection. /// </summary> /// <param name="model">The model.</param> /// <returns>MPObject.</returns> private MPObject CreateServerCollection(ServerCollection model) { var propertys = this.ServerCollectionClass.PropertyCollection; var obj = new MPObject(MGroup.Instance, this.ServerCollectionClass); obj[propertys["ResourceName"]].Value = model.ResourceName; obj[propertys["Health"]].Value = model.Health.ToString(); obj[this.DisplayNameField].Value = model.ResourceName; return(obj); }
private static string FindServer() { string result = null; lock (Servers) { //Servers = new ServerCollection("Servers.xml"); Servers = new ServerCollection(); if (Servers.Items.ContainsKey(PreferedServer) && Servers.Items[PreferedServer].State == ServerState.Online) { result = PreferedServer; } else { foreach (string server in Servers.Items.Keys.ToArray()) { if (Servers.Items[server].State == ServerState.Offline) { continue; } if (Servers.Items[server].Role != ServerRole.Primary) { continue; } result = Servers.Items[server].IP; break; } } if (result == null) { foreach (string server in Servers.Items.Keys) { if (Servers.Items[server].State == ServerState.Offline) { continue; } if (Servers.Items[server].Role != ServerRole.Failover) { continue; } result = Servers.Items[server].IP; break; } } } return(result); }
private void GetServers(HttpContext context) { // Get all defined servers. ServerCollection servers = new ServerCollection(Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "App_Data", "Servers.xml" )); // Create a new string builder that // holds the result html string. StringBuilder result = new StringBuilder(); result.Append("["); // Run through all defined servers. foreach (string ip in servers.Items.Keys) { Server server = servers.Items[ip]; result.Append("{"); result.Append(string.Format( "\"IP\": \"{0}\", ", server.IP )); result.Append(string.Format( "\"Description\": \"{0}\", ", server.Description )); result.Append(string.Format( "\"Role\": \"{0}\", ", server.Role )); result.Append(string.Format( "\"State\": \"{0}\"", server.State )); result.Append("},"); } if (servers.Items.Count != 0) { result = result.Remove(result.Length - 1, 1); } result.Append("]"); context.Response.Write(result.ToString()); }
//- $FindServerConfiguration -// private static ServerElement FindServerConfiguration(String serverKey, ServerCollection servers) { try { return(FindServerConfiguration(serverKey, servers, String.Empty)); } catch (ConfigurationErrorsException) { throw new ConfigurationErrorsException(String.Format("Server '{0}' does not exist.", serverKey)); } }
private void RefreshServers() { Application.Current.Dispatcher.BeginInvoke(() => { ServerCollection.Clear(); foreach (var server in _vtubeMonServerConnection.Servers) { ServerCollection.Add(new ServerViewModel(server)); } }); }
// Creates a Dictionary of DGS Servers, using the server name as the key private static ServerCollection CreateServerItemList() { ServerCollection itemDic = new ServerCollection(); // Get the Server Inventory as a ListItemCollection ListItemCollection list = GetServerListItems(); // Itterate through each item in the list foreach (ListItem lItem in list) { try { ServerItem serv = new ServerItem(lItem["Title"].ToString().ToLower()); // Get each user in the "Support Staff" field var str = (FieldUserValue[])lItem.FieldValues[_supportStaffField]; // Add support staff if it exists if (str != null) { foreach (FieldUserValue user in str) { serv.AddStaff(user.LookupValue); } } // Set the simple text fields serv.BusinessUnit = lItem[_businessUnitField] != null ? (string)lItem[_businessUnitField] : ""; serv.ServerType = lItem[_serverTypeField] != null ? (string)lItem[_serverTypeField] : ""; serv.Environment = lItem[_environmentField] != null ? (string)lItem[_environmentField] : ""; // Set the FieldNote value for Server Description string description = lItem[_serverDescriptionField] != null ? lItem.FieldValuesAsText[_serverDescriptionField] : ""; // Remove non-ASCII characters from the string description = description.Replace("\n", ""); description = Regex.Replace(description, @"[^\u0000-\u007F]", string.Empty); serv.ServerDescription = description; // Add server to the Dictionary if (!itemDic.ContainsKey(serv.ServerName)) { itemDic.Add(serv); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(itemDic); }
//- $FindServerConfiguration -// private static ServerElement FindServerConfiguration(String serverKey, ServerCollection servers, String profileName) { String lowerCaseServerKey = serverKey.ToLower(System.Globalization.CultureInfo.CurrentCulture); for (Int32 i = 0; i < servers.Count; i++) { if (servers[i].Key.ToLower(System.Globalization.CultureInfo.CurrentCulture) == lowerCaseServerKey) { return(servers[i]); } } throw new ConfigurationErrorsException(String.Format("Server '{0}' referenced by profile '{1}' does not exist.", serverKey, profileName)); }
/// <summary> /// 初始化 /// </summary> /// <param name="servers">服务器信息集合</param> /// <param name="cfgcache">配置文件缓存</param> public void Initial(ServerCollection servers, CfgCache cfgcache) { this.Servers = servers; /* * this.Channels.procAskAccountInfo = * new Delegate_AskAccountInfo(this.Servers.AskAccountInfo); */ this.Channels.AskAccountInfo -= new AskAccountInfoEventHandle(this.Servers.OnAskAccountInfo); this.Channels.AskAccountInfo += new AskAccountInfoEventHandle(this.Servers.OnAskAccountInfo); this.cfgCache = cfgcache; }
public void ReadConfig(Configuration config) { ServerCollection.Clear(); foreach (var server in config.configs) { ServerCollection.Add(server); } if (config.index >= 0 && config.index < ServerCollection.Count) { SelectedServer = ServerCollection[config.index]; } ServerCollection.CollectionChanged -= ServerCollection_CollectionChanged; ServerCollection.CollectionChanged += ServerCollection_CollectionChanged; }
private void MainFormNew_FormClosed(object sender, FormClosedEventArgs e) { this.Servers.ServerChanged -= new ServerChangedEventHandle(Servers_ServerChanged); // 保存到文件 // parameters: // strFileName 文件名。如果==null,表示使用装载时保存的那个文件名 Servers.Save(null); Servers = null; string strError; int nRet = cfgCache.Save(null, out strError); if (nRet == -1) { MessageBox.Show(this, strError); } // 保存窗口尺寸状态 if (AppInfo != null) { // 只要存在Search窗口 this.AppInfo.SetInt( "main_form", "last_search_window", this.TopSearchForm != null ? 1 : 0); /* * // MDI子窗口是否最大化 * if (this.ActiveMdiChild != null) * { * this.applicationInfo.SetString( * "mdiwindows", "window_state", * Enum.GetName(typeof(FormWindowState), * this.ActiveMdiChild.WindowState)); * } */ AppInfo.SaveFormStates(this, "mainformstate"); } //记住save,保存信息XML文件 AppInfo.Save(); AppInfo = null; // 避免后面再用这个对象 }
public void Enviar() { ServerCollection servers = new ServerCollection(); Server Nlayer = new Server(); Message message = new Message(); MimeBody mimeBody = new MimeBody(BodyFormat.Html); AddressCollection destinos = new AddressCollection(); Nlayer.Host = "mail.softwareNlayer.com"; Nlayer.Password = "******"; Nlayer.Port = 25; Nlayer.Username = "******"; servers.Add(Nlayer); if (_destinos != null) { foreach (string destino in _destinos) { destinos.Add(new Address(destino)); } } if (_adjuntos != null) { foreach (string adjunto in _adjuntos) { message.Attachments.Add(adjunto, false); } } mimeBody.Text = _mensaje; message.BodyHtml = mimeBody; message.Date = DateTime.Now; message.From = new Address("*****@*****.**"); message.Organization = "Nlayer Software"; message.Priority = MessagePriority.Normal; message.To = destinos; message.Subject = _asunto; AsyncCallback beginCallback = IniciaEnvio; SmtpClient.BeginSend(message, servers, beginCallback); }
private void _bSendMessage_Click(object sender, EventArgs e) { this.AddLogEntry("Creating message."); // We create the message object ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message(); // We assign the sender email message.From.Email = this._tbFromEmail.Text; // We assign the recipient email message.To.Add(this._tbToEmail.Text); // We assign the subject message.Subject = this._tbSubject.Text; // We assign the body text message.BodyText.Text = this._tbBodyText.Text; ServerCollection smtpServers = new ServerCollection(); smtpServers.Add(this._tbMainSmtpServer.Text); smtpServers.Add(this._tbBackupSmtpServer.Text); // We send the email using the specified SMTP server this.AddLogEntry("Sending message."); try { SmtpClient.Send(message, smtpServers); this.AddLogEntry("Message sent successfully."); } catch (SmtpException ex) { this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } }
private void menuItem_serversCfg_Click(object sender, System.EventArgs e) { ServersDlg dlg = new ServersDlg(); MainForm.SetControlFont(dlg, this.DefaultFont); ServerCollection newServers = Servers.Dup(); string strWidths = this.AppInfo.GetString( "serversdlg", "list_column_width", ""); if (String.IsNullOrEmpty(strWidths) == false) { ListViewUtil.SetColumnHeaderWidth(dlg.ListView, strWidths, true); } dlg.Servers = newServers; this.AppInfo.LinkFormState(dlg, "serversdlg_state"); dlg.ShowDialog(this); this.AppInfo.UnlinkFormState(dlg); strWidths = ListViewUtil.GetColumnWidthListString(dlg.ListView); this.AppInfo.SetString( "serversdlg", "list_column_width", strWidths); if (dlg.DialogResult != DialogResult.OK) { return; } // this.Servers = newServers; this.Servers.Import(newServers); // this.treeView_res.Servers = this.Servers; treeView_res.Fill(null); }
private void MenuItemClone_Click(object sender, RoutedEventArgs e) { if (IServerProfilesMenu.SelectedIndex == -1) { return; } var temp = Properties.Settings.Default.Servers.ServerProfiles.FirstOrDefault(s => s.SafeName == ((ListBoxItem)IServerProfilesMenu.SelectedItem).Name); if (temp == null) { Instance.IMessageDialog.IsOpen = true; Instance.IMessageDialogText.Text = "Could not find the selected profile."; return; } Models.ServerProfile serverProfile = temp.CloneObjectSerializable(); serverProfile.DisplayName += " 2"; serverProfile.SafeName = "_" + Functions.SafeName(serverProfile.DisplayName); ServerCollection.AddServerProfile(serverProfile); }
public void ReadConfig(Configuration config) { ServerCollection.Clear(); foreach (var server in config.configs) { var serverObject = ServerObject.CopyFromServer(server); serverObject.Enable = server.enable; serverObject.Protocoldata = server.getProtocolData(); serverObject.Obfsdata = server.getObfsData(); ServerCollection.Add(serverObject); } if (config.index >= 0 && config.index < ServerCollection.Count) { SelectedServer = ServerCollection[config.index]; } }
void ManageServers(bool bFirstRun) { ServersDlg dlg = new ServersDlg(); MainForm.SetControlFont(dlg, this.DefaultFont); string strWidths = this.AppInfo.GetString( "serversdlg", "list_column_width", ""); if (String.IsNullOrEmpty(strWidths) == false) { ListViewUtil.SetColumnHeaderWidth(dlg.ListView, strWidths, true); } ServerCollection newServers = Servers.Dup(); if (bFirstRun == true) { dlg.Text = "首次运行: 请指定服务器参数"; } dlg.Servers = newServers; this.AppInfo.LinkFormState(dlg, "serversdlg_state"); dlg.ShowDialog(this); this.AppInfo.UnlinkFormState(dlg); strWidths = ListViewUtil.GetColumnWidthListString(dlg.ListView); this.AppInfo.SetString( "serversdlg", "list_column_width", strWidths); if (dlg.DialogResult != DialogResult.OK) { return; } // this.Servers = newServers; this.Servers.Import(newServers); }
public ServerCollection GetAllServers(LoadingMode loadingMode) { ClearLastErrors(); EnsureConnected(); ServerCollection servers = null; try { string systemEngineProvider = GetSystemEngineProvider(); var dataSources = DBEngineUtils.GetDataSources(systemEngineProvider); List <Server> items = new List <Server>(); foreach (var item in dataSources.OrderBy(info => info.Host)) { items.Add(new Server { Name = item.Host, IsClustered = item.IsClustered, Version = item.Version }); } items.Insert(0, new Server("localhost")); servers = new ServerCollection(items); if (loadingMode == LoadingMode.RecursiveAllLevels) { foreach (Server server in servers) { InternalRefresh(server, loadingMode, false); } } } catch (Exception e) { UpdateLastError(e); } return(servers); }
static void SetServerOffline(string server, bool sendMail) { lock (Servers) { //Servers = new ServerCollection("Servers.xml"); try { ServerCollection servers = new ServerCollection(); Servers = servers; } catch { } if (Servers.Items.ContainsKey(server)) { if (Servers.Items[server].State == ServerState.Offline) { return; } Servers.Items[server].State = ServerState.Offline; Servers.Save(); if (sendMail) { SendServerOfflineNotification(Servers.Items[server]); } } lock (Sessions) { foreach (string s in Sessions.Keys.ToArray()) { if (Sessions[s] == server) { Sessions[s] = null; } } } } }
private void ICreateProfileButton_Click(object sender, RoutedEventArgs e) { Analytics.TrackEvent("Main - Creating new profile"); INewProfileName.Text = INewProfileName.Text.Trim(); if (string.IsNullOrEmpty(INewProfileName.Text)) { INewServerProfileDialog.IsOpen = false; IMessageDialog.IsOpen = true; IMessageDialogText.Text = "Please use a suitable profile name."; } else { Mouse.OverrideCursor = Cursors.Wait; var profileName = INewProfileName.Text; INewServerProfileDialog.IsOpen = false; ServerCollection.AddServerProfile(profileName, "_" + Functions.SafeName(profileName)); INewProfileName.Text = string.Empty; Mouse.OverrideCursor = Cursors.Arrow; } }
public App( IEnumerable <SimualtionTimeEvent> events, IReportService reportService, ServerCollection serverCollection, VmAsigner vmAsigner, DiagnosticService diagnosticService, MigrationManager migrationManager, PrognosingService prognosingService ) { this.servers = serverCollection; this.reportService = reportService; this.events = events; this.vmAsigner = vmAsigner; this.diagnosticService = diagnosticService; this.migrationManager = migrationManager; this.prognosingService = prognosingService; prognoseStates = new ServerCollection[prognosingService.Params.PrognoseDepth]; }
public Boolean AddHost(string host) { try { if (Session["Hosts"] != null && Session["Hosts"] as ServerCollection != null) { ((ServerCollection)Session["Hosts"]).Add(host); } else { Session["Hosts"] = new ServerCollection(); ((ServerCollection)Session["Hosts"]).Add(host); } return(true); } catch (Exception ex) { return(false); } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); ServerCollection serverCollection = App.ServerCollection; serverCollection.Load(); MainListBox.ItemsSource = serverCollection; serverCollection.GetStatus(); if (serverCollection.Count == 0) { AddText.Visibility = System.Windows.Visibility.Visible; } else { AddText.Visibility = System.Windows.Visibility.Collapsed; } }