Ejemplo n.º 1
0
 public int CreateRunLog(RunLog log, List <int> prods)
 {
     db.RunLog.InsertOnSubmit(log);
     db.SubmitChanges();
     LinkRunLogToProducts(log, prods);
     return(log.RunLogID);
 }
Ejemplo n.º 2
0
 public int Insert(RunLog entityToInsert)
 {
     using (Conn)
     {
         return(Conn.Insert <int>(entityToInsert));
     }
 }
        public RunLogExplorerForm(RunLog log, string fileName)
            : this()
        {
            this.runLog = log;

            this.fileNameLabel.Text = fileName;

            if (log == null)
            {
                return;
            }

            string effectiveName;

            if (log.RunSequence.SequenceName == "" || log.RunSequence.SequenceName == null)
            {
                effectiveName = "Unnamed Sequence";
            }
            else
            {
                effectiveName = log.RunSequence.SequenceName;
            }

            this.Text = effectiveName + " Iteration #" + log.RunSequence.ListIterationNumber + "/" + log.RunSequence.Lists.iterationsCount() + " Time: " + log.RunTime.ToString() + " - Elgin";
            this.seqNameLabel.Text = log.RunSequence.SequenceName;
            this.seqDesc.Text      = log.RunSequence.SequenceDescription;

            this.timeLabel.Text = log.RunTime.ToString();
            this.sequenceGrid.SelectedObject = log.RunSequence;
            this.settingsGrid.SelectedObject = log.RunSettings;
        }
 // Define the event handlers.
 private void OnCreated(object source, FileSystemEventArgs e)
 {
     addEventLogText("Reading file... ");
     while (IsFileLocked(e.FullPath))
     {
     }                                   // Do nothing while file is being written by cicero
     Debug.WriteLine("File is probably unlocked");
     // If the file is ready to read,
     if (!IsFileLocked(e.FullPath))
     {
         Debug.WriteLine("File is defo unlocked");
         // Specify what is done when a file is changed, created, or deleted.
         Debug.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
         RunLog rlg = Common.loadBinaryObjectFromFile(e.FullPath) as RunLog;
         if (BreadboardSettings.ContainsKey("SnippetFolder"))
         {
             string destination = BreadboardSettings["SnippetFolder"];
             writeVariablesToAPI(rlg);
             writeVariablesToFile(rlg, destination);
         }
         else
         {
             MessageBox.Show("Please enter a Snippet Folder");
         }
     }
 }
 /// <summary>
 /// Return a string that contains either the variable value in string form for the given column and runlog,
 /// or an appropriate "Undefined" or "Unassigned" string if the runlog doesn't contain a variable of the intended name or id,
 /// or if no name or id is assigned to this column.
 /// </summary>
 /// <param name="variableColumn"></param>
 /// <param name="rlg"></param>
 /// <returns></returns>
 private string getVariableString(DataGridViewColumn variableColumn, RunLog rlg)
 {
     if (variableSelections.ContainsKey(variableColumn))
     {
         if (variableSelections[variableColumn].usingName)
         {
             Variable var = rlg.RunSequence.getVariable(variableSelections[variableColumn].name);
             if (var != null)
             {
                 return(var.VariableValue.ToString());
             }
             else
             {
                 return("Undefined");
             }
         }
         else
         {
             Variable var = rlg.RunSequence.getVariable(variableSelections[variableColumn].id);
             if (var != null)
             {
                 return(var.VariableValue.ToString());
             }
             else
             {
                 return("Undefined");
             }
         }
     }
     else
     {
         return("Unassigned");
     }
 }
Ejemplo n.º 6
0
 public int CreateOrder(RunLog run, List <int> products)
 {
     log.LogStart();
     SERVDataContract.DbLinq.RunLog runLog = new SERVDataContract.DbLinq.RunLog();
     runLog.CallDateTime               = DateTime.Now;
     runLog.CallFromLocationID         = run.CallFromLocationID;
     runLog.CollectionLocationID       = run.CollectionLocationID;
     runLog.ControllerMemberID         = 0;     //TODO System COntroller Id;
     runLog.CreateDate                 = DateTime.Now;
     runLog.CreatedByUserID            = run.CreatedByUserID;
     runLog.DeliverToLocationID        = run.DeliverToLocationID;
     runLog.DutyDate                   = run.DutyDate;
     runLog.FinalDestinationLocationID = run.FinalDestinationLocationID;
     runLog.OriginLocationID           = run.OriginLocationID;
     runLog.Urgency          = run.Urgency;
     runLog.Notes            = run.Notes;
     runLog.Boxes            = products.Count;
     runLog.CallerNumber     = run.CallerNumber.Trim().Replace(" ", "");
     runLog.CallerExt        = run.CallerExt.Trim().Replace(" ", "");
     runLog.RiderMemberID    = null;
     runLog.CollectDateTime  = null;
     runLog.DeliverDateTime  = null;
     runLog.HomeSafeDateTime = null;
     runLog.VehicleTypeID    = null;
     return(SERVDALFactory.Factory.RunLogDAL().CreateRunLog(runLog, products));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Add run log to database.
        /// </summary>
        /// <param name="runLogFileName"></param>
        /// <param name="log"></param>
        public void addRunLog(string runLogFileName, RunLog log)
        {
            if (conn == null)
            {
                throw new RunLogDatabaseException("Handler not connected to database, unable to add run log.");
            }

            MySqlCommand cmdq = new MySqlCommand(@"SELECT path FROM filelist_runloginfo WHERE path=@path", this.conn);

            cmdq.Parameters.AddWithValue("@path", runLogFileName);

            object result = cmdq.ExecuteScalar();

            if (result == null)
            {
                MySqlCommand cmd = new MySqlCommand(@"INSERT IGNORE INTO filelist_runloginfo 
                         (path, loc_key, time, sequencepath, listiterationnumber, liststarttime, sequenceduration, description) 
                         VALUES (@path, @loc_key, @time, @sequencepath, @listiterationnumber, @liststarttime, @sequenceduration, @description)", this.conn);

                cmd.Parameters.AddWithValue("@path", runLogFileName);
                cmd.Parameters.AddWithValue("@loc_key", "default");
                cmd.Parameters.AddWithValue("@time", log.RunTime);
                cmd.Parameters.AddWithValue("@sequencepath", log.SequenceFileName);
                cmd.Parameters.AddWithValue("@listiterationnumber", log.RunSequence.ListIterationNumber);
                cmd.Parameters.AddWithValue("@liststarttime", log.ListStartTime);
                cmd.Parameters.AddWithValue("@sequenceduration", log.RunSequence.SequenceDuration);
                cmd.Parameters.AddWithValue("@description", log.RunSequence.SequenceDescription);

                cmd.ExecuteNonQuery();

                this.addVariables(runLogFileName, log);
            }
        }
Ejemplo n.º 8
0
 public int Delete(RunLog entityToInsert)
 {
     using (Conn)
     {
         return(Conn.Delete(entityToInsert));
     }
 }
Ejemplo n.º 9
0
 public void ExecuteExecutionPlan(List <DesignerItemBase> executionPlan, RunLog runLog)
 {
     foreach (var item in executionPlan)
     {
         ExecuteItem(item, runLog);
     }
 }
Ejemplo n.º 10
0
        private void ExecutePackageFlow()
        {
            if (mainFlowContent.Content == null)
            {
                return;
            }

            SaveDiagram();

            packageIsRunning = true;
            FlowManager flowManager = new FlowManager(this.Connections, this.moduleLoader.Modules, this.Package);

            FlowDesign.FlowDesigner mainFlowDesigner = mainFlowContent.Content as FlowDesign.FlowDesigner;
            mainFlowDesigner.MyDesigner.ExecuteFlow(flowManager);
            flowManager.DesignerItemStart += flowManager_ProgressReport;
            flowManager.ProgressReport    += flowManager_ProgressReport;
            flowManager.DesignerItemStop  += flowManager_ProgressReport;
            flowManager.RunCompleted      += flowManager_RunCompleted;
            AdditionalInfosArea.Height     = new GridLength(120);

            RunLog runLog = new RunLog();

            this.Package.ParentProject.RunLogs.Add(runLog);
            flowManager.Run(runLog);
        }
Ejemplo n.º 11
0
        public void SetAcceptedDateTime(int runLogId)
        {
            RunLog l = (from rl in db.RunLog where rl.RunLogID == runLogId select rl).FirstOrDefault();

            l.AcceptedDateTime = DateTime.Now;
            db.SubmitChanges();
        }
Ejemplo n.º 12
0
 public int Update(RunLog entityToInsert)
 {
     using (Conn)
     {
         return(Conn.Update(entityToInsert));
     }
 }
Ejemplo n.º 13
0
        private void LinkRunLogToProducts(RunLog log, List <int> prods)
        {
            Dictionary <int, int> prodD = new Dictionary <int, int>();

            foreach (int p in prods)
            {
                if (prodD.ContainsKey(p))
                {
                    prodD[p] = prodD[p] + 1;
                }
                else
                {
                    prodD.Add(p, 1);
                }
            }
            foreach (int p in prodD.Keys)
            {
                RunLogProduct rlp = new RunLogProduct();
                rlp.ProductID    = p;
                rlp.RunLogID     = log.RunLogID;
                rlp.Quantity     = prodD[p];
                log.Description += string.Format("{0} x {1} ", prodD[p], (from prod in db.Product
                                                                          where prod.ProductID == p
                                                                          select prod).FirstOrDefault().Product1);
                db.RunLogProduct.InsertOnSubmit(rlp);
            }
            db.SubmitChanges();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 保存指定设备ID的对应表数据集,使用前创建DeviceTableInfo对象,并复制DevId属性
        /// </summary>
        /// <param name="deviceTableInfo"></param>
        /// <returns></returns>
        public bool SaveTableToDB(DeviceTableInfo deviceTableInfo)
        {
            if (deviceTableInfo == null)
            {
                return(false);
            }
            if (deviceTableInfo.TableList.Count <= 0)
            {
                return(false);
            }
            StreamWriter recWriter = null;

            try
            {
                string filePath = this.GetFilePath(deviceTableInfo.DevId.ToString());
                recWriter = new StreamWriter(filePath, true);
                //recWriter.BaseStream.Seek(0, SeekOrigin.End);
                foreach (TableInfo recInfo in deviceTableInfo.TableList.Values)
                {
                    string recInfoJson = JsonConvert.SerializeObject(recInfo);
                    recWriter.WriteLine(recInfoJson);
                    recWriter.Flush();
                }
                recWriter.Close();
                return(true);
            }
            catch (Exception e)
            {
                RunLog.Log(string.Format("保存楼层对应表失败,设备ID:{0},错误:{1}", deviceTableInfo.DevId, e.Message));
                return(false);
            }
        }
        /// <summary>
        /// Add run log to database.
        /// </summary>
        /// <param name="runLogFileName"></param>
        /// <param name="log"></param>
        public void addRunLog(string runLogFileName, RunLog log)
        {
            if (conn == null)
            {
                throw new RunLogDatabaseException("Handler not connected to database, unable to add run log.");
            }

            MySqlCommand cmdq = new MySqlCommand(@"SELECT path FROM filelist_runloginfo WHERE path=@path", this.conn);
            cmdq.Parameters.AddWithValue("@path", runLogFileName);

            object result = cmdq.ExecuteScalar();

            if (result == null)
            {
                MySqlCommand cmd = new MySqlCommand(@"INSERT IGNORE INTO filelist_runloginfo
                         (path, loc_key, time, sequencepath, listiterationnumber, liststarttime, sequenceduration, description)
                         VALUES (@path, @loc_key, @time, @sequencepath, @listiterationnumber, @liststarttime, @sequenceduration, @description)", this.conn);

                cmd.Parameters.AddWithValue("@path", runLogFileName);
                cmd.Parameters.AddWithValue("@loc_key", "default");
                cmd.Parameters.AddWithValue("@time", log.RunTime);
                cmd.Parameters.AddWithValue("@sequencepath", log.SequenceFileName);
                cmd.Parameters.AddWithValue("@listiterationnumber", log.RunSequence.ListIterationNumber);
                cmd.Parameters.AddWithValue("@liststarttime", log.ListStartTime);
                cmd.Parameters.AddWithValue("@sequenceduration", log.RunSequence.SequenceDuration);
                cmd.Parameters.AddWithValue("@description", log.RunSequence.SequenceDescription);

                cmd.ExecuteNonQuery();

                this.addVariables(runLogFileName, log);
            }
        }
        /// <summary>
        /// 获取命令报文
        /// </summary>
        /// <param name="devId"></param>
        /// <param name="commandWord"></param>
        /// <param name="sendData"></param>
        /// <returns></returns>
        protected string GetWriteReport(int devId, string cmdWord, string sendData)
        {
            string strCmdData = string.Empty;

            int ctrlNo  = devId;
            int groupID = 0;

            if (devId == 0)
            {
                groupID = 0;
                ctrlNo  = 0;
            }
            else
            {
                groupID = ((ctrlNo - 1) / 0xFF) + 1;
                ctrlNo  = (ctrlNo % 0xFF);
                //解决255的倍数问题
                if (ctrlNo == 0)
                {
                    ctrlNo = 0xFF;
                }
            }

            //设备组号
            string strDevGroupID = StrUtils.IntToHex(groupID, 2);
            //设备地址
            string strDevCtrlID = StrUtils.IntToHex(ctrlNo, 2);
            //设备类型
            string strDevType = StrUtils.IntToHex((int)this.DevType, 2);
            //流水号
            string strCmdSerialNo = this.GetCmdNumber();
            //命令字
            string strCmdWord = cmdWord;

            //生成固定部分的命令报文
            strCmdData = strDevGroupID + strDevCtrlID + StrUtils.IntToHex((int)DevType, 2) + strCmdSerialNo + strCmdWord + sendData;
            // 计算校验位
            string strXorCheck = StrUtils.GetXORCheck(strCmdData);

            RunLog.Log("************CheckXor strCmdData : " + strCmdData);
            // 命令报文+校验位
            strCmdData = strCmdData + strXorCheck;

            // 格式化命令报文,如果报文中出现>= 0xF0的数据,则做特定处理
            // 特别注意:校验位也需检测

            strCmdData = CommandProcesserHelper.AddF0Escape(strCmdData);

            RunLog.Log("************ AddF0Escape strCmdData :" + strCmdData);


            // 组合报文,加上起始字和结束字
            strCmdData = CommandProcesserHelper.CMD_START_FLAG + strCmdData + CommandProcesserHelper.CMD_END_FLAG;

            IsDownLoadDevLength = strCmdData;
            RunLog.Log(strCmdData);
            return(strCmdData);
        }
Ejemplo n.º 17
0
        private void lbLogs_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            RunLog runLog = ((ListBox)sender).SelectedItem as RunLog;

            if (runLog != null && RunLogDblClicked != null)
            {
                RunLogDblClicked(runLog, e);
            }
        }
Ejemplo n.º 18
0
        public void Execute(RunLog runLog)
        {
            moduleExecution = new ModuleExecution(objectResolver, runLog, parentItemLog);

            var targetItems   = this.FlowGraph.DesignerItems.Where(t => t.ModuleDescription.Attributes.ModuleType == ModuleType.Target).ToList();
            var executionPlan = CreateExecutionPlan(targetItems);

            ExecuteExecutionPlan(executionPlan, runLog);
        }
Ejemplo n.º 19
0
        public LogOverview(RunLog runLog, List <ModuleDescription> moduleDescriptions)
        {
            InitializeComponent();
            this.DataContext          = this.runLog = runLog;
            this.moduleDescriptions   = moduleDescriptions;
            this.LogLeader.Visibility = System.Windows.Visibility.Hidden;

            InitializeLogMenu();
        }
Ejemplo n.º 20
0
        public void EndToEndAnalysisWithNoIssues()
        {
            RunLog runLog = AnalyzeFile(this.GetType().Assembly.Location);

            int issueCount = 0;

            SarifHelpers.ValidateRunLog(runLog, (issue) => { issueCount++; });
            Assert.Equal(1, issueCount);
        }
Ejemplo n.º 21
0
        public static void ValidateRunLog(RunLog runLog, Action <Result> resultAction)
        {
            ValidateToolInfo(runLog.ToolInfo);

            foreach (Result result in runLog.Results)
            {
                resultAction(result);
            }
        }
Ejemplo n.º 22
0
        public static void ValidateRunLog(RunLog runLog, Action <Issue> issueAction)
        {
            ValidateToolInfo(runLog.ToolInfo);

            foreach (Issue issue in runLog.Issues)
            {
                issueAction(issue);
            }
        }
Ejemplo n.º 23
0
        static async Task RunPackage(Package package, ObservableCollection <ConnectionConfigurationBase> connections, List <ModuleDescription> modules, Type[] extraTypes)
        {
            FlowManager flowManager = new FlowManager(connections, modules, package);

            flowManager.ProgressReport += flowManager_ProgressReport;

            RunLog runLog = new RunLog();
            await flowManager.Run(runLog);
        }
Ejemplo n.º 24
0
        public void EndToEndAnalysisWithDefaultRules()
        {
            AnalyzeCommand.DefaultRuleAssemblies = null;
            RunLog runLog = AnalyzeFile(this.GetType().Assembly.Location);

            int issueCount = 0;

            SarifHelpers.ValidateRunLog(runLog, (issue) => { issueCount++; });
            Assert.Equal(17, issueCount);
        }
Ejemplo n.º 25
0
        } /* RunLogAddMsg */

        private void  RunLogMsgQueueFlush()
        {
            String msg = runLogMsgQueue.GetNextMsg();

            while (msg != null)
            {
                RunLog.AppendText(msg);
                msg = runLogMsgQueue.GetNextMsg();
            }
        } /* RunLogMsgQueueFlush */
Ejemplo n.º 26
0
        public void LogProcessStart()
        {
            var entity = new RunLog()
            {
                Date = DateTime.Now,
                Status = RunLogStatus.Started.ToString()
            };

            repo.Add(entity);
        }
Ejemplo n.º 27
0
 public void LevelStart(int level, int millisecondsOffset = 0)
 {
     DoAfterUpdate(() =>
     {
         var realTime = _speedrunStopwatch.RealTime + TimeSpan.FromMilliseconds(millisecondsOffset);
         var gameTime = _beatTimer.Time.AddOffset(millisecondsOffset);
         var time     = new SpeedrunTime(realTime, gameTime);
         RunLog.LevelStart(level, time);
     });
 }
Ejemplo n.º 28
0
 /// <summary>
 /// 关闭的时候写log
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         RunLog.WriteLog(LogBoxText);
     }
     catch (Exception ex)
     {
         logBox.Items.Add(ex.Message);
     }
 }
Ejemplo n.º 29
0
        public void DeleteRunLog(int runLogID)
        {
            RunLog d = Get(runLogID);

            foreach (RunLogProduct rlp in d.RunLogProduct)
            {
                db.RunLogProduct.DeleteOnSubmit(rlp);
            }
            db.RunLog.DeleteOnSubmit(d);
            db.SubmitChanges();
        }
        private void OutputSarifRulesMetada(string outputFilePath, ImmutableArray <IRuleDescriptor> skimmers, ImmutableArray <IOptionsProvider> options)
        {
            var log = new ResultLog();

            log.Version = SarifVersion.ZeroDotFour;

            // The SARIF spec currently requires an array
            // of run logs with at least one member
            log.RunLogs = new List <RunLog>();

            var runLog = new RunLog();

            runLog.ToolInfo = new ToolInfo();

            runLog.ToolInfo.InitializeFromAssembly(this.GetType().Assembly, Prerelease);
            runLog.Results = new List <Result>();

            log.RunLogs.Add(runLog);
            runLog.ToolInfo.RuleInfo = new List <RuleDescriptor>();

            SortedDictionary <int, RuleDescriptor> sortedRuleDescriptors = new SortedDictionary <int, RuleDescriptor>();

            foreach (IRuleDescriptor descriptor in skimmers)
            {
                var ruleDescriptor = new RuleDescriptor();

                ruleDescriptor.Id               = descriptor.Id;
                ruleDescriptor.Name             = descriptor.Name;
                ruleDescriptor.Options          = descriptor.Options;
                ruleDescriptor.HelpUri          = descriptor.HelpUri;
                ruleDescriptor.Properties       = descriptor.Properties;
                ruleDescriptor.FullDescription  = descriptor.FullDescription;
                ruleDescriptor.FormatSpecifiers = descriptor.FormatSpecifiers;

                ruleDescriptor.ShortDescription = ruleDescriptor.ShortDescription;

                int numericId = GetIdIntegerSuffix(ruleDescriptor.Id);

                sortedRuleDescriptors[numericId] = ruleDescriptor;
            }

            foreach (RuleDescriptor ruleDescriptor in sortedRuleDescriptors.Values)
            {
                runLog.ToolInfo.RuleInfo.Add(ruleDescriptor);
            }

            var settings = new JsonSerializerSettings()
            {
                ContractResolver = SarifContractResolver.Instance,
                Formatting       = Formatting.Indented,
            };

            File.WriteAllText(outputFilePath, JsonConvert.SerializeObject(log, settings));
        }
Ejemplo n.º 31
0
        } /* RunLogAddMsg */

        private void  RunLogMsgQueueFlush()
        {
            String msg = runLogMsgQueue.GetNextMsg();

            while (msg != null)
            {
                RunLog.AppendText(msg + "\n");
                backGroundLog.Writeln(msg);
                msg = runLogMsgQueue.GetNextMsg();
            }
        } /* RunLogMsgQueueFlush */
Ejemplo n.º 32
0
        /*public void StopTimer()
         * {
         *      DoAfterUpdate(() =>
         *      {
         *              _visualFreeze = false;
         *              _beatTimer.PauseTimer();
         *      });
         * }*/

        public void ResetTimer()
        {
            _speedrunStopwatch.Reset();
            _beatTimer.ResetTimer();
            _visualFreeze = false;
            RunLog        = new RunLog();

            if (LiveSplitSyncEnabled)
            {
                _liveSplitSync.Reset();
            }
        }
        private void addVariables(string fileName, RunLog log)
        {
            foreach (Variable var in log.RunSequence.Variables)
            {
                MySqlCommand cmd = new MySqlCommand(@"INSERT INTO filelist_variablevalue
                       (name, value, runlog_id)
                       VALUES (@name, @value, @runlog)", this.conn);

                cmd.Parameters.AddWithValue("@name", var.VariableName);
                cmd.Parameters.AddWithValue("@value", var.VariableValue);
                cmd.Parameters.AddWithValue("@runlog", fileName);

                cmd.ExecuteNonQuery();
            }
        }
Ejemplo n.º 34
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (stopped)
            {
                dgvStats.Rows.Clear();
                chPlots.Series.Clear();
                blockedSoFar = 0;
                StaticRandom.Init(seed);
                Simulator.Reset();

                #region UI Initialization
                btnStart.Text = "Stop";
                cbLogY.Enabled = false;
                stopped = stopRequest = exitRequest = logIncConsidered = false;

                // Set up plots
                chPlots.Series.Add(new Series(cbThirsty.Text));
                chPlots.Series.Add(new Series(cbm.Text));
                chPlots.Series.Add(new Series(cbb.Text));
                chPlots.Series.Add(new Series(cbN.Text));
                chPlots.Series.Add(new Series(cbDistMessageCount.Text));
                chPlots.Series.Add(new Series(cbEmailCount.Text));
                chPlots.Series.Add(new Series(cbTime.Text));
                chPlots.Series.Add(new Series(cbmm.Text));
                chPlots.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray;
                chPlots.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray;
                chPlots.ChartAreas[0].AxisX.LabelStyle.Font = plotScreenFont;
                chPlots.ChartAreas[0].AxisY.LabelStyle.Font = plotScreenFont;
                chPlots.ChartAreas[0].AxisX.TitleFont = plotScreenFont;
                chPlots.ChartAreas[0].AxisY.TitleFont = plotScreenFont;
                chPlots.Legends[0].Font = plotScreenFont;
                chPlots.Legends[0].IsDockedInsideChartArea = true;
                chPlots.ApplyPaletteColors();

                foreach (var series in chPlots.Series)
                {
                    series.BorderWidth = plotThickness;
                    series.ChartType = SeriesChartType.Line;
                    series.MarkerSize = plotMarkerSize;
                }
                chPlots.Series[0].MarkerStyle = MarkerStyle.Square;
                chPlots.Series[1].MarkerStyle = MarkerStyle.Triangle;
                chPlots.Series[2].MarkerStyle = MarkerStyle.Diamond;
                chPlots.Series[3].MarkerStyle = MarkerStyle.Circle;

                chPlots.Series[5].Color = chPlots.Series[2].Color;
                chPlots.Series[5].MarkerStyle = MarkerStyle.Circle;

                chPlots.Series[6].Color = chPlots.Series[2].Color;
                chPlots.Series[6].MarkerStyle = MarkerStyle.Circle;
                chPlots.Series[7].Color = chPlots.Series[3].Color;
                chPlots.Series[7].MarkerStyle = MarkerStyle.Square;
                UpdatePlots();
                Application.DoEvents();
                #endregion

                int n = (int)Math.Pow(2, tbUserCount.Value);
                int t_max = rbMultipleRuns.Checked ? t_max = tbBadCountMax.Value : tbCorruptCount.Value + 1;

                for (int t = tbCorruptCount.Value; t < t_max && !stopRequest; t++)
                {
                    // Create the distributors
                    var dists = new List<Distributor>();

                    for (int i = 1; i < tbDistCount.Value; i++)
                        dists.Add(new Distributor());

                    var leader = new LeaderDistributor(dists.Select(d => d.Id).ToList(),
                        rbBnb.Checked ? DistributeAlgorithm.BallsAndBins : DistributeAlgorithm.Matrix, seed);
                    dists.Insert(0, leader);

                    var distIds = dists.Select(d => d.Pseudonym).ToList();

                    // Add honest users
                    for (int i = 0; i < n - t; i++)
                        new User(distIds);

                    // Add corrupt users
                    var attackModel = AttackModel.Aggressive;
                    if (rbPrudent.Checked)
                        attackModel = AttackModel.Prudent;
                    else if (rbStochastic.Checked)
                        attackModel = AttackModel.Stochastic;

                    var censor = new Censor(dists, attackModel, tbStochastic.Value / 40.0, seed);
                    censor.AddCorruptUsers(t);

                    // Create a sufficient number of bridges
                    repeatCount = tbC.Value == 0 ? 1 : tbC.Value * (int)Math.Ceiling(Math.Log(n, 2));
                    var bridges = new List<Bridge>();
                    for (int i = 0; i < (3.2 * t + 32) * repeatCount; i++)    // See the bridge cost lemma in the paper
                        bridges.Add(new Bridge(distIds));

                    leader.BridgePseudonyms = bridges.Select(b => b.Pseudonym).ToList();
                    runLog = new RunLog();
                    leader.OnRoundEnd += OnRoundEnd;

                    leader.Run(repeatCount);

                    logIncConsidered = cbLogY.Checked;
                    cbLogY.Enabled = true;
                    if (rbMultipleRuns.Checked)
                    {
                        // Add one point to the plot for this run for each plot
                        chPlots.Series[cbTime.Text].Points.AddXY(t, runLog.RoundsCount);

                        var N = runLog.Sum(r => r.BlockedCount) + runLog.Last().BridgeCount;
                        chPlots.Series[cbmm.Text].Points.AddXY(t, N);
                    }
                }

                //for (int x = 8; x < 12 && !stopRequest; x++)
                //{
                //    blockedSoFar = 0;
                //    Simulator.Reset();

                //    int n = (int)Math.Pow(2, x);
                //    int t = n / 2;
                //    // Create the distributors
                //    var dists = new List<Distributor>();

                //    for (int i = 1; i < tbDistCount.Value; i++)
                //        dists.Add(new Distributor());

                //    var leader = new LeaderDistributor(dists.Select(d => d.Id).ToList(),
                //        rbBnb.Checked ? DistributeAlgorithm.BallsAndBins : DistributeAlgorithm.Matrix, seed);
                //    dists.Insert(0, leader);

                //    var distIds = dists.Select(d => d.Pseudonym).ToList();

                //    // Add honest users
                //    for (int i = 0; i < n - t; i++)
                //        new User(distIds);

                //    // Add corrupt users
                //    var attackModel = AttackModel.Aggressive;
                //    if (rbPrudent.Checked)
                //        attackModel = AttackModel.Prudent;
                //    else if (rbStochastic.Checked)
                //        attackModel = AttackModel.Stochastic;

                //    var censor = new Censor(dists, attackModel, tbStochastic.Value / 40.0, seed);
                //    censor.AddCorruptUsers(t);

                //    // Create a sufficient number of bridges
                //    repeatCount = tbC.Value == 0 ? 1 : tbC.Value * (int)Math.Ceiling(Math.Log(n, 2));
                //    var bridges = new List<Bridge>();
                //    for (int i = 0; i < (8 * t - 2) * repeatCount; i++)
                //        bridges.Add(new Bridge(distIds));

                //    leader.BridgePseudonyms = bridges.Select(b => b.Pseudonym).ToList();
                //    runLog = new RunLog();
                //    leader.OnRoundEnd += OnRoundEnd;

                //    leader.Run(repeatCount);

                //    logIncConsidered = cbLogY.Checked;
                //    cbLogY.Enabled = true;

                //    chPlots.Series[cbEmailCount.Text].Points.AddXY(n, (double)runLog.Sum(r => r.EmailCount) / n);

                //}

                //chPlots.Series[cbEmailCount.Text].Points.AddXY(32, 5);
                //chPlots.Series[cbEmailCount.Text].Points.AddXY(64, 10);
                //chPlots.Series[cbEmailCount.Text].Points.AddXY(128, 30);
                //chPlots.Series[cbEmailCount.Text].Points.AddXY(256, 60);
                //chPlots.Series[cbEmailCount.Text].Points.AddXY(512, 90);
                //chPlots.Series[cbEmailCount.Text].Points.AddXY(1024, 126);
                //chPlots.Series[cbEmailCount.Text].Points.AddXY(2048, 168);
                //chPlots.Series[cbEmailCount.Text].Points.AddXY(4096, 210);
            }
            else stopRequest = true;

            btnStart.Text = "Start";
            stopped = true;

            if (exitRequest)
                Close();
        }
Ejemplo n.º 35
0
        public static void ValidateRunLog(RunLog runLog, Action<Issue> issueAction)
        {
            ValidateToolInfo(runLog.ToolInfo);

            foreach (Issue issue in runLog.Issues) { issueAction(issue); }
        }
Ejemplo n.º 36
0
        public static void ValidateRunLog(RunLog runLog, Action<Result> resultAction)
        {
            ValidateToolInfo(runLog.ToolInfo);

            foreach (Result result in runLog.Results) { resultAction(result); }
        }