Ejemplo n.º 1
0
 public static WorkflowJsonObject GetJsonObject(int id)
 {
     using (BasicWebContext context = new BasicWebContext())
     {
         WorkflowJsonObject json = new WorkflowJsonObject();
         var inst    = context.FlowInstances.Find(id);
         var nodes   = context.FlowNodes.Include("ToNodes").Where(x => x.WorkflowID == inst.WorkflowID).ToList();
         var actions = context.FlowInstanceActions.Where(x => x.FlowInstanceID == id).OrderBy(x => x.PerformTime).ToList();
         json.nodes = nodes.Select(x =>
         {
             string status = "unreached";
             if (inst.CurrentNodeID == x.ID)
             {
                 status = "current";
             }
             else if (actions.Any(y => y.FromNodeID == x.ID))
             {
                 status = "passed";
             }
             return(new FlowNodeJsonObject {
                 name = x.Name, user = x.AllowedUsers, role = x.AllowedRoles, xpos = x.FlowChartPositionX, ypos = x.FlowChartPositionY, status = status
             });
         }).ToList();
         json.connections = nodes.SelectMany(x => x.ToNodes.Select(y => new NodeConnectionJsonObject {
             from = nodes.IndexOf(x), to = nodes.IndexOf(y), label = GetLabel(x, y)
         })).ToList();
         json.labels = context.FlowChartTextLabels.Where(x => x.WorkflowID == inst.WorkflowID).Select(x => new TextLabelJsonObject {
             text = x.Text, xpos = x.PositionX, ypos = x.PositionY, centerAligned = x.CenterAligned, fontFamily = x.FontFamily, fontSize = x.FontSize
         }).ToList();
         return(json);
     }
 }
Ejemplo n.º 2
0
        public static void New(string name, WorkflowJsonObject flow)
        {
            var nodes = new List <FlowNode>();

            foreach (var jsonNode in flow.nodes)
            {
                FlowNode node = new FlowNode(Guid.NewGuid(), jsonNode.name, jsonNode.user, jsonNode.role, jsonNode.xpos, jsonNode.ypos);
                nodes.Add(node);
            }
            foreach (var jsonConn in flow.connections)
            {
                nodes[jsonConn.from].ConnectTo(nodes[jsonConn.to]);
            }
            WorkflowManager.New(Guid.NewGuid(), name, nodes);
        }
Ejemplo n.º 3
0
 public static void UpdateFromJson(WorkflowJsonObject flow)
 {
     using (var context = new TongJi.Web.Models.BasicWebContext())
     {
         foreach (var node in flow.nodes)
         {
             var flowNode = context.FlowNodes.Find(node.id);
             flowNode.Name = node.name;
             flowNode.FlowChartPositionX = node.xpos;
             flowNode.FlowChartPositionY = node.ypos;
             flowNode.AllowedUsers       = node.user;
             flowNode.AllowedRoles       = node.role;
         }
         context.SaveChanges();
     }
 }
Ejemplo n.º 4
0
 public static WorkflowJsonObject GetJsonObject(Guid id)
 {
     using (BasicWebContext context = new BasicWebContext())
     {
         WorkflowJsonObject json = new WorkflowJsonObject();
         var nodes = context.FlowNodes.Include("ToNodes").Where(x => x.WorkflowID == id).ToList();
         json.id    = id.ToString();
         json.nodes = nodes.Select(x => new FlowNodeJsonObject {
             id = x.ID.ToString(), name = x.Name, user = x.AllowedUsers, role = x.AllowedRoles, xpos = x.FlowChartPositionX, ypos = x.FlowChartPositionY, status = ""
         }).ToList();
         json.connections = nodes.SelectMany(x => x.ToNodes.Select(y => new NodeConnectionJsonObject {
             from = nodes.IndexOf(x), to = nodes.IndexOf(y), label = GetLabel(x, y)
         })).ToList();
         json.labels = context.FlowChartTextLabels.Where(x => x.WorkflowID == id).Select(x => new TextLabelJsonObject {
             text = x.Text, xpos = x.PositionX, ypos = x.PositionY, centerAligned = x.CenterAligned, fontFamily = x.FontFamily, fontSize = x.FontSize
         }).ToList();
         return(json);
     }
 }