Exemplo n.º 1
0
        private void AddAnalyzerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AssignUserForm assignUserForm = new AssignUserForm();
            assignUserForm.Prompt = "Add task analyzer";
            TreeNode analyzersNode = null;
            BindingTask task;
            if (DialogResult.OK == assignUserForm.ShowDialog())
            {
                analyzersNode = WorkspaceTreeView.SelectedNode;
                task = ((TaskModel)analyzersNode.Parent.Tag).mTask;
                UpdateTaskRequest request = new UpdateTaskRequest();
                request.Type = UpdateTaskType.AddAnalyzer.ToString();
                foreach (string user in assignUserForm.Users)
                {
                    if (request.Analyzer.Contains(user))
                        continue;

                    request.Analyzer.Add(user);
                }

                if (request.Analyzer.Count == 0)
                    return;

                HTTPAgent.instance().updateTask(this, task.ID, request, "Add analyzers", analyzersNode);
            }
        }
Exemplo n.º 2
0
        private void AddSiteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SiteManagementForm siteManagementForm = new SiteManagementForm();
            siteManagementForm.UseForSelect = true;

            TreeNode sitesNode = WorkspaceTreeView.SelectedNode;
            if (sitesNode.Parent.Tag is SubRegion)
            {
                if (siteManagementForm.ShowDialog() == DialogResult.Cancel)
                    return;

                List<Site> selectedSites = siteManagementForm.SelectedSites;
                if (selectedSites.Count == 0)
                    return;

                SubRegion originRegion = (SubRegion)sitesNode.Parent.Tag;
                UpdateRegionRequest request = new UpdateRegionRequest();
                request.Type = UpdateRegionType.AddSite.ToString();
                request.Region = new SubRegion();
                request.Region.ID = originRegion.ID;
                if (originRegion.Site == null)
                    originRegion.Site = new List<string>();
                foreach (Site selectedSite in selectedSites)
                {
                    if (originRegion.Site.Contains(selectedSite.SiteID))
                        continue;

                    request.Region.Site.Add(selectedSite.SiteID);
                }

                if (request.Region.Site.Count == 0)
                    return;

                HTTPAgent.instance().updateRegion(this, DataCenter.Instance().GlobalRegion.Version, request,
                    "Add region sites", sitesNode);
            }
            else if (sitesNode.Parent.Tag is TaskModel)
            {
                siteManagementForm.AvailableSites = Utility.GetAvailableSites((SubRegion)sitesNode.Parent.Parent.Tag);
                if (siteManagementForm.ShowDialog() == DialogResult.Cancel)
                    return;

                List<Site> selectedSites = siteManagementForm.SelectedSites;
                if (selectedSites.Count == 0)
                    return;

                BindingTask task = ((TaskModel)sitesNode.Parent.Tag).mTask;
                UpdateTaskRequest request = new UpdateTaskRequest();
                request.Type = UpdateTaskType.AddSite.ToString();
                foreach(Site selectedSite in selectedSites)
                {
                    if (task.Site.Contains(selectedSite.SiteID))
                        continue;

                    request.Site.Add(selectedSite.SiteID);
                }

                if (request.Site.Count == 0)
                    return;

                HTTPAgent.instance().updateTask(this, task.ID, request, "Add task sites", sitesNode);
            }
        }
Exemplo n.º 3
0
        void WorkspaceForm_onUpdateTaskFailed(long taskID, UpdateTaskRequest request, HttpStatusCode statusCode, string messageText)
        {
            MessageBox.Show(messageText + " failed, status=" + statusCode.ToString());
            if (UpdateTaskType.AddAnalyzer.ToString().Equals(request.Type))
            {
                ReLoad();
                FocusNode(NodeType.TaskAnalyzers, (object)taskID);
            }
            else if (UpdateTaskType.RemoveAnalyzer.ToString().Equals(request.Type))
            {
                ReLoad();
                FocusNode(NodeType.TaskAnalyzers, (object)taskID);

            }
            else if (UpdateTaskType.AddSite.ToString().Equals(request.Type))
            {
                ReLoad();
                FocusNode(NodeType.TaskSites, (object)taskID);
            }
            else if (UpdateTaskType.RemoveSite.ToString().Equals(request.Type))
            {
                ReLoad();
                FocusNode(NodeType.TaskSites, (object)taskID);
            }
        }
Exemplo n.º 4
0
        void WorkspaceForm_onUpdateTaskSuccessfully(long taskID, UpdateTaskRequest request, object context)
        {
            if (UpdateTaskType.AddAnalyzer.ToString().Equals(request.Type))
            {
                string lastAnalyzer = null;
                foreach (string analyzer in request.Analyzer)
                {
                    if (!DataCenter.Instance().Tasks[taskID].Analyzer.Contains(analyzer))
                    {
                        DataCenter.Instance().Tasks[taskID].Analyzer.Add(analyzer);
                        lastAnalyzer = analyzer;
                    }
                }

                if (lastAnalyzer != null)
                {
                    ReLoad();
                    FocusNode(NodeType.TaskAnalyzer, (object)taskID, lastAnalyzer);
                }
            }
            else if (UpdateTaskType.RemoveAnalyzer.ToString().Equals(request.Type))
            {
                ReLoad();
                FocusNode(NodeType.TaskAnalyzers, (object)taskID);

            }
            else if (UpdateTaskType.AddSite.ToString().Equals(request.Type))
            {
                string lastSite = null;
                foreach (string site in request.Site)
                {
                    if (!DataCenter.Instance().Tasks[taskID].Site.Contains(site))
                    {
                        DataCenter.Instance().Tasks[taskID].Site.Add(site);
                        lastSite = site;
                    }
                }

                if (lastSite != null)
                {
                    ReLoad();
                    FocusNode(NodeType.TaskSite, (object)taskID, lastSite);
                }
            }
            else if (UpdateTaskType.RemoveSite.ToString().Equals(request.Type))
            {
                ReLoad();
                FocusNode(NodeType.TaskSites, (object)taskID);
            }
            else if (UpdateTaskType.RenameTask.ToString().Equals(request.Type))
            {
                ReLoad();
                FocusNode(NodeType.Task, (object)taskID);
            }
            else
            {
                return;
            }
        }
Exemplo n.º 5
0
        private void RemoveSiteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string prompt = "Remove site '" + WorkspaceTreeView.SelectedNode.Text + "', are you sure ?";
            if (DialogResult.No == MessageBox.Show(prompt, "Warning", MessageBoxButtons.YesNo))
                return;

            TreeNode siteNode = WorkspaceTreeView.SelectedNode;
            if (siteNode.Parent.Parent.Tag is SubRegion)
            {
                SubRegion origionRegion = (SubRegion)siteNode.Parent.Parent.Tag;
                UpdateRegionRequest request = new UpdateRegionRequest();
                request.Type = UpdateRegionType.RemoveSite.ToString();
                request.Region = new SubRegion();
                request.Region.ID = origionRegion.ID;

                string siteID = ((SiteModel)siteNode.Tag).Site.SiteID;
                if (!origionRegion.Site.Contains(siteID))
                    return;

                request.Region.Site.Add(siteID);
                HTTPAgent.instance().updateRegion(this, DataCenter.Instance().GlobalRegion.Version, request,
                    "Remove site '" + siteID + "'", siteNode);

            }
            else if (siteNode.Parent.Parent.Tag is TaskModel)
            {
                BindingTask task = ((TaskModel)siteNode.Parent.Parent.Tag).mTask;
                UpdateTaskRequest request = new UpdateTaskRequest();
                request.Type = UpdateTaskType.RemoveSite.ToString();

                string siteID = ((SiteModel)siteNode.Tag).Site.SiteID;
                if (!task.Site.Contains(siteID))
                    return;

                request.Site.Add(siteID);
                HTTPAgent.instance().updateTask(this, task.ID, request, "Remove site '" + siteID + "'", siteNode);
            }
        }
Exemplo n.º 6
0
        private void RenameTaskToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string oldTaskName = WorkspaceTreeView.SelectedNode.Text;
            RenameForm renameForm = new RenameForm("Rename task", oldTaskName);
            renameForm.CheckInputDelegate = new CheckInputDelegate(CheckTaskName);
            if (DialogResult.OK == renameForm.ShowDialog() && renameForm.Updated)
            {
                UpdateTaskRequest request = new UpdateTaskRequest();
                request.Type = UpdateTaskType.RenameTask.ToString();
                request.NewName = renameForm.NewName;

                long taskID = ((TaskModel)WorkspaceTreeView.SelectedNode.Tag).mTask.ID;

                HTTPAgent.instance().updateTask(this, taskID, request,
                    "Rename task '" + oldTaskName + "'", WorkspaceTreeView.SelectedNode);
            }
        }
Exemplo n.º 7
0
        private void RemoveAnalyzerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string prompt = "Remove analyzer '" + WorkspaceTreeView.SelectedNode.Text + "', are you sure ?";
            if (DialogResult.No == MessageBox.Show(prompt, "Warning", MessageBoxButtons.YesNo))
                return;

            BindingTask task = ((TaskModel)WorkspaceTreeView.SelectedNode.Parent.Parent.Tag).mTask;
            UpdateTaskRequest request = new UpdateTaskRequest();
            request.Type = UpdateTaskType.RemoveAnalyzer.ToString();

            TreeNode analyzerNode = WorkspaceTreeView.SelectedNode;
            string analyzer = analyzerNode.Text;
            if (!task.Analyzer.Contains(analyzer))
                return;

            request.Analyzer.Add(analyzer);
            HTTPAgent.instance().updateTask(this, task.ID, request, "Remove analyzer '" + analyzer + "'", analyzerNode);
        }
Exemplo n.º 8
0
        public void updateTask(Form attachedForm, long taskID, UpdateTaskRequest request, string messageText, object context)
        {
            new Thread(delegate()
            {
                byte[] respData;
                WebHeaderCollection headers;
                string url = getUrl(Action.updatetask, taskID);
                HttpStatusCode statusCode = HTTPRequest.MakeRequest(url, "PUT",
                    null, Constants.JSON_MIME,
                    Encoding.UTF8.GetBytes(Utility.JsonSerialize<UpdateTaskRequest>(request)), out respData, out headers);
                if (statusCode == HttpStatusCode.Accepted)
                {
                    if (onUpdateTaskSuccessfully != null)
                    {
                        attachedForm.BeginInvoke(onUpdateTaskSuccessfully, taskID, request, context);
                    }
                }
                else
                {
                    if (onUpdateTaskFailed != null)
                    {
                        attachedForm.BeginInvoke(onUpdateTaskFailed, taskID, request, statusCode, messageText);
                    }
                }

            }).Start();
        }
Exemplo n.º 9
0
        private void UploadButton_Click(object sender, EventArgs e)
        {
            if (EMIFileCheckedListBox.CheckedItems.Count == 0)
            {
                MessageBox.Show("No file was selected to upload !");
                return;
            }

            int count = 0;
            HashSet<string> md5List = new HashSet<string>();
            string fileName;
            string md5;
            List<string> uploadFileNames = new List<string>();
            List<string> identialFiles = new List<string>();
            foreach (object item in EMIFileCheckedListBox.CheckedItems)
            {
                fileName = item.ToString();

                md5 = Utility.MD5File(fileName);
                if (md5List.Contains(md5))
                {
                    identialFiles.Add(fileName);
                    continue;
                }
                md5List.Add(md5);

                uploadFileNames.Add(fileName);
                count++;
            }

            if (identialFiles.Count > 0)
            {
                string msg = "Following file:\r\n";
                foreach (string identialFile in identialFiles)
                {
                    msg += identialFile + "\r\n";
                }
                msg += "are identical to other files !";

                MessageBox.Show(msg);
            }

            Dictionary<string, EMIFileData> uploadEmis = new Dictionary<string, EMIFileData>();
            foreach (string emiFileName in uploadFileNames)
                uploadEmis[emiFileName] = mEMIDatas[emiFileName];

            UploadEMIProgressForm progressForm = new UploadEMIProgressForm(this, uploadEmis);
            progressForm.OnEmiFileUploadHandler += new UploadEMIProgressForm.EmiFileUploadedDelegate(progressForm_OnEmiFileUploadHandler);
            progressForm.ShowDialog();
            progressForm.OnEmiFileUploadHandler -= new UploadEMIProgressForm.EmiFileUploadedDelegate(progressForm_OnEmiFileUploadHandler);

            if (mUploadedEmis.Count > 0)
            {
                HashSet<string> unAssignedSites = new HashSet<string>();
                foreach (EMIFileData emi in mUploadedEmis)
                {
                    if (!mTask.Site.Contains(emi.Site_ID) && !mTask.UnassignedSite.Contains(emi.Site_ID))
                    {
                        unAssignedSites.Add(emi.Site_ID);
                    }
                }

                if (unAssignedSites.Count > 0)
                {
                    UpdateTaskRequest updateTaskRequest = new UpdateTaskRequest();
                    updateTaskRequest.Type = UpdateTaskType.AddUnassignedSite.ToString();
                    foreach (string site in unAssignedSites)
                    {
                        updateTaskRequest.Site.Add(site);
                    }
                    HTTPAgent.instance().updateTask(this, mTask.ID, updateTaskRequest, "Add unassigned sites for task " + mTask.ID, null);
                }

            }
        }
Exemplo n.º 10
0
 void EMIFileUploadForm_onUpdateTaskSuccessfully(long taskID, UpdateTaskRequest request, object context)
 {
 }
Exemplo n.º 11
0
 void EMIFileUploadForm_onUpdateTaskFailed(long taskID, UpdateTaskRequest request, System.Net.HttpStatusCode statusCode, string messageText)
 {
     MessageBox.Show(messageText + " failed, status code = " + statusCode.ToString());
 }