Ejemplo n.º 1
0
        public ScriptViewModel GetScriptDetail(string name)
        {
            Scripts entity = script_repo.GetAll().FirstOrDefault(x => x.Name == name);

            if (entity != null)
            {
                ScriptViewModel scriptVM = new ScriptViewModel
                {
                    Difficulty = entity.Difficulty,
                    Id         = entity.Id,
                    Intro      = entity.Intro,
                    IsPlace    = entity.IsPlace,
                    Name       = entity.Name,
                    Owner      = user_repo.GetAll().FirstOrDefault(x => x.Id == entity.UserId).Name,
                    PlayerNum  = entity.PlayerNum.ToString(),
                    Price      = entity.Price.ToString(),
                    Time       = entity.Time.ToString(),
                    Tags       = entity.Tags.Split('&').ToList(),
                    GameMaster = entity.GameMaster,
                    Characters = character_repo.GetAll().Where(x => x.ScriptId == entity.Id).Select(x => new Character
                    {
                        Image = x.Image,
                        Intro = x.Intro,
                        Name  = x.Name
                    }).ToList()
                };

                return(scriptVM);
            }
            else
            {
                return(null);
            }
        }
 public StringViewModel(ScriptViewModel script, ScriptNode node) : base(script, node)
 {
     _value        = node.Value;
     _subscription = this.WhenAnyValue(_ => _.EditableValue).Throttle(TimeSpan.FromSeconds(0.25))
                     .ObserveOnDispatcher()
                     .Subscribe(_ => BuildNodeValue());
 }
        public Vector4ViewModel(ScriptViewModel script, ScriptNode node) : base(script, node)
        {
            CanRename = NodeTypes.IsParameter(node.Type);

            var components = (node.Value ?? "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (components.Length > 0)
            {
                _x = components[0];
                if (components.Length > 1)
                {
                    _y = components[1];
                    if (components.Length > 2)
                    {
                        _z = components[2];
                        if (components.Length > 3)
                        {
                            _w = components[3];
                        }
                    }
                }
            }

            _subscription = this.WhenAnyValue(_ => _.X, _ => _.Y, _ => _.Z, _ => _.W)
                            .Throttle(TimeSpan.FromSeconds(0.25))
                            .ObserveOnDispatcher()
                            .Subscribe(_ => BuildNodeValue());
        }
        public Mat3ViewModel(ScriptViewModel script, ScriptNode node) : base(script, node)
        {
            CanRename = NodeTypes.IsParameter(node.Type);
            var components = (node.Value ?? "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            for (var index = 0; index < _m.Length; index++)
            {
                _m[index] = "0.0";
            }

            for (var index = 0; index < components.Length; index++)
            {
                _m[index] = components[index];
            }

            _subscription = Observable.CombineLatest(
                this.ObservableForProperty(_ => _.M00, false, false),
                this.ObservableForProperty(_ => _.M01, false, false),
                this.ObservableForProperty(_ => _.M02, false, false),
                this.ObservableForProperty(_ => _.M10, false, false),
                this.ObservableForProperty(_ => _.M11, false, false),
                this.ObservableForProperty(_ => _.M12, false, false),
                this.ObservableForProperty(_ => _.M20, false, false),
                this.ObservableForProperty(_ => _.M21, false, false),
                this.ObservableForProperty(_ => _.M22, false, false)
                )
                            .Throttle(TimeSpan.FromSeconds(0.25))
                            .ObserveOnDispatcher()
                            .Subscribe(_ => BuildNodeValue());
        }
Ejemplo n.º 5
0
 public SamplerCubeViewModel(ScriptViewModel script, ScriptNode node, UrhoContext context) : base(script, node)
 {
     _context            = context;
     PickTextureCommand  = new ScriptingCommand(PickTexture);
     ResetTextureCommand = new ScriptingCommand(ResetTexture);
     UpdateImageSource();
 }
Ejemplo n.º 6
0
        public IntViewModel(ScriptViewModel script, ScriptNode node) : base(script, node)
        {
            CanRename = NodeTypes.IsParameter(node.Type);

            _x            = node.Value;
            _subscription = this.WhenAnyValue(_ => _.X).Throttle(TimeSpan.FromSeconds(0.25)).ObserveOnDispatcher()
                            .Subscribe(_ => BuildNodeValue());
        }
Ejemplo n.º 7
0
        public ActionResult <object> CreateFile(ScriptViewModel script)
        {
            var scriptUrl = _gitLabService.CreateNewFileFromApi(script);

            var result = _elasticsearchService.CreateNewDocumentFromApi(script, scriptUrl);

            return(Ok(result));
        }
Ejemplo n.º 8
0
        public ActionResult New()
        {
            ScriptViewModel vmPlane = new ScriptViewModel();

            vmPlane.AllActions = _ActionRepository.GetAll(true);
            _PreferenceRepository.LoadBasePreferences(vmPlane);
            return(View(vmPlane));
        }
Ejemplo n.º 9
0
    public override object Copy(IDictionary <object, object>?shared)
    {
        var copy = new ScriptViewModel(ServiceProvider)
        {
            Code = _code
        };

        return(copy);
    }
Ejemplo n.º 10
0
 public NodeViewModel Create(ScriptViewModel script, ScriptNode node)
 {
     //if (node.Category == NodeCategory.Event)
     //    return new EventNodeViewModel(script, node);
     if (node.Category == NodeCategory.Value)
     {
         return(new ConstantNodeViewModel(script, node));
     }
     return(new NodeViewModel(script, node));
 }
Ejemplo n.º 11
0
        public bool CreateScript(ScriptViewModel scriptVM, string account)
        {
            try
            {
                Guid userId = user_repo.GetAll().FirstOrDefault(x => x.Account == account).Id;

                Scripts script = new Scripts
                {
                    Id         = Guid.NewGuid(),
                    Name       = scriptVM.Name,
                    Intro      = scriptVM.Intro,
                    Difficulty = scriptVM.Difficulty,
                    CreateTime = DateTime.Now,
                    IsPlace    = scriptVM.IsPlace,
                    Price      = int.Parse(scriptVM.Price),
                    Time       = int.Parse(scriptVM.Time),
                    Tags       = string.Join('&', scriptVM.Tags),
                    PlayerNum  = int.Parse(scriptVM.PlayerNum),
                    GameMaster = scriptVM.GameMaster,
                    UserId     = userId,
                    CategoryId = scriptVM.Category
                };
                script_repo.Create(script);

                for (int i = 0; i < scriptVM.Characters.Count; i++)
                {
                    Characters character = new Characters
                    {
                        Intro    = scriptVM.Characters[i].Intro,
                        Name     = scriptVM.Characters[i].Name,
                        Image    = scriptVM.Characters[i].Image,
                        ScriptId = script.Id
                    };
                    character_repo.Create(character);
                }

                for (int i = 0; i < scriptVM.Images.Count; i++)
                {
                    ScriptImages image = new ScriptImages
                    {
                        ScriptId    = script.Id,
                        Image       = scriptVM.Images[i].url,
                        OrderNumber = int.Parse(scriptVM.Images[i].orderNum)
                    };
                    scriptImg_repo.Create(image);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
 public IActionResult CreateScript(ScriptViewModel scriptVM)
 {
     if (_scriptService.CreateScript(scriptVM, User.Identity.Name))
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 13
0
        public string CreateNewFileFromApi(ScriptViewModel script)
        {
            var request = new RestRequest($"projects/35544/repository/files/scripts%2F{script.Name}%2Eps1", Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Content-type", "application/json");

            request.AddBody(new GitLabFileDTO {
                branch         = "master",
                content        = script.Content,
                commit_message = "Create new script from powershell gallery"
            });

            var response = _client.Execute(request);

            return($"{GitLabRepoBaseUrl}/{script.Name}.ps1");
        }
Ejemplo n.º 14
0
        public MainWindowViewModel()
        {
            Script = new ScriptViewModel();

            SetGLSL(@"
#version 450
layout(location = 0) in int Attr;
void main()
{
    float x = 1.1;
    for (int i=0; i<Attr;++i)
    {
        //x *= x;
    }
    gl_Position = vec4(x);
}", ShaderStages.Vertex, true);
        }
        public MainViewModel(ScriptViewModel scriptViewModel, ShaderGenerator generator, UrhoContext context,
                             GraphValidator validator, ConfigurationRepository <AppConfiguration> config)
        {
            _backgroundScheduler = new EventLoopScheduler();
            _disposables.Add(_backgroundScheduler);
            _generator             = generator;
            _context               = context;
            _validator             = validator;
            _config                = config;
            NewCommand             = new ScriptingCommand(New);
            NewEmptyCommand        = new ScriptingCommand(NewEmpty);
            OpenCommand            = new ScriptingCommand(Open);
            MergeCommand           = new ScriptingCommand(Merge);
            SaveCommand            = new ScriptingCommand(Save);
            SaveAsCommand          = new ScriptingCommand(SaveAs);
            ExportCommand          = new ScriptingCommand(Export);
            OpenSceneCommand       = new ScriptingCommand <string>(OpenScene);
            OpenMDLCommand         = new ScriptingCommand <string>(OpenMDL);
            OpenAnimatedMDLCommand = new ScriptingCommand <string>(OpenAnimatedMDL);

            SetResourcePathCommand   = new ScriptingCommand(SetResourcePath);
            ExitCommand              = new ScriptingCommand(Exit);
            SetRenderPathCommand     = new ScriptingCommand <string>(SetRenderPath);
            SetShadowQualityCommand  = new ScriptingCommand <string>(SetShadowQuality);
            _rearrangeCommand        = new ScriptingCommand(() => ScriptViewModel.Rearrange());
            _centerGraphCommand      = new ScriptingCommand(() => ToCenter());
            SaveSelectedAsCommand    = new ScriptingCommand(SaveSelectedAs);
            RunScriptAnalizerCommand = new ScriptingCommand(RunScriptAnalizer);
            TestAllNodeTypesCommand  = new ScriptingCommand(TestAllNodeTypes);
            TestNodesCommand         = new ScriptingCommand(TestNodes);
            TestPerformanceCommand   = new ScriptingCommand(TestPerformance);
            ScriptViewModel          = scriptViewModel;

            _errors = new Subject <MaterialCompilationException>();
            _disposables.Add(_errors.ObserveOnDispatcher().Subscribe(HandleError));

            _preview = new Subject <PreviewData>();
            _disposables.Add(_preview.Throttle(TimeSpan.FromSeconds(0.1f)).ObserveOn(_backgroundScheduler)
                             .Subscribe(new Generator(this)));

            ScriptViewModel.ScriptChanged    += OnScriptViewModelOnScriptChanged;
            ScriptViewModel.SelectionChanged += OnScriptViewModelOnSelectionChanged;
            New();
        }
Ejemplo n.º 16
0
        public NodeViewModel Create(ScriptViewModel script, ScriptNode node)
        {
            if (node.Type == NodeTypes.MakeType(NodeTypes.ParameterPrefix, PinTypes.Special.Color))
            {
                if (node.Name == MaterialNodeRegistry.Parameters.MatSpecColor)
                {
                    return(new SpecularViewModel(script, node));
                }
            }
            switch (node.Type)
            {
            case NodeTypes.SamplerCube:
            case NodeTypes.Sampler2D:
                switch (node.Name)
                {
                case SamplerNodeFactory.Screen:
                case SamplerNodeFactory.LightRampMap:
                case SamplerNodeFactory.ShadowMap:
                case SamplerNodeFactory.FaceSelectCubeMap:
                case SamplerNodeFactory.IndirectionCubeMap:
                case SamplerNodeFactory.ZoneCubeMap:
                    return(new NodeViewModel(script, node));
                }

                break;
            }

            NodeViewModel vm;

            if (!_container.TryResolveNamed(node.Type, out vm, TypedParameter.From(script), TypedParameter.From(node)))
            {
                if (NodeTypes.IsConnectorType(node.Type))
                {
                    vm = new ConnectorNodeViewModel(script, node);
                }
                else if (NodeTypes._attributes.ContainsKey(node.Type))
                {
                    vm = new NodeViewModel(script, node)
                    {
                        CanRename = true
                    }
                }
            }
            ;
Ejemplo n.º 17
0
        public IActionResult Put([FromBody] ScriptViewModel scriptViewModel)
        {
            if (scriptViewModel == null)
            {
                return(StatusCode(500, new InternalServerError()));
            }

            var user = User.GetUser(_context);

            var userHasController = _context.UserHasControllers
                                    .Where(p => p.UserId == user.Id)
                                    .Where(p => p.ControllerId == scriptViewModel.ControllerId)
                                    .FirstOrDefault();

            if (userHasController == null)
            {
                return(Unauthorized(new UnauthorizedError()));
            }

            var script = new Script
            {
                ControllerId         = scriptViewModel.ControllerId,
                Priority             = scriptViewModel.Priority,
                ConditionTypeId      = scriptViewModel.ConditionTypeId,
                Complited            = false,
                RepeatTimes          = scriptViewModel.RepeatTimes,
                TimeTo               = scriptViewModel.TimeTo,
                TimeFrom             = scriptViewModel.TimeFrom,
                Delta                = scriptViewModel.Delta,
                SensorId             = scriptViewModel.SensorId,
                Visible              = true,
                LastModificationDate = DateTime.Now,
                ConditionValue       = scriptViewModel.ConditionValue,
                UserId               = user.Id,
                Status               = false,
                Name = scriptViewModel.Name
            };

            _context.Scripts.Add(script);
            _context.SaveChanges();

            return(Json(script.Adapt <ScriptViewModel>()));
        }
Ejemplo n.º 18
0
        public object CreateNewDocumentFromApi(ScriptViewModel script, string scriptUrl)
        {
            var request = new RestRequest($"/script/_doc/", Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Content-type", "application/json");

            request.AddBody(new Script {
                ScriptName        = script.Name,
                ScriptDescription = script.Description,
                ScriptTags        = script.Tags,
                DateCreated       = DateTime.UtcNow,
                LastModified      = DateTime.UtcNow,
                GitLabUrl         = scriptUrl
            });

            var response = _client.Execute(request);

            return(response.Content);
        }
Ejemplo n.º 19
0
        public MainWindowViewModel()
        {
            Script = new ScriptViewModel();

            //            SetGLSL(@"
            //#version 450
            //void main()
            //{
            //    gl_Position = vec4(0,0,0,1);
            //}",
            //                @"
            //#version 450
            //layout(location = 0) out vec4 fragColor;
            //void main()
            //{
            //    fragColor = vec4(1,0,1,1);
            //}");

            SetGLSL(_vertexShaderSource, _fragmentShaderSource);
        }
Ejemplo n.º 20
0
    public bool Validate(ref ModelStateDictionary state, ScriptViewModel myViewModel)
    {
        Script myScript = myViewModel.Current;

        if (string.IsNullOrEmpty(myScript.Name))
        {
            state.AddModelError("1", "Debe introducir un nombre");
        }

        if (string.IsNullOrEmpty(myScript.Description))
        {
            state.AddModelError("2", "Debe introducir una descripcion");
        }

        if (myViewModel.Actions == null || myViewModel.Actions.Count == 0)
        {
            state.AddModelError("3", "Debe introducir acciones");
        }

        return(state.IsValid);
    }
        public ColorViewModel(ScriptViewModel script, ScriptNode node) : base(script, node)
        {
            CanRename = NodeTypes.IsParameter(node.Type);

            var components = (node.Value ?? "").Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (components.Length > 0)
            {
                if (!float.TryParse(components[0], NumberStyles.Any, FormatProvider, out _r))
                {
                    _r = 0.0f;
                }
                if (components.Length > 1)
                {
                    if (!float.TryParse(components[1], NumberStyles.Any, FormatProvider, out _g))
                    {
                        _g = 0.0f;
                    }
                    if (components.Length > 2)
                    {
                        if (!float.TryParse(components[2], NumberStyles.Any, FormatProvider, out _b))
                        {
                            _b = 0.0f;
                        }
                        if (components.Length > 3)
                        {
                            if (!float.TryParse(components[3], NumberStyles.Any, FormatProvider, out _a))
                            {
                                _a = 1.0f;
                            }
                        }
                    }
                }
            }

            _subscription = this.WhenAnyValue(_ => _.R, _ => _.G, _ => _.B, _ => _.A)
                            .Throttle(TimeSpan.FromSeconds(0.25))
                            .ObserveOnDispatcher().Subscribe(_ => BuildNodeValue());
        }
Ejemplo n.º 22
0
        public IActionResult Post([FromBody] ScriptViewModel scriptViewModel)
        {
            if (scriptViewModel == null)
            {
                return(StatusCode(500, new InternalServerError()));
            }

            var script = _context.Scripts.Find(scriptViewModel.Id);

            if (script == null)
            {
                return(NotFound(new NotFoundError()));
            }

            var user = User.GetUser(_context);

            if (script.UserId != user.Id)
            {
                return(Unauthorized(new UnauthorizedError()));
            }

            script.Priority             = scriptViewModel.Priority;
            script.ConditionTypeId      = scriptViewModel.ConditionTypeId;
            script.RepeatTimes          = scriptViewModel.RepeatTimes;
            script.TimeTo               = scriptViewModel.TimeTo;
            script.TimeFrom             = scriptViewModel.TimeFrom;
            script.Delta                = scriptViewModel.Delta;
            script.SensorId             = scriptViewModel.SensorId;
            script.Visible              = true;
            script.LastModificationDate = DateTime.Now;
            script.Status               = scriptViewModel.Status;
            script.Name           = scriptViewModel.Name;
            script.ConditionValue = scriptViewModel.ConditionValue;
            _context.Scripts.Update(script);
            _context.SaveChanges();

            //TODO
            return(Json(script.Adapt <ScriptViewModel>()));
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> UploadScript(ScriptViewModel attachment)
        {
            try
            {
                Log($"Receiving script for job '{attachment.Id}'");

                var job = _jobs.Find(attachment.Id);

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

                var tempFilename = Path.GetTempFileName();

                Log($"Creating {attachment.SourceFileName} in {tempFilename}");

                using (var fs = System.IO.File.Create(tempFilename))
                {
                    await attachment.Content.CopyToAsync(fs);
                }

                job.Attachments.Add(new ScriptAttachment
                {
                    TempFilename = tempFilename,
                    Filename     = attachment.SourceFileName
                });

                _jobs.Update(job);

                return(Ok());
            }
            catch (Exception e)
            {
                Log(e.Message);
                return(new StatusCodeResult((int)HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 24
0
        public static bool RunSqlScriptOnConnection(string connectionString, ScriptViewModel script)
        {
            try
            {
                var filePath = script.Path;

                var scriptContents = File.ReadAllText(filePath);
                var sqlConnection  = new SqlConnection(connectionString);
                var server         = new Server(new ServerConnection(sqlConnection));
                server.ConnectionContext.ExecuteNonQuery(scriptContents);

                script.ErrorMessage = string.Empty;

                return(true);
            }
            catch (ExecutionFailureException ex)
            {
                var sqlException = ex.InnerException as SqlException;
                if (sqlException != null)
                {
                    script.ErrorMessage = string.Format("At line {0}:\n{1}", sqlException.LineNumber, sqlException.Message);
                }
                else if (ex.InnerException != null)
                {
                    script.ErrorMessage = ex.InnerException.Message;
                }
                else
                {
                    script.ErrorMessage = ex.Message;
                }
            }
            catch (Exception ex)
            {
                script.ErrorMessage = ex.Message;
            }

            return(false);
        }
Ejemplo n.º 25
0
        public ActionResult Save(ScriptViewModel myModel)
        {
            try
            {
                _LoggingService.Write("ScriptController (Save) page access", true);

                var myModelState = ModelState;
                if (_ScriptRepository.Validate(ref myModelState, myModel))
                {
                    _ScriptRepository.Save(myModel.Current, myModel.Actions);
                    _LoggingService.Write("ScriptController - Save () successful: ", true);
                    return(RedirectToAction("Index", "Home"));
                }

                myModel.AllActions = _ActionRepository.GetAll(true);
                return(View("New", myModel));
            }
            catch (Exception ex)
            {
                _LoggingService.WriteWithInner(ex, true, "ScriptController(Save) error: ");
                return(new HttpNotFoundResult());
            }
        }
Ejemplo n.º 26
0
        private void EditScript(ScriptViewModel scriptViewModel)
        {
            var script = _scriptRepository.Get(scriptViewModel.Id);

            RunEditScript(script);
        }
Ejemplo n.º 27
0
 public ScriptPage()
 {
     InitializeComponent();
     DataContext = new ScriptViewModel();
 }
Ejemplo n.º 28
0
 public EnumViewModel(ScriptViewModel script, ScriptNode node) : base(script, node, typeof(T))
 {
 }
Ejemplo n.º 29
0
 public ConnectorNodeViewModel(ScriptViewModel script, ScriptNode node) : base(script, node)
 {
     this.HasGroupPins = true;
 }
Ejemplo n.º 30
0
 public MainViewModel(ScriptViewModel scriptViewModel)
 {
     ScriptViewModel = scriptViewModel;
     OpenCommand     = new ScriptingCommand(Open);
 }