public IHttpActionResult Get(Guid id)
        {
            Data.Workspace w = null;

            try
            {
                w = _unit.Workspaces.Find(id);

                if (w == null)
                {
                    return(NotFound());
                }

                return(Ok(w));
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    return(BadRequest(ex.InnerException.Message));
                }
                else if (ex.Message != null)
                {
                    return(BadRequest(ex.Message));
                }
                else
                {
                    return(BadRequest("something bad"));
                }
            }
        }
Exemple #2
0
        private async Task <GameState> Launch(Data.Workspace workspace, string isolationId = null)
        {
            var gamespaces = await _gamespaceStore
                             .ListByProfile(User.Id)
                             .ToArrayAsync();

            var game = gamespaces
                       .Where(m => m.WorkspaceId == workspace.Id)
                       .SingleOrDefault();

            if (game == null)
            {
                if (gamespaces.Length >= _options.GamespaceLimit)
                {
                    throw new GamespaceLimitReachedException();
                }

                game = await Create(workspace, Client.Id, isolationId);
            }

            await Deploy(game);

            var state = await LoadState(game);

            return(state);
        }
 private async Task <GameState> LoadState(Data.Workspace workspace)
 {
     return(new GameState
     {
         Name = workspace.Name,
         Markdown = (await LoadMarkdown(workspace.Id)).Split("<!-- cut -->").First()
                    ?? $"# {workspace.Name}"
     });
 }
Exemple #4
0
        /// <summary>
        /// Load a workspace by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Workspace</returns>
        public async Task <Workspace> Load(int id)
        {
            Data.Workspace topo = await _workspaceStore.Load(id);

            if (topo == null)
            {
                throw new InvalidOperationException();
            }

            return(Mapper.Map <Workspace>(topo, WithActor()));
        }
Exemple #5
0
        private Task <GameState> LoadState(Data.Workspace workspace)
        {
            if (workspace == null || !workspace.IsPublished)
            {
                throw new InvalidOperationException();
            }

            var state = new GameState();

            state.Name = workspace.Name;

            state.WorkspaceDocument = workspace.Document;

            state.Vms = workspace.Templates
                        .Where(t => !t.IsHidden)
                        .Select(t => new VmState {
                Name = t.Name, TemplateId = t.Id
            })
                        .ToArray();

            return(Task.FromResult(state));
        }
Exemple #6
0
        private async Task <Data.Gamespace> Create(
            Data.Workspace workspace,
            string client,
            string isolationId
            )
        {
            var gamespace = new Data.Gamespace
            {
                GlobalId  = isolationId,
                Name      = workspace.Name,
                Workspace = workspace,
                ShareCode = Guid.NewGuid().ToString("n"),
                Audience  = client
            };

            gamespace.Players.Add(
                new Data.Player
            {
                PersonId   = User.Id,
                Permission = Data.Permission.Manager
                             // LastSeen = DateTime.UtcNow
            }
                );

            // glean randomize targets
            var regex = new Regex("##[^#]*##");

            var map = new Dictionary <string, string>();

            foreach (var t in gamespace.Workspace.Templates)
            {
                foreach (Match match in regex.Matches(t.Guestinfo ?? ""))
                {
                    map.TryAdd(match.Value, "");
                }

                foreach (Match match in regex.Matches(t.Detail ?? t.Parent?.Detail ?? ""))
                {
                    map.TryAdd(match.Value, "");
                }
            }

            // clone challenge
            var spec = new ChallengeSpec();

            if (!string.IsNullOrEmpty(workspace.Challenge))
            {
                spec = JsonSerializer.Deserialize <ChallengeSpec>(workspace.Challenge ?? "{}", jsonOptions);

                foreach (var question in spec.Questions)
                {
                    foreach (Match match in regex.Matches(question.Answer))
                    {
                        string key = match.Value;
                        string val = "";

                        if (key.Contains(":list##"))
                        {
                            string[] list = question.Answer
                                            .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                            .Skip(1)
                                            .ToArray();

                            if (list.Length > 0)
                            {
                                val = list[_random.Next(list.Length)];

                                question.Answer = key;

                                if (map.ContainsKey(key))
                                {
                                    map[key] = val;
                                }
                            }
                        }

                        map.TryAdd(key, val);
                    }
                }
            }

            // resolve macros
            foreach (string key in map.Keys.ToArray())
            {
                if (string.IsNullOrEmpty(map[key]))
                {
                    map[key] = ResolveRandom(key);
                }
            }

            // apply macros to spec answers
            foreach (var q in spec.Questions)
            {
                foreach (string key in map.Keys)
                {
                    q.Answer = q.Answer.Replace(key, map[key]);
                }
            }

            spec.Randoms = map;

            gamespace.Challenge = JsonSerializer.Serialize(spec, jsonOptions);

            await _gamespaceStore.Add(gamespace);

            return(gamespace);
        }
Exemple #7
0
        private async Task <GameState> LoadState(Data.Gamespace gamespace, int topoId)
        {
            GameState state = null;

            // gamespace should never be null in the engine service
            if (gamespace == null)
            {
                Data.Workspace topo = await _workspaceStore.Load(topoId);

                if (topo == null || !topo.IsPublished)
                {
                    throw new InvalidOperationException();
                }

                state = new GameState();

                state.Name = gamespace?.Name ?? topo.Name;

                state.WorkspaceDocument = topo.Document;

                state.Vms = topo.Templates
                            .Where(t => !t.IsHidden)
                            .Select(t => new VmState {
                    Name = t.Name, TemplateId = t.Id
                })
                            .ToArray();
            }
            else
            {
                // get vm's, look up template, add if template not mark as hidden.

                state = Mapper.Map <GameState>(gamespace);

                var vmState = new List <VmState>();

                var vms = await _pod.Find(gamespace.GlobalId);

                foreach (Vm vm in vms)
                {
                    string name = vm.Name.Untagged();

                    // a vm could be a replica, denoted by `_1` or some number,
                    // so strip that to find template.
                    int x = name.LastIndexOf('_');

                    var tmpl = gamespace.Workspace.Templates
                               .Where(t => !t.IsHidden && t.Name == name)
                               .FirstOrDefault();

                    if (tmpl == null && x == name.Length - 2)
                    {
                        name = name.Substring(0, x);

                        tmpl = gamespace.Workspace.Templates
                               .Where(t => !t.IsHidden && t.Name == name)
                               .FirstOrDefault();
                    }

                    if (tmpl != null)
                    {
                        vmState.Add(new VmState
                        {
                            Id         = vm.Id,
                            Name       = vm.Name,
                            IsRunning  = (vm.State == VmPowerState.Running),
                            TemplateId = tmpl.Id
                        });
                    }
                }

                state.Vms = vmState.ToArray();
            }

            return(state);
        }
        private void CreateK2UKApp()
        {
            //Database.SetInitializer(new DropCreateDatabaseAlways<K2Field.SmartForms.Workspace.Model.WorkspaceContext>());

            using (var unit = new ApplicationUnit())
            {
                Data.WorkspaceUser u = new Data.WorkspaceUser()
                {
                    Username    = @"denallix\administrator",
                    FQN         = @"denallix\administrator",
                    DisplayName = "Administrator",
                    Email       = "*****@*****.**",
                    IsActive    = true
                };


                ObservableCollection <Data.WorkspaceUser> r = new ObservableCollection <Data.WorkspaceUser>();
                r.Add(u);

                Data.WorkspaceTeam scna = new Data.WorkspaceTeam()
                {
                    Name           = "scna",
                    DisplayName    = "K2 SCNA",
                    Description    = "K2 North American Team",
                    IsActive       = true,
                    WorkspaceUsers = r,
                };

                Data.WorkspaceTeam scuk = new Data.WorkspaceTeam()
                {
                    Name           = "scuk",
                    DisplayName    = "K2 SCUK",
                    Description    = "K2 UK Europe Team",
                    IsActive       = true,
                    WorkspaceUsers = r,
                };

                Data.WorkspaceLink link1a = new Data.WorkspaceLink()
                {
                    Name        = "mytasks",
                    DisplayName = "My Tasks",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/Runtime/Runtime/Form/Worklist/",
                    Type        = "Link",
                    Icon        = "fa fa-male fa-fw",
                    MinHeight   = 400
                };

                Data.WorkspaceLink link1b = new Data.WorkspaceLink()
                {
                    Name        = "teamtasks",
                    DisplayName = "Team Tasks",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/Runtime/Runtime/Form/Worklist/",
                    Type        = "Link",
                    Icon        = "fa fa-group fa-fw",
                    MinHeight   = 400
                };

                Data.WorkspaceLink link1c = new Data.WorkspaceLink()
                {
                    Name        = "servicetasks",
                    DisplayName = "Service Tasks",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/Runtime/Runtime/Form/Worklist/",
                    Type        = "Link",
                    Icon        = "fa fa-sort-amount-asc fa-fw",
                    MinHeight   = 400
                };

                ObservableCollection <Data.WorkspaceLink> tasks = new ObservableCollection <Data.WorkspaceLink>();
                tasks.Add(link1a);
                tasks.Add(link1b);
                tasks.Add(link1c);

                Data.WorkspaceLink link1 = new Data.WorkspaceLink()
                {
                    Name        = "tasks",
                    DisplayName = "Tasks",
                    IsEnabled   = true,
                    IsSmartForm = false,
                    Level       = 0,
                    Type        = "Heading",
                    ChildLinks  = tasks,
                    Icon        = "fa fa-tasks fa-fw",
                };


                Data.WorkspaceLink link2 = new Data.WorkspaceLink()
                {
                    Name        = "apps",
                    DisplayName = "Apps",
                    IsEnabled   = true,
                    IsSmartForm = false,
                    Level       = 0,
                    //Url = "https://k2.denallix.com/Runtime/Runtime/View/Demo+CRM+Account+List/",
                    Type      = "Heading",
                    Icon      = "fa fa-cogs fa-fw",
                    MinHeight = 500
                };

                Data.WorkspaceLink taskalloc = new Data.WorkspaceLink()
                {
                    Name        = "taskallocation",
                    DisplayName = "Task Allocation",
                    Description = "Allocate a managed tasks to users",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/runtime/runtime/form/cm.task__create.form/?_theme=jove1",
                    Type        = "Link",
                    Icon        = "fa fa-sitemap fa-fw",
                    MinHeight   = 500,
                    Sequence    = 0,
                };

                Data.WorkspaceLink sendmessage = new Data.WorkspaceLink()
                {
                    Name        = "sendmessage",
                    DisplayName = "Send Message",
                    Description = "Send a tracked email or SMS message",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/runtime/runtime/form/cm.sendmessage.form/?_theme=jove1",
                    Type        = "Link",
                    Icon        = "fa fa-paper-plane fa-fw",
                    MinHeight   = 500,
                    Sequence    = 0,
                };

                Data.WorkspaceLink customerfeedback = new Data.WorkspaceLink()
                {
                    Name        = "customerfeedback",
                    DisplayName = "Customer Feedback",
                    Description = "Record and manage customer feedback",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/runtime/runtime/form/newportal__denallix__com__sales__lists__customer__feedbacktaskform/?_theme=jove1",
                    Type        = "Link",
                    Icon        = "fa fa-rocket fa-fw",
                    MinHeight   = 500,
                    Sequence    = 0,
                };

                Data.WorkspaceLink logaconversation = new Data.WorkspaceLink()
                {
                    Name        = "logaconversation",
                    DisplayName = "Log a Conversation",
                    Description = "Log a conversation with an employee or customer",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/runtime/runtime/form/cm.logconversation.form/",
                    Type        = "Link",
                    Icon        = "fa fa-wechat fa-fw",
                    MinHeight   = 500,
                    Sequence    = 0,
                };

                Data.WorkspaceLink employeeonboarding = new Data.WorkspaceLink()
                {
                    Name        = "employeeonboarding",
                    DisplayName = "Employee Onboarding",
                    Description = "Onboard a new employee",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/runtime/runtime/form/eo.submitnewemployee.form/",
                    Type        = "Link",
                    Icon        = "fa fa-desktop fa-fw",
                    MinHeight   = 500,
                    Sequence    = 0,
                };

                Data.WorkspaceLink raiseapurchaseorder = new Data.WorkspaceLink()
                {
                    Name        = "raiseapurchaseorder",
                    DisplayName = "Raise Purchase Order",
                    Description = "Raise new purchase order",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/runtime/runtime/form/po.raisenewpo.form/?_theme=jove1",
                    Type        = "Link",
                    Icon        = "fa fa-usd fa-fw",
                    MinHeight   = 500,
                    Sequence    = 0,
                };

                ObservableCollection <Data.WorkspaceLink> apps = new ObservableCollection <Data.WorkspaceLink>();
                apps.Add(taskalloc);
                apps.Add(sendmessage);
                apps.Add(customerfeedback);
                apps.Add(logaconversation);
                apps.Add(employeeonboarding);
                apps.Add(raiseapurchaseorder);

                link2.ChildLinks = apps;

                Data.WorkspaceLink link3 = new Data.WorkspaceLink()
                {
                    Name        = "dashboards",
                    DisplayName = "Dashboards",
                    IsEnabled   = true,
                    IsSmartForm = false,
                    Level       = 0,
                    Type        = "Heading",
                    Icon        = "fa fa-dashboard fa-fw",
                    MinHeight   = 500,
                    Sequence    = 2,
                };


                Data.WorkspaceLink chart1 = new Data.WorkspaceLink()
                {
                    Name        = "chart1",
                    DisplayName = "Org KPI ",
                    Description = "Organization wide KPIs",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/runtime/runtime/form/po.raisenewpo.form/?_theme=jove1",
                    Type        = "Link",
                    Icon        = "fa fa-area-chart fa-fw",
                    MinHeight   = 500,
                    Sequence    = 0,
                };


                Data.WorkspaceLink chart2 = new Data.WorkspaceLink()
                {
                    Name        = "chart2",
                    DisplayName = "Task Dashboard ",
                    Description = "Task Dashboard",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/runtime/runtime/form/po.raisenewpo.form/?_theme=jove1",
                    Type        = "Link",
                    Icon        = "fa fa-line-chart fa-fw",
                    MinHeight   = 500,
                    Sequence    = 0,
                };

                Data.WorkspaceLink chart3 = new Data.WorkspaceLink()
                {
                    Name        = "chart3",
                    DisplayName = "Customer Service Dashboard ",
                    Description = "Customer Service  Dashboard",
                    IsEnabled   = true,
                    IsSmartForm = true,
                    Level       = 1,
                    Url         = "https://k2.denallix.com/runtime/runtime/form/po.raisenewpo.form/?_theme=jove1",
                    Type        = "Link",
                    Icon        = "fa fa-pie-chart fa-fw",
                    MinHeight   = 500,
                    Sequence    = 0,
                };

                ObservableCollection <Data.WorkspaceLink> dash = new ObservableCollection <Data.WorkspaceLink>();
                dash.Add(chart1);
                dash.Add(chart2);
                dash.Add(chart3);

                link3.ChildLinks = dash;

                ObservableCollection <Data.WorkspaceLink> headings = new ObservableCollection <Data.WorkspaceLink>();
                headings.Add(link1);
                headings.Add(link2);
                headings.Add(link3);

                //Url = "https://k2.denallix.com/Runtime/Runtime/View/Demo+CRM+Account+List/",


                //unit.WorklistUsers.Add(u);


                Data.Workspace w = new Data.Workspace()
                {
                    DisplayName          = "K2 Workdesk",
                    Name                 = "K2workdesk",
                    Description          = "K2 Workdesk description....",
                    SmartFormsRuntimeUrl = "https://k2.denallix.com/runtime/",
                    Links                = headings,
                    Icon                 = "fa fa-suitcase fa-2x",
                };



                ObservableCollection <Data.WorkspaceLink> headings1 = new ObservableCollection <Data.WorkspaceLink>();
                headings1.Add(link1a);
                headings1.Add(link1b);
                headings1.Add(link1c);
                headings1.Add(chart1);
                headings1.Add(chart2);

                Data.Workspace w1 = new Data.Workspace()
                {
                    DisplayName          = "Task Management",
                    Name                 = "taskmanagement",
                    Description          = "Task Management workdesk description...",
                    SmartFormsRuntimeUrl = "https://k2.denallix.com/runtime/",
                    Links                = headings1,
                    Icon                 = "fa fa-share-alt fa-2x",
                };


                Data.WorkspaceLink linkservice = new Data.WorkspaceLink()
                {
                    Name        = "serviceapps",
                    DisplayName = "Service Apps",
                    IsEnabled   = true,
                    IsSmartForm = false,
                    Level       = 0,
                    //Url = "https://k2.denallix.com/Runtime/Runtime/View/Demo+CRM+Account+List/",
                    Type      = "Heading",
                    Icon      = "fa fa-cogs fa-fw",
                    MinHeight = 500
                };

                ObservableCollection <Data.WorkspaceLink> serviceapps = new ObservableCollection <Data.WorkspaceLink>();
                serviceapps.Add(customerfeedback);
                serviceapps.Add(sendmessage);
                serviceapps.Add(logaconversation);
                serviceapps.Add(taskalloc);

                linkservice.ChildLinks = serviceapps;

                ObservableCollection <Data.WorkspaceLink> headings2 = new ObservableCollection <Data.WorkspaceLink>();
                headings2.Add(link1a);
                headings2.Add(link1b);
                headings2.Add(linkservice);
                headings2.Add(chart1);
                headings2.Add(chart3);


                Data.Workspace w2 = new Data.Workspace()
                {
                    DisplayName          = "Service Desks",
                    Name                 = "servicedesk",
                    Description          = "Customer Service Desk description...",
                    SmartFormsRuntimeUrl = "https://k2.denallix.com/runtime/",
                    Links                = headings2,
                    Icon                 = "fa fa-trophy fa-2x",
                };

                w.WorkspaceTeams = new ObservableCollection <Data.WorkspaceTeam>();
                w.WorkspaceTeams.Add(scna);
                w.WorkspaceTeams.Add(scuk);

                w1.WorkspaceTeams = new ObservableCollection <Data.WorkspaceTeam>();
                w1.WorkspaceTeams.Add(scna);
                w1.WorkspaceTeams.Add(scuk);

                w2.WorkspaceTeams = new ObservableCollection <Data.WorkspaceTeam>();
                w2.WorkspaceTeams.Add(scna);
                w2.WorkspaceTeams.Add(scuk);

                //unit.WorkspaceTeams.Add(t);
                unit.Workspaces.Add(w);
                unit.Workspaces.Add(w1);
                unit.Workspaces.Add(w2);

                int rows = unit.SaveChanges();
                MessageBox.Show("Rows: " + rows);
            }
        }
Exemple #9
0
        public async Task <Workspace> Load(string id)
        {
            Data.Workspace entity = await _store.Load(id);

            return(Mapper.Map <Workspace>(entity));
        }