Пример #1
0
        public async Task BatchAffinity_Unbind(string affinityKey, ComplexRequest request)
        {
            var service      = new CopyService();
            var bindConfig   = CreateApiConfig(affinityKey, Command.Bind);
            var unbindConfig = CreateApiConfig(affinityKey, Command.Unbind);

            // First we need to Bind.
            // Bind works, we test elsewhere.
            Bind();

            // Test for Unbind async
            await RunWithServer(
                service,
                unbindConfig,
                async (invoker, client) =>
            {
                await client.DoComplexAsync(request);
                AssertNoAffinity(invoker);
            },
                (invoker, client) =>
            {
                // No op, we are testing unbind async here.
                // Can't unbind twice.
            });

            // Bind again so we can test sync unbind
            Bind();

            // Test for Unbind sync
            await RunWithServer(
                service,
                unbindConfig,
                async (invoker, client) =>
            {
                // No op, we are testing unbind sync here.
                // Can't unbind twice.
                await Task.FromResult(0);
            },
                (invoker, client) =>
            {
                client.DoComplex(request);
                AssertNoAffinity(invoker);
            });

            async void Bind()
            {
                await RunWithServer(
                    service,
                    bindConfig,
                    async (invoker, client) =>
                {
                    await client.DoComplexAsync(request);
                },
                    (invoker, client) =>
                {
                    // No op, we are just binding to test unbind after.
                    // We are not testing Bind here.
                });
            }
        }
        void DoSth()
        {
            // That's a non-sense piece of code for code metrics calculations:
            int    x = 33;
            string z = "";

            for (int i = 0; i < x; ++i)
            {
                z += i;
            }

            var asdf = (string)z.Clone();

            asdf += "asdf";

            CircleDrawer drawer;
            IShapeDrawer drawer0;
            ShapeDrawingUtility <CircleDrawer> shapeDrawingUtility;
            RectangleDrawer rectangleDrawer;
            Circle          circle;
            CopyService     copyService = new CopyService();
            IReader         reader;
            IWriter         writer;

            new Solid.DependencyInversionPrinciple.CopyService().Copy();
            IAnimal animal;
        }
Пример #3
0
        public SavedTournament Save()
        {
            List <TournamentMatch>  matches = null;
            List <TournamentPlayer> players;

            lock (_resultsLock)
            {
                // obtain a thread safe copy of current state
                if (_matches != null)
                {
                    matches = new CopyService().CopyRoot(_matches);
                    players = matches.SelectMany(x => new[] { x.Player1, x.Player2 }).ToList();
                }
                else
                {
                    players = new CopyService().CopyRoot(_players);
                }
            }

            return(new SavedTournament
            {
                RoundsToGo = _roundsLeft,
                CurrentRoundMatches = matches,
                Players = players,
                SavedMatch = MatchInProgress ? Ui.Match.Save() : null,
                HumanLibrary = _humanLibrary,
                Type = _type
            });
        }
Пример #4
0
        public SearchStatistics Start(ISearchNode searchNode)
        {
            _stopwatch.Start();

            // Lock original changer tracker.
            // So we are sure that original game state stays intact.
            // This is usefull for debuging state copy issues.
            _game.ChangeTracker.Lock();

            // Both original and copied tracker will be enabled,
            // but only the copy is unlocked and can track state.
            _game.ChangeTracker.Enable();


            // Copy game state,
            var searchNodeCopy = new CopyService().CopyRoot(searchNode);

            // create the first worker
            var worker = CreateWorker(_root, searchNodeCopy.Game);

            // and start the search.
            worker.StartSearch(searchNodeCopy);

            RemoveWorker(worker);

            _game.ChangeTracker.Disable();
            _game.ChangeTracker.Unlock();

            _root.EvaluateSubtree();
            _stopwatch.Stop();

            return(GetSearchStatistics());
        }
Пример #5
0
        public void RespectSameReferences()
        {
            var majkl = new Person {
                Name = "Majkl"
            };

            var village = new Village(
                new House
            {
                Age       = 15,
                FrontDoor = new Door().Lock(),
                Owner     = majkl
            },
                new House
            {
                Age       = 75,
                FrontDoor = new Door(),
                Owner     = majkl
            });

            var copyService = new CopyService();
            var villageCopy = copyService.Copy(village);

            Assert.NotSame(villageCopy, village);
            Assert.Equal(2, villageCopy.Count());
            Assert.True(villageCopy.HousesHaveSameOwner);
        }
Пример #6
0
        private void InitializeCopyCache()
        {
            // this is done to get more accurate performance measurements
            var copyService = new CopyService();

            copyService.CopyRoot(Game);
        }
Пример #7
0
        public void HashOfCopyShouldNotChange1()
        {
            var gameCopy = new CopyService().CopyRoot(Game);

              var originalHash = Game.CalculateHash();
              var copyHash = gameCopy.CalculateHash();

              Assert.Equal(originalHash, copyHash);
        }
Пример #8
0
        public void HashOfCopyShouldNotChange1()
        {
            var gameCopy = new CopyService().CopyRoot(Game);

            var originalHash = Game.CalculateHash();
            var copyHash     = gameCopy.CalculateHash();


            Assert.Equal(originalHash, copyHash);
        }
        private void PasteMonumentAction(object sender, RoutedEventArgs e)
        {
            CopyService cs       = CopyService.Instance;
            var         monument = new Monument(findNextId(), cs.Copied.Name, cs.Copied.Description, cs.Copied.Image, cs.Copied.Type, cs.Copied.Era, cs.Copied.Icon, cs.Copied.ArcheologicallyExplored, cs.Copied.Unesco, cs.Copied.PopulatedRegion, cs.Copied.TouristicStatus, cs.Copied.Income, cs.Copied.DiscoveryDate, new List <Tag>(cs.Copied.Tags));

            ((MainWindow)Application.Current.MainWindow).MainContent.addMonumentCallback(monument);
            if (monument != null)
            {
                monumentClicked(monument.Id);
                ScrollToSelected();
            }
        }
Пример #10
0
        public void CopyDictionary()
        {
            var org = new HasDictionary();

            org.Dictionary.Add("dino", new Dinosaur {
                Age = 5
            });

            var copy = new CopyService().Copy(org);

            Assert.NotSame(org.Dictionary, copy.Dictionary);
            Assert.Equal(5, copy.Dictionary["dino"].Age);
        }
Пример #11
0
        public void HashOfCopyShouldNotChange2()
        {
            var mountain = C("Mountain");
              Hand(P1, mountain);

              var calc = new HashCalculator();

              var cardCopy = new CopyService().CopyRoot(C(mountain));

              var originalHash = calc.Calculate(C(mountain));
              var copyHash = calc.Calculate(cardCopy);

              Assert.Equal(originalHash, copyHash);
        }
Пример #12
0
        public Map()
        {
            InitializeComponent();
            Root.DataContext = this;
            CopyService cs = CopyService.Instance;

            this.Copied       = cs.Copied;
            RemovePinCallback = new onRemovePin(RemovePinFromMap);
            EWidth            = 160;
            EHeight           = 160;
            //ova dva namestiti na polovinu velicine grida koji sadrzi monument pinove. nisam uspeo da izvucem iz xamla
            PinContainerWidth  = 80;
            PinContainerHeight = 80;
        }
        private void onRightClick(object sender, MouseButtonEventArgs e)
        {
            ContextMenu cm = this.FindResource("cmMonumentTable") as ContextMenu;
            CopyService cs = CopyService.Instance;

            if (cs.Copied == null)
            {
                GetByUid(cm, "cmPaste").IsEnabled = false;
            }
            else
            {
                GetByUid(cm, "cmPaste").IsEnabled = true;
            }
            cm.IsOpen = true;
        }
Пример #14
0
        public void HashOfCopyShouldNotChange2()
        {
            var mountain = C("Mountain");

            Hand(P1, mountain);

            var calc = new HashCalculator();

            var cardCopy = new CopyService().CopyRoot(C(mountain));

            var originalHash = calc.Calculate(C(mountain));
            var copyHash     = calc.Calculate(cardCopy);


            Assert.Equal(originalHash, copyHash);
        }
Пример #15
0
        public void DoNotCopyEventsRegistrations()
        {
            var copyService = new CopyService();

            var count = 0;
            var has   = new HasEvents();

            has.Raised += delegate { count++; };
            has.Raise();

            var hasCopy = copyService.Copy(has);

            hasCopy.Raise();

            Assert.Equal(1, count);
        }
Пример #16
0
        public Byte[] RetrieveDocument(String fileName)
        {
            Byte[] result = null;
            try
            {
                String sourceUrl = DocumentServerUrl + "/" + fileName;
                DocumentCopyService.FieldInformation[] ffieldInfoArray = { new DocumentCopyService.FieldInformation() };
                UInt32 retrieveResult = CopyService.GetItem(sourceUrl, out ffieldInfoArray, out result);
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
Пример #17
0
        public async Task CopyFile()
        {
            // Arrange
            const string src = _existingFilePath;
            string       dst = Path.Combine(_existingDirPath2, Guid.NewGuid().ToString());

            Directory.CreateDirectory(dst);

            ICopyService copyService = new CopyService(_mockedLoger);

            // Act
            await copyService.CopyDirectory(src, dst);

            // Assert
            Validate(src, dst);
        }
Пример #18
0
        public void HashPerformance()
        {
            var count = 10000;

              // create a copy to remove proxies
              var game = new CopyService().CopyRoot(Game);

              var stopWatch = new Stopwatch();
              stopWatch.Start();

              for (var i = 0; i < count; i++)
              {
            game.CalculateHash();
              }

              stopWatch.Stop();
              Console.WriteLine("Hashing of {0} game objects took: {1} ms.", count, stopWatch.Elapsed.TotalMilliseconds);
        }
Пример #19
0
        public void CopyInherited()
        {
            var triceratops = new BabyTriceratops
            {
                Age            = 3,
                HasBeenVaxined = true,
                NumOfHorns     = 5
            };

            var copyService     = new CopyService();
            var triceratopsCopy = copyService.Copy(triceratops);


            Assert.NotSame(triceratops, triceratopsCopy);
            Assert.Equal(triceratops.Age, triceratopsCopy.Age);
            Assert.Equal(triceratops.NumOfHorns, triceratopsCopy.NumOfHorns);
            Assert.Equal(triceratops.HasBeenVaxined, triceratopsCopy.HasBeenVaxined);
        }
Пример #20
0
        private void PasteMonumentAction(object sender, RoutedEventArgs e)
        {
            CopyService cs       = CopyService.Instance;
            var         monument = new Monument(findNextId(), cs.Copied.Name, cs.Copied.Description, cs.Copied.Image, cs.Copied.Type, cs.Copied.Era, cs.Copied.Icon, cs.Copied.ArcheologicallyExplored, cs.Copied.Unesco, cs.Copied.PopulatedRegion, cs.Copied.TouristicStatus, cs.Copied.Income, cs.Copied.DiscoveryDate, new List <Tag>(cs.Copied.Tags));

            ((MainWindow)Application.Current.MainWindow).MainContent.addMonumentCallback(monument);
            if (monument != null)
            {
                PinClickedCallback(monument.Id);
                var tmp = new List <MonumentPosition>(Positions);
                tmp.Add(new MonumentPosition(Convert.ToInt32(CurrentMousePoint.X - PinContainerWidth),
                                             Convert.ToInt32(CurrentMousePoint.Y - PinContainerWidth), monument));
                Positions = new ObservableCollection <MonumentPosition>(tmp);
                saveMapData();
                UpdateLayout();
                this.updateSelection();
            }
        }
Пример #21
0
        private void Copy(PanelViewModel from, PanelViewModel to)
        {
            string fromfull = from.TotalPath + "\\" + from.SelectedItem;

            if (from.IsFile)
            {
                CopyService.CopyFile(fromfull, to.TotalPath);
            }
            else if (from.IsDir)
            {
                var dialog = MessageBox.Show($"Przekopiować folder wraz z całą jego zawartością?", "Uwaga", MessageBoxButton.YesNoCancel);
                if (dialog != MessageBoxResult.Cancel)
                {
                    CopyService.CopyDirectory(fromfull, to.TotalPath, dialog == MessageBoxResult.Yes);
                }
            }
            to.TotalPath = to.TotalPath; //Reload the panel
        }
Пример #22
0
        public void HashPerformance()
        {
            var count = 10000;

            // create a copy to remove proxies
            var game = new CopyService().CopyRoot(Game);

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            for (var i = 0; i < count; i++)
            {
                game.CalculateHash();
            }

            stopWatch.Stop();
            Console.WriteLine("Hashing of {0} game objects took: {1} ms.", count, stopWatch.Elapsed.TotalMilliseconds);
        }
Пример #23
0
        public Task EvaluateBranch(SearchWorker worker, ISearchNode rootNode, InnerResult rootResult, int moveIndex)
        {
            var shouldCreateNewWorker = IsItFeasibleToCreateNewWorker(rootNode, moveIndex);

              if (shouldCreateNewWorker)
              {
            rootNode = new CopyService().CopyRoot(rootNode);
            worker = CreateWorker(rootResult, rootNode.Game);

            var task = Task.Factory.StartNew(() =>
              {
            worker.EvaluateBranch(moveIndex, rootNode, rootResult);
            RemoveWorker(worker);
              }, TaskCreationOptions.PreferFairness);

            return task;
              }
              worker.EvaluateBranch(moveIndex, rootNode, rootResult);
              return null;
        }
Пример #24
0
        public Task EvaluateBranch(SearchWorker worker, ISearchNode rootNode, InnerResult rootResult, int moveIndex)
        {
            var shouldCreateNewWorker = IsItFeasibleToCreateNewWorker(rootNode, moveIndex);

            if (shouldCreateNewWorker)
            {
                rootNode = new CopyService().CopyRoot(rootNode);
                worker   = CreateWorker(rootResult, rootNode.Game);

                var task = Task.Factory.StartNew(() =>
                {
                    worker.EvaluateBranch(moveIndex, rootNode, rootResult);
                    RemoveWorker(worker);
                }, TaskCreationOptions.PreferFairness);

                return(task);
            }
            worker.EvaluateBranch(moveIndex, rootNode, rootResult);
            return(null);
        }
Пример #25
0
        public String UploadDocument(String fileName, Byte[] fileByteStream, String deleteFileUrl)
        {
            try
            {
                String resultUrl = String.Empty;
                try
                {
                    if (deleteFileUrl != String.Empty)
                    {
                        DeleteDocument(deleteFileUrl);
                    }

                    String[] destinationUrl = { DocumentServerUrl + "/" + "[" + DateTime.UtcNow.ToString("ddMMyyyy") + "]" + fileName };

                    DocumentCopyService.CopyResult[]       cResultArray    = { new DocumentCopyService.CopyResult() };
                    DocumentCopyService.FieldInformation[] ffieldInfoArray = { new DocumentCopyService.FieldInformation() };

                    UInt32 copyResult = CopyService.CopyIntoItems(destinationUrl[0], destinationUrl, ffieldInfoArray, fileByteStream, out cResultArray); //Remove if testing model uploading locally

                    if (cResultArray[0].ErrorCode == CopyErrorCode.Success)                                                                              //Remove if testing model uploading locally
                    {
                        resultUrl = cResultArray[0].DestinationUrl;
                    }
                }
                catch (Exception)
                {
                    throw;
                }

                return(resultUrl);
            }
            catch (Exception ex)
            {
                ExceptionTrace.LogException(ex);
                string networkFaultMessage = ServiceFaultResourceManager.GetString("NetworkFault").ToString();
                throw new FaultException <ServiceFault>(new ServiceFault(networkFaultMessage), new FaultReason(ex.Message));
            }
        }
Пример #26
0
        private void Start_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(CopySource.Text))
            {
                //Messagebox isn't great, but it is quick
                MessageBox.Show("Please enter a copy source");
                return;
            }

            if (string.IsNullOrEmpty(CopyDestination.Text))
            {
                //Messagebox isn't great, but it is quick
                MessageBox.Show("Please enter a copy destination");
                return;
            }

            CopyService copyService = new CopyService();

            //Event handler
            copyService.FileCopied += copyService_FileCopied;

            copyService.CopyDirectory(CopySource.Text, CopyDestination.Text);
        }
Пример #27
0
        static void Main(string[] args)
        {
            int threadsCount;

            if (!(args.Length == 3))
            {
                Console.WriteLine("Wrong parameters count");
                return;
            }
            if (!int.TryParse(args[2], out threadsCount))
            {
                Console.WriteLine("Wrong threads count");
                return;
            }
            try
            {
                CopyService copyService = new CopyService(args[0], args[1], threadsCount);
                copyService.StartCopy();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #28
0
        private void onRightClick(object sender, MouseButtonEventArgs e)
        {
            CopyService cs = CopyService.Instance;

            if (cs.Copied == null)
            {
                ContextMenu cm = this.FindResource("cmMap") as ContextMenu;
                GetByUid(cm, "cmPaste").IsEnabled = false;
            }
            else
            {
                ContextMenu cm = this.FindResource("cmMap") as ContextMenu;
                GetByUid(cm, "cmPaste").IsEnabled = true;
            }
            if (e.Source.GetType().Name.Equals("MapWorld"))
            {
                CurrentMousePoint = e.GetPosition((IInputElement)sender);

                // open context menu

                ContextMenu cm = this.FindResource("cmMap") as ContextMenu;
                cm.IsOpen = true;
            }
        }
Пример #29
0
        public SearchStatistics Start(ISearchNode searchNode)
        {
            _stopwatch.Start();

              // Lock original changer tracker.
              // So we are sure that original game state stays intact.
              // This is usefull for debuging state copy issues.
              _game.ChangeTracker.Lock();

              // Both original and copied tracker will be enabled,
              // but only the copy is unlocked and can track state.
              _game.ChangeTracker.Enable();

              // Copy game state,
              var searchNodeCopy = new CopyService().CopyRoot(searchNode);

              // create the first worker
              var worker = CreateWorker(_root, searchNodeCopy.Game);

              // and start the search.
              worker.StartSearch(searchNodeCopy);

              RemoveWorker(worker);

              _game.ChangeTracker.Disable();
              _game.ChangeTracker.Unlock();

              _root.EvaluateSubtree();
              _stopwatch.Stop();

              return GetSearchStatistics();
        }
Пример #30
0
        private void CopyAction(object sender, RoutedEventArgs e)
        {
            CopyService cs = CopyService.Instance;

            cs.Copied = this.MyMonument;
        }
        private void copyMenuAction(object s, RoutedEventArgs ea)
        {
            CopyService cs = CopyService.Instance;

            cs.Copied = ((MainWindow)Application.Current.MainWindow).MainContent.findMonumentCallback(MonumentId);
        }
Пример #32
0
 public void Copy(object original, CopyService copyService)
 {
     Seed = (int) DateTime.Now.Ticks;
       _random = new Random(Seed);
 }
Пример #33
0
 private void InitializeCopyCache()
 {
     // this is done to get more accurate performance measurements
       var copyService = new CopyService();
       copyService.CopyRoot(Game);
 }
Пример #34
0
        public SavedTournament Save()
        {
            List<TournamentMatch> matches = null;
              List<TournamentPlayer> players;

              lock (_resultsLock)
              {
            // obtain a thread safe copy of current state
            if (_matches != null)
            {
              matches = new CopyService().CopyRoot(_matches);
              players = matches.SelectMany(x => new[] {x.Player1, x.Player2}).ToList();
            }
            else
            {
              players = new CopyService().CopyRoot(_players);
            }
              }

              return new SavedTournament
            {
              RoundsToGo = _roundsLeft,
              CurrentRoundMatches = matches,
              Players = players,
              SavedMatch = MatchInProgress ? Ui.Match.Save() : null,
              HumanLibrary = _humanLibrary,
              Type = _type
            };
        }