Exemplo n.º 1
0
        public async Task <HttpResponseMessage> BulkPost()
        {
            using (var cts = new CancellationTokenSource())
                using (cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout))
                {
                    var jsonCommandArray = await ReadJsonArrayAsync();

                    cts.Token.ThrowIfCancellationRequested();

                    var transactionInformation = GetRequestTransaction();
                    var commands =
                        (from RavenJObject jsonCommand in jsonCommandArray select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation)).ToArray();

                    Log.Debug(
                        () =>
                    {
                        if (commands.Length > 15) // this is probably an import method, we will input minimal information, to avoid filling up the log
                        {
                            return("\tExecuted "
                                   + string.Join(
                                       ", ", commands.GroupBy(x => x.Method).Select(x => string.Format("{0:#,#;;0} {1} operations", x.Count(), x.Key))));
                        }

                        var sb = new StringBuilder();
                        foreach (var commandData in commands)
                        {
                            sb.AppendFormat("\t{0} {1}{2}", commandData.Method, commandData.Key, Environment.NewLine);
                        }
                        return(sb.ToString());
                    });

                    var batchResult = Database.Batch(commands, cts.Token);
                    return(GetMessageWithObject(batchResult));
                }
        }
Exemplo n.º 2
0
        //Start new EVT from scratch
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Re-initialize some things that may have changed if you already opened a PAK
            evtPath               = "";
            pakPath               = "";
            bmdPath               = "";
            bmd                   = "";
            this.Text             = "EVTEditor";
            txt_MsgEditor.Enabled = false;
            evt                   = new EvtFile();
            //Add field command to EVT to start with
            var command = new Command();

            command.Type     = "Fd__";
            command.Time     = trackBar.Value;
            command.DataSize = 64;
            command.Data     = CommandDataFactory.Create(command.Type);
            evt.Commands.Add(command);
            //Add field object to EVT to start with
            var obj = new EvtObject();

            obj.Type = EvtObjectType.Field;
            evt.Objects.Add(obj);

            //Enable controls
            AddCommandToolStripMenuItem.Visible = true;
            trackBar.Enabled = true;

            //Enable datagridviews
            EVTSetup();
        }
Exemplo n.º 3
0
        private void Batch(IHttpContext context)
        {
            var jsonCommandArray = context.ReadJsonArray();

            var transactionInformation = GetRequestTransaction(context);
            var commands = (from RavenJObject jsonCommand in jsonCommandArray
                            select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation))
                           .ToArray();

            context.Log(log => log.Debug(() =>
            {
                if (commands.Length > 15)                // this is probably an import method, we will input minimal information, to avoid filling up the log
                {
                    return("\tExecuted " + string.Join(", ", commands.GroupBy(x => x.Method).Select(x => string.Format("{0:#,#} {1} operations", x.Count(), x.Key))));
                }

                var sb = new StringBuilder();
                foreach (var commandData in commands)
                {
                    sb.AppendFormat("\t{0} {1}{2}", commandData.Method, commandData.Key, Environment.NewLine);
                }
                return(sb.ToString());
            }));

            var batchResult = Database.Batch(commands);

            context.WriteJson(batchResult);
        }
        public async Task <HttpResponseMessage> BulkPost()
        {
            using (var cts = new CancellationTokenSource())
                using (cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout))
                {
                    RavenJArray jsonCommandArray;

                    try
                    {
                        jsonCommandArray = await ReadJsonArrayAsync();
                    }
                    catch (InvalidOperationException e)
                    {
                        Log.DebugException("Failed to deserialize document batch request.", e);
                        return(GetMessageWithObject(new
                        {
                            Message = "Could not understand json, please check its validity."
                        }, (HttpStatusCode)422)); //http code 422 - Unprocessable entity
                    }
                    catch (InvalidDataException e)
                    {
                        Log.DebugException("Failed to deserialize document batch request.", e);
                        return(GetMessageWithObject(new
                        {
                            e.Message
                        }, (HttpStatusCode)422)); //http code 422 - Unprocessable entity
                    }

                    cts.Token.ThrowIfCancellationRequested();

                    var transactionInformation = GetRequestTransaction();
                    var commands =
                        (from RavenJObject jsonCommand in jsonCommandArray select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation)).ToArray();

                    Log.Debug(
                        () =>
                    {
                        if (commands.Length > 15) // this is probably an import method, we will input minimal information, to avoid filling up the log
                        {
                            return("\tExecuted "
                                   + string.Join(
                                       ", ", commands.GroupBy(x => x.Method).Select(x => string.Format("{0:#,#;;0} {1} operations", x.Count(), x.Key))));
                        }

                        var sb = new StringBuilder();
                        foreach (var commandData in commands)
                        {
                            sb.AppendFormat("\t{0} {1}{2}", commandData.Method, commandData.Key, Environment.NewLine);
                        }
                        return(sb.ToString());
                    });

                    var batchResult = Database.Batch(commands, cts.Token);
                    return(GetMessageWithObject(batchResult));
                }
        }
Exemplo n.º 5
0
        //Add a command at the selected Time
        private void AddNewCommandTypeClickHandler(object sender, EventArgs e)
        {
            ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
            var command = new Command();

            command.Type = clickedItem.Name;
            command.Time = trackBar.Value;
            command.Data = CommandDataFactory.Create(clickedItem.Name);

            evt.Commands.Add(command);
            RefreshEVT();
        }
Exemplo n.º 6
0
        private void Batch(IHttpContext context)
        {
            var jsonCommandArray = context.ReadJsonArray();

            var transactionInformation = GetRequestTransaction(context);
            var commands = (from JObject jsonCommand in jsonCommandArray
                            select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation)).ToList();

            var batchResult = Database.Batch(commands);

            context.WriteJson(batchResult);
        }
Exemplo n.º 7
0
        //Update tabs based on currently selected Command
        private void TabControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl.TabPages.Count != 0)
            {
                TabPage tp = tabControl.SelectedTab;
                GridViewRefresh(dgv);
                GridViewRefresh(dgv2);
                tp.Controls.Add(dgv);
                tp.Controls.Add(dgv2);

                foreach (Command command in evt.Commands.Where(cmd => Convert.ToInt32(GetSubstringByString("[", "]", tabControl.SelectedTab.Text)) == evt.Commands.IndexOf(cmd)))
                {
                    //Update datagridview with command and command data properties
                    foreach (PropertyInfo prop in typeof(Command).GetProperties())
                    {
                        if (prop.Name != "Data")
                        {
                            dgv.Rows.Add(new string[] { $"{prop.Name}", $"{prop.GetValue(command, null)}" });
                        }
                        else
                        {
                            var cmdData = CommandDataFactory.Create(GetSubstringByString("[", "]", tabControl.SelectedTab.Text));
                            cmdData = command.Data;
                            var cmdDataType = cmdData.GetType();
                            foreach (PropertyInfo cmdDataProp in cmdDataType.GetProperties())
                            {
                                if (prop.Name != "Entries")
                                {
                                    dgv2.Rows.Add(new string[] { $"{cmdDataProp.Name}", $"{cmdDataProp.GetValue(cmdData, null)}" });
                                }
                            }
                        }
                    }

                    //Decompile and show BMD text if possible
                    if (File.Exists(bmdPath) && command.Type == "Msg_")
                    {
                        txt_MsgEditor.Enabled = true;
                        txt_MsgEditor.Text    = bmd;
                    }
                    else
                    {
                        txt_MsgEditor.Enabled = false;
                        txt_MsgEditor.Clear();
                    }
                }
            }
        }
Exemplo n.º 8
0
        //Update CommandData's property value in EVT to the changed cell's value
        private void UpdateEVTCommandData(object sender, DataGridViewCellEventArgs e)
        {
            //Narrow down the selected property in the evt so we can update it
            Command command = evt.Commands.Find(cmd => Convert.ToInt32(GetSubstringByString("[", "]", tabControl.SelectedTab.Text)) == evt.Commands.IndexOf(cmd));
            var     cmdData = CommandDataFactory.Create(GetSubstringByString("[", "]", tabControl.SelectedTab.Text));

            cmdData = command.Data;

            //Try to update value using the proper type
            PropertyInfo prop      = cmdData.GetType().GetProperty(dgv2.CurrentCell.OwningRow.Cells[0].Value.ToString());
            var          cellValue = dgv2.CurrentCell.Value;

            UpdateProperty(prop, cmdData, cellValue);

            //Update tabs and datagridview with new data
            BeginInvoke(new MethodInvoker(RefreshEVT));
        }
Exemplo n.º 9
0
        private void Batch(IHttpContext context)
        {
            var jsonCommandArray = context.ReadJsonArray();

            var transactionInformation = GetRequestTransaction(context);
            var commands = (from JObject jsonCommand in jsonCommandArray
                            select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation))
                           .ToArray();

            context.Log(log =>
            {
                if (log.IsDebugEnabled)
                {
                    foreach (var commandData in commands)
                    {
                        log.DebugFormat("\t{0} {1}", commandData.Method, commandData.Key);
                    }
                }
            });

            var batchResult = Database.Batch(commands);

            context.WriteJson(batchResult);
        }
Exemplo n.º 10
0
        public async Task <HttpResponseMessage> BulkPost()
        {
            using (var cts = new CancellationTokenSource())
                using (cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout))
                {
                    RavenJArray jsonCommandArray;

                    try
                    {
                        jsonCommandArray = await ReadJsonArrayAsync().ConfigureAwait(false);
                    }
                    catch (InvalidOperationException e)
                    {
                        if (Log.IsDebugEnabled)
                        {
                            Log.DebugException("Failed to read json documents batch.", e);
                        }
                        return(GetMessageWithObject(new
                        {
                            Message = "Could not understand json, please check its validity."
                        }, (HttpStatusCode)422)); //http code 422 - Unprocessable entity
                    }
                    catch (InvalidDataException e)
                    {
                        if (Log.IsDebugEnabled)
                        {
                            Log.DebugException("Failed to read json documents batch.", e);
                        }
                        return(GetMessageWithObject(new
                        {
                            e.Message
                        }, (HttpStatusCode)422)); //http code 422 - Unprocessable entity
                    }

                    cts.Token.ThrowIfCancellationRequested();

                    var transactionInformation = GetRequestTransaction();
                    var commands =
                        (from RavenJObject jsonCommand in jsonCommandArray
                         select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation))
                        .ToArray();

                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug(
                            () =>
                        {
                            if (commands.Length > 15) // this is probably an import method, we will input minimal information, to avoid filling up the log
                            {
                                return("\tExecuted "
                                       + string.Join(
                                           ", ", commands.GroupBy(x => x.Method).Select(x => string.Format("{0:#,#;;0} {1} operations", x.Count(), x.Key))));
                            }

                            var sb = new StringBuilder();
                            foreach (var commandData in commands)
                            {
                                sb.AppendFormat("\t{0} {1}{2}", commandData.Method, commandData.Key, Environment.NewLine);
                            }
                            return(sb.ToString());
                        });
                    }

                    //take "snapshots" of NextIndexingRound TaskCompletionSource's --> prevent a race condition
                    //between NextIndexingRound completion after the Batch() execution and waiting for it's completion in WaitForIndexesAsync()
                    var nextIndexingRoundsByIndexId = new Dictionary <int, Task>();
                    var existingIndexes             = Database.IndexStorage.GetAllIndexes().ToArray();
                    foreach (var index in existingIndexes)
                    {
                        nextIndexingRoundsByIndexId.Add(index.indexId, index.NextIndexingRound);
                    }

                    var batchResult = Database.Batch(commands, cts.Token);

                    var writeAssurance = GetHeader("Raven-Write-Assurance");
                    if (writeAssurance != null)
                    {
                        await WaitForReplicationAsync(writeAssurance, batchResult.LastOrDefault(x => x.Etag != null)).ConfigureAwait(false);
                    }

                    var waitIndexes = GetHeader("Raven-Wait-Indexes");
                    if (waitIndexes != null)
                    {
                        //take care to pass existing indexes, in case any index is added or removed between Database.Batch() and WaitForIndexesAsync()
                        //(essentially create "snapshot" of indexes just before the Batch() execution)
                        await WaitForIndexesAsync(waitIndexes, nextIndexingRoundsByIndexId, existingIndexes, batchResult).ConfigureAwait(false);
                    }

                    return(GetMessageWithObject(batchResult));
                }
        }