static void Main(string[] args) { var options = ProcessOptions(args); if (options.ContainsKey("daemon")) { var fileMgr = new FileMgr(GetDictItem(options, "target-dir")); var listener = new FileMgrListener(GetDictItem(options, "service-url"), fileMgr); if (listener.StartListen()) { Console.WriteLine("server listen uri: " + listener.BaseUri + "."); while (Console.ReadLine() != "exit") { Task.Delay(1000).Wait(); } } else { Console.WriteLine("start listen failed."); } } else if (options.ContainsKey("sync")) { var client = new FileSync(); client.Sync(GetDictItem(options, "service-url"), GetDictItem(options, "name"), GetDictItem(options, "target-dir")); Console.WriteLine("done"); } else { Console.Write(GetHelpText()); } }
public FileMgrProxy(string serviceUrl = null) : base(FileMgrListener.CreateServiceEndpoint(serviceUrl)) { if (serviceUrl == null) { serviceUrl = FileMgrListener.GetDefaultListenUri(); } this.serviceUrl = serviceUrl; }
public static ServiceEndpoint CreateServiceEndpoint(string listenUri) { if (listenUri == null) { listenUri = FileMgrListener.GetDefaultListenUri(); } var endpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(FileMgrInterface))); endpoint.Address = new EndpointAddress(listenUri); endpoint.Binding = new WebHttpBinding(); endpoint.EndpointBehaviors.Add(new WebHttpBehavior { HelpEnabled = true }); return(endpoint); }
public void Sync(string serviceUrl, string name, string targetDir) { try { if (serviceUrl == null) { serviceUrl = FileMgrListener.GetDefaultListenUri(); } if (name == null) { name = "latest"; } if (targetDir == null) { targetDir = AppDomain.CurrentDomain.BaseDirectory; } SyncFiles(serviceUrl, name, targetDir); } catch (Exception ex) { Logger.Instance.Write(LogLevel.Warn, ex.Message); } }