예제 #1
0
        public async Task <ActionResult> ProvisionWorkflowPost()
        {
            var token = await O365Util.GetAccessToken(ServiceResources.Dashboard);

            var suiteLevelWebAppUrl = Regex.Match(Request.Url.AbsoluteUri, "https?://[^/]+?(?=/)", RegexOptions.Compiled).Value;

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(DemoSiteCollectionUrl, token))
            {
                var service       = new WorkflowProvisionService(clientContext);
                var incidentsList = CSOMUtil.getListByTitle(clientContext, "Incidents");

                service.Unsubscribe(incidentsList.Id, "Incident");
                service.DeleteDefinitions("Incident");
                service.DeleteList("Incident Workflow Tasks");
                service.DeleteList("Incident Workflow History");

                var workflow = System.IO.File.ReadAllText(Server.MapPath("~/Workflows/Incident.xaml"));

                workflow = workflow.Replace("(SuiteLevelWebAppUrlPlaceholder)", suiteLevelWebAppUrl)
                           .Replace("(dispatcherPlaceHolder)", ConfigurationManager.AppSettings["DispatcherName"]);
                workflow = WorkflowUtil.TranslateWorkflow(workflow);
                var definitionId  = service.SaveDefinitionAndPublish("Incident", workflow);
                var taskListId    = service.CreateTaskList("Incident Workflow Tasks");
                var historyListId = service.CreateHistoryList("Incident Workflow History");
                service.Subscribe("Incident Workflow", definitionId, incidentsList.Id, WorkflowSubscritpionEventType.ItemAdded, taskListId, historyListId);

                ViewBag.Message = "Incident Workflow, Incident Workflow Tasks list and Incident Workflow History list have been created successfully. Click the Create Sample Data menu item to proceed.";
            }
            return(View());
        }
예제 #2
0
        private void CreateWorkflowList(int userId)
        {
            workflowNode            = "";
            workflowList.InnerHtml  = "";
            numberShowing.InnerHtml = "";
            List <WorkflowModel> workflows = WorkflowUtil.GetCoachWorkflows(userId);

            for (int i = 0; i < 10 && i < workflows.Count; i++)
            {
                MakeText(workflows, workflowNode, i);
            }
            var showing = "Showing 1 - " + count + " of " + workflows.Count + " Results";

            numberShowing.InnerHtml += showing;
        }
예제 #3
0
        private void MakeAdminText(List <Project> projects, string projectNode, int i)
        {
            User          coach    = UserUtil.GetCoach(projects[i].CoachId);
            WorkflowModel workflow = WorkflowUtil.GetWorkflow(projects[i].WorkflowId);

            projectNode  = "<div class=\"item\"><div class=\"ui small image\"><i class=\"huge inbox icon\"/></i></div>";
            projectNode += "<div class=\"content\"><a class=\"header\" href='Projects.aspx?pid=" + projects[i].ProjectId + "'>" + projects[i].Name + "</a><div class=\"meta\">";
            projectNode += "<span class=\"stay\">" + coach.FullName + " | " + workflow.WorkflowName + " | <a href='Projects.aspx?pid=" + projects[i].ProjectId + "&edit=1'>Edit Project</a>" + " | <a href='Projects.aspx?pid=" + projects[i].ProjectId + "&del=1'>Delete Project</a></span></div><div class=\"description\">";
            projectNode += projects[i].Notes + "</div></div></div>";


            projectList.InnerHtml += projectNode;
            projectNode            = "";
            count++;
        }
예제 #4
0
        private void CreateClientWorkflowList(int companyId)
        {
            CreateNewWorkflowBtn.Visible = false;
            workflowNode            = "";
            workflowList.InnerHtml  = "";
            numberShowing.InnerHtml = "";
            List <WorkflowModel> workflows = WorkflowUtil.GetCompanyWorkflows(companyId);

            for (int i = 0; i < 10 && i < workflows.Count; i++)
            {
                MakeClientText(workflows, workflowNode, i);
            }
            var showing = "Showing 1 - " + count + " of " + workflows.Count + " Results";

            numberShowing.InnerHtml += showing;
        }
예제 #5
0
        protected void LoadMoreWorkflows(object sender, EventArgs e)
        {
            ViewState["workflowcount"] = Convert.ToInt32(ViewState["workflowcount"]) + 1;
            int loaded = Convert.ToInt32(ViewState["workflowcount"]);

            List <WorkflowModel> workflows = new List <WorkflowModel>();
            User user = (User)Session["User"];

            if (user.RoleId == 1)
            {
                workflows = WorkflowUtil.GetCompanyWorkflows(user.CompanyId);
            }
            else if (user.RoleId == 2)
            {
                workflows = WorkflowUtil.GetCoachWorkflows(user.UserId);
            }
            else if (user.RoleId == 4 || user.RoleId == 3)
            {
                workflows = WorkflowUtil.GetWorkflows();
            }
            if (loaded == 1)
            {
                ViewState["workflowcount"] = Convert.ToInt32(ViewState["workflowcount"]) + 1;
                loaded = Convert.ToInt32(ViewState["workflowcount"]);
            }
            for (int i = 10; i < loaded * 10 && i < workflows.Count; i++)
            {
                if (user.RoleId == 4)
                {
                    MakeAdminText(workflows, workflowNode, i);
                }
                else if (user.RoleId == 1)
                {
                    MakeClientText(workflows, workflowNode, i);
                }
                else
                {
                    MakeText(workflows, workflowNode, i);
                }
            }

            numberShowing.InnerHtml = "";
            var showing = "Showing 1 - " + count + " of " + workflows.Count + " Results";

            numberShowing.InnerHtml += showing;
        }
예제 #6
0
        private void SaveComponents(int workflowId)
        {
            User                     user     = (User)Session["User"];
            WorkflowModel            w        = WorkflowUtil.GetWorkflow(workflowId);
            List <WorkflowComponent> compList = WorkflowComponentUtil.GetWorkflowComponents(workflowId);
            int i = 0;

            foreach (Panel panelControls in WorkflowSteps.Controls.OfType <Panel>())
            {
                string       id           = panelControls.ID.Replace("stepControl", string.Empty);
                Panel        div          = (Panel)panelControls.FindControl("title" + id);
                TextBox      stepTitle    = (TextBox)div.FindControl("stepTitle" + id);
                DropDownList formSelector = (DropDownList)panelControls.FindControl("formSelector" + id);
                int          formId       = int.Parse(formSelector.SelectedValue);
                WorkflowComponentUtil.UpdateWorkflowComponent(compList[i].WFComponentID, stepTitle.Text, formId);
                Log.Info(user.Identity + " updated " + w.WorkflowName + " with component " + stepTitle.Text + " assigned to form " + FormUtil.GetFormTemplate(formId).FormName);
                i++;
            }
        }
예제 #7
0
        protected void CreateWorkflowBtn_Click(object sender, EventArgs e)
        {
            //create new
            if (WorkflowName.Text.Length > 0 && Request.QueryString["wid"] == null)
            {
                WorkflowModel w    = WorkflowUtil.CreateWorkflow(WorkflowName.Text);
                User          user = (User)Session["User"];
                Log.Info(user.Identity + " created a new workflow template " + w.WorkflowName);
                SaveComponents(w.WorkflowId);
            }
            //update existing
            else if (WorkflowName.Text.Length > 0 && Request.QueryString["wid"] != null)
            {
                int workflowId = int.Parse(Request.QueryString["wid"]);
                WorkflowUtil.UpdateWorkflow(workflowId, WorkflowName.Text);

                SaveComponents(workflowId);
            }
        }
예제 #8
0
        protected void AddWorkflowComponentBtn_Click(object sender, EventArgs e)
        {
            if (WorkflowName.Text.Length > 0)
            {
                int         workflowId = 0;
                List <Guid> ids        = this.ControlIDs;
                Guid        guid       = Guid.NewGuid();
                ids.Add(guid);

                WorkflowComponent wc = null;
                if (Request.QueryString["wid"] != null)
                {
                    if (WorkflowName.Text.Length > 0)
                    {
                        workflowId = int.Parse(Request.QueryString["wid"]);
                        WorkflowUtil.UpdateWorkflow(workflowId, WorkflowName.Text);
                        SaveComponents(workflowId);
                        wc = WorkflowComponentUtil.CreateWorkflowComponent(workflowId);
                    }
                }
                else
                {
                    if (WorkflowName.Text.Length > 0)
                    {
                        WorkflowModel w    = WorkflowUtil.CreateWorkflow(WorkflowName.Text);
                        User          user = (User)Session["User"];
                        Log.Info(user.Identity + " created workflow template " + w.WorkflowName);
                        workflowId = w.WorkflowId;
                        SaveComponents(workflowId);
                        wc = WorkflowComponentUtil.CreateWorkflowComponent(workflowId);
                    }
                }
                Panel componentPanel = CreateWorkflowStep(guid, wc);
                this.ControlIDs = ids;
                Response.Redirect("Workflows.aspx?edit=1&wid=" + workflowId);
            }
            else
            {
                WorkflowError.Visible = true;
                WorkflowError.Text    = "Please name the Workflow before adding steps";
            }
        }
예제 #9
0
        protected void ProjectFileDownloader_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["pid"] != null)
            {
                int                      projId             = int.Parse(Request.QueryString["pid"]);
                Project                  p                  = ProjectUtil.GetProject(projId);
                Company                  c                  = CompanyUtil.GetCompany(p.CompanyId);
                WorkflowModel            w                  = WorkflowUtil.GetWorkflow(p.WorkflowId);
                List <WorkflowComponent> workflowComponents = WorkflowComponentUtil.GetWorkflowComponents(w.WorkflowId);
                string                   zipPath            = String.Format("{0} - {1} - {2}.zip", w.WorkflowName, p.Name, CompanyUtil.GetCompanyName(p.CompanyId));
                //delete the zip if it exists
                if (File.Exists(zipPath))
                {
                    File.Delete(zipPath);
                }

                using (ZipArchive zip = ZipFile.Open(zipPath, ZipArchiveMode.Create))
                {
                    //for each form get the file
                    foreach (WorkflowComponent wc in workflowComponents)
                    {
                        Form f = FormUtil.GetProjectFormByTemplate(wc.FormID, projId);
                        if (f.FilePath.Length > 0)
                        {
                            string fileType = f.FilePath.Split('.')[1];
                            string fileName = string.Format("{0} {1} Attachment.{2}", CompanyUtil.GetCompanyName(p.CompanyId), f.FormName, fileType);
                            zip.CreateEntryFromFile(f.FilePath, fileName);
                        }
                        string pdfName = string.Format("{0} - {1} - {2}.pdf", w.WorkflowName, f.FormName, c.CompanyName);
                        string pdfPath = string.Format("./PDFGen/{0}", pdfName);
                        zip.CreateEntryFromFile(pdfPath, pdfName);
                    }
                }

                SendFile(zipPath);
            }
        }
예제 #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //validates that the user is logged in
            if (Session["User"] != null)
            {
                User user = (User)Session["User"];
                userLbl.Text = user.FullName;
                if (user.RoleId == 4)
                {
                    AdminBtn.Visible = true;
                }

                if (user.RoleId == 1)
                {
                    CreateClientWorkflowList(user.CompanyId);
                    CreateNewWorkflowBtn.Visible = false;
                }
                else if (user.RoleId == 2)
                {
                    CreateWorkflowList(user.UserId);
                    CreateNewWorkflowBtn.Visible = false;
                }
                else if (user.RoleId == 4 || user.RoleId == 3)
                {
                    CreateAdminWorkflowList();
                }

                //loads the selected form if there is one
                if (Request.QueryString["wid"] != null)
                {
                    int           workflowId = int.Parse(Request.QueryString["wid"]);
                    WorkflowModel w          = WorkflowUtil.GetWorkflow(workflowId);

                    //admin and trying to del
                    if (Request.QueryString["del"] != null && user.RoleId == 4)
                    {
                        if (WorkflowUtil.DeleteWorkflow(w.WorkflowId))
                        {
                            Log.Info(user.Identity + " deleted a workflow template " + w.WorkflowName);
                            ReloadSection();
                        }
                        else
                        {
                            WorkflowError.Visible = true;
                            WorkflowError.Text    = "Unable to delete Workflow " + w.WorkflowName;
                        }
                    }
                    else
                    {
                        workflowListing.Visible = false;

                        //if they are trying to edit and they are admin, show workflow builder
                        if (Request.QueryString["edit"] != null && user.RoleId == 4)
                        {
                            if (WorkflowUtil.EditableWorkflow(w.WorkflowId))
                            {
                                workflowBuilder.Visible = true;
                                WorkflowName.Text       = w.WorkflowName;
                                CreateWorkflowBtn.Text  = "Update Workflow";

                                LoadWorkflowSteps(workflowId);
                            }
                            else
                            {
                                workflowListing.Visible = true;
                                WorkflowError.Visible   = true;
                                WorkflowError.Text      = "Unable to edit Workflow " + w.WorkflowName + " while projects are assigned to it";
                            }
                        }
                        //otherwise just show the workflow viewer
                        else
                        {
                            workflowViewer.Visible = true;
                            List <WorkflowComponent> comps = WorkflowComponentUtil.GetWorkflowComponents(w.WorkflowId);
                            ProjectInformation(w, comps);
                        }
                    }
                }
                //if theyre an admin and trying to make a new form
                else if (Request.QueryString["edit"] != null && Request.QueryString["wid"] == null && user.RoleId == 4)
                {
                    workflowListing.Visible = false;
                    workflowBuilder.Visible = true;
                }
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
예제 #11
0
        protected void CreateProjectBtn_Click(object sender, EventArgs e)
        {
            int    companyId    = int.Parse(SelectedCompany.Value);
            int    workflowId   = int.Parse(SelectedWorkflow.Value);
            int    coachId      = int.Parse(SelectedCoach.Value);
            string projectName  = ProjectName.Text;
            string projectNotes = ProjectNotes.Text;

            if (projectName.Length > 0)
            {
                if (companyId != -1)
                {
                    if (workflowId != -1)
                    {
                        if (coachId != -1)
                        {
                            if (Request.QueryString["pid"] != null)
                            {
                                int     projId = int.Parse(Request.QueryString["pid"]);
                                Project p      = ProjectUtil.UpdateProject(projId, projectName, companyId, coachId, projectNotes);
                                User    user   = (User)Session["User"];
                                Log.Info(user.Identity + " updated project " + projectName + " with a Workflow of " + WorkflowUtil.GetWorklowName(workflowId) + " assigned to " + CompanyUtil.GetCompanyName(companyId) + " under Coach " + UserUtil.GetCoachName(coachId) + " with notes: " + projectNotes);
                                Response.Redirect("Projects.aspx?pid=" + p.ProjectId);
                            }
                            else
                            {
                                Project p    = ProjectUtil.CreateProject(projectName, workflowId, companyId, coachId, projectNotes);
                                User    user = (User)Session["User"];
                                Log.Info(user.Identity + " created project " + projectName + " with a Workflow of " + WorkflowUtil.GetWorklowName(workflowId) + " assigned to " + CompanyUtil.GetCompanyName(companyId) + " under Coach " + UserUtil.GetCoachName(coachId) + " with notes: " + projectNotes);
                                Response.Redirect("Projects.aspx?pid=" + p.ProjectId);
                            }
                        }
                    }
                }
            }
            else
            {
                //enter valid name
            }
        }
예제 #12
0
        protected void ApproveFormBtn_Click(object sender, EventArgs e)
        {
            FormResult.Visible = false;
            //updating a form not, creating it
            if (Request.QueryString["pfid"] != null)
            {
                int           formId = int.Parse(Request.QueryString["pfid"]);
                Form          f      = FormUtil.GetForm(formId);
                Project       p      = ProjectUtil.GetProject(f.ProjectId);
                WorkflowModel w      = WorkflowUtil.GetWorkflow(p.WorkflowId);

                User user = (User)Session["User"];
                FormUtil.ApproveForm(formId, user.RoleId);
                Log.Info(user.Identity + " approved " + CompanyUtil.GetCompanyName(p.CompanyId) + "'s form " + f.FormName + " - " + p.Name);
                FormResult.CssClass = "success";
                FormResult.Text     = "Approved form " + f.FormName;
                FormResult.Visible  = true;

                //prep html for pdf generation
                HtmlDocument doc     = new HtmlDocument();
                string       pdfName = string.Format("{0} - {1} - {2}", w.WorkflowName, f.FormName, CompanyUtil.GetCompanyName(p.CompanyId));
                string       html    = formViewerData.Value;
                if (html.Contains("user-data"))
                {
                    html = html.Replace("user-data", "value");
                }
                if (html.Contains("\""))
                {
                    html = html.Replace("\"", "'");
                }
                doc.LoadHtml(html);
                doc.Save("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html");

                //radiobtns
                foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@type]"))
                {
                    HtmlAttribute type = link.Attributes["type"];
                    if (type.Value.Equals("radio"))
                    {
                        if (link.Attributes.Contains("checked"))
                        {
                        }
                        else
                        {
                            if (link.Attributes.Contains("id"))
                            {
                                string toDelId = link.Attributes["id"].Value;

                                foreach (HtmlNode label in doc.DocumentNode.SelectNodes("//label[@for]"))
                                {
                                    string forId = label.Attributes["for"].Value;
                                    if (forId.Equals(toDelId))
                                    {
                                        label.Remove();
                                    }
                                }
                            }
                        }
                        link.Attributes.Remove("value");
                    }
                }

                //text fields, dates, + similar
                foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@value]"))
                {
                    HtmlAttribute value = link.Attributes["value"];
                    if (link.Attributes.Contains("placeholder"))
                    {
                        link.Attributes.Remove("placeholder");
                    }
                    string val = value.Value;
                    link.InnerHtml = val;
                    link.Attributes.Remove("value");
                }

                //text areas
                foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//textarea[@value]"))
                {
                    HtmlAttribute value = link.Attributes["value"];
                    if (link.Attributes.Contains("placeholder"))
                    {
                        link.Attributes.Remove("placeholder");
                    }
                    string val = value.Value;
                    link.InnerHtml = val;
                    link.Attributes.Remove("value");
                }

                //attached files
                if (f.FilePath.Length > 0)
                {
                    foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@type]"))
                    {
                        HtmlAttribute type = link.Attributes["type"];
                        if (type.Value.Equals("file"))
                        {
                            string fileType = f.FilePath.Split('.')[1];
                            string fileName = string.Format("{0} {1} Attachment.{2}", CompanyUtil.GetCompanyName(p.CompanyId), f.FormName, fileType);
                            link.InnerHtml = "See " + fileName;
                        }
                    }
                }
                doc.Save("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html");
                doc.Load("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html");
                html = doc.Text;

                //pdf gen
                PDFGen.CreateHTMLPDF(html, pdfName);
                Response.Redirect("Forms.aspx?pfid=" + formId);
            }
        }