internal static OperationView GetOne(int id) { OperationsEntities db = new OperationsEntities(); OperationView operationView = db.OperationViews.Where(x => x.OperationId == id).FirstOrDefault(); return(operationView); }
public static IList <OperationView> GetAllOperations(string connection = "") { List <OperationView> Operations = new List <OperationView>(); using (SqlConnection con = new SqlConnection(connection)) { SqlCommand cmd = new SqlCommand("sp_ManagePayment", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter { ParameterName = "@Mode", Value = "GetAllOperations" }); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { OperationView operation = new OperationView(); operation.Id = Convert.ToInt32(rdr["Id"]); operation.Description = rdr["Description"].ToString(); DateTime d = Convert.ToDateTime(rdr["DateStamp"]); operation.DateString = d.ToString("yyyy-MM-dd"); operation.Amount = Convert.ToDecimal(rdr["Amount"]); operation.Currency = rdr["Currency"].ToString(); operation.OprTypeId = Convert.ToInt32(rdr["OprTypeId"]); operation.RelationId = Convert.ToInt32(rdr["RelationId"]); operation.Agent = rdr["Agent"].ToString(); operation.PaymentMethod = rdr["PaymentMethod"].ToString(); operation.Captured = Convert.ToInt32(rdr["Captured"]); d = Convert.ToDateTime(rdr["CaptureOn"]); operation.CapDateString = d.ToString("yyyy-MM-dd"); Operations.Add(operation); } con.Close(); } return(Operations); }
public static void ChangeOperationType(OperationView opView, IOperable <T> opCalc) { var operationPair = operationsView.Where(e => e.Value == opView).ToList()[0]; operationPair.Key.SetOperationCalculator(opCalc); opView.operationLabel.Text = operationPair.Key.GetStringRepresentation(); if (opCalc.operationType == OperationType.Unary || opCalc.operationType == OperationType.Multiarial) { opView.workingPanelRight.Enabled = false; opView.workingPanelRight.Visible = false; opView.isUnaryOrMultiarial = true; } else { opView.workingPanelRight.Enabled = true; opView.workingPanelRight.Visible = true; opView.isUnaryOrMultiarial = false; } if (operationPair.Key.operationCalculator.operationType == OperationType.Multiarial) { opView.изменитьАргументыToolStripMenuItem.Enabled = true; } else { opView.изменитьАргументыToolStripMenuItem.Enabled = false; } operationPair.Value.argumentsChanged.Invoke(opCalc, null); }
public static void serverReceivedData(byte[] data, int fromWho) { try { int endPoint = data.Length; // RPC call. RPCs can be -> Client OR -> Server // The next byte will contain the object ID: short index = BitConverter.ToInt16(data, 0); if (index == 0 || (operationObjects.Count > 0 && operationObjects[index] != null && operationObjects[index].GetComponent <OperationView>() != null && operationObjects[index].GetComponent <OperationView>().gameObject != null)) { byte[] rpcData = new byte[data.Length - 3]; Buffer.BlockCopy(data, 3, rpcData, 0, data.Length - 3); endPoint = operationObjects[index].GetComponent <OperationView>().ReceiveRPC(data[2], fromWho, rpcData) + 3; } else { byte[] rpcData = new byte[data.Length - 3]; Buffer.BlockCopy(data, 3, rpcData, 0, data.Length - 3); endPoint = OperationView.ReceiveFakeRPC(data[2], fromWho, rpcData) + 3; } if (endPoint < data.Length) { byte[] nextData = new byte[data.Length - endPoint]; Buffer.BlockCopy(data, endPoint, nextData, 0, data.Length - endPoint); serverReceivedData(nextData, fromWho); } } catch (Exception e) { Debug.LogError("Error at server receive: " + e.Message); } }
public void Execute() { if (isMatrixController) { if (grid.side == WorkingPanelSide.List) { var data = MatrixController <T> .DeleteMatrix(grid); matrix = data.matrix; } else { matrix = MatrixController <T> .GetMatrix(grid); opView = OperationController <T> .GetOperationView(matrix); MatrixController <T> .DeleteMatrix(grid); } } else { operation = OperationController <T> .GetOperation(opView); OperationController <T> .DeleteOperation(opView); } }
public static void OpenEditForm(OperationView opView) { var operationPair = operationsView.Where(e => e.Value == opView).ToList()[0]; var list = operationPair.Key.operationCalculator.DataBinds; EditOperandForm EOF = new EditOperandForm(list, opView); EOF.Show(); }
public ActionResult PreAlertLetter(int houseBillId, int isNotifier = 0) { HouseBillView hbill = HouseBillHelper.GetHBView(houseBillId); int operationID = hbill.OperationId; OperationView operation = OperationHelper.GetOne(operationID); ViewBag.houseBL = hbill.HouseBL; ViewBag.isNotifie = isNotifier; return(View(hbill)); //operation }
public async Task ExecuteAsync(object parameter) { var cancel = new CancellationTokenSource(); parserlog.dotnet.core.interfaces.IOperationParse analyze_log = new parserlog.dotnet.core.operations.OperationParserLines(model_view.LogName, cancel.Token); OperationView operation_view = new OperationView(model_view.Operations, cancel); analyze_log.OnStart += (sender, e) => { operation_view.Title = "Parsing log file..."; model_view.LinesByThread = new MultiSortedList <ulong, core.model.LineInfo>(); model_view.Lines.Clear(); model_view.Threads.Clear(); model_view.Series.Clear(); model_view.SeriesMainPage.Clear(); }; analyze_log.OnProgress += (sender, e) => { operation_view.Progress = e.Progress; }; analyze_log.OnParsedLine += (sender, e) => { model_view.LinesByThread.Add(e.Info.m_ThreadId, e.Info); model_view.Lines.Add(e.Info); }; analyze_log.OnError += (sender, e) => { operation_view.Complete = true; }; analyze_log.OnComplete += (sender, e) => { operation_view.Complete = true; SortedList <ulong, ulong> sumThread = new SortedList <ulong, ulong>(); foreach (var thread in model_view.LinesByThread) { if (sumThread.ContainsKey(thread.Key)) { ++sumThread[thread.Key]; } else { sumThread.Add(thread.Key, 1); } } MultiSortedList <ulong, ulong> byCount = new MultiSortedList <ulong, ulong>(new CompareReverse <ulong>()); model_view.Threads.Clear(); foreach (var thread in sumThread) { byCount.Add(thread.Value, thread.Key); } foreach (var thread in byCount) { model_view.Threads.Add(thread.Value); } }; await analyze_log.ExecuteAsync(); }
// Use this for initialization void Start() { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; // Other stuff Application.targetFrameRate = 90; // Currently, there are issues with the game relying on framerate for simulation. (Like mainCamera rotation) -which is unavoidable. // This guarantees the RPCs will be set before the game connects: OperationView.initRPCs(); }
public byte num; // Set on init by PlayerHud public void SelectClassNum() { if (OperationNetwork.connected && Player.thisPlayer != null) { OperationView opView = Player.thisPlayer.GetComponent <OperationView> (); if (opView != null && num != Player.thisPlayer.classNum) { opView.RPC("switchTeam", OperationNetwork.ToServer, Player.thisPlayer.team, num); } } }
public static void DeleteOperation(OperationView opView) { var operationPair = operationsView.Where(e => e.Value == opView).ToList()[0]; DeleteArgument(opView, WorkingPanelSide.Left); DeleteArgument(opView, WorkingPanelSide.Right); DeleteArgument(opView, WorkingPanelSide.Result); operations.Remove(operationPair.Key); operationsView.Remove(operationPair); operationPair.Value.Dispose(); }
public static OperationView CreateEmptyOperation() { Operation <T> op = new Operation <T>(); operations.Add(op); OperationView ov = new OperationView(); operationsView.Add(new KeyValuePair <Operation <T>, OperationView>(op, ov)); ov.Parent = OperationsPanel; ov.Dock = DockStyle.Top; ov.operationLabel.Text = op.GetStringRepresentation(); op.argumentsInvalid += (o, e) => ov.argumentsInvalid.Invoke(o, e); ov.изменитьАргументыToolStripMenuItem.Enabled = false; return(ov); }
public void Undo() { if (isMatrixController) { if (matrix != null) { if (grid.side == WorkingPanelSide.List) { MatrixController <T> .CreateMatrix(matrix); } else { //костыль (: //зато работает! var side = grid.side; grid = MatrixController <T> .CreateMatrix(matrix); OperationController <T> .ExecuteDragDrop(side, grid, opView); MatrixController <T> .DeleteMatrix(matrix); } } } else { //тоже костыль :( opView = OperationController <T> .CreateEmptyOperation(); var left = operation.leftMatrix; var right = operation.rightMatrix; if (left != null) { var leftGrid = MatrixController <T> .CreateMatrix(left); OperationController <T> .ExecuteDragDrop(WorkingPanelSide.Left, leftGrid, opView); MatrixController <T> .DeleteMatrix(leftGrid); } if (right != null) { var rightGrid = MatrixController <T> .CreateMatrix(right); OperationController <T> .ExecuteDragDrop(WorkingPanelSide.Right, rightGrid, opView); MatrixController <T> .DeleteMatrix(rightGrid); } } }
public void Execute() { if (type == CreationType.Matrix) { if (data.GetLength(0) != 0 || data.GetLength(1) != 0) { grid = MatrixController <T> .CreateMatrix(data); } grid.MatrixName = name; } else { opView = OperationController <T> .CreateEmptyOperation(); } }
public void SelectTeam() { if (OperationNetwork.connected && Player.thisPlayer != null) { OperationView opView = Player.thisPlayer.GetComponent <OperationView> (); if (opView != null && num != Player.thisPlayer.team) { opView.RPC("switchTeam", OperationNetwork.ToServer, num, Player.thisPlayer.classNum); if (num == 2) { OptionsMenu.classSelectionMenuOpen = false; OptionsMenu.ChangeLockState(); } } } }
// InitialConnect is key. public static void InitialConnect() { if (OperationNetwork.isServer) { GameObject lSync = Instantiate(levelSync); OperationNetwork.OperationAddSyncState(lSync); OperationNetwork.connected = true; // Server connection works like this. PlayerConnect(PlayerInformation.steamName, OperationNetwork.FromServerClient); } else { // Sends out request for "Connect" (with name). ID is sent to the player. OperationView.RPC(null, "PlayerConnect", OperationNetwork.ToServer, PlayerInformation.steamName); } }
public void Authenticate(object obj) { var WR = (HttpWebRequest)WebRequest.Create("https://www.gettertools.com/en/62-Login"); WR.Method = "POST"; WR.ContentType = "application/x-www-form-urlencoded"; Cookie cookie = GetPHPSESSION(); WR.CookieContainer = new CookieContainer(); WR.CookieContainer.Add(cookie); WR.Referer = "https://www.gettertools.com/en/62-Login"; WR.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0"; WR.Host = "www.gettertools.com"; WR.KeepAlive = true; WR.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; WR.Headers.Add("Upgrade-Insecure-Request", "1"); WR.Headers.Add("Cache-Control", "no-cache"); WR.Headers.Add("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3"); WR.Headers.Add("Accept-Encoding", "gzip, deflate, br"); string data = "action=login&username="******"&password=" + Password; byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(data); WR.ContentLength = byteArray.Length; using (Stream dataStream = WR.GetRequestStream()) { dataStream.Write(byteArray, 0, byteArray.Length); } HttpWebResponse response = (HttpWebResponse)WR.GetResponse(); using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { var Cookie = response.Cookies; OperationView ov = new OperationView(Cookie); ov.Show(); _ltv.Close(); } } }
public void Execute(object parameter) { var cancel = new CancellationTokenSource(); core.utilities.Wrapped <long> count = new core.utilities.Wrapped <long>(0); parserlog.dotnet.core.interfaces.IOperation count_lines = new parserlog.dotnet.core.operations.OperationCountLines(model_view.LogName, cancel.Token, count); OperationView operation_view = new OperationView(model_view.Operations, cancel); count_lines.OnStart += (sender, e) => { operation_view.Title = "Starting calculate count"; }; count_lines.OnProgress += (sender, e) => { operation_view.Progress = e.Progress; }; count_lines.OnError += (sender, e) => { operation_view.Complete = true; }; count_lines.OnComplete += (sender, e) => { operation_view.Complete = true; }; count_lines.ExecuteAsync(); }
public static void DeleteArgument(OperationView opView, WorkingPanelSide side) { var operationList = operationsView.Where(e => e.Value == opView).ToList(); //if (operationList.Count == 0) // return; var operationPair = operationList[0]; if (side == WorkingPanelSide.Left && operationPair.Key.leftMatrix != null) { MatrixController <T> .DeleteMatrix(operationPair.Key.leftMatrix); } else if (side == WorkingPanelSide.Right && operationPair.Key.rightMatrix != null) { MatrixController <T> .DeleteMatrix(operationPair.Key.rightMatrix); } else if (side == WorkingPanelSide.Result && operationPair.Key.ResultMatrix != null) { MatrixController <T> .DeleteMatrix(operationPair.Key.ResultMatrix); } }
public static void ExecuteDragDrop(WorkingPanelSide side, MatrixGrid grid, OperationView opView) { var operationPair = operationsView.Where(e => e.Value == opView).ToList()[0]; var oldMatrix = MatrixController <T> .matricesView.Where(e => e.Value == grid).ToList(); var matrix = (Matrix <T>)oldMatrix[0].Key.Clone(); var newGrid = MatrixController <T> .CreateMatrix(matrix); if (side == WorkingPanelSide.Left) { newGrid.Parent = operationPair.Value.workingPanelLeft; newGrid.side = WorkingPanelSide.Left; operationPair.Key.leftMatrix = matrix; matrix.Changed += (o, e) => operationPair.Value.argumentsChanged.Invoke(matrix, null); matrix.DisposeEvent += (o, e) => { operationPair.Value.leftNotNull = false; }; } else if (side == WorkingPanelSide.Right) { newGrid.Parent = operationPair.Value.workingPanelRight; newGrid.side = WorkingPanelSide.Right; operationPair.Key.rightMatrix = matrix; matrix.Changed += (o, e) => operationPair.Value.argumentsChanged.Invoke(matrix, null); matrix.DisposeEvent += (o, e) => { operationPair.Value.rightNotNull = false; }; } newGrid.lines = matrix.lines; newGrid.MatrixName = grid.MatrixName; if (grid.dragDropExecuted != null) { grid.dragDropExecuted.Invoke(newGrid, null); } }
public static MatrixGrid Calculate(OperationView opView) { var operationPair = operationsView.Where(e => e.Value == opView).ToList()[0]; if (operationPair.Key.leftMatrix == null && operationPair.Key.rightMatrix == null) { var matr = new Matrix <T>(1, 1); var gr = MatrixController <T> .CreateMatrix(matr); gr.side = WorkingPanelSide.Result; gr.Parent = opView.resultPanel; if (operationPair.Key.ResultMatrix != null) { MatrixController <T> .DeleteMatrix(operationPair.Key.ResultMatrix); } operationPair.Key.ResultMatrix = matr; return(gr); } if (operationPair.Key.ResultMatrix != null) { MatrixController <T> .DeleteMatrix(operationPair.Key.ResultMatrix); } var t = MatrixController <T> .matrices; var matrix = operationPair.Key.Calculate(); var grid = MatrixController <T> .CreateMatrix(matrix); var left = MatrixController <T> .GetMatrixGrid(operationPair.Key.leftMatrix); grid.lines = matrix.lines; grid.Parent = opView.resultPanel; grid.side = WorkingPanelSide.Result; return(grid); }
public List <CS_CustQuotasOperation> GetSimulationOperations2_2(int id, string item) { //return _context.CS_CustQuotasOperation.Where(x => x.Id == id && x.BOM == item).ToList(); try { List <CS_CustQuotasOperation> listOp = new List <CS_CustQuotasOperation>(); conn.Open(); string sql = $"SELECT *, (SELECT ISNULL(AdditionalCost, 0) FROM MA_Operations WHERE Operation = CQ.Operation) AS Cost FROM CS_CustQuotasOperation CQ WHERE id = { id } AND BOM = '{ item }'"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { CS_CustQuotasOperation op = new CS_CustQuotasOperation(); op.Id = Convert.ToInt32(reader["Id"]); op.Line = Convert.ToInt32(reader["Line"]); op.Operation = reader["Operation"].ToString().Trim(); op.DescriptionOperation = reader["DescriptionOperation"].ToString().Trim(); op.TimeProcess = Convert.ToDateTime(reader["TimeProcess"]); op.Item = reader["Item"].ToString().Trim(); op.BOM = reader["BOM"].ToString().Trim(); op.Obs = reader["Obs"].ToString().Trim(); op.TimeProcessStr = reader["TimeProcessStr"].ToString(); double valor = OperationView.CalculateCostOperation(reader["TimeProcessStr"].ToString(), Convert.ToDouble(reader["Cost"])); op.CostOperation = Math.Round(valor, 2); op.UoM = reader["UoM"].ToString().Trim(); op.Qty = string.IsNullOrEmpty(reader["Qty"].ToString()) ? 0 : Convert.ToDouble(reader["Qty"]); listOp.Add(op); } conn.Close(); return(listOp); } catch (Exception ex) { conn.Close(); throw ex; } }
public static JObject GetOperationOrders(FormCollection form) { OperationsEntities db = new OperationsEntities(); OperationView oprObj = new OperationView(); string where = CommonHelper.AdvancedSearch <OperationView>(form, oprObj); var operationList = db.OperationViews.Where(where.ToString()) .Select(x => new { x.OperationId, x.CarrierType, x.QuoteId, x.CreateDate, x.OperationCode, x.ShipperNameEn, x.ConsigneeNameEn, x.CarrierNameEn, x.FromPort, x.ToPort, x.DateOfDeparture, x.StatusName, x.StatusId, x.IsConsolidation, x.OrderFrom, x.AgentNameEn }) .ToList(); JTokenWriter pJTokenWriter = new JTokenWriter(); JObject ordersJson = new JObject(); pJTokenWriter.WriteStartObject(); pJTokenWriter.WritePropertyName("data"); pJTokenWriter.WriteStartArray(); foreach (var item in operationList) { pJTokenWriter.WriteStartObject(); pJTokenWriter.WritePropertyName("OperationId"); pJTokenWriter.WriteValue(item.OperationId); pJTokenWriter.WritePropertyName("CarrierTypeImg"); switch (item.CarrierType) { case 1: pJTokenWriter.WriteValue("<i class='fa fa-ship'></i>"); break; case 2: pJTokenWriter.WriteValue("<i class='fa fa-plane'></i>"); break; } pJTokenWriter.WritePropertyName("ConsolidationImg"); switch (item.IsConsolidation) { case true: pJTokenWriter.WriteValue("<i class='fa fa-users'></i>"); break; case false: pJTokenWriter.WriteValue("<i class='fa fa-user'></i>"); break; } switch (item.OrderFrom) { case 1: pJTokenWriter.WritePropertyName("OrderFromImg"); pJTokenWriter.WriteValue("<i class='fa fa-level-up'></i>"); pJTokenWriter.WritePropertyName("ClientName"); pJTokenWriter.WriteValue(item.ShipperNameEn); break; case 2: pJTokenWriter.WritePropertyName("OrderFromImg"); pJTokenWriter.WriteValue("<i class='fa fa-level-down'></i>"); pJTokenWriter.WritePropertyName("ClientName"); pJTokenWriter.WriteValue(item.ConsigneeNameEn); break; } pJTokenWriter.WritePropertyName("QuoteId"); if (item.QuoteId != null) { pJTokenWriter.WriteValue(item.QuoteId); } else { pJTokenWriter.WriteValue(""); } pJTokenWriter.WritePropertyName("CarrierType"); pJTokenWriter.WriteValue(item.CarrierType); pJTokenWriter.WritePropertyName("CreateDate"); pJTokenWriter.WriteValue(item.CreateDate.ToString("dd/MM/yyyy")); pJTokenWriter.WritePropertyName("OperationCode"); pJTokenWriter.WriteValue(item.OperationCode); pJTokenWriter.WritePropertyName("ShipperName"); pJTokenWriter.WriteValue(item.ShipperNameEn); pJTokenWriter.WritePropertyName("ConsigneeName"); pJTokenWriter.WriteValue(item.ConsigneeNameEn); pJTokenWriter.WritePropertyName("CarrierName"); pJTokenWriter.WriteValue(item.CarrierNameEn); pJTokenWriter.WritePropertyName("FromPort"); pJTokenWriter.WriteValue(item.FromPort); pJTokenWriter.WritePropertyName("ToPort"); pJTokenWriter.WriteValue(item.ToPort); pJTokenWriter.WritePropertyName("DateOfDeparture"); pJTokenWriter.WriteValue(item.DateOfDeparture != null ? item.DateOfDeparture.Value.ToString("dd/MM/yyyy") : ""); pJTokenWriter.WritePropertyName("StatusName"); pJTokenWriter.WriteValue(item.StatusName); pJTokenWriter.WritePropertyName("StatusId"); pJTokenWriter.WriteValue(item.StatusId); pJTokenWriter.WritePropertyName("OrderFrom"); pJTokenWriter.WriteValue(item.OrderFrom); pJTokenWriter.WritePropertyName("AgentName"); pJTokenWriter.WriteValue(item.AgentNameEn); pJTokenWriter.WriteEndObject(); } pJTokenWriter.WriteEndArray(); pJTokenWriter.WriteEndObject(); ordersJson = (JObject)pJTokenWriter.Token; return(ordersJson); }
public EditOperandForm(List <IData> data, OperationView opView) { InitializeComponent(); this.opView = opView; foreach (IData info in data) { if (info.GetType() == typeof(DataBind <int>)) { var bind = (DataBind <int>)(info); Panel p = new Panel(); TextBox tb = new TextBox(); tb.TextChanged += (o, e) => bind.data = Convert.ToInt32(tb.Text); tb.Text = bind.data.ToString(); tb.Dock = DockStyle.Left; tb.Width = 50; p.Controls.Add(tb); Label l = new Label(); l.Text = bind.information[0]; l.Dock = DockStyle.Left; p.Controls.Add(l); l.Width = 100; p.Padding = new Padding(10); panel1.Controls.Add(p); p.Dock = DockStyle.Top; p.BackColor = Color.White; } if (info.GetType() == typeof(DataBind <bool>)) { var bind = (DataBind <bool>)(info); Panel p = new Panel(); RadioButton RB = new RadioButton(); RB.CheckedChanged += (o, e) => bind.data = true; RB.Text = bind.information[1]; RB.Dock = DockStyle.Top; p.Controls.Add(RB); RadioButton RB1 = new RadioButton(); RB1.CheckedChanged += (o, e) => bind.data = false; if (bind.data) { RB.Checked = true; } else { RB1.Checked = true; } RB1.Text = bind.information[2]; RB1.Dock = DockStyle.Top; p.Controls.Add(RB1); Label l = new Label(); l.Text = bind.information[0]; l.Dock = DockStyle.Top; p.Controls.Add(l); p.Padding = new Padding(10); p.Dock = DockStyle.Top; panel1.Controls.Add(p); p.BackColor = Color.White; } if (info.GetType() == typeof(DataBind <Matrix <int> >)) { var bind = (DataBind <Matrix <int> >)(info); var grid = MatrixController <int> .CreateMatrix(bind.data); //grid.OnlyEditValues = true; Panel p = new Panel(); grid.Parent = p; grid.Dock = DockStyle.Top; Label l = new Label(); l.Text = bind.information[0]; l.Dock = DockStyle.Top; p.Dock = DockStyle.Top; panel1.Controls.Add(p); p.Controls.Add(l); p.Dock = DockStyle.Top; grid.GridSizeChanged += (o, e) => p.Height = p.Height + grid.GridSize.Height * 15; p.Height = p.Height + grid.GridSize.Height * 15; p.BackColor = Color.White; } } }
// sendToSelf is only for server use. public static void RPC(OperationView oV, string methodName, int sendToSelf, params object[] objects) { // The server doesn't send RPCs: (However the Server can send itself RPCs as if it was a client) if (OperationNetwork.isServer && sendToSelf != OperationNetwork.ToServer) { return; } // Demos aren't actually connected so they can't send RPCs. if (OperationNetwork.isDemo) { return; } // Needs to turn the data into bytes: byte[] data = new byte[300]; int writeLocation = 3; for (int i = 0; i < objects.Length; i++) { if (objects[i] is float) { Buffer.BlockCopy(BitConverter.GetBytes((float)objects[i]), 0, data, writeLocation, 4); writeLocation += 4; } else if (objects[i] is int) { Buffer.BlockCopy(BitConverter.GetBytes((int)objects[i]), 0, data, writeLocation, 4); writeLocation += 4; } else if (objects[i] is bool) { data[writeLocation] = Convert.ToByte((bool)objects[i]); writeLocation += 1; } else if (objects[i] is byte) { data[writeLocation] = (byte)objects[i]; writeLocation += 1; } else if (objects[i] is Vector3) { Buffer.BlockCopy(BitConverter.GetBytes(((Vector3)objects[i]).x), 0, data, writeLocation, 4); writeLocation += 4; Buffer.BlockCopy(BitConverter.GetBytes(((Vector3)objects[i]).y), 0, data, writeLocation, 4); writeLocation += 4; Buffer.BlockCopy(BitConverter.GetBytes(((Vector3)objects[i]).z), 0, data, writeLocation, 4); writeLocation += 4; } else if (objects[i] is Vector3[]) { byte length = (byte)((Vector3[])objects[i]).Length; // Maximum length of 255 data[writeLocation] = length; writeLocation += 1; for (int sk = 0; sk < length; sk++) { Buffer.BlockCopy(BitConverter.GetBytes(((Vector3[])objects[i])[sk].x), 0, data, writeLocation, 4); writeLocation += 4; Buffer.BlockCopy(BitConverter.GetBytes(((Vector3[])objects[i])[sk].y), 0, data, writeLocation, 4); writeLocation += 4; Buffer.BlockCopy(BitConverter.GetBytes(((Vector3[])objects[i])[sk].z), 0, data, writeLocation, 4); writeLocation += 4; } } else if (objects[i] is Quaternion) { Buffer.BlockCopy(BitConverter.GetBytes(((Quaternion)objects[i]).x), 0, data, writeLocation, 4); writeLocation += 4; Buffer.BlockCopy(BitConverter.GetBytes(((Quaternion)objects[i]).y), 0, data, writeLocation, 4); writeLocation += 4; Buffer.BlockCopy(BitConverter.GetBytes(((Quaternion)objects[i]).z), 0, data, writeLocation, 4); writeLocation += 4; Buffer.BlockCopy(BitConverter.GetBytes(((Quaternion)objects[i]).w), 0, data, writeLocation, 4); writeLocation += 4; } else if (objects[i] is float[]) { byte length = (byte)((float[])objects[i]).Length; // Maximum length of 255 data[writeLocation] = length; writeLocation += 1; Buffer.BlockCopy((float[])objects[i], 0, data, writeLocation, ((float[])objects[i]).Length * 4); writeLocation += ((float[])objects[i]).Length * 4; } else if (objects[i] is byte[]) { if (((byte[])objects [i]).Length > 255) { Debug.LogError("BYTE DATA OVERLOAD- Probably mirrors for playerInput hitscanData"); } byte length = (byte)((byte[])objects[i]).Length; // Maximum length of 255 data[writeLocation] = length; writeLocation += 1; Buffer.BlockCopy((byte[])objects[i], 0, data, writeLocation, ((byte[])objects[i]).Length); writeLocation += ((byte[])objects[i]).Length; } else if (objects[i] is string) { byte[] stringBytes = Encoding.ASCII.GetBytes((string)objects[i]); if (stringBytes.Length > 255) { // Cut it off: byte[] extraStringBytes = stringBytes; stringBytes = new byte[255]; Buffer.BlockCopy(extraStringBytes, 0, stringBytes, 0, 255); } data [writeLocation] = (byte)(stringBytes.Length); writeLocation += 1; Buffer.BlockCopy(stringBytes, 0, data, writeLocation, stringBytes.Length); writeLocation += stringBytes.Length; } else if (objects[i] is short) { Buffer.BlockCopy(BitConverter.GetBytes((short)objects[i]), 0, data, writeLocation, 2); writeLocation += 2; } } // Trim data: (Probably should just use writeLocation in "sendData" instead) Array.Resize(ref data, writeLocation); // All OperationViews come with a SyncGameState. if (oV != null) { Buffer.BlockCopy(BitConverter.GetBytes(oV.GetComponent <SyncGameState> ().objectID), 0, data, 0, 2); } else { Buffer.BlockCopy(BitConverter.GetBytes((short)0), 0, data, 0, 2); } data[2] = rpcIDList[methodName]; // Which RPC call if (OperationNetwork.isServer) { // This is no longer how the server interacts with the players if (sendToSelf == OperationNetwork.ToServer) { byte[] sendData = new byte[data.Length - 3]; Buffer.BlockCopy(data, 3, sendData, 0, data.Length - 3); oV.ReceiveRPC(data [2], OperationNetwork.FromServerClient, sendData); } return; } else { // Just send to server. (Client can't send anywhere else) OperationNetwork.sendDataToServer(data); } }
public static Operation <T> GetOperation(OperationView opView) { var operationPair = operationsView.Where(e => e.Value == opView).ToList()[0]; return(operationPair.Key); }
// Non-recursive.. but it still can handle more than one tick. public int recieveData(byte[] data, bool isMainGS, out bool isInOrder) { isInOrder = true; int index = 0; short length = BitConverter.ToInt16(data, 0); index += 2; if (OperationNetwork.isDemo) { OperationNetwork.currentByte += 2; } // It is assumed to be valid, of course: (as this is server -> player if (isMainGS) { // We check what the tick number will be: int gameStateTickNumber = BitConverter.ToInt32(data, index); bool fullGameSend = false; // Negative means that it's a full gamestate send: if (gameStateTickNumber < 0) { fullGameSend = true; gameStateTickNumber = -gameStateTickNumber - 1; Debug.Log("Full resend received: " + gameStateTickNumber); } // Gamestates that are out of order are ignored.. if (fullGameSend || (receivedFullStates[0] != null && (gameStateTickNumber > receivedFullStates [0].tickNumber && gameStateTickNumber <= receivedFullStates[0].tickNumber + ServerState.MAX_CHOKE_TICKS))) { GameState ngs = new GameState(data, index, length, receivedFullStates [0], true, -1); shiftBuffer(receivedFullStates); // Pushes off the oldest one. receivedFullStates [0] = ngs; if (receivedFullStates [1] == null) { // Set initial variables: tickNumber = receivedFullStates [0].tickNumber - interp / Time.fixedDeltaTime; lastTickLoaded = Mathf.FloorToInt(tickNumber); // This is an initial variable. Last tick loaded is to do with interp, so it starts off based on data recieved time sub interp currentTickDelta = 0; } else { currentTickDelta = (receivedFullStates [0].tickNumber - interp / Time.fixedDeltaTime) - tickNumber; // Doesn't edit tickNumber. } OperationNetwork.lastTickLoaded = Mathf.FloorToInt(receivedFullStates [0].tickNumber); } else { if (receivedFullStates[0] == null || gameStateTickNumber > receivedFullStates [0].tickNumber + ServerState.MAX_CHOKE_TICKS) { Debug.LogError("Choke is too high! " + gameStateTickNumber); // Ask for full resend: OperationView.RPC(null, "ResendTicks", OperationNetwork.ToServer); } isInOrder = false; // Hand this information over so lastReceivedPlayerState doesn't update either } } else { lastReceivedPlayerState = new GameState(data, index, length, lastReceivedPlayerState, false, receivedFullStates[0].tickNumber); // Since main gamestate is always read right before playerstate // Instantly run "interp" on this state, even though there it's just the one tick GameState.interp(lastReceivedPlayerState, null, 0, true, true); } index += length; // Includes the length from above already. if (OperationNetwork.isDemo) { OperationNetwork.currentByte += length; } return(index); }
public void ReadMessages() { int numData = 0; for (int i = 0; i < 250; i++) // Up to 250 messages read per tick // Receive messages: { int recHostId; int recConnectionId; int recChannelId; byte[] recBuffer = new byte[1500]; // Prepare for 1500. Warning on server is made at 1000 currently. Probably will have to adjust this one day. int bufferSize = 1500; int dataSize; byte error; NetworkEventType networkEvent = NetworkTransport.Receive(out recHostId, out recConnectionId, out recChannelId, recBuffer, bufferSize, out dataSize, out error); NetworkError networkError = (NetworkError)error; if (networkError != NetworkError.Ok) { Debug.LogError(string.Format("Error recieving event: {0} with recHostId: {1}, recConnectionId: {2}, recChannelId: {3}", networkError, recHostId, recConnectionId, recChannelId)); } switch (networkEvent) { case NetworkEventType.Nothing: return; case NetworkEventType.ConnectEvent: OperationNetwork.connected = true; Debug.LogError("We have connected! "); GameManager.InitialConnect(); break; case NetworkEventType.DataEvent: numData++; dataInRate += dataSize; Interp.shiftBuffer(previousDataInRate); Interp.shiftBuffer(previousDataInTimes); previousDataInRate [0] = dataSize; previousDataInTimes [0] = Time.time; if (OperationNetwork.initialConnected == 0) { if (recChannelId == reliableSequencedChannelId) { Player.myID = BitConverter.ToInt16(recBuffer, 0); OperationNetwork.initialConnected = 1; } else { // We send a RPC looking for a full game resend, if this is not a full game state: if (BitConverter.ToInt32(recBuffer, 2) >= 0) { OperationView.RPC(null, "ResendTicks", OperationNetwork.ToServer); } } } else { OperationNetwork.clientReceivedData(recBuffer); // Note that dataSize could be used as a way of trimming this. } break; case NetworkEventType.DisconnectEvent: Debug.LogError("Server Shut Down"); break; } } Debug.LogError("Missing Messages! Num Data Messages (/250): " + numData); }
public static IOperable <T> GetOperationType(OperationView opView) { var operationPair = operationsView.Where(e => e.Value == opView).ToList()[0]; return(operationPair.Key.operationCalculator); }
public DeleteCommand(OperationView opView) { this.opView = opView; isMatrixController = false; }