コード例 #1
0
        private void ExecuteOpenConnectionInfoCommand(object parameter)
        {
            ConnectionInfoViewModel civm = new ConnectionInfoViewModel();

            if (civm.IsOpen == false)
            {
                civm.IsOpen = true;

                ConnectionInfo connectionInfo = new ConnectionInfo();

                civm.ConnectionInfoChanged();

                connectionInfo.DataContext = civm;

                ShellFillerShell sfs = new ShellFillerShell()
                {
                    DataContext = this
                };

                sfs.MainScroll.Content = connectionInfo;
                sfs.Header.Text        = (string)parameter;

                PlaceOrFocusControlInShell(ShellPosition.LEFT, sfs, false, null);

                Database.ViewModels.Add(ViewModelType.CONNECTION_INFO, civm);

                return;
            }

            PlaceOrFocusControlInShell(ShellPosition.LEFT, null, true, "Connection Info");
        }
コード例 #2
0
 public ConnectionInfoView(ConnectionInfoViewModel connectionInfoViewModel) : this()
 {
     DataContext = connectionInfoViewModel;
     connectionInfoViewModel.CloseRequest += (sender, e) => this.Close();
     WindowStartupLocation = WindowStartupLocation.CenterScreen;
     ElementHost.EnableModelessKeyboardInterop(this);
 }
コード例 #3
0
 public ServerItemViewModel(Server server, sbyte userTier, StreamingInfoPopupViewModel streamingInfoPopupViewModel = null)
 {
     _streamingInfoPopupViewModel = streamingInfoPopupViewModel;
     _userTier = userTier;
     AssignServer(server);
     SetServerFeatures(server);
     ConnectionInfoViewModel = new ConnectionInfoViewModel(server);
 }
コード例 #4
0
        /// <summary>
        /// Redraw selected line
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void RefreshOneLine_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            ConnectionInfoViewModel viewModel = ViewModel.ConnectionInfoViewModels.FirstOrDefault(t => t.IsSelected);

            if (viewModel != null)
            {
                await viewModel.RebuildVisual(ViewModel);
            }
        }
コード例 #5
0
        public IViewAdaper <ConnectionInfoView, ViewResult> GetConnectionInfoView(IProjectManager projectManager, IProjectConfigurationManager configurationManager)
        {
            var viewModel = new ConnectionInfoViewModel(authManager, this, configurationManager, projectManager);
            var view      = new ConnectionInfoView();

            view.DataContext = viewModel;

            AttachToParentWindow(view);
            return(new ConnectionInfoViewAdapter(view));
        }
コード例 #6
0
 /// <summary>
 /// Remove lines from canvas
 /// </summary>
 /// <param name="connection">Viewmodel of relationship</param>
 private void RemoveConnectionElement(ConnectionInfoViewModel connection)
 {
     foreach (ConnectionLine connectionLine in connection.Lines)
     {
         ModelDesignerCanvas.Children.Remove(connectionLine.Line);
     }
     ModelDesignerCanvas.Children.Remove(connection.SourceConnector.ConnectionPath);
     ModelDesignerCanvas.Children.Remove(connection.SourceConnector.Symbol);
     ModelDesignerCanvas.Children.Remove(connection.DestinationConnector.ConnectionPath);
     ModelDesignerCanvas.Children.Remove(connection.DestinationConnector.Symbol);
 }
コード例 #7
0
        /// <summary>
        /// Add given relationship to diagrram
        /// </summary>
        /// <param name="relationship">Relationship</param>
        /// <param name="canvas">Canvas for relationship add</param>
        /// <returns>Task for async execution</returns>
        public async Task AddRelationship(RelationshipModel relationship, DesignerCanvas canvas)
        {
            ConnectionInfoViewModel vm = new ConnectionInfoViewModel();

            vm.DesignerCanvas       = canvas;
            vm.RelationshipModel    = relationship;
            vm.SourceViewModel      = ViewModel.TableViewModels.FirstOrDefault(t => t.Model.Equals(relationship.Source));
            vm.DestinationViewModel = ViewModel.TableViewModels.FirstOrDefault(t => t.Model.Equals(relationship.Destination));
            await vm.BuildConnection3(ViewModel);

            ViewModel.ConnectionInfoViewModels.Add(vm);
        }
コード例 #8
0
        public ConfigurationWindow(IConnectionInfo cxInfo)
        {
            if (cxInfo == null)
            {
                throw new ArgumentNullException(nameof(cxInfo));
            }

            InitializeComponent();

            var viewModel = new ConnectionInfoViewModel(cxInfo, () => passwordBox.Password, s => passwordBox.Password = s);

            DataContext = viewModel;
        }
コード例 #9
0
        public ForeignKeysDialog(DatabaseModelDesignerViewModel viewModel, ConnectionInfoViewModel selected = null)
        {
            InitializeComponent();
            DatabaseModelDesignerViewModel = viewModel;

            int index = 0;

            if (selected != null)
            {
                index = DatabaseModelDesignerViewModel.ConnectionInfoViewModels.IndexOf(selected);
            }

            SetupListBoxData(index);
            SetupFlyout();
        }
コード例 #10
0
        public void GetWorkflowStoreInfo_ClientErrorOccurs_PopulatesModelWithException()
        {
            const string    exceptionMessage = "test exception";
            ConnectionModel connectionModel  = new ConnectionModel();

            IWorkflowStore workflowStore = Substitute.For <IWorkflowStore>();

            workflowStore.When(x => x.GetIncompleteCount()).Do((ci) => { throw new Exception(exceptionMessage); });
            _workflowStoreFactory.GetWorkflowStore(connectionModel).Returns(workflowStore);

            ConnectionInfoViewModel model = _workflowInfoService.GetWorkflowStoreInfo(connectionModel);

            Assert.AreEqual(exceptionMessage, model.ConnectionError);
            Assert.IsNull(model.ActiveCount);
        }
コード例 #11
0
        /// <summary>
        /// If is grid enabled, snap to intersects
        /// </summary>
        private void SnapToGrid()
        {
            if (_canvas.IsGridEnabled)
            {
                int cellWidth = DesignerCanvas.GridCellWidth;

                var selected = _canvas.SelectedTables.ToArray();

                double topConnectionLimit    = double.MaxValue;
                double bottomConnectionLimit = double.MaxValue;
                double leftConnectionLimit   = double.MaxValue;
                double rightConnectionLimit  = double.MaxValue;

                foreach (TableContent item in _canvas.SelectedTables)
                {
                    foreach (ConnectionInfoViewModel model in _connections.Where(t => t.SourceViewModel.Equals(item.TableViewModel)))
                    {
                        ConnectionInfoViewModel.GetConnectionLimits(ref topConnectionLimit, ref bottomConnectionLimit, ref leftConnectionLimit, ref rightConnectionLimit, model.SourceConnector, model);
                    }

                    foreach (ConnectionInfoViewModel model in _connections.Where(t => t.DestinationViewModel.Equals(item.TableViewModel)))
                    {
                        ConnectionInfoViewModel.GetConnectionLimits(ref topConnectionLimit, ref bottomConnectionLimit, ref leftConnectionLimit, ref rightConnectionLimit, model.DestinationConnector, model);
                    }
                }

                foreach (TableContent item in selected)
                {
                    double top    = item.TableViewModel.Top;
                    double left   = item.TableViewModel.Left;
                    double bottom = top + item.TableViewModel.Height;
                    double right  = left + item.TableViewModel.Width;

                    double approxCellTop  = Math.Round(top / cellWidth, MidpointRounding.AwayFromZero) * cellWidth;
                    double approxCellLeft = Math.Round(left / cellWidth, MidpointRounding.AwayFromZero) * cellWidth;

                    if (WillSnapToGridBrokeConnections(topConnectionLimit, leftConnectionLimit, bottomConnectionLimit, rightConnectionLimit, top, left, bottom, right, approxCellTop, approxCellLeft))
                    {
                        continue;
                    }

                    DesignerCanvas.SetLeft(item, approxCellLeft);
                    DesignerCanvas.SetTop(item, approxCellTop);
                    item.TableViewModel.Left = approxCellLeft;
                    item.TableViewModel.Top  = approxCellTop;
                }
            }
        }
コード例 #12
0
        public dynamic Info()
        {
            var id = Request.Form["id"];
            //System.Threading.Thread.Sleep(2000);  // useful for testing
            // load the connections for the current user
            var conn = _userStore.GetConnection(id);

            if (conn == null)
            {
                var notFoundResult = new { Error = "Connection not found" };
                return(this.Response.AsJson(notFoundResult, HttpStatusCode.NotFound));
            }

            ConnectionInfoViewModel infoModel = _workflowInfoService.GetWorkflowStoreInfo(conn);

            return(this.Response.AsJson <ConnectionInfoViewModel>(infoModel));
        }
コード例 #13
0
        public IViewAdaper <ConnectionInfoView, ViewResult> GetConnectionInfoView(IProjectManager projectManager, IProjectConfigurationManager configurationManager)
        {
            var projectConfiguration = configurationManager.Load(projectManager.ProjectConfigPath);

            var viewModel = new ConnectionInfoViewModel(authManager, this, configurationManager, projectManager, projectConfiguration);
            var view      = new ConnectionInfoView();

            view.DataContext = viewModel;

            IntPtr hwnd;

            projectManager.UIShell.GetDialogOwnerHwnd(out hwnd);
            var windowInteropHelper = new WindowInteropHelper(view);

            windowInteropHelper.Owner = hwnd;

            return(new ConnectionInfoViewAdapter(view));
        }
コード例 #14
0
ファイル: ProfileViewModel.cs プロジェクト: zhenguang/win-app
        public ProfileViewModel(Profile profile)
        {
            Id           = profile.Id;
            IsPredefined = profile.IsPredefined;
            Name         = profile.Name;
            Protocol     = profile.Protocol;
            Color        = profile.ColorCode;
            SecureCore   = profile.Features.IsSecureCore();
            Type         = profile.ProfileType;

            if (profile.Server != null)
            {
                ConnectionInfoViewModel = new ConnectionInfoViewModel(profile.Server);
            }

            _syncStatus       = profile.SyncStatus;
            _originSyncStatus = profile.SyncStatus;
        }
コード例 #15
0
        public void Info_ConnectionFound_ReturnsConnectionInfo()
        {
            // setup
            var currentUser = new UserIdentity()
            {
                Id = Guid.NewGuid(), UserName = "******"
            };

            currentUser.Claims = new string[] { Claims.ConnectionDelete };
            var browser      = CreateBrowser(currentUser);
            var connectionId = Guid.NewGuid();

            ConnectionModel conn = new ConnectionModel();

            conn.Id = connectionId;
            _userStore.GetConnection(connectionId).Returns(conn);

            Random r = new Random();
            ConnectionInfoViewModel infoViewModel = new ConnectionInfoViewModel();

            infoViewModel.ActiveCount    = r.Next(1, 10);
            infoViewModel.SuspendedCount = r.Next(11, 20);
            infoViewModel.CompleteCount  = r.Next(100, 1000);
            _workflowStoreService.GetWorkflowStoreInfo(conn).Returns(infoViewModel);

            // execute
            var response = browser.Post(Actions.Connection.Info, (with) =>
            {
                with.HttpRequest();
                with.FormsAuth(currentUser.Id, new Nancy.Authentication.Forms.FormsAuthenticationConfiguration());
                with.FormValue("id", connectionId.ToString());
            });

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            _workflowStoreService.Received(1).GetWorkflowStoreInfo(conn);

            ConnectionInfoViewModel result = JsonConvert.DeserializeObject <ConnectionInfoViewModel>(response.Body.AsString());

            Assert.AreEqual(infoViewModel.ActiveCount, result.ActiveCount);
            Assert.AreEqual(infoViewModel.SuspendedCount, result.SuspendedCount);
            Assert.AreEqual(infoViewModel.CompleteCount, result.CompleteCount);
        }
コード例 #16
0
        /// <summary>
        /// Create new
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Confirm_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var isOk = await CheckIntegrity();

            if (isOk)
            {
                var relModel = new RelationshipModel
                {
                    Name        = RelationshipName,
                    Source      = SourceTableVm.Model,
                    Destination = DestinationTableVm.Model
                };
                relModel.Attributes.AddRange(GridData);
                relModel.Optionality = relModel.Attributes.All(t => t.Destination.AllowNull)
                                ? Optionality.Optional
                                : Optionality.Mandatory;
                relModel.DeleteAction = OnDeleteComboBox.SelectedValue as string;
                relModel.UpdateAction = OnUpdateComboBox.SelectedValue as string;

                var    updater = new DatabaseUpdater();
                string res     = updater.AddRelationship(relModel);

                if (res != null)
                {
                    await this.ShowMessageAsync("Add foreign key", res);
                }
                else
                {
                    ConnectionInfoViewModel model = new ConnectionInfoViewModel()
                    {
                        DestinationViewModel = DestinationTableVm,
                        SourceViewModel      = SourceTableVm,
                        DesignerCanvas       = Canvas
                    };
                    model.RelationshipModel.RefreshModel(relModel);
                    await model.BuildConnection3(DesignerViewModel);

                    DesignerViewModel.ConnectionInfoViewModels.Add(model);
                    DialogResult = true;
                    Close();
                }
            }
        }
コード例 #17
0
        public void GetWorkflowStoreInfo_NoClientErrorOccurs_PopulatesModelWithCounts()
        {
            Random r              = new Random();
            long   activeCount    = r.Next(11, 1000);
            long   suspendedCount = r.Next(1, 10);
            long   completedCount = r.Next(1001, 10000);

            ConnectionModel connectionModel = new ConnectionModel();

            IWorkflowStore workflowStore = Substitute.For <IWorkflowStore>();

            workflowStore.GetIncompleteCount().Returns(activeCount);
            workflowStore.GetSuspendedCount().Returns(suspendedCount);
            workflowStore.GetCompletedCount().Returns(completedCount);
            _workflowStoreFactory.GetWorkflowStore(connectionModel).Returns(workflowStore);

            ConnectionInfoViewModel model = _workflowInfoService.GetWorkflowStoreInfo(connectionModel);

            Assert.AreEqual(activeCount, model.ActiveCount);
            Assert.AreEqual(completedCount, model.CompleteCount);
            Assert.AreEqual(suspendedCount, model.SuspendedCount);
        }
コード例 #18
0
        public ConnectionInfoViewModel GetWorkflowStoreInfo(ConnectionModel connectionModel)
        {
            if (connectionModel == null)
            {
                throw new ArgumentNullException("Null connection model supplied");
            }

            ConnectionInfoViewModel model = new ConnectionInfoViewModel();

            try
            {
                IWorkflowStore workflowStore = _workflowStoreFactory.GetWorkflowStore(connectionModel);
                model.ActiveCount    = workflowStore.GetIncompleteCount();
                model.SuspendedCount = workflowStore.GetSuspendedCount();
                model.CompleteCount  = workflowStore.GetCompletedCount();
            }
            catch (Exception ex)
            {
                model.ConnectionError = ex.Message;
            }

            return(model);
        }
コード例 #19
0
        void DrawGraph(ConnectionInfoViewModel info, int width, int height)
        {
            var buffer     = info.GraphicBuffer;
            var bufferSize = width * height;

            if (buffer == null || buffer.Length != bufferSize)
            {
                // new buffer
                info.GraphTexture  = new Texture2D(width, height, TextureFormat.ARGB32, false);
                info.GraphicBuffer = buffer = new Color32[width * height]; // x * y;
            }

            lock (info.GraphListLock)
            {
                var graphList = info.GraphList;
                if (graphList.Capacity < width)
                {
                    graphList.Capacity += width;
                }

                var bufferStart = (width < graphList.Count)
                    ? graphList.Count - width
                    : 0;

                var maxValue    = 0;
                var maxReceived = 0;
                var maxSent     = 0;
                for (int i = bufferStart; i < graphList.Count; i++)
                {
                    var tuple = graphList[i];
                    var max   = tuple.Item1 + tuple.Item2;
                    if (maxValue < max)
                    {
                        maxValue = max;
                    }
                    if (maxSent < tuple.Item1)
                    {
                        maxSent = tuple.Item1;
                    }
                    if (maxReceived < tuple.Item2)
                    {
                        maxReceived = tuple.Item2;
                    }
                }

                // side effect:)
                info.MaxSize     = ToHumanReadableSize(maxValue);
                info.MaxReceived = ToHumanReadableSize(maxReceived);
                info.MaxSent     = ToHumanReadableSize(maxSent);

                var basis = (maxValue != 0)
                    ? (double)height / (double)maxValue
                    : 0;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        var index = y * width + x;

                        var color = Color.clear;
                        if (x < graphList.Count)
                        {
                            var size     = graphList[bufferStart + x];
                            var sent     = ConvertToHeight(size.Item1, basis);
                            var received = ConvertToHeight(size.Item2, basis);
                            var max      = sent + received;
                            if (y < max)
                            {
                                if (y < received)
                                {
                                    color = Color.green;
                                }
                                else
                                {
                                    color = Color.red;
                                }
                            }
                            else
                            {
                                color = Color.clear;
                            }
                        }

                        buffer[index] = color;
                    }
                }
            }

            if (buffer.Length != 0)
            {
                info.GraphTexture.SetPixels32(buffer);
                info.GraphTexture.Apply();
            }
        }
コード例 #20
0
        /// <summary>
        /// Load diagram from DB
        /// </summary>
        /// <param name="canvas">Canvas for diagram</param>
        /// <param name="data">XML attribute from DB</param>
        public async Task LoadDiagram(DesignerCanvas canvas, XDocument data)
        {
            var root = data.Root;

            ViewModel.LoadFromElement(data.Root);

            if (ViewModel.CanvasWidth != DatabaseModelDesignerViewModel.DefaultWidth || ViewModel.CanvasHeight != DatabaseModelDesignerViewModel.DefaultWidth)
            {
                StreamGeometry geometry = DesignerCanvas.CreateGridWithStreamGeometry(ViewModel.CanvasHeight, ViewModel.CanvasWidth,
                                                                                      DesignerCanvas.GridCellWidth);
                canvas.RefreshGuideLines(geometry);
            }

            var labels = root?.XPathSelectElements("LabelViewModels/LabelViewModel")
                         .Select(t =>
            {
                var vm = new LabelViewModel();
                vm.LoadFromElement(t);
                return(vm);
            }).ToList();

            if (labels != null && labels.Any())
            {
                foreach (LabelViewModel label in labels)
                {
                    ViewModel.LabelViewModels.Add(label);
                }
            }

            var ctx        = new DatabaseContext(SessionProvider.Instance.ConnectionType);
            var tablesInDb = await Task.Run(() => ctx.ListTables());

            var tableElements = root?.XPathSelectElements("TableViewModels/TableViewModel")
                                .Select(t =>
            {
                var vm = new TableViewModel();
                vm.LoadFromElement(t);
                return(vm);
            })
                                .Where(s => tablesInDb.Any(t => t.Id.Equals(s.Model.Id)))
                                .ToList();

            Output.WriteLine(DiagramLoaded);

            if (tableElements == null || !tableElements.Any())
            {
                return;
            }

            var relationShipsInDb = await Task.Run(() => ctx.ListAllForeignKeys());

            var allRelationshipsDetailsPom = new List <RelationshipModel>();

            foreach (TableViewModel model in tableElements)
            {
                TableModel tab = ctx.ReadTableDetails(model.Model.Id, model.Model.Title);
                model.Model.RefreshModel(tab);
                ViewModel.TableViewModels.Add(model);
            }

            foreach (TableViewModel model in tableElements)
            {
                IEnumerable <RelationshipModel> models = await Task.Run(() => ctx.ListRelationshipsForTable(model.Model.Title, tableElements.Select(s => s.Model)));

                allRelationshipsDetailsPom.AddRange(models);
            }

            var allRelationshipsDetails = allRelationshipsDetailsPom
                                          .GroupBy(t => t.Name)
                                          .Select(t => t.FirstOrDefault())
                                          .ToList();

            var relationElements = root?.XPathSelectElements("ConnectionInfoViewModels/ConnectionInfoViewModel")
                                   .Select(t =>
            {
                var vm = new ConnectionInfoViewModel {
                    DesignerCanvas = canvas
                };
                vm.LoadFromElement(t);
                return(vm);
            })
                                   .Where(t => relationShipsInDb.Any(s => s.Equals(t.RelationshipModel.Name)))
                                   .Where(t => allRelationshipsDetails.Any(s => ctx.AreRelationshipModelsTheSame(t.RelationshipModel, s)))
                                   .ToList();


            relationElements.ForEach(t =>
            {
                t.SourceViewModel      = tableElements.FirstOrDefault(s => s.Model.Id.Equals(t.RelationshipModel.Source.Id));
                t.DestinationViewModel = tableElements.FirstOrDefault(s => s.Model.Id.Equals(t.RelationshipModel.Destination.Id));
                t.RelationshipModel.RefreshModel(allRelationshipsDetails.FirstOrDefault(s => ctx.AreRelationshipModelsTheSame(t.RelationshipModel, s)));
                ViewModel.ConnectionInfoViewModels.Add(t);
                t.BuildLoadedConnection();
            });

            var newRelations =
                allRelationshipsDetails
                .Where(t => !relationElements.Any(s => s.RelationshipModel.Name.Equals(t.Name)))
                .Select(t =>
            {
                var vm = new ConnectionInfoViewModel
                {
                    DesignerCanvas       = canvas,
                    SourceViewModel      = tableElements.FirstOrDefault(s => s.Model.Id.Equals(t.Source.Id)),
                    DestinationViewModel = tableElements.FirstOrDefault(s => s.Model.Id.Equals(t.Destination.Id))
                };
                vm.RelationshipModel.RefreshModel(t);
                return(vm);
            })
                .ToList();

            newRelations.ForEach(async t =>
            {
                ViewModel.ConnectionInfoViewModels.Add(t);
                await t.BuildConnection3(ViewModel);
            });
        }
コード例 #21
0
        /// <summary>
        /// Mouse drag in progress
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="dragDeltaEventArgs"></param>
        private void OnDragDelta(object sender, DragDeltaEventArgs dragDeltaEventArgs)
        {
            if (_item != null && _canvas != null && _item.IsSelected)
            {
                double minLeft = double.MaxValue;
                double minTop  = double.MaxValue;

                double maxTop  = double.MinValue;
                double maxLeft = double.MinValue;

                foreach (TableContent item in _canvas.SelectedTables)
                {
                    minLeft = Math.Min(DesignerCanvas.GetLeft(item), minLeft);
                    minTop  = Math.Min(DesignerCanvas.GetTop(item), minTop);
                    maxLeft = Math.Max(DesignerCanvas.GetLeft(item) + item.ActualWidth, maxLeft);
                    maxTop  = Math.Max(DesignerCanvas.GetTop(item) + item.ActualHeight, maxTop);
                }

                double deltaHorizontal = (int)Math.Max(-minLeft, dragDeltaEventArgs.HorizontalChange);
                double deltaVertical   = (int)Math.Max(-minTop, dragDeltaEventArgs.VerticalChange);

                //Limit movement by connection position
                double topConnectionLimit    = double.MaxValue;
                double bottomConnectionLimit = double.MaxValue;
                double leftConnectionLimit   = double.MaxValue;
                double rightConnectionLimit  = double.MaxValue;

                foreach (TableContent item in _canvas.SelectedTables)
                {
                    foreach (ConnectionInfoViewModel model in _connections.Where(t => t.SourceViewModel.Equals(item.TableViewModel)))
                    {
                        ConnectionInfoViewModel.GetConnectionLimits(ref topConnectionLimit, ref bottomConnectionLimit, ref leftConnectionLimit, ref rightConnectionLimit, model.SourceConnector, model);
                    }

                    foreach (ConnectionInfoViewModel model in _connections.Where(t => t.DestinationViewModel.Equals(item.TableViewModel)))
                    {
                        ConnectionInfoViewModel.GetConnectionLimits(ref topConnectionLimit, ref bottomConnectionLimit, ref leftConnectionLimit, ref rightConnectionLimit, model.DestinationConnector, model);
                    }
                }

                if (_item.TableViewModel.AreLimitsEnabled)
                {
                    if (topConnectionLimit < double.MaxValue)
                    {
                        if (deltaVertical < 0 && minTop + deltaVertical <= minTop - topConnectionLimit)
                        {
                            deltaVertical = 0;
                        }
                    }

                    if (bottomConnectionLimit < double.MaxValue)
                    {
                        if (deltaVertical > 0 && maxTop + deltaVertical >= maxTop + bottomConnectionLimit)
                        {
                            deltaVertical = 0;
                        }
                    }

                    if (leftConnectionLimit < double.MaxValue)
                    {
                        if (deltaHorizontal < 0 && minLeft + deltaHorizontal <= minLeft - leftConnectionLimit)
                        {
                            deltaHorizontal = 0;
                        }
                    }

                    if (rightConnectionLimit < double.MaxValue)
                    {
                        if (deltaHorizontal > 0 && maxLeft + deltaHorizontal >= maxLeft + rightConnectionLimit)
                        {
                            deltaHorizontal = 0;
                        }
                    }

                    if (maxLeft >= _canvas.ActualWidth && dragDeltaEventArgs.HorizontalChange > 0)
                    {
                        deltaHorizontal = 0;
                    }

                    if (maxTop >= _canvas.ActualHeight && dragDeltaEventArgs.VerticalChange > 0)
                    {
                        deltaVertical = 0;
                    }
                }

                var selected = _canvas.SelectedTables.ToArray();

                foreach (TableContent item in selected)
                {
                    var leftPos = DesignerCanvas.GetLeft(item) + deltaHorizontal;
                    var topPos  = DesignerCanvas.GetTop(item) + deltaVertical;
                    DesignerCanvas.SetLeft(item, leftPos);
                    DesignerCanvas.SetTop(item, topPos);
                    item.TableViewModel.Left = leftPos;
                    item.TableViewModel.Top  = topPos;
                }

                dragDeltaEventArgs.Handled = true;
            }
        }
コード例 #22
0
ファイル: PhotonWireWindow.cs プロジェクト: neuecc/PhotonWire
        void DrawGraph(ConnectionInfoViewModel info, int width, int height)
        {
            var buffer = info.GraphicBuffer;
            var bufferSize = width * height;
            if (buffer == null || buffer.Length != bufferSize)
            {
                // new buffer
                info.GraphTexture = new Texture2D(width, height, TextureFormat.ARGB32, false);
                info.GraphicBuffer = buffer = new Color32[width * height]; // x * y;
            }

            lock (info.GraphListLock)
            {
                var graphList = info.GraphList;
                if (graphList.Capacity < width)
                {
                    graphList.Capacity += width;
                }

                var bufferStart = (width < graphList.Count)
                    ? graphList.Count - width
                    : 0;

                var maxValue = 0;
                var maxReceived = 0;
                var maxSent = 0;
                for (int i = bufferStart; i < graphList.Count; i++)
                {
                    var tuple = graphList[i];
                    var max = tuple.Item1 + tuple.Item2;
                    if (maxValue < max) maxValue = max;
                    if (maxSent < tuple.Item1) maxSent = tuple.Item1;
                    if (maxReceived < tuple.Item2) maxReceived = tuple.Item2;
                }

                // side effect:)
                info.MaxSize = ToHumanReadableSize(maxValue);
                info.MaxReceived = ToHumanReadableSize(maxReceived);
                info.MaxSent = ToHumanReadableSize(maxSent);

                var basis = (maxValue != 0)
                    ? (double)height / (double)maxValue
                    : 0;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        var index = y * width + x;

                        var color = Color.clear;
                        if (x < graphList.Count)
                        {
                            var size = graphList[bufferStart + x];
                            var sent = ConvertToHeight(size.Item1, basis);
                            var received = ConvertToHeight(size.Item2, basis);
                            var max = sent + received;
                            if (y < max)
                            {
                                if (y < received)
                                {
                                    color = Color.green;
                                }
                                else
                                {
                                    color = Color.red;
                                }
                            }
                            else
                            {
                                color = Color.clear;
                            }
                        }

                        buffer[index] = color;
                    }
                }
            }

            if (buffer.Length != 0)
            {
                info.GraphTexture.SetPixels32(buffer);
                info.GraphTexture.Apply();
            }
        }
コード例 #23
0
        /// <summary>
        /// If is grid enabled, snap to intersects
        /// </summary>
        private void SnapToGrid()
        {
            if (_canvas.IsGridEnabled)
            {
                double topConnectionLimit    = double.MaxValue;
                double bottomConnectionLimit = double.MaxValue;
                double leftConnectionLimit   = double.MaxValue;
                double rightConnectionLimit  = double.MaxValue;

                foreach (ConnectionInfoViewModel model in _connections.Where(t => t.SourceViewModel.Equals(_item.TableViewModel)))
                {
                    ConnectionInfoViewModel.GetConnectionLimits(ref topConnectionLimit, ref bottomConnectionLimit, ref leftConnectionLimit, ref rightConnectionLimit, model.SourceConnector, model);
                }

                foreach (ConnectionInfoViewModel model in _connections.Where(t => t.DestinationViewModel.Equals(_item.TableViewModel)))
                {
                    ConnectionInfoViewModel.GetConnectionLimits(ref topConnectionLimit, ref bottomConnectionLimit, ref leftConnectionLimit, ref rightConnectionLimit, model.DestinationConnector, model);
                }

                double top       = _item.TableViewModel.Top;
                double left      = _item.TableViewModel.Left;
                double bottom    = top + _item.TableViewModel.Height;
                double right     = left + _item.TableViewModel.Width;
                int    cellWidth = DesignerCanvas.GridCellWidth;

                double approxCell;

                switch (VerticalAlignment)
                {
                case VerticalAlignment.Top:
                    approxCell = Math.Round(top / cellWidth, MidpointRounding.AwayFromZero) * cellWidth;
                    if (topConnectionLimit < double.MaxValue)
                    {
                        if (approxCell > top - topConnectionLimit)
                        {
                            DesignerCanvas.SetTop(_item, approxCell);
                            _item.TableViewModel.Top = approxCell;
                        }
                    }
                    else
                    {
                        DesignerCanvas.SetTop(_item, approxCell);
                        _item.TableViewModel.Top = approxCell;
                    }
                    break;

                case VerticalAlignment.Bottom:
                    approxCell = Math.Round(bottom / cellWidth, MidpointRounding.AwayFromZero) * cellWidth;
                    if (bottomConnectionLimit < double.MaxValue)
                    {
                        if (approxCell < bottom + bottomConnectionLimit)
                        {
                            _item.TableViewModel.Height = approxCell - _item.TableViewModel.Top;
                            _item.Height = _item.TableViewModel.Height;
                        }
                    }
                    else
                    {
                        _item.TableViewModel.Height = approxCell - _item.TableViewModel.Top;
                        _item.Height = _item.TableViewModel.Height;
                    }
                    break;
                }

                switch (HorizontalAlignment)
                {
                case HorizontalAlignment.Left:
                    approxCell = Math.Round(left / cellWidth, MidpointRounding.AwayFromZero) * cellWidth;
                    if (leftConnectionLimit < double.MaxValue)
                    {
                        if (approxCell > left - leftConnectionLimit)
                        {
                            DesignerCanvas.SetLeft(_item, approxCell);
                            _item.TableViewModel.Left = approxCell;
                        }
                    }
                    else
                    {
                        DesignerCanvas.SetLeft(_item, approxCell);
                        _item.TableViewModel.Left = approxCell;
                    }
                    break;

                case HorizontalAlignment.Right:
                    approxCell = Math.Round(right / cellWidth, MidpointRounding.AwayFromZero) * cellWidth;
                    if (rightConnectionLimit < double.MaxValue)
                    {
                        if (approxCell < right + rightConnectionLimit)
                        {
                            _item.TableViewModel.Width = approxCell - _item.TableViewModel.Left;
                            _item.Width = _item.TableViewModel.Width;
                        }
                    }
                    else
                    {
                        _item.TableViewModel.Width = approxCell - _item.TableViewModel.Left;
                        _item.Width = _item.TableViewModel.Width;
                    }
                    break;
                }
            }
        }
コード例 #24
0
        /// <summary>
        /// Drag of thumb in progress
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            if (_item != null && _canvas != null && _item.IsSelected)
            {
                double maxDeltaVertical   = _canvas.ActualHeight - (DesignerCanvas.GetTop(_item) + _item.ActualHeight);
                double maxDeltaHorizontal = _canvas.ActualWidth - (DesignerCanvas.GetLeft(_item) + _item.ActualWidth);

                var minDeltaVertical   = _item.ActualHeight - _item.MinHeight;
                var minDeltaHorizontal = _item.ActualWidth - _item.MinWidth;

                #region Bad approach

                //Bad approach
                //foreach(TableContent item in _canvas.SelectedTables)
                //{
                //	minLeft = Math.Min(DesignerCanvas.GetLeft(item), minLeft);
                //	minTop = Math.Min(DesignerCanvas.GetTop(item), minTop);

                //	maxLeft = Math.Max(DesignerCanvas.GetLeft(item) + item.ActualWidth, maxLeft);
                //	maxTop = Math.Max(DesignerCanvas.GetTop(item) + item.ActualHeight, maxTop);

                //	if (item.TableViewModel.ViewMode != TableViewMode.NameOnly)
                //	{
                //		minDeltaVertical = Math.Min(item.ActualHeight - item.MinHeight, minDeltaVertical);
                //	}
                //	minDeltaHorizontal = Math.Min(item.ActualWidth - item.MinWidth, minDeltaHorizontal);

                //	maxDeltaVertical = Math.Min(_canvas.ActualHeight - (DesignerCanvas.GetTop(item) + item.ActualHeight), maxDeltaVertical);
                //	maxDeltaHorizontal = Math.Min(_canvas.ActualWidth - (DesignerCanvas.GetLeft(item) + item.ActualWidth), maxDeltaHorizontal);
                //}

                #endregion

                double topConnectionLimit    = double.MaxValue;
                double bottomConnectionLimit = double.MaxValue;
                double leftConnectionLimit   = double.MaxValue;
                double rightConnectionLimit  = double.MaxValue;

                foreach (ConnectionInfoViewModel model in _connections.Where(t => t.SourceViewModel.Equals(_item.TableViewModel)))
                {
                    ConnectionInfoViewModel.GetConnectionLimits(ref topConnectionLimit, ref bottomConnectionLimit, ref leftConnectionLimit, ref rightConnectionLimit, model.SourceConnector, model);
                }

                foreach (ConnectionInfoViewModel model in _connections.Where(t => t.DestinationViewModel.Equals(_item.TableViewModel)))
                {
                    ConnectionInfoViewModel.GetConnectionLimits(ref topConnectionLimit, ref bottomConnectionLimit, ref leftConnectionLimit, ref rightConnectionLimit, model.DestinationConnector, model);
                }

                if (_item.TableViewModel.ViewMode != TableViewMode.NameOnly)
                {
                    double deltaVertical;
                    switch (VerticalAlignment)
                    {
                    case VerticalAlignment.Bottom:
                        deltaVertical = e.VerticalChange > 0 && e.VerticalChange >= maxDeltaVertical ? 0 : Math.Min(-e.VerticalChange, minDeltaVertical);
                        if (bottomConnectionLimit < double.MaxValue)
                        {
                            if (DesignerCanvas.GetTop(_item) + _item.ActualHeight - deltaVertical >= (DesignerCanvas.GetTop(_item) + _item.ActualHeight) + bottomConnectionLimit)
                            {
                                deltaVertical = 0;
                            }
                        }
                        _item.Height = _item.ActualHeight - (int)deltaVertical;
                        _item.TableViewModel.Height = _item.Height;
                        break;

                    case VerticalAlignment.Top:
                        deltaVertical = (int)Math.Min(Math.Max(-DesignerCanvas.GetTop(_item), e.VerticalChange), minDeltaVertical);
                        if (topConnectionLimit < double.MaxValue)
                        {
                            if (deltaVertical < 0 && DesignerCanvas.GetTop(_item) + deltaVertical <= DesignerCanvas.GetTop(_item) - topConnectionLimit)
                            {
                                deltaVertical = 0;
                            }
                        }
                        var topPos = DesignerCanvas.GetTop(_item) + deltaVertical;
                        DesignerCanvas.SetTop(_item, topPos);
                        _item.Height = _item.ActualHeight - deltaVertical;
                        _item.TableViewModel.Height = _item.Height;
                        _item.TableViewModel.Top    = topPos;
                        break;
                    }
                }

                double deltaHorizontal;
                switch (HorizontalAlignment)
                {
                case HorizontalAlignment.Left:
                    deltaHorizontal = (int)Math.Min(Math.Max(-DesignerCanvas.GetLeft(_item), e.HorizontalChange), minDeltaHorizontal);
                    if (leftConnectionLimit < double.MaxValue)
                    {
                        if (deltaHorizontal < 0 && DesignerCanvas.GetLeft(_item) + deltaHorizontal <= DesignerCanvas.GetLeft(_item) - leftConnectionLimit)
                        {
                            deltaHorizontal = 0;
                        }
                    }
                    var leftPos = DesignerCanvas.GetLeft(_item) + deltaHorizontal;
                    DesignerCanvas.SetLeft(_item, leftPos);
                    _item.Width = _item.ActualWidth - deltaHorizontal;
                    _item.TableViewModel.Width = _item.Width;
                    _item.TableViewModel.Left  = leftPos;
                    break;

                case HorizontalAlignment.Right:
                    deltaHorizontal = e.HorizontalChange > 0 && e.HorizontalChange >= maxDeltaHorizontal ? 0 : (int)Math.Min(-e.HorizontalChange, minDeltaHorizontal);
                    if (rightConnectionLimit < double.MaxValue)
                    {
                        if (DesignerCanvas.GetLeft(_item) + _item.ActualWidth - deltaHorizontal >= DesignerCanvas.GetLeft(_item) + _item.ActualWidth + rightConnectionLimit)
                        {
                            deltaHorizontal = 0;
                        }
                    }
                    _item.Width = _item.ActualWidth - deltaHorizontal;
                    _item.TableViewModel.Width = _item.Width;
                    break;
                }
            }
            e.Handled = true;
        }