public async Task GetEditRow()
        {
            // Setup: Create a row delete
            var columns = Common.GetColumns(false);
            var rs      = await Common.GetResultSet(columns, false);

            var       etm = Common.GetStandardMetadata(columns);
            RowDelete rd  = new RowDelete(0, rs, etm);

            // If: I attempt to get an edit row
            DbCellValue[] cells = rs.GetRow(0).ToArray();
            EditRow       er    = rd.GetEditRow(cells);

            // Then:
            // ... The state should be dirty
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyDelete, er.State);

            // ... The ID should be the same as the one provided
            Assert.Equal(0, er.Id);

            // ... The row should match the cells that were given and should be dirty
            Assert.Equal(cells.Length, er.Cells.Length);
            for (int i = 0; i < cells.Length; i++)
            {
                DbCellValue originalCell = cells[i];
                EditCell    outputCell   = er.Cells[i];

                Assert.Equal(originalCell.DisplayValue, outputCell.DisplayValue);
                Assert.Equal(originalCell.IsNull, outputCell.IsNull);
                Assert.True(outputCell.IsDirty);
                // Note: No real need to check the RawObject property
            }
        }
예제 #2
0
        private int version; // The version the client-side is. The spreadsheet sends updates to correct when the version is wrong.

        #endregion Fields

        #region Constructors

        /// <summary>
        ///  Creates the communication outlet that the client will use to "talk" to the server.
        /// </summary>
        /// <param name="ipAddress"></param>
        public ClientSocket(string ipAddress, EditCell spreadsheet, ClientToGUI_SS receivedMessage, int port, SendXML xmlSender)
        {
            changePayload.contents = "";
            try
            {
                // set private instance variables
                this.ipAddress = ipAddress;
                this.clientGUI_SS = receivedMessage;
                this.e_Cell = spreadsheet;
                this.send_XML = xmlSender;

                TcpClient client = new TcpClient(ipAddress, port);
                Socket sock = client.Client;

                socket = new SSOffical(sock, new UTF8Encoding());
                socket.BeginReceive(MasterCallback, null, CustomNetworking.callbacks.MASTER);
                version = 0;
                password = "";
                nameOfSpreadsheet = "";
            }
            catch (Exception e)
            {
                clientGUI_SS("Server connection aborted, \n" + e.Message, true);
            }
        }
        public async Task GetEditRowWithAdditions()
        {
            // Setp: Generate a row create with a cell added to it
            RowCreate rc = await GetStandardRowCreate();

            const string setValue = "foo";

            rc.SetCell(0, setValue);

            // If: I request an edit row from the row create
            EditRow er = rc.GetEditRow(null);

            // Then:
            // ... The row should not be null and contain the same number of cells as columns
            Assert.NotNull(er);
            Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);

            // ... The row should not be clean
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);

            // ... The row should have a single non-empty cell at the beginning that is dirty
            Assert.Equal(setValue, er.Cells[0].DisplayValue);
            Assert.False(er.Cells[0].IsNull);
            Assert.True(er.Cells[0].IsDirty);

            // ... The rest of the cells should be blank, but dirty
            for (int i = 1; i < er.Cells.Length; i++)
            {
                EditCell ec = er.Cells[i];
                Assert.Equal(string.Empty, ec.DisplayValue);
                Assert.False(ec.IsNull);
                Assert.True(ec.IsDirty);
            }
        }
예제 #4
0
        public void AsEditCellValue(bool isNull)
        {
            // Setup: Create a cell update
            var        value = isNull ? "NULL" : "foo";
            var        col   = GetWrapper <string>("NTEXT");
            CellUpdate cu    = new CellUpdate(col, value);

            // If: I convert the cell update to an EditCell
            EditCell ec = cu.AsEditCell;

            // Then:
            // ... It should not be null
            Assert.NotNull(ec);

            // ... The display value should be the same as the value we supplied
            Assert.Equal(value, ec.DisplayValue);

            // ... The null-ness of the value should be the same as what we supplied
            Assert.Equal(isNull, ec.IsNull);

            // ... We don't care *too* much about the raw value, but we'll check it anyhow
            Assert.Equal(isNull ? (object)DBNull.Value : value, ec.RawObject);

            // ... The edit cell should be dirty
            Assert.True(ec.IsDirty);
        }
        /// <summary>
        ///     Updates the selected cell on the spreadsheet
        /// </summary>
        private void EditSelectedCell()
        {
            var edit = new EditCell();

            edit.SetCellName(_selection);
            edit.SetContents(BoxContents.Text);

            _clientController.SendUpdatesToServer(edit);
        }
예제 #6
0
 /// <summary>
 /// Handles the Validated event of the InnerControl control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void InnerControl_Validated(object sender, EventArgs e)
 {
     try
     {
         if (IsEditing)
         {
             EditCell.EndEdit(false);
         }
     }
     catch (Exception ex)
     {
         OnEditException(new EditExceptionEventArgs(ex));
     }
 }
예제 #7
0
 protected virtual void InnerControl_Validated(object sender, EventArgs e)
 {
     try
     {
         if (IsEditing)
         {
             EditCell.EndEdit(false);
         }
     }
     catch (Exception err)
     {
         OnEditException(new EditExceptionEventArgs(err));
         System.Diagnostics.Debug.Assert(false);
     }
 }
        public async Task GetEditRow()
        {
            // Setup: Create a row update with a cell set
            var columns = Common.GetColumns(false);
            var rs      = await Common.GetResultSet(columns, false);

            var       etm = Common.GetStandardMetadata(columns);
            RowUpdate ru  = new RowUpdate(0, rs, etm);

            ru.SetCell(0, "foo");

            // If: I attempt to get an edit row
            DbCellValue[] cells = rs.GetRow(0).ToArray();
            EditRow       er    = ru.GetEditRow(cells);

            // Then:
            // ... The state should be dirty
            Assert.True(er.IsDirty);
            Assert.Equal(EditRow.EditRowState.DirtyUpdate, er.State);

            // ... The ID should be the same as the one provided
            Assert.Equal(0, er.Id);

            // ... The row should match the cells that were given, except for the updated cell
            Assert.Equal(cells.Length, er.Cells.Length);
            for (int i = 1; i < cells.Length; i++)
            {
                DbCellValue originalCell = cells[i];
                DbCellValue outputCell   = er.Cells[i];

                Assert.Equal(originalCell.DisplayValue, outputCell.DisplayValue);
                Assert.Equal(originalCell.IsNull, outputCell.IsNull);
                // Note: No real need to check the RawObject property
            }

            // ... The updated cell should match what it was set to and be dirty
            EditCell newCell = er.Cells[0];

            Assert.Equal("foo", newCell.DisplayValue);
            Assert.False(newCell.IsNull);
            Assert.True(newCell.IsDirty);
        }
예제 #9
0
        public void ConstructValid()
        {
            // Setup: Create a DbCellValue to copy the values from
            DbCellValue source = new DbCellValue
            {
                DisplayValue = "qqq",
                IsNull       = true,
                RawObject    = 12
            };

            // If: I construct an EditCell with a valid DbCellValue
            EditCell ec = new EditCell(source, true);

            // Then:
            // ... The values I provided in the DbCellValue should be present
            Assert.Equal(source.DisplayValue, ec.DisplayValue);
            Assert.Equal(source.IsNull, ec.IsNull);
            Assert.Equal(source.RawObject, ec.RawObject);

            // ... The is dirty value I set should be present
            Assert.True(ec.IsDirty);
        }
예제 #10
0
        /// <summary>
        ///     Receives messages from server and handles them
        /// </summary>
        /// <param name="state"></param>
        private void ReceiveUpdatesLoop(SocketState state)
        {
            if (state.ErrorOccured)
            {
                // inform the view
                Error?.Invoke(state.ErrorMessage, "Error In Event Loop");
                Disconnect();
                return;
            }

            string incomingMessages = state.GetData();

            string[] data = Regex.Split(incomingMessages, @"(?<=[\n])");

            foreach (string message in data.Where(message => message.Length != 0))
            {
                //Last Step of handshake if message is the id
                if (int.TryParse(message, out int i))
                {
                    IDReceive?.Invoke(i);
                    continue;
                }

                // The regex splitter will include the last string even if it doesn't end with a '\n',
                // So we need to ignore it if this happens.
                if (message.Last() != '\n' || message[0] != '{')
                {
                    continue;
                }

                Console.WriteLine("Received:" + message);

                //Parse message as json object
                var x = JObject.Parse(message);
                switch (x["messageType"]?.ToString())
                {
                case "cellUpdated":
                {
                    if (EditCell is null)
                    {
                        continue;
                    }
                    var updated = JsonConvert.DeserializeObject <CellUpdated>(message);
                    EditCell.Invoke(updated);
                    break;
                }

                case "cellSelected":
                {
                    if (SelectCell is null)
                    {
                        continue;
                    }
                    var selected = JsonConvert.DeserializeObject <CellSelected>(message);
                    SelectCell.Invoke(selected);
                    break;
                }

                case "serverError":
                {
                    if (ServerShutdown is null)
                    {
                        continue;
                    }
                    var error = JsonConvert.DeserializeObject <ServerShutdownError>(message);
                    ServerShutdown.Invoke(error);
                    break;
                }

                case "requestError":
                {
                    if (RequestError is null)
                    {
                        continue;
                    }
                    var error = JsonConvert.DeserializeObject <RequestError>(message);
                    RequestError.Invoke(error);
                    break;
                }

                case "disconnected":
                {
                    var d = JsonConvert.DeserializeObject <Disconnected>(message);
                    ClientDisconnected?.Invoke(d);
                    break;
                }
                }

                state.RemoveData(0, message.Length);
            }

            Networking.GetData(state);
        }