public static void Add(DelayedDelegateParameters method, DelegateParameters param, float delay) { PreAdd(); delayedDelegatesParams.Add(method); delayedDelegatesTimeParams.Add(Time.fixedTime + delay); delegateParameters.Add(param); }
public static int CallDelegateParameters(int a, int b) { status = 9999; DelegateParameters d = DelegateParametersTarget; d(a, b); return(status); }
public void TestParallelUploads() { // Initialize parameters. string sourceOneTag = "TestSource1"; ImageSource source = new ImageSource(true, false, true, ImageSource.source); ImageSource root = new ImageSource(false, false, false, ImageSource.storeRoot); ImageSource sourceOne = new ImageSource(true, false, true, sourceOneTag); AutoResetEvent operationFinishedEvent = new AutoResetEvent(false); AutoResetEvent operationToStartEvent = new AutoResetEvent(false); DelegateParameters param = new DelegateParameters() { operationFinishedEvent = operationFinishedEvent, operationToStartEvent = operationToStartEvent, result = false }; // Start the other thread. Thread thread = new Thread(FileImageStoreTest.UploadDelegate); thread.Start(param); // Initialize parameters of this thread. FileImageStore store = new FileImageStore("file:.\\TestRoot"); string sourceOnePath = Path.Combine(sourceOneTag, ImageSource.sourceFile); // Wait for the other thread to start. operationToStartEvent.WaitOne(); Thread.Sleep(100); // Start upload bool result = true; try { store.UploadContent(ImageSource.sourceFile, sourceOnePath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true); } catch (Exception) { result = false; } // Wait for the other upload to complete. operationFinishedEvent.WaitOne(); // Ensure only one of the uploads passes. Verify.IsTrue(result != param.result, String.Format("Result from other thread is {0}, this thread is {1}", result, param.result)); Verify.IsTrue(File.Exists(sourceOnePath)); // Ensure that you can upload. store.UploadContent(ImageSource.sourceFile, sourceOnePath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true); Verify.IsTrue(File.Exists(sourceOnePath)); sourceOne.Delete(); source.Delete(); root.Delete(); }
public void TestParallelUploadsAndDownloads() { // Initialize parameters. string destinationLocation = "TestDest"; ImageSource source = new ImageSource(true, false, true, ImageSource.source); ImageSource root = new ImageSource(false, false, false, ImageSource.storeRoot); ImageSource destiantion = new ImageSource(false, false, false, destinationLocation); AutoResetEvent operationFinishedEvent = new AutoResetEvent(false); AutoResetEvent operationToStartEvent = new AutoResetEvent(false); DelegateParameters param = new DelegateParameters() { operationFinishedEvent = operationFinishedEvent, operationToStartEvent = operationToStartEvent, result = false }; // Start the delegate thread. Thread thread = new Thread(FileImageStoreTest.UploadDelegate); thread.Start(param); // Wait for the other thread to start and sleep a little so that the other thread has started. operationToStartEvent.WaitOne(); // Verify you cant download. FileImageStore store = new FileImageStore("file:.\\TestRoot"); string destinationPath = Path.Combine(destinationLocation, ImageSource.sourceFile); while (!File.Exists("TestRoot\\Test")) { Thread.Sleep(100); } Verify.Throws <FabricTransientException>( () => store.DownloadContent(ImageSource.sourceFile, destinationPath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent), "Download should have failed because of parallel upload."); // Once the upload in the other thread is complete this one should complete too. operationFinishedEvent.WaitOne(); store.DownloadContent(ImageSource.sourceFile, destinationPath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent); Verify.IsTrue(File.Exists(destinationPath)); destiantion.Delete(); source.Delete(); root.Delete(); }
public static void UploadDelegate(object delegateParameters) { DelegateParameters param = (DelegateParameters)delegateParameters; FileImageStore store = new FileImageStore("file:.\\TestRoot"); param.operationToStartEvent.Set(); Console.WriteLine("Event to upload to start"); bool success = true; try { store.UploadContent(ImageSource.sourceFile, Path.Combine(ImageSource.source, ImageSource.sourceFile), TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true); } catch (Exception) { success = false; } param.result = success; param.operationFinishedEvent.Set(); }
internal override bool DoesMatch(MetadataItemBase other) { if (base.DoesMatch(other) == false) { return(false); } var otherTyped = other as DeclaringTypeData; if (otherTyped == null) { return(false); } if (BaseType == null ^ otherTyped.BaseType == null) { return(false); } if (BaseType != null && BaseType.DisplayName != otherTyped.BaseType.DisplayName) { return(false); } if (DelegateParameters == null ^ otherTyped.DelegateParameters == null) { return(false); } if (DelegateParameters != null && DelegateParameters.DoesMatch(otherTyped.DelegateParameters) == false) { return(false); } if (DelegateReturnType == null ^ otherTyped.DelegateReturnType == null) { return(false); } if (DelegateReturnType != null && DelegateReturnType.DisplayName != otherTyped.DelegateReturnType.DisplayName) { return(false); } if (DelegateReturnTypeIsDynamic != DelegateReturnTypeIsDynamic) { return(false); } if (GenericArity != otherTyped.GenericArity) { return(false); } if (_membersByName.Count != otherTyped._membersByName.Count) { return(false); } foreach (var pair in _membersByName) { var value = pair.Value; if (otherTyped._membersByName.TryGetValue(pair.Key, out List <MemberDataBase> otherValue) == false) { return(false); } if (value.Count != otherValue.Count) { return(false); } for (int i = 0; i < value.Count; i++) { if (value[i].DoesMatch(otherValue[i]) == false) { return(false); } } } return(true); }