コード例 #1
0
        public void SortByRemovingOrderTests()
        {
            var expected = new[]
            {
                new MockWorkerInfo {
                    StampName = "slave-stamp", WorkerName = "1", LoadFactor = 10
                },
                new MockWorkerInfo {
                    StampName = "slave-stamp", WorkerName = "2", LoadFactor = 50
                },
                new MockWorkerInfo {
                    StampName = "slave-stamp", WorkerName = "3", LoadFactor = 90
                },
                new MockWorkerInfo {
                    StampName = "home-stamp", WorkerName = "4", LoadFactor = 10
                },
                new MockWorkerInfo {
                    StampName = "home-stamp", WorkerName = "5", LoadFactor = 50
                },
                new MockWorkerInfo {
                    StampName = "home-stamp", WorkerName = "6", LoadFactor = 90
                },
            };

            // Test
            var random = new Random();
            var actual = expected.OrderBy(_ => random.Next())
                         .SortByRemovingOrder().ToArray();

            // Assert
            for (int i = 0; i < 0; ++i)
            {
                Assert.True(ScaleUtils.Equals(expected[i], actual[i]));
            }
        }
コード例 #2
0
        public async Task SuccessfulSetTests(IWorkerInfo worker, IWorkerInfo current)
        {
            var activityId = Guid.NewGuid().ToString();
            var tableLock  = new MockWorkerTableLock();

            // Test
            using (var scaleManager = new MockScaleManager(MockBehavior.Strict))
            {
                // Setup
                scaleManager.MockWorkerTable.Setup(t => t.AcquireLock())
                .Returns(() => tableLock.AcquireLock());
                scaleManager.MockWorkerTable.Setup(t => t.GetManager())
                .Returns(Task.FromResult(current));
                scaleManager.MockWorkerTable.Setup(t => t.SetManager(worker))
                .Returns(Task.CompletedTask);
                scaleManager.MockScaleTracer.Setup(t => t.TraceInformation(activityId, worker, It.Is <string>(c => c.Contains("Acquire table lock"))));
                scaleManager.MockScaleTracer.Setup(t => t.TraceInformation(activityId, worker, It.Is <string>(c => c.Contains("Release table lock"))));
                scaleManager.MockScaleTracer.Setup(t => t.TraceInformation(activityId, worker, It.Is <string>(c => c.Contains("is set to be a manager"))));

                // test
                var newManager = await scaleManager.MockSetManager(activityId, worker, current);

                // assert
                scaleManager.VerifyAll();
                Assert.True(ScaleUtils.Equals(newManager, worker));
                Assert.False(ScaleUtils.Equals(newManager, current));
            }
        }
コード例 #3
0
        protected virtual Series CreatePointSeries(StrategyDataItemInfo info)
        {
            Series s = new Series();

            s.Name = info.Name;
            s.ArgumentDataMember = GetArgumentDataMember(info);
            s.ArgumentScaleType  = GetArgumentScaleType(info);
            s.ValueDataMembers.AddRange(info.FieldName);
            s.ValueScaleType = ScaleType.Numerical;
            PointSeriesView view = new PointSeriesView();

            view.Color = info.Color;
            view.PointMarkerOptions.Size = info.GraphWidth == 1 ? view.PointMarkerOptions.Size : (int)(info.GraphWidth * DpiProvider.Default.DpiScaleFactor);
            s.View = view;
            object           dataSource = GetDataSource(info);
            IResizeableArray array      = dataSource as IResizeableArray;

            if (array == null || array.Count < BigDataCount)
            {
                s.DataSource = dataSource;
            }
            else
            {
                view.PointMarkerOptions.BorderVisible = false;
                view.PointMarkerOptions.Kind          = MarkerKind.Square;
                view.PointMarkerOptions.Size          = ScaleUtils.ScaleValue(4);
                s.Points.AddRange(CreateSeriesPoints(info));
            }
            return(s);
        }
コード例 #4
0
        public async Task GetSetManagerTests(string storageConnectionString, string siteName)
        {
            if (string.IsNullOrEmpty(storageConnectionString))
            {
                return;
            }

            AppServiceSettings.StorageConnectionString = storageConnectionString;
            AppServiceSettings.SiteName         = siteName;
            AppServiceSettings.WorkerName       = "127.0.0.1";
            AppServiceSettings.HomeStampName    = "waws-prod-stamp-001";
            AppServiceSettings.CurrentStampName = "waws-prod-stamp-001";

            var worker = new AppServiceWorkerInfo
            {
                PartitionKey = AppServiceSettings.WorkerPartitionKey,
                RowKey       = AppServiceSettings.GetWorkerRowKey(AppServiceSettings.CurrentStampName, AppServiceSettings.WorkerName),
                StampName    = AppServiceSettings.CurrentStampName,
                WorkerName   = AppServiceSettings.WorkerName,
                LoadFactor   = 55
            };

            try
            {
                var table = AppServiceWorkerTable.Instance;

                // intialize
                await DeleteAllWorkers(table);

                var current = await table.GetManager();

                Assert.Null(current);

                // set manager
                await table.AddOrUpdate(worker);

                await table.SetManager(worker);

                current = await table.GetManager();

                Assert.True(ScaleUtils.WorkerEquals(worker, current));

                // delete
                await table.Delete(worker);

                current = await table.GetManager();

                Assert.Null(current);
            }
            finally
            {
                ResetEnvironment();
            }
        }
コード例 #5
0
 protected override void OnViewControlsCreated()
 {
     base.OnViewControlsCreated();
     if ((Frame != null) && (Frame.Template != null) && (Frame.Template is PopupForm))
     {
         PopupForm popupForm = (PopupForm)Frame.Template;
         popupForm.CustomizeClientSize += (s, e) => {
             popupForm.ButtonsContainer.Padding = ScaleUtils.ScalePadding(new Padding(12, 12, 12, 12));
             Padding formPadding = popupForm.Padding;
             popupForm.Padding = ScaleUtils.ScalePadding(new Padding(formPadding.Left, formPadding.Top, formPadding.Right, 12));
             e.CustomSize      = ScaleUtils.GetScaleSize(new System.Drawing.Size(480, 220));
             e.Handled         = true;
         };
     }
 }
コード例 #6
0
        private void bidGridView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
            if (e.Column == this.gcAmount2)
            {
                GridViewInfo   gvi = (GridViewInfo)this.bidGridView.GetViewInfo();
                GridRowInfo    gri = gvi.GetGridRowInfo(e.RowHandle);
                OrderBookEntry ee  = (OrderBookEntry)this.bidGridView.GetRow(e.RowHandle);
                if (ee == null)
                {
                    return;
                }

                int height = ScaleUtils.ScaleValue(3);
                int width  = (int)(gri.Bounds.Width * ee.VolumePercent + 0.5f);
                e.Cache.FillRectangle(Color.FromArgb(0x20, Exchange.BidColor), new Rectangle(gri.Bounds.Right - width, gri.Bounds.Y, width, gri.Bounds.Height));
            }
        }
コード例 #7
0
        public void GetAndValidateTokenTests(DateTime expiredUtc, bool expected)
        {
            var token = ScaleUtils.GetToken(expiredUtc);

            if (expected)
            {
                // test
                ScaleUtils.ValidateToken(token);
            }
            else
            {
                // test
                var exception = Assert.Throws <InvalidOperationException>(() => ScaleUtils.ValidateToken(token));

                // Assert
                Assert.Contains("expired", exception.Message);
            }
        }
コード例 #8
0
        public TickerForm()
        {
            InitializeComponent();
            this.beHr24HighLow.EditHeight = ScaleUtils.ScaleValue(50);

            GridTransparentRowHelper.Apply(this.gvAccountTrades);
            GridTransparentRowHelper.Apply(this.gvInfo);
            GridTransparentRowHelper.Apply(this.gvOpenedOrders);
            GridTransparentRowHelper.Apply(this.gvPositions);
            GridTransparentRowHelper.Apply(this.gvTrades);

            ((FormatConditionRuleValue)this.gvTrades.FormatRules[0].Rule).Appearance.ForeColor = Exchange.BidColor;
            ((FormatConditionRuleValue)this.gvTrades.FormatRules[1].Rule).Appearance.ForeColor = Exchange.AskColor;

            ((FormatConditionRuleValue)this.gvOpenedOrders.FormatRules[0].Rule).Appearance.ForeColor = Exchange.BidColor;
            ((FormatConditionRuleValue)this.gvOpenedOrders.FormatRules[1].Rule).Appearance.ForeColor = Exchange.AskColor;

            ((FormatConditionRuleValue)this.gvAccountTrades.FormatRules[0].Rule).Appearance.ForeColor = Exchange.BidColor;
            ((FormatConditionRuleValue)this.gvAccountTrades.FormatRules[1].Rule).Appearance.ForeColor = Exchange.AskColor;
        }
コード例 #9
0
        public void GetAndValidateTokenTests(DateTime expiredUtc, bool expected)
        {
            var encryptionKey = GenerateEncryptionKey();

            using (new TestScopedEnvironmentVariable("WEBSITE_AUTH_ENCRYPTION_KEY", Convert.ToBase64String(encryptionKey)))
            {
                var token = ScaleUtils.GetToken(expiredUtc);

                if (expected)
                {
                    // test
                    ScaleUtils.ValidateToken(token);
                }
                else
                {
                    // test
                    var exception = Assert.Throws <InvalidOperationException>(() => ScaleUtils.ValidateToken(token));

                    // Assert
                    Assert.Contains("expired", exception.Message);
                }
            }
        }
コード例 #10
0
        public async Task BasicTests(IWorkerInfo worker, IWorkerInfo current, IEnumerable <IWorkerInfo> workers, IWorkerInfo expected)
        {
            var activityId  = Guid.NewGuid().ToString();
            var mockManager = new Mock <MockScaleManager>(MockBehavior.Default)
            {
                CallBase = true
            };

            // Test
            using (var scaleManager = mockManager.Object)
            {
                // Setup
                IWorkerInfo newManager = null;
                if (expected != current)
                {
                    mockManager.Setup(m => m.MockSetManager(activityId, worker, current))
                    .Callback((string acticityId1, IWorkerInfo info1, IWorkerInfo current1) => newManager = info1)
                    .Returns(() => Task.FromResult(newManager));
                }

                scaleManager.MockWorkerTable.Setup(t => t.GetManager())
                .Returns(Task.FromResult <IWorkerInfo>(current));
                if (workers != null)
                {
                    scaleManager.MockWorkerTable.Setup(t => t.List())
                    .Returns(Task.FromResult(workers));
                }

                // test
                var actual = await scaleManager.MockEnsureManager(activityId, worker);

                // assert
                mockManager.VerifyAll();
                scaleManager.VerifyAll();
                Assert.True(ScaleUtils.Equals(expected, actual));
            }
        }
コード例 #11
0
        protected override object CreateControlCore()
        {
            var richEditControl = new RichEditControl();

            richEditControl.ReadOnly       = !AllowEdit;
            richEditControl.ActiveViewType = RichEditViewType.Draft;
            richEditControl.Dock           = System.Windows.Forms.DockStyle.Fill;
            richEditControl.LayoutUnit     = DocumentLayoutUnit.Pixel;
            richEditControl.Location       = new Point(2, 28);
            richEditControl.Name           = "richEditControl";
            richEditControl.Options.AutoCorrect.DetectUrls                    = false;
            richEditControl.Options.AutoCorrect.ReplaceTextAsYouType          = false;
            richEditControl.Options.DocumentCapabilities.Bookmarks            = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.CharacterStyle       = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.HeadersFooters       = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.Hyperlinks           = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.InlinePictures       = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.Numbering.Bulleted   = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.Numbering.MultiLevel = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.Numbering.Simple     = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.ParagraphFormatting  = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.Paragraphs           = DocumentCapability.Enabled;
            richEditControl.Options.DocumentCapabilities.ParagraphStyle       = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.Sections             = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.Tables               = DocumentCapability.Disabled;
            richEditControl.Options.DocumentCapabilities.TableStyle           = DocumentCapability.Disabled;
            richEditControl.Options.HorizontalRuler.Visibility                = RichEditRulerVisibility.Hidden;
            richEditControl.Text = "richEditControl1";
            richEditControl.Views.DraftView.AllowDisplayLineNumbers = true;
            richEditControl.Views.DraftView.Padding = ToPortable(ScaleUtils.ScalePadding(new System.Windows.Forms.Padding(70, 4, 0, 0)));
            richEditControl.InitializeDocument     += new EventHandler(this.RichEditControl_InitializeDocument);


            richEditControl.AddService(typeof(ISyntaxHighlightService), new SyntaxHighlightService(richEditControl));
            return(richEditControl);
        }
コード例 #12
0
        public void WorkerEqualsTests(IWorkerInfo src, IWorkerInfo dst, bool expected)
        {
            var actual = ScaleUtils.WorkerEquals(src, dst);

            Assert.Equal(expected, actual);
        }
コード例 #13
0
        public async Task CRUDTests(string storageConnectionString, string siteName)
        {
            if (string.IsNullOrEmpty(storageConnectionString))
            {
                return;
            }

            AppServiceSettings.StorageConnectionString = storageConnectionString;
            AppServiceSettings.SiteName         = siteName;
            AppServiceSettings.WorkerName       = "127.0.0.1";
            AppServiceSettings.HomeStampName    = "waws-prod-stamp-001";
            AppServiceSettings.CurrentStampName = "waws-prod-stamp-001";

            var worker = new AppServiceWorkerInfo
            {
                PartitionKey = AppServiceSettings.WorkerPartitionKey,
                RowKey       = AppServiceSettings.GetWorkerRowKey(AppServiceSettings.CurrentStampName, AppServiceSettings.WorkerName),
                StampName    = AppServiceSettings.CurrentStampName,
                WorkerName   = AppServiceSettings.WorkerName,
                LoadFactor   = 55
            };

            try
            {
                var table = AppServiceWorkerTable.Instance;

                // intialize
                await DeleteAllWorkers(table);

                var workers = await table.List();

                Assert.Equal(0, workers.Count());

                // insert
                await table.AddOrUpdate(worker);

                workers = await table.List();

                Assert.Equal(1, workers.Count());
                var entity1 = workers.FirstOrDefault();
                Assert.True(ScaleUtils.WorkerEquals(entity1, worker));
                Assert.True(DateTime.UtcNow >= entity1.LastModifiedTimeUtc);
                Assert.True(DateTime.UtcNow - entity1.LastModifiedTimeUtc <= TimeSpan.FromSeconds(30));
                Assert.Equal(worker.LoadFactor, entity1.LoadFactor);
                Assert.False(entity1.IsStale);
                Assert.Equal(worker.IsHomeStamp, entity1.IsHomeStamp);

                // update
                worker.LoadFactor = 45;
                await table.AddOrUpdate(worker);

                workers = await table.List();

                Assert.Equal(1, workers.Count());
                var entity2 = workers.FirstOrDefault();
                Assert.True(ScaleUtils.WorkerEquals(entity1, entity2));
                Assert.True(entity2.LastModifiedTimeUtc > entity1.LastModifiedTimeUtc);
                Assert.Equal(worker.LoadFactor, entity2.LoadFactor);
                Assert.NotEqual(entity1.LoadFactor, entity2.LoadFactor);

                // delete
                await table.Delete(worker);

                workers = await table.List();

                Assert.Equal(0, workers.Count());
            }
            finally
            {
                ResetEnvironment();
            }
        }
        public static Image CreateImage(byte[] data, ISkinProvider skinProvider = null)
        {
            SvgBitmap svgBitmap = new SvgBitmap(data);

            return(svgBitmap.Render(SvgPaletteHelper.GetSvgPalette(skinProvider ?? UserLookAndFeel.Default, ObjectState.Normal), ScaleUtils.GetScaleFactor().Height));
        }
コード例 #15
0
 public TickerForm()
 {
     InitializeComponent();
     this.beHr24HighLow.EditHeight = ScaleUtils.ScaleValue(50);
 }