/// <summary> /// Step1 Button: Open Folder. /// </summary> private void Button_Step1_Open_OnClick(object sender, RoutedEventArgs e) { var fd = new FolderBrowserDialog { RootFolder = Environment.SpecialFolder.Desktop }; var dr = fd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { this.TextBox_Step1_Open.Text = fd.SelectedPath; MPController.CurrentTransaction.ProcessLocalPath = null; MPController.CurrentTransaction.BOVector = new List <Dictionary <string, string> >(); MPController.LoadProcessFromDirectory(this.TextBox_Step1_Open.Text); var boList = MPController.GetBOList(); this.ComboBox_Step1_MainBO.Items.Clear(); this.ListBox_Step1_BO.Items.Clear(); if (boList != null) { foreach (var boName in boList) { this.ComboBox_Step1_MainBO.Items.Add(boName); this.ListBox_Step1_BO.Items.Add(boName); } if (this.ComboBox_Step1_MainBO.Items.Count > 0) { this.ComboBox_Step1_MainBO.SelectedIndex = 0; } } } else { return; } }
public void Init(short count) { for (int i = 0; i < count; i++) { MPController mp = new MPController(CONTROLLER_MODE.FIFO) { Name = "MP" + i.ToString(), }; Thread thr = new Thread(mp.Simulator) { IsBackground = true, Name = mp.Name }; mp.RequestEvent += OnRequest; mp.ChangeEvent += OnStatusChanged; mp.ExecuteEvent += OnExecuted; MPPool.Add(mp); ThreadPool.Add(thr); thr.Start(); } //CommandList.Enqueue(new COMMAND(1, COMMAND_TYPE.CACHE)); //CommandList.Enqueue(new COMMAND(2, COMMAND_TYPE.CACHE)); CommandList.Enqueue(new COMMAND(1, COMMAND_TYPE.NON_CACHE)); ModulesIsReady = true; }
/// <summary> /// Step1 Button: Next. /// </summary> private void Button_Step1_Next_OnClick(object sender, RoutedEventArgs e) { if (this.ComboBox_Step1_Processes.SelectedIndex == 0) // new process { if (this.ListBox_Step1_BO.Items.Count == 0) { MessageBox.Show(@"A process should contain at lease one BO"); return; } if (this.ComboBox_Step1_MainBO.SelectedIndex == -1) { MessageBox.Show(@"There must have a main BO"); return; } var npf = new ProcessNameForm(); npf.ShowDialog(); if (npf.ProcessName == null) { return; } // create new process var pid = MPController.CreateProcess(npf.ProcessName, this.ComboBox_Step1_MainBO.SelectedItem.ToString().Trim()); if (String.IsNullOrEmpty(pid)) { MessageBox.Show(@"Failed to create new process"); return; } MPController.CurrentTransaction.ProcessName = npf.ProcessName; MPController.CurrentTransaction.ProcessPID = pid; var BRList = new List <string>(); // upload BO Content foreach (var boDict in MPController.CurrentTransaction.BOVector) { var retKVP = MPController.UploadBO(boDict["bo_name"], boDict["bo_content"]).First(); boDict["boid"] = retKVP.Key; var response = JsonConvert.DeserializeObject <StdResponseEntity>(retKVP.Value); var responseDict = ReturnDataHelper.DecodeList(response); BRList.AddRange(responseDict.Select(br => br.ToString())); } MPController.CurrentTransaction.BusinessRoleList = new HashSet <string>(); foreach (var br in BRList) { MPController.CurrentTransaction.BusinessRoleList.Add(br); } } else // exist process { if (this.ComboBox_Step1_MainBO.Items.Count == 0) { MessageBox.Show(@"There must be a Main BO"); return; } MPController.CurrentTransaction.ProcessName = this.ComboBox_Step1_Processes.SelectedItem.ToString(); MPController.CurrentTransaction.ProcessPID = GlobalContext.Current_Ren_Process_List[this.ComboBox_Step1_Processes.SelectedIndex - 1]["pid"]; } this.tabControl.SelectedIndex += 1; }
/// <summary> /// Step2: Refresh Preivew Mappings Listbox. /// </summary> private void RefreshPreviewMappings() { this.ListBox_Step2_PreviewMap.Items.Clear(); foreach (var mapKVP in MPController.CurrentTransaction.Mappings) { var resourceType = MPController.GetResourceTypeByGid(mapKVP.Value); var resourceStr = ""; DataRow dr; switch (resourceType) { case ResourceType.Human: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["human"], mapKVP.Value); resourceStr = String.Format("[H] {0}: {1} {2}", dr["PersonId"], dr["FirstName"], dr["LastName"]); break; case ResourceType.Agent: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["agent"], mapKVP.Value); resourceStr = String.Format("[A] {0}", dr["Name"]); break; case ResourceType.Group: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["group"], mapKVP.Value); resourceStr = String.Format("[G] {0} ({1})", dr["Name"], MPController.ParseGroupType(dr["GroupType"])); break; case ResourceType.Position: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["position"], mapKVP.Value); var belongTo = dr["BelongToGroup"] as string; var belongToStr = ""; if (belongTo != null) { var fetched = GlobalContext.ResourcesDataSet.Tables["group"].Rows.Cast <DataRow>() .FirstOrDefault(groupRow => groupRow["GlobalId"] as string == belongTo); if (fetched != null) { belongToStr = $" (Group: {fetched["Name"]})"; } } resourceStr = String.Format("[P] {0}{1}", dr["Name"], belongToStr); break; case ResourceType.Capability: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["capability"], mapKVP.Value); resourceStr = String.Format("[C] {0}", dr["Name"]); break; default: throw new ArgumentOutOfRangeException(); } this.ListBox_Step2_PreviewMap.Items.Add(String.Format("{0} => {1}", mapKVP.Key, resourceStr)); } }
/// <summary> /// Step1: Preview BO content by double click listbox. /// </summary> private void ListBox_Step1_BO_MouseDoubleClick(object sender, MouseButtonEventArgs e) { var idx = this.ListBox_Step1_BO.SelectedIndex; if (idx != -1) { var boName = this.ListBox_Step1_BO.Items[idx].ToString(); var pf = new TextPreviewForm(boName, MPController.GetBOContent(boName)); pf.ShowDialog(); } }
/// <summary> /// Create a new main window. /// </summary> public MainWindow() { InitializeComponent(); var processList = MPController.GetProcess(); GlobalContext.Current_Ren_Process_List = processList; foreach (var process in processList) { this.ComboBox_Step1_Processes.Items.Add(process["processName"]); } this.InitFlag = true; }
/// <summary> /// Step1: ComboBox of process choosing selection changed. /// </summary> private void ComboBox_Step1_ProcessChoose_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.ComboBox_Step1_Processes.SelectedIndex != 0) { this.Button_Step1_Open.Visibility = Visibility.Hidden; this.TextBox_Step1_Open.Visibility = Visibility.Hidden; this.ComboBox_Step1_MainBO.IsEnabled = false; var processEntity = GlobalContext.Current_Ren_Process_List[this.ComboBox_Step1_Processes.SelectedIndex - 1]; var boList = MPController.GetProcessBO(processEntity["pid"]); this.ListBox_Step1_BO.Items.Clear(); this.ComboBox_Step1_MainBO.Items.Clear(); foreach (var bo in boList) { var boName = bo["bo_name"]; this.ListBox_Step1_BO.Items.Add(boName); this.ComboBox_Step1_MainBO.Items.Add(boName); } if (this.ComboBox_Step1_MainBO.Items.Count > 0) { this.ComboBox_Step1_MainBO.SelectedIndex = 0; foreach (var item in this.ComboBox_Step1_MainBO.Items) { if (item.ToString() == processEntity["mainBo"]) { this.ComboBox_Step1_MainBO.SelectedItem = item; break; } } } MPController.CurrentTransaction.BOVector = boList; } else { this.Button_Step1_Open.Visibility = Visibility.Visible; this.TextBox_Step1_Open.Visibility = Visibility.Visible; this.ComboBox_Step1_MainBO.IsEnabled = true; MPController.CurrentTransaction.BOVector = new List <Dictionary <string, string> >(); this.ListBox_Step1_BO.Items.Clear(); this.ComboBox_Step1_MainBO.Items.Clear(); } }
/// <summary> /// Step3 Button: Next. /// </summary> private void Button_Step3_Next_OnClick(object sender, RoutedEventArgs e) { // make sure var dr = MessageBox.Show(@"Are you sure to submit this launch transaction?", @"Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (dr == System.Windows.Forms.DialogResult.Cancel) { return; } // upload to NS and Launch process MPController.CurrentTransaction.LaunchType = this.ComboBox_Step3_Launch.SelectedIndex; MPController.CurrentTransaction.IsolationType = this.ComboBox_Step3_WhenMapChange.SelectedIndex; MPController.CurrentTransaction.FailureType = this.ComboBox_Step3_WhenFailure.SelectedIndex; MPController.CurrentTransaction.AuthType = this.ComboBox_Step3_AuthorizationType.SelectedIndex; var submitRes = MPController.SubmitProcess(); var submitResItem = submitRes.Split(','); GlobalContext.CurrentRTID = submitResItem[0]; GlobalContext.CurrentProcessSelfSignature = submitResItem[1]; Debug.Assert(GlobalContext.CurrentRTID != null); MPController.RegisterMappings(); // update UI this.Label_Step4_Rtid.Text = GlobalContext.CurrentRTID; if (String.IsNullOrEmpty(GlobalContext.CurrentProcessSelfSignature)) { this.Label_Step4_AuthSign.Visibility = this.Label_Step4_AuthSign_Warn.Visibility = this.TextBox_Step4_AuthSign.Visibility = Visibility.Hidden; } else { this.Label_Step4_AuthSign.Visibility = this.Label_Step4_AuthSign_Warn.Visibility = this.TextBox_Step4_AuthSign.Visibility = Visibility.Visible; this.TextBox_Step4_AuthSign.Text = GlobalContext.CurrentProcessSelfSignature; } this.tabControl.SelectedIndex += 1; }
private void Button_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(this.TextBox_username.Text) || String.IsNullOrEmpty(this.PasswordBox_password.Password)) { MessageBox.Show("请完整填写"); return; } var retVal = MPController.Login(this.TextBox_username.Text.Trim(), this.PasswordBox_password.Password); if (retVal.Key) { MPController.CurrentTransaction.AuthToken = retVal.Value; MPController.CurrentTransaction.RenUsername = this.TextBox_username.Text.Trim(); var mw = new MainWindow(); mw.Title += $" [{this.TextBox_username.Text.Trim()}]"; mw.Show(); this.Close(); } else { MessageBox.Show("Fail"); } }
/// <summary> /// Step3 Button: Next. /// </summary> private void Button_Step4_DebugStart(object sender, RoutedEventArgs e) { MPController.LoadParticipant(); MessageBox.Show(@"OK"); }
/// <summary> /// Create a new mapping management form. /// </summary> public ManageMappingForm() { InitializeComponent(); // Business Roles foreach (var br in MPController.CurrentTransaction.BusinessRoleList) { this.ListBox_BusinessRole.Items.Add(br); } // Mappings foreach (var mapItem in MPController.CurrentTransaction.Mappings) { this.CurrentMap.Add(mapItem); } foreach (var mapKVP in MPController.CurrentTransaction.Mappings) { var resourceType = MPController.GetResourceTypeByGid(mapKVP.Value); var resourceStr = ""; DataRow dr; switch (resourceType) { case ResourceType.Human: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["human"], mapKVP.Value); resourceStr = String.Format("[H] {0}: {1} {2}", dr["PersonId"], dr["FirstName"], dr["LastName"]); break; case ResourceType.Agent: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["agent"], mapKVP.Value); resourceStr = String.Format("[A] {0}", dr["Name"]); break; case ResourceType.Group: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["group"], mapKVP.Value); resourceStr = String.Format("[G] {0} ({1})", dr["Name"], MPController.ParseGroupType(dr["GroupType"])); break; case ResourceType.Position: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["position"], mapKVP.Value); var belongTo = dr["BelongToGroup"] as string; var belongToStr = ""; if (belongTo != null) { var fetched = GlobalContext.ResourcesDataSet.Tables["group"].Rows.Cast <DataRow>() .FirstOrDefault(groupRow => groupRow["GlobalId"] as string == belongTo); if (fetched != null) { belongToStr = $" (Group: {fetched["Name"]})"; } } resourceStr = String.Format("[P] {0}{1}", dr["Name"], belongToStr); break; case ResourceType.Capability: dr = MPController.FindResourceDataRow(GlobalContext.ResourcesDataSet.Tables["capability"], mapKVP.Value); resourceStr = String.Format("[C] {0}", dr["Name"]); break; default: throw new ArgumentOutOfRangeException(); } this.ListBox_Mappings.Items.Add(String.Format("{0} => {1}", mapKVP.Key, resourceStr)); } // refresh resource list this.RefreshLists(true, true, true, true, true); // filter ComboBoxs foreach (DataRow dataRow in GlobalContext.ResourcesDataSet.Tables["group"].Rows) { this.ComboBox_Step2_Filter_G.Items.Add($"{dataRow["Name"]}"); } foreach (DataRow dataRow in GlobalContext.ResourcesDataSet.Tables["position"].Rows) { this.ComboBox_Step2_Filter_P.Items.Add($"{dataRow["Name"]}"); } foreach (DataRow dataRow in GlobalContext.ResourcesDataSet.Tables["capability"].Rows) { this.ComboBox_Step2_Filter_C.Items.Add($"{dataRow["Name"]}"); } // set finish flag this.initFinish = true; }
/// <summary> /// Refresh all list in the form. /// </summary> private void RefreshLists(bool?showHuman, bool?showAgent, bool?showGroup, bool?showPosition, bool?showCapability) { // Resources this.ListBox_Resources.Items.Clear(); var counter = 0; string dv1, dv2; DataSet ds; do { dv1 = MPController.GetDataVersion(); ds = MPController.GetAllResourceInCOrgan(); dv2 = MPController.GetDataVersion(); counter++; } while (dv1 != dv2); if (counter > 100) { MessageBox.Show("Data version is Error!"); throw new Exception(); } GlobalContext.ResourcesDataSet = ds; var dvItems = dv1.Substring(1, dv1.Length - 2).Split(','); Debug.Assert(dvItems.Length == 2); GlobalContext.ResourcesDataVersion = dvItems[0]; GlobalContext.ResourcesCOrganGid = dvItems[1]; if (showHuman == true) { foreach (DataRow row in ds.Tables["human"].Rows) { var lb = new Label { Content = String.Format("[H] {0}: {1} {2}", row["PersonId"], row["FirstName"], row["LastName"]), Tag = row["GlobalId"] }; this.ListBox_Resources.Items.Add(lb); } } if (showAgent == true) { foreach (DataRow row in ds.Tables["agent"].Rows) { var lb = new Label { Content = String.Format("[A] {0}", row["Name"]), Tag = row["GlobalId"], ToolTip = String.Format("{0}, {1}", MPController.ParseAgentType(row["Type"]), row["Location"]) }; this.ListBox_Resources.Items.Add(lb); } } if (showGroup == true) { foreach (DataRow row in ds.Tables["group"].Rows) { var lb = new Label { Content = String.Format("[G] {0} ({1})", row["Name"], MPController.ParseGroupType(row["GroupType"])), Tag = row["GlobalId"] }; this.ListBox_Resources.Items.Add(lb); } } if (showPosition == true) { foreach (DataRow row in ds.Tables["position"].Rows) { var belongTo = row["BelongToGroup"] as string; var belongToStr = ""; if (belongTo != null) { var fetched = ds.Tables["group"].Rows.Cast <DataRow>() .FirstOrDefault(groupRow => groupRow["GlobalId"] as string == belongTo); if (fetched != null) { belongToStr = $" (Group: {fetched["Name"]})"; } } var lb = new Label { Content = String.Format("[P] {0}{1}", row["Name"], belongToStr), Tag = row["GlobalId"] }; this.ListBox_Resources.Items.Add(lb); } } if (showCapability == true) { foreach (DataRow row in ds.Tables["capability"].Rows) { var lb = new Label { Content = String.Format("[C] {0}", row["Name"]), Tag = row["GlobalId"] }; this.ListBox_Resources.Items.Add(lb); } } }