Пример #1
0
        public static void Subtask3(int[] _array, int value)
        {
            Stopwatch     RunTime        = new Stopwatch();
            List <double> ArrayForMedian = new List <double>();
            int           rezult         = -1;

            RunTime.Start();

            for (int i = 0; i < 40; i++)
            {
                RunTime.Restart();
                AnonymousMethod IsIn = delegate(int[] array, int _value)
                {
                    return(GetIndexOfElement(array, _value));
                };
                rezult = IsIn(_array, value);
                ArrayForMedian.Add(RunTime.Elapsed.TotalMilliseconds);
            }

            RunTime.Stop();
            double ftime = ArrayForMedian[0];

            ArrayForMedian.Sort();
            double median = ArrayForMedian[20];

            Console.WriteLine("The third method has worked for {0} milliseconds,\nwith median measurement {1} milliseconds.", ftime, median);
            if (rezult != -1)
            {
                Console.WriteLine("Index of value {0} is {1}.\n", value, rezult + 1);
            }
            else
            {
                Console.WriteLine("Value {0} is not exist in this array.\n", value);
            }
        }
Пример #2
0
        private void SaveAsync(Stream stream, string path)
        {
            if (this.Model == null)
            {
                return;
            }

            SavingEventArgs savingEventArgs = new SavingEventArgs(path);

            this.OnSavingInternal(savingEventArgs);
            this.RaiseSavingEvent(savingEventArgs);

            SendOrPostCallback onSaved = delegate(object eventArgs)
            {
                SavedEventArgs savedEventArgs = eventArgs as SavedEventArgs;
                Debug.Assert(savedEventArgs != null);
                this.OnSavedInternal(savedEventArgs);
            };

            SendOrPostCallback raiseEvent = delegate(object eventArgs)
            {
                SavedEventArgs savedEventArgs = eventArgs as SavedEventArgs;
                Debug.Assert(savedEventArgs != null);
                this.RaiseSavedEvent(savedEventArgs);
            };

            AnonymousMethod save = delegate
            {
                SavedEventArgs savedEventArgs = null;

                try
                {
                    this.SaveInternal(stream, path);
                    savedEventArgs = new SavedEventArgs(path, null);
                }
                catch (Exception exception)
                {
                    savedEventArgs = new SavedEventArgs(path, exception);
                }

                try
                {
                    // For the OnSaved virtual method, do a synchronous send so that we
                    // can trap any exceptions and report them to the event handlers
                    this.asyncOperation.SynchronizationContext.Send(onSaved, savedEventArgs);
                }
                catch (Exception exception)
                {
                    savedEventArgs = new SavedEventArgs(path, exception);
                }

                // For the Saved event, do an asynchronous post because we don't care about
                // exceptions that are raised by event handlers
                this.asyncOperation.Post(raiseEvent, savedEventArgs);
            };

            save.BeginInvoke(null, null);
        }
Пример #3
0
        private void RunOptionallyThrowingException(AnonymousMethod action, bool throwException)
        {
            try
            {
                action();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());

                if (throwException)
                {
                    throw;
                }
            }
        }
        public void AnonymousMethodTest()
        {
            AnonymousMethod invoker = new AnonymousMethod();

            Assert.AreEqual <string>("hello,world", invoker[0] + invoker[1] + invoker[2]);
        }
Пример #5
0
        private void RunOptionallyThrowingException(AnonymousMethod action, bool throwException)
        {
            try
            {
                action();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());

                if (throwException)
                {
                    throw;
                }
            }
        }
Пример #6
0
 private Expression ParseAnonymousMethod(TokenSet followers)
   //^ requires this.currentToken == Token.Delegate;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken);
   this.GetNextToken();
   List<Ast.ParameterDeclaration> parameters = new List<Ast.ParameterDeclaration>();
   if (this.currentToken == Token.LeftParenthesis)
     this.ParseParameters(parameters, Token.RightParenthesis, followers);
   BlockStatement body = this.ParseBody(followers); //TODO: just parse a block
   //^ assert followers[this.currentToken] || this.currentToken == Token.EndOfFile;
   slb.UpdateToSpan(body.SourceLocation);
   Expression result = new AnonymousMethod(parameters, body, slb);
   //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile;
   return result;
 }
Пример #7
0
        private void OpenAsync(Stream stream, string path)
        {
            if (this.Close())
            {
                OpeningEventArgs openingEventArgs = new OpeningEventArgs(path);
                this.OnOpeningInternal(openingEventArgs);
                this.RaiseOpeningEvent(openingEventArgs);

                SendOrPostCallback onOpened = delegate(object eventArgs)
                {
                    OpenedEventArgs openedEventArgs = eventArgs as OpenedEventArgs;
                    Debug.Assert(openedEventArgs != null);
                    this.OnOpenedInternal(openedEventArgs);
                };

                SendOrPostCallback raiseEvent = delegate(object eventArgs)
                {
                    OpenedEventArgs openedEventArgs = eventArgs as OpenedEventArgs;
                    Debug.Assert(openedEventArgs != null);
                    this.RaiseOpenedEvent(openedEventArgs);
                };

                AnonymousMethod open = delegate
                {
                    OpenedEventArgs openedEventArgs = null;

                    try
                    {
                        this.OpenInternal(stream, path);
                        openedEventArgs = new OpenedEventArgs(path, null);
                    }
                    catch (ConfigurationSchemaViolationException e)
                    {
                        openedEventArgs = new OpenedEventArgs(path, e);
                    }
                    catch (ConfigurationBusinessRuleViolationException e)
                    {
                        openedEventArgs = new OpenedEventArgs(path, e);
                    }
                    catch (Exception exception)
                    {
                        openedEventArgs = new OpenedEventArgs(path, exception);
                    }

                    try
                    {
                        // For the OnOpened virtual method, do a synchronous send so that we
                        // can trap any exceptions and report them to the event handlers
                        this.asyncOperation.SynchronizationContext.Send(onOpened, openedEventArgs);
                    }
                    catch (Exception exception)
                    {
                        openedEventArgs = new OpenedEventArgs(path, exception);
                    }

                    // For the Opened event, do an asynchronous post because we don't care about
                    // exceptions that are raised by event handlers
                    this.asyncOperation.Post(raiseEvent, openedEventArgs);
                };

                open.BeginInvoke(null, null);
            }
        }