public ConnectionQuality GetConnectionQuality() { try { ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", this.IP )); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); bool result = false; try { service.Request(new string[] { "Method=Ping" }); result = true; } catch { } stopwatch.Stop(); return(new ConnectionQuality(result, stopwatch.ElapsedMilliseconds)); } catch { return(new ConnectionQuality()); } }
private bool GetServerSynchState(string ip) { if (this.ServersSynchStates.ContainsKey(ip)) { return(this.ServersSynchStates[ip]); } bool result = false; try { ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); // Get server state of target. string serverState = service.Request(service.Address + "?Method=GetServerState" + (string.IsNullOrEmpty(ip) ? "" : ("&IP=" + ip)), new byte[0]); if (serverState == "Online") { result = true; } } catch { } this.ServersSynchStates.Add(ip, result); return(this.ServersSynchStates[ip]); }
protected Endpoint(ServiceLink link, TSchema schema) { Schema = schema; Link = link; Log = link.LogFactory.CreateLog(GetType()).With("service", schema.Service.Name) .With("endpoint", schema.Name); }
private void DeleteFile(string relativePath, string server) { try { ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server )); string result = service.Request( service.Address + "?Method=DeleteFile&Path=" + relativePath, new byte[0] ); if (this.FileStates.ContainsKey(relativePath)) { this.FileStates.Remove(relativePath); } if (this.Files.ContainsKey(relativePath)) { this.Files.Remove(relativePath); } } catch (Exception ex) { } }
public ServiceLinkViewModel(ServiceLink link) { Id = link.Id; IsPractice = link.IsPractice; CreatedAt = link.CreatedAt; IsAuthenticated = link.Credentials != null; }
private void Bind() { if (!Id.Equals(Guid.Empty)) { ServiceLink bll = new ServiceLink(); var model = bll.GetModelByJoin(Id); if (model != null) { hServiceLinkId.Value = model.Id.ToString(); txtNamed_ServiceLink.Value = model.Named; string pictureUrl = ""; if (!string.IsNullOrWhiteSpace(model.FileDirectory)) { pictureUrl = PictureUrlHelper.GetMPicture(model.FileDirectory, model.RandomFolder, model.FileExtension); } imgPicture_ServiceLink.Src = string.IsNullOrWhiteSpace(pictureUrl) ? "../../Images/nopic.gif" : pictureUrl; hPictureId_ServiceLink.Value = model.PictureId.ToString(); txtUrl_ServiceLink.Value = model.Url; txtEnableStartTime_ServiceLink.Value = model.EnableStartTime == DateTime.MinValue ? "" : model.EnableStartTime.ToString("yyyy-MM-dd HH:mm:ss"); txtEnableEndTime_ServiceLink.Value = model.EnableStartTime == DateTime.MinValue ? "" : model.EnableStartTime.ToString("yyyy-MM-dd HH:mm:ss"); var li = rbtnList_ServiceLink.Items.FindByValue(model.IsDisable.ToString().ToLower()); if (li != null) { li.Selected = true; } myDataAppend.Append("<div code=\"myDataForModel\">[{\"Id\":\"" + model.Id + "\",\"ServiceItemId\":\"" + model.ServiceItemId + "\",\"ServiceItemName\":\"" + model.ServiceItemName + "\",\"Sort\":\"" + model.Sort + "\"}]</div>"); } } }
protected Endpoint(ServiceLink link, TSchema schema, IReadOnlyDictionary <string, object> store) : base(store) { Schema = schema; Link = link; Log = link.LogFactory.CreateLog(GetType()).With("service", schema.Service.Name) .With("endpoint", schema.Name); }
public string DelServiceLink(string itemAppend) { string errorMsg = string.Empty; try { itemAppend = itemAppend.Trim(); if (string.IsNullOrEmpty(itemAppend)) { return(MessageContent.Submit_InvalidRow); } string[] items = itemAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); ServiceLink bll = new ServiceLink(); bll.DeleteBatch(items.ToList <object>()); } catch (Exception ex) { errorMsg = ex.Message; } if (!string.IsNullOrEmpty(errorMsg)) { return(MessageContent.AlertTitle_Ex_Error + ":" + errorMsg); } return("1"); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="serviceLinkId">The service link ID to accept.</param> public void Run(AdWordsUser user, long serviceLinkId) { using (CustomerService customerService = (CustomerService)user.GetService( AdWordsService.v201806.CustomerService)) { // Create the operation to set the status to ACTIVE. ServiceLinkOperation op = new ServiceLinkOperation(); op.@operator = Operator.SET; ServiceLink serviceLink = new ServiceLink(); serviceLink.serviceLinkId = serviceLinkId; serviceLink.serviceType = ServiceType.MERCHANT_CENTER; serviceLink.linkStatus = ServiceLinkLinkStatus.ACTIVE; op.operand = serviceLink; try { // Update the service link. ServiceLink[] mutatedServiceLinks = customerService.mutateServiceLinks(new ServiceLinkOperation[] { op }); // Display the results. foreach (ServiceLink mutatedServiceLink in mutatedServiceLinks) { Console.WriteLine("Service link with service link ID {0}, type '{1}' updated to " + "status: {2}.", mutatedServiceLink.serviceLinkId, mutatedServiceLink.serviceType, mutatedServiceLink.linkStatus); } } catch (Exception e) { throw new System.ApplicationException("Failed to update service link.", e); } } }
public async Task <ServiceLink> CreateLink(string userId, IQuestradeLink questradeLink) { QuestradeCredentials questradeCredentials = await GetLinkCredentials(questradeLink); QuestradeClient client = m_clientFactory.CreateClient(questradeCredentials); AccountsResponse response = await client.FetchAccounts(); ServiceType serviceType = ServiceType.Questrade; string serviceId = response.UserId.ToString(); if (LinkExists(userId, serviceType, serviceId)) { throw new ConflictException(); } ServiceLink link = new ServiceLink(userId, ServiceType.Questrade, serviceId, questradeLink.IsPractice); using (IDbContextTransaction transaction = m_context.Database.BeginTransaction()) { m_context.ServiceLinks.Add(link); m_context.SaveChanges(); Credentials credentials = new Credentials(link, questradeCredentials); m_context.Credentials.Add(credentials); m_context.SaveChanges(); m_accountsManager.SynchronizeAccounts(link, response.Accounts); transaction.Commit(); } return(link); }
public void Save() { // Create a new string builder that // contains the result xml string. StringBuilder result = new StringBuilder(); result.Append("<Servers>"); // Run through all defined servers. foreach (Server server in this.Items.Values) { result.Append(string.Format( "<Server IP=\"{0}\" Description=\"{1}\" Role=\"{2}\" Countries=\"{3}\" State=\"{4}\"></Server>", server.IP, server.Description, server.Role.ToString(), string.Join(",", server.Countries), server.State.ToString() )); } result.Append("</Servers>"); ServiceLink service = new ServiceLink( ConfigurationManager.AppSettings["LinkSwitchServiceUrl"] ); service.Request(new string[] { "Method=SetServers" }, System.Text.Encoding.UTF8.GetBytes(result.ToString())); }
private void BindServerInfo() { try { ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); string server = service.Request(new string[] { "Method=WhoAmI" }); lblServer.Text = server; HttpContext.Current.Session["Server"] = server; } catch (Exception ex) { } try { lblInstance.Text = new DirectoryInfo(Path.GetDirectoryName( Request.PhysicalApplicationPath )).Name; } catch { } }
private void SynchFile(string server, string client, string path) { //TEST: //server = "127.0.0.1"; if (!File.Exists(path)) { return; } FileInfo fInfo = new FileInfo(path); string relativePath = path.Replace(Path.GetDirectoryName( ConfigurationManager.AppSettings["InstanceRoot"]), ""); if (this.FileStates.ContainsKey(relativePath) && long.Parse(this.FileStates[relativePath]) >= long.Parse(fInfo.LastWriteTimeUtc.ToString("yyyyMMddHHmmssfff"))) { return; } try { ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server )); string result = service.Request( service.Address + "?Method=SynchFile&Path=" + relativePath + "&LastWriteTime=" + fInfo.LastWriteTimeUtc.ToString("yyyyMMddHHmmssfff"), File.ReadAllBytes(path) ); if (!this.LatestFileSynchActions.ContainsKey(client)) { this.LatestFileSynchActions.Add(client, DateTime.UtcNow); } else { this.LatestFileSynchActions[client] = DateTime.UtcNow; } if (!this.FileStates.ContainsKey(relativePath)) { this.FileStates.Add(relativePath, fInfo.LastWriteTimeUtc.ToString("yyyyMMddHHmmssfff")); } else { this.FileStates[relativePath] = fInfo.LastWriteTimeUtc.ToString("yyyyMMddHHmmssfff"); } this.SynchLog.Files++; } catch (Exception ex) { this.SynchLog.FilesFailed++; } }
public InstanceCollection(ServerCollection servers = null) { this.Servers = servers; this.Instances = new Dictionary <string, Instance>(); if (this.Servers == null) { // Get all defined servers. this.Servers = new ServerCollection(Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "App_Data", "Servers.xml" )); } foreach (string ip in this.Servers.Items.Keys) { Server server = this.Servers.Items[ip]; if (server.State == ServerState.Offline) { continue; } ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", server.IP )); string xmlString; try { xmlString = service.Request(new string[] { "Method=GetInstances" }); } catch (Exception ex) { continue; } XmlDocument document = new XmlDocument(); document.LoadXml(xmlString); foreach (XmlNode xmlNode in document.DocumentElement.SelectNodes("Instance")) { string instanceName = xmlNode.Attributes["Name"].Value; if (!this.Instances.ContainsKey(instanceName)) { this.Instances.Add(instanceName, new Instance(this, xmlNode)); } this.Instances[instanceName].BindPortals(xmlNode, server); } } }
public IEnumerable <Account> SynchronizeAccounts(ServiceLink link, IEnumerable <QuestradeAccount> questradeAccounts) { IEnumerable <Account> accounts = questradeAccounts.Select(account => { AccountType type = AccountTypeTransformer.Transform(account.Type); return(new Account(link, account.Number, type)); }); return(SynchronizeAccounts(accounts)); }
public IEnumerable <Account> GetManagedAccounts(string userId, int linkId) { ServiceLink link = m_context.ServiceLinks.Find(linkId, userId); if (link == null) { return(null); } return(link.ManagedAccounts); }
public IActionResult GetServiceLink(int id) { string userId = m_userManager.GetUserId(HttpContext.User); ServiceLink link = m_serviceLinksManager.GetLink(userId, id); if (link == null) { return(NotFound()); } return(Ok(new ServiceLinkViewModel(link))); }
private async Task UpdateBackgroundService() { await ServiceLink.SetEnabledAsync(Settings.Default.BackgroundEnabled); await ServiceLink.SetInitialDelayAsync((uint)Settings.Default.InitialBackgroundMailCheckInterval); await ServiceLink.SetIntervalDelayAsync((uint)Settings.Default.BackgroundMailCheckInterval); await ServiceLink.SetSupressFullscreenAsync(!Settings.Default.SupressNotificationsFullscreen); Settings.Default.UpdateBackgroundSettings = 0; Settings.Default.Save(); }
public async Task <IEnumerable <Account> > SynchronizeAccounts(string userId, int linkId) { ServiceLink link = m_context.ServiceLinks.Find(linkId, userId); if (link == null) { return(null); } QuestradeClient client = m_clientFactory.CreateClient(userId, linkId); AccountsResponse response = await client.FetchAccounts(); return(SynchronizeAccounts(link, response.Accounts)); }
private void Bind() { if (!Id.Equals(Guid.Empty)) { ServiceLink bll = new ServiceLink(); var model = bll.GetModelByJoin(Id); if (model != null) { hServiceLinkId.Value = model.Id.ToString(); txtNamed_ServiceLink.Value = model.Named; imgPicture_ServiceLink.Src = string.IsNullOrWhiteSpace(model.MPicture) ? "../../Images/nopic.gif" : model.MPicture; hPictureId_ServiceLink.Value = model.PictureId.ToString(); txtUrl_ServiceLink.Value = model.Url; myDataAppend.Append("<div code=\"myDataForModel\">[{\"Id\":\"" + model.Id + "\",\"ServiceItemId\":\"" + model.ServiceItemId + "\",\"ServiceItemName\":\"" + model.ServiceItemName + "\",\"Sort\":\"" + model.Sort + "\"}]</div>"); } } }
public ServerCollection() { this.Source = null; ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); XmlDocument document = new XmlDocument(); document.LoadXml(service.Request(new string[] { "Method=GetServers" })); Parse(document); }
public string GetServiceLinkById(Guid Id) { try { if (Id.Equals(Guid.Empty)) { return(""); } ServiceLink scBll = new ServiceLink(); var model = scBll.GetModelByJoin(Id); if (model == null) { return(""); } IList <object> listArr = new List <object>(); Dictionary <string, string> dic = null; if (!string.IsNullOrWhiteSpace(model.FileDirectory) && !string.IsNullOrWhiteSpace(model.RandomFolder) && !string.IsNullOrWhiteSpace(model.FileExtension)) { EnumData.Platform platform = EnumData.Platform.Android; dic = PictureUrlHelper.GetUrlByPlatform(model.FileDirectory, model.RandomFolder, model.FileExtension, platform); } listArr.Add(dic == null ? "" : WebSiteHost + dic["OriginalPicture"]); listArr.Add(dic == null ? "" : WebSiteHost + dic["BPicture"]); listArr.Add(dic == null ? "" : WebSiteHost + dic["MPicture"]); listArr.Add(dic == null ? "" : WebSiteHost + dic["SPicture"]); StringBuilder sb = new StringBuilder(3000); sb.Append("<Rsp>"); sb.AppendFormat("<Id>{0}</Id><Name>{1}</Name><Url>{2}</Url><LastUpdatedDate>{3}</LastUpdatedDate>", model.Id, model.Named, model.Url, model.LastUpdatedDate.ToString("yyyy-MM-dd HH:mm")); sb.AppendFormat("<OriginalPicture>{0}</OriginalPicture><BPicture>{1}</BPicture><MPicture>{2}</MPicture><SPicture>{3}</SPicture>", listArr.ToArray()); sb.Append("</Rsp>"); return(sb.ToString()); } catch (Exception ex) { new CustomException(string.Format("服务-接口:string GetServiceLinkById,异常:{0}", ex.Message), ex); return(""); } }
public void Save() { // Create a new string builder that // contains the result xml string. StringBuilder result = new StringBuilder(); result.Append("<Servers>"); // Run through all defined servers. foreach (Server server in this.Items.Values) { result.Append(string.Format( "<Server IP=\"{0}\" Description=\"{1}\" Role=\"{2}\" Countries=\"{3}\" State=\"{4}\"></Server>", server.IP, server.Description, server.Role.ToString(), string.Join(",", server.Countries), server.State.ToString() )); } result.Append("</Servers>"); if (this.Source != null) { System.IO.File.WriteAllText( this.Source, result.ToString() ); } else { ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); service.Request(new string[] { "Method=SetServers&Data=" + HttpUtility.UrlEncode(result.ToString()) }); } }
public ServerCollection() { // Create a new list for the result server list. this.Items = new Dictionary <string, Server>(); // Create a new xml document that // contains the server configuration. XmlDocument document = new XmlDocument(); // Build the full path to the server // configuration file and load it's // contents to the xml document. /*document.Load(Path.Combine( * Global.SwitchRoot, * "App_Data", * "Servers.xml" * ));*/ ServiceLink service = new ServiceLink( ConfigurationManager.AppSettings["LinkSwitchServiceUrl"] ); document.LoadXml(service.Request(new string[] { "Method=GetServers" })); // Run through all xml nodes that define a server. foreach (XmlNode xmlNode in document.DocumentElement.SelectNodes("Server")) { Server server = new Server(xmlNode); if (this.Items.ContainsKey(server.IP)) { continue; } // Parse the server definition. this.Items.Add(server.IP, server); } }
private async void ServiceLink_StateChanged(object sender, EventArgs e) { if (!ServiceLink.IsConnected) { return; } if (Settings.Default.UpdateBackgroundSettings > 0) { await UpdateBackgroundService(); } else { Settings.Default.BackgroundEnabled = await ServiceLink.GetEnabledAsync(); Settings.Default.BackgroundMailCheckInterval = await ServiceLink.GetIntervalDelayAsync(); Settings.Default.InitialBackgroundMailCheckInterval = await ServiceLink.GetInitialDelayAsync(); Settings.Default.Save(); } }
public bool SynchEnabled() { if (this.State == ServerState.Offline) { return(false); } ServiceLink service = new ServiceLink(string.Format( "http://{0}:8080/Handler.ashx", this.IP )); try { return(bool.Parse(service.Request(new string[] { "Method=SynchEnabled" }))); } catch { return(false); } }
protected void Session_Start(object sender, EventArgs e) { // Initialize the session's language manager. LanguageManager = new LanguageManager("", HttpContext.Current.Request.PhysicalApplicationPath); Language = LanguageManager.DefaultLanguage; // Initialize the session's permission core. //PermissionCore = new PermissionCore.PermissionCore("LinkOnline"); // Initialize the session's client manager. ClientManager = new ClientManager(); try { HttpContext.Current.Session["Version"] = System.Reflection.Assembly. GetExecutingAssembly().GetName().Version.ToString().Replace(".", ""); } catch { } ClearSessionTemp(); HierarchyFilters = new HierarchyFilterCollection(); try { ServiceLink service = new ServiceLink(string.Format( "http://{0}/Handlers/Public.ashx", ConfigurationManager.AppSettings["LinkAdminHostname"] )); string server = service.Request(new string[] { "Method=WhoAmI" }); HttpContext.Current.Session["Server"] = server; } catch (Exception ex) { } }
private void Application_Exit(object sender, ExitEventArgs e) { ServiceLink.Dispose(); Client.Dispose(); mLog.Info("Application shutdown"); }
private CallEndpoint(ServiceLink link, IRabbitMqCallSchema schema, IReadOnlyDictionary <string, object> store) : base(link, schema, store) { }
public CallEndpoint(ServiceLink link, IRabbitMqCallSchema schema) : base(link, schema) { }