public WaitForMany(int n) { wait = joiner.NewSyncMethod(Wait); signal = joiner.NewAsyncMethod(Signal); (wait & n * signal).Do(() => { }); }
public SyncBuffer() { get = joiner.NewSyncMethod <T>(Get); put = joiner.NewSyncMethod <T>(Put); (get & put).Do((T t) => { Log.Trace("Match 'get & put': passing " + t + " from Put to Get"); return(t); }); }
/// <summary> /// New FileSync Object, Choosing synchronization method /// </summary> /// <param name="MasterRepositoryPath">Master repository path</param> /// <param name="BackUpRepositoryPath">Backup repository path</param> /// <param name="method">synchronization method</param> public FilesSync(string MasterRepositoryPath, string BackUpRepositoryPath, SyncMethod method) { MasterRepository = MasterRepositoryPath; BackUpRepository = BackUpRepositoryPath; Method = method; diMasterRep = new DirectoryInfo(MasterRepository); diBackUpRep = new DirectoryInfo(BackUpRepository); isMasterRepValid = diMasterRep.Exists; isBackUpRepValid = diBackUpRep.Exists; }
public async Task SyncAction() { string inputString = "hello"; var syncMethod = new SyncMethod(_controller.Echo); var result = await ControllerActionExecutor.ExecuteAsync( syncMethod.GetMethodInfo(), _controller, new Dictionary <string, object>() { { "input", inputString } }); Assert.Equal(inputString, result); }
public async Task SyncAction_WithException() { string inputString = "hello"; var syncMethod = new SyncMethod(_controller.EchoWithException); await Assert.ThrowsAsync <NotImplementedException>( () => ControllerActionExecutor.ExecuteAsync( syncMethod.GetMethodInfo(), _controller, new Dictionary <string, object>() { { "input", inputString } })); }
public AsyncBuffer() { #region initialization joiner = new Joiner(); get = joiner.NewSyncMethod <T>(Get); put = joiner.NewAsyncMethod <T>(Put); #endregion (get & put).Do((T t) => { Log.Trace("Match 'get & put': passing " + t + " from Put to Get"); return(t); }); }
public async Task ExecuteAsync_WithArgumentDictionary_DefaultValueAttributeUsed() { // Arrange var syncMethod = new SyncMethod(_controller.EchoWithDefaultValue); // Act var result = await ControllerActionExecutor.ExecuteAsync( syncMethod.GetMethodInfo(), _controller, new Dictionary <string, object>()); // Assert Assert.Equal("hello", result); }
public async Task ExecuteAsync_WithArgumentDictionary_AnyValue_HasPrecedenceOverDefaults() { // Arrange var syncMethod = new SyncMethod(_controller.EchoWithDefaultValueAndAttribute); // Act var result = await ExecuteAction( syncMethod, _controller, new Dictionary <string, object>() { { "input", null } }); // Assert Assert.Null(result); }
public async Task ExecuteAsync_WithArgumentArray_DefaultValueAttributeIgnored() { // Arrange var syncMethod = new SyncMethod(_controller.EchoWithDefaultValue); // Act var result = await ExecuteAction( syncMethod, _controller, new object[] { null, }); // Assert Assert.Null(result); }
public async Task ExecuteAsync_WithArgumentDictionary_DefaultParameterValueUsed() { // Arrange var syncMethod = new SyncMethod(_controller.EchoWithDefaultValueAndAttribute); // Act var result = await ExecuteAction( syncMethod, _controller, new Dictionary <string, object>()); // Assert Assert.Equal("world", result); }
public async Task SyncAction() { // Arrange var inputString = "hello"; var syncMethod = new SyncMethod(_controller.Echo); // Act var result = await ExecuteAction( syncMethod, _controller, new Dictionary <string, object>() { { "input", inputString } }); // Assert Assert.Equal(inputString, result); }
public async Task SyncAction_WithException() { // Arrange var inputString = "hello"; var syncMethod = new SyncMethod(_controller.EchoWithException); // Act & Assert await Assert.ThrowsAsync <NotImplementedException>( () => ExecuteAction( syncMethod, _controller, new Dictionary <string, object>() { { "input", inputString } })); }
public async Task SyncAction_WithException() { string inputString = "hello"; var syncMethod = new SyncMethod(_controller.EchoWithException); var expectedException = "The method or operation is not implemented."; await AssertThrowsAsync <NotImplementedException>( async() => await ReflectedActionExecutor.ExecuteAsync( syncMethod.GetMethodInfo(), _controller, new Dictionary <string, object>() { { "input", inputString } }), expectedException); }
public AsyncBuffer() { joiner = new Joiner(); // initialize and register the Method instances // with the Jointer get = joiner.NewSyncMethod <T>(Get); put = joiner.NewAsyncMethod <T>(Put); // combine the Methods to define patterns/chords the code in // the lambda will be invoked whenever there is a match. // In this case there will be a match whenever // both Get and Put have been invoked (get & put).Do((T t) => { Log.Trace("Match 'get & put': passing " + t + " from Put to Get"); return(t); }); }
public override object[] GetCustomAttributes(Type attributeType, bool inherit) { //NOTE: Do we have to take 'inherit' parameter into account here somehow? if (attributeType == typeof(OperationContractAttribute)) { var operationContract = SyncMethod.GetAttribute <OperationContractAttribute>(); operationContract.AsyncPattern = true; return(new[] { operationContract }); } if (typeof(IOperationBehavior).IsAssignableFrom(attributeType) || attributeType == typeof(ServiceKnownTypeAttribute) || attributeType == typeof(FaultContractAttribute)) { return(new object[0]); } return(SyncMethod.GetCustomAttributes(attributeType, inherit)); }
public BoundedSyncBuffer(int size) { #region initialization joiner = new Joiner(); put = joiner.NewSyncMethod <T>(Put); get = joiner.NewSyncMethod <T>(Get); emptySlot = joiner.NewAsyncMethod(EmptySlot); fullSlot = joiner.NewAsyncMethod <T>(FullSlot); #endregion (put & emptySlot).Do((T t) => { Log.Trace("Match 'put & emptySlot': passing " + t + " from Put to EmptySlot"); FullSlot(t); }); (get & fullSlot).Do((T t) => { Log.Trace("Match 'get & fullSlot': passing " + t + " from FullSlot to Get"); EmptySlot(); return(t); }); size.Times(() => EmptySlot()); }
public async Task ExecuteAsync_WithArgumentArray_DefaultValueAttributeIgnored() { // Arrange var syncMethod = new SyncMethod(_controller.EchoWithDefaultValue); // Act var result = await ControllerActionExecutor.ExecuteAsync( syncMethod.GetMethodInfo(), _controller, new object[] { null, }); // Assert Assert.Null(result); }
public override MethodImplAttributes GetMethodImplementationFlags() { return(SyncMethod.GetMethodImplementationFlags()); }
public override bool IsDefined(Type attributeType, bool inherit) { return(SyncMethod.IsDefined(attributeType, inherit)); }
public override object[] GetCustomAttributes(bool inherit) { return(SyncMethod.GetCustomAttributes(inherit)); }
public async Task SyncAction_WithException() { // Arrange var inputString = "hello"; var syncMethod = new SyncMethod(_controller.EchoWithException); // Act & Assert await Assert.ThrowsAsync<NotImplementedException>( () => ControllerActionExecutor.ExecuteAsync( syncMethod.GetMethodInfo(), _controller, new Dictionary<string, object>() { { "input", inputString } })); }
public void ProcessRequest(HttpContext context) { HttpRequest Request = context.Request; HttpResponse Response = context.Response; HttpSessionState Session = context.Session; try { // Make sure that there is a session. if (Session != null) { HttpService Service = (HttpService)Session[ServiceString]; // Set no cache-ing. Response.Cache.SetCacheability(HttpCacheability.NoCache); string httpMethod = Request.HttpMethod; SyncMethod method = (SyncMethod)Enum.Parse(typeof(SyncMethod), Request.Headers.Get(SyncHeaders.Method), true); if (string.Compare(httpMethod, "POST", true) == 0) { // Determine What work we need to do. switch (method) { case SyncMethod.StartSync: Session.Timeout = 6; if (Service != null) { Service.Dispose(); } Service = new HttpService(); Session[ServiceString] = Service; Service.StartSync(Request, Response, Session); break; case SyncMethod.GetNextInfoList: Service.GetNextInfoList(Request, Response); break; case SyncMethod.PutNodes: Service.PutNodes(Request, Response); break; case SyncMethod.GetNodes: Service.GetNodes(Request, Response); break; case SyncMethod.PutDirs: Service.PutDirs(Request, Response); break; case SyncMethod.GetDirs: Service.GetDirs(Request, Response); break; case SyncMethod.DeleteNodes: Service.DeleteNodes(Request, Response); break; case SyncMethod.OpenFilePut: Service.OpenFilePut(Request, Response); break; case SyncMethod.OpenFileGet: Service.OpenFileGet(Request, Response); break; case SyncMethod.GetHashMap: Service.GetHashMap(Request, Response, false); break; case SyncMethod.GetHashMap2: Service.GetHashMap(Request, Response, true); break; case SyncMethod.PutHashMap: Service.PutHashMap(Request, Response); break; case SyncMethod.ReadFile: Service.ReadFile(Request, Response); break; case SyncMethod.WriteFile: Service.WriteFile(Request, Response); break; case SyncMethod.CopyFile: Service.CopyFile(Request, Response); break; case SyncMethod.CloseFile: Service.CloseFile(Request, Response); break; case SyncMethod.EndSync: Service.EndSync(Request, Response); Service.Dispose(); Session.Remove(ServiceString); break; default: Response.StatusCode = (int)HttpStatusCode.BadRequest; break; } } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; } } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; } } catch (Exception ex) { Sync.Log.log.Debug("Request Failed exception\n{0}\n{1}", ex.Message, ex.StackTrace); throw ex; } Response.End(); }
public JoinMany(int n) { join = joiner.NewSyncMethod(Join); (n * join).Do(() => { }); }
public async Task ExecuteAsync_WithArgumentDictionary_DefaultParameterValueUsed() { // Arrange var syncMethod = new SyncMethod(_controller.EchoWithDefaultValueAndAttribute); // Act var result = await ControllerActionExecutor.ExecuteAsync( syncMethod.GetMethodInfo(), _controller, new Dictionary<string, object>()); // Assert Assert.Equal("world", result); }
public async Task ExecuteAsync_WithArgumentDictionary_AnyValue_HasPrecedenceOverDefaults() { // Arrange var syncMethod = new SyncMethod(_controller.EchoWithDefaultValueAndAttribute); // Act var result = await ControllerActionExecutor.ExecuteAsync( syncMethod.GetMethodInfo(), _controller, new Dictionary<string, object>() { { "input", null } }); // Assert Assert.Null(result); }
public FairReaderWriterLock() { #region initialization joiner = new Joiner(); getWriter = joiner.NewSyncMethod(GetWriter); releaseWriter = joiner.NewSyncMethod(ReleaseWriter); getReader = joiner.NewSyncMethod(GetReader); releaseReader = joiner.NewSyncMethod(ReleaseReader); idle = joiner.NewAsyncMethod(Idle); readers = joiner.NewAsyncMethod <int>(Readers); fewerReaders = joiner.NewAsyncMethod <int>(FewerReaders); zeroReader = joiner.NewSyncMethod(ZeroReader); idleWriter = joiner.NewAsyncMethod(IdleWriter); writer = joiner.NewAsyncMethod(Writer); #endregion (getWriter & idle).Do(() => { Writer(); }); (releaseWriter & writer).Do(() => { Idle(); }); (getReader & idle).Do(() => { Readers(1); }); (getReader & readers).Do((int n) => { Readers(n + 1); }); (releaseReader & readers).Do((int n) => { if (n == 1) { Idle(); } else { Readers(n - 1); } }); (getWriter & readers).Do((int n) => { FewerReaders(n); ZeroReader(); }); (zeroReader & idleWriter).Do(() => { Writer(); }); (releaseReader & fewerReaders).Do((int n) => { if (n == 1) { IdleWriter(); } else { FewerReaders(n - 1); } }); //start state Idle(); }
public async Task SyncAction() { // Arrange var inputString = "hello"; var syncMethod = new SyncMethod(_controller.Echo); // Act var result = await ControllerActionExecutor.ExecuteAsync( syncMethod.GetMethodInfo(), _controller, new Dictionary<string, object>() { { "input", inputString } }); // Assert Assert.Equal(inputString, result); }
public ReaderWriterLock() { #region initialization joiner = new Joiner(); getWriter = joiner.NewSyncMethod(GetWriter); releaseWriter = joiner.NewSyncMethod(ReleaseWriter); getReader = joiner.NewSyncMethod(GetReader); releaseReader = joiner.NewSyncMethod(ReleaseReader); idle = joiner.NewAsyncMethod(Idle); readers = joiner.NewAsyncMethod <int>(Readers); writer = joiner.NewAsyncMethod(Writer); #endregion (getWriter & idle).Do(() => { Writer(); }); (releaseWriter & readers).Do((int n) => { Readers(n); throw new Exception("Cannot release writer lock if not taken"); }); // getReader & idle => Readers(1); (releaseReader & idle).Do(() => { Idle(); throw new Exception("Cannot release reader lock if not taken"); }); //need a async Writer state, otherwise a call to releaseWriter will generate an idle... // releaseWriter & writer => Idle() (releaseWriter & writer).Do(() => { Log.Trace("Match 'releaseWriter & writer': idle"); Idle(); }); // getReader & idle => Readers(1); (getReader & idle).Do(() => { Log.Trace("Match 'getReader & idle': " + 1 + " readers"); Readers(1); }); // getReader & readers(n) => Readers(n+1); (getReader & readers).Do((int n) => { Log.Trace("Match 'getReader & readers': " + (n + 1) + " readers"); Readers(n + 1); }); // releaseReader & readers(n) => Readers(n-1); (releaseReader & readers).Do((int n) => { if (n == 1) { Log.Trace("Match 'releaseReader & readers': " + 0 + " readers"); Idle(); } else { Log.Trace("Match 'releaseReader & readers': " + (n - 1) + " readers"); Readers(n - 1); } }); //start state Idle(); }
private void Sync <T>(IEnumerator <T> filesInSource, IEnumerator <T> filesInDestination, AbstractDirectory destination, SyncMethod <T> sync) where T : AbstractFile { bool moveSourceNext = true; bool moveDestinationNext = true; while (true) { if (moveSourceNext && !filesInSource.MoveNext()) { // Source reached end first. Remove remaining files in destination. while (filesInDestination.MoveNext()) { filesInDestination.Current.Remove(); } break; } else if (moveDestinationNext && !filesInDestination.MoveNext()) { // Destination reached end first. Copy remaining files in source to destination. // Note that filesInSource already did MoveNext(). do { filesInSource.Current.CopyTo(destination); }while (filesInSource.MoveNext()); break; } else { T sourceCurrent = filesInSource.Current; T destinationCurrent = filesInDestination.Current; if (string.Compare(sourceCurrent.Name, destinationCurrent.Name) < 0) { sourceCurrent.CopyTo(destination); moveSourceNext = true; moveDestinationNext = false; } else if (string.Compare(sourceCurrent.Name, destinationCurrent.Name) > 0) { destinationCurrent.Remove(); moveSourceNext = false; moveDestinationNext = true; } else { sync(sourceCurrent, destinationCurrent); moveSourceNext = true; moveDestinationNext = true; } } } }
static void Main(string[] args) { string MasterRepository = ""; string BackUpRepository = ""; SyncMethod Method = SyncMethod.single; if (File.Exists("Configs.xml")) { XmlReader xmlReader = XmlReader.Create("Configs.xml"); while (xmlReader.Read()) { if ((xmlReader.NodeType == XmlNodeType.Element)) { switch (xmlReader.Name) { case "MasterRepository": if (xmlReader.HasAttributes) { MasterRepository = xmlReader.GetAttribute("path"); } break; case "BackupRepository": if (xmlReader.HasAttributes) { BackUpRepository = xmlReader.GetAttribute("path"); } break; case "Method": if (xmlReader.HasAttributes) { switch (xmlReader.GetAttribute("method")) { case "1": Method = SyncMethod.single; break; case "2": Method = SyncMethod.mirror; break; } } break; } } } FilesSync filesSync = new FilesSync(MasterRepository, BackUpRepository, Method); filesSync.beforeCopyEachFile = (f, i, t, s) => Console.Write(f.FullName + " " + i.ToString() + " of " + t.ToString() + " (" + calculatePercent(i, t) + ")"); filesSync.afterCopyEachFile = (f, i, t, s) => Console.WriteLine((s? " - Copied!": " - Error")); filesSync.beforeDeleteEachFile = (f, i, t, s) => Console.Write(f.FullName + " " + i.ToString() + " of " + t.ToString() + " (" + calculatePercent(i, t) + ")"); filesSync.afterDeleteEachFile = (f, i, t, s) => Console.WriteLine((s ? " - Deleted!" : " - Error")); Console.WriteLine("Working:"); SFile[] filesToCopy = filesSync.GetFilesToCopy(); SFile[] filesToDelete = filesSync.GetFilesToDelete(); string answer = "y"; if (filesToCopy.Length > 0) { Console.WriteLine(filesToCopy.Length + " Files will be copied!"); } if (filesToDelete.Length > 0) { Console.WriteLine(filesToDelete.Length + " Files will be deleted!"); } if ((filesToCopy.Length + filesToDelete.Length) > 0) { Console.WriteLine("Do you want to continue y/n"); answer = Console.ReadLine(); } else if (!filesSync.isMasterRepValid) { Console.WriteLine("Master repository is not valid!"); answer = "n"; } else if (!filesSync.isBackUpRepValid) { Console.WriteLine("Backup repository is not valid!"); answer = "n"; } else { Console.WriteLine("Backup repository is up to date!"); answer = "n"; } if (answer.ToLower() == "y") { SyncResult result = filesSync.StartSync(); Console.WriteLine((result.success ? "Success!" : "Error!")); Console.WriteLine(result.message); } Console.ReadKey(); } else { Console.WriteLine("*Configs.xml* Not found!"); Console.ReadKey(); } }