public static IScriptResource FromZipArchiveEntry(string archivePath, ZipArchiveEntry entry, bool userLoaded = false)
    {
        using var stream = entry.Open();

        var origin    = userLoaded ? ScriptResourceOrigin.User : ScriptResourceOrigin.Automatic;
        var keyframes = ScriptReader.Read(ScriptType.Funscript, stream);

        return(new ScriptResource(entry.Name, archivePath, keyframes, origin));
    }
    public static IScriptResource FromFileInfo(FileInfo file, bool userLoaded = false)
    {
        if (!file.Exists)
        {
            return(null);
        }

        var path      = file.FullName;
        var origin    = userLoaded ? ScriptResourceOrigin.User : ScriptResourceOrigin.Automatic;
        var keyframes = ScriptReader.Read(ScriptType.Funscript, File.ReadAllBytes(path));

        return(new ScriptResource(Path.GetFileName(path), Path.GetDirectoryName(path), keyframes, origin));
    }
Exemple #3
0
        public ScriptDocument Open(Uri uri)
        {
            DomNode node     = null;
            string  filePath = uri.LocalPath;

            if (!File.Exists(filePath))
            {
                Outputs.WriteLine(OutputMessageType.Error, "Failed to open source file {0}", filePath);
                return(null);
            }

            // read existing document using standard XML reader
            using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                ScriptReader reader = new ScriptReader(m_nodeDefinitionManager.NodeTypeManager);
                node = reader.Read(stream, uri);
            }

            ScriptDocument scriptDocument = null;

            if (node != null)
            {
                // now that the data is complete, initialize all other extensions to the Dom data
                node.InitializeExtensions();

                scriptDocument = node.Cast <ScriptDocument>();
                string      fileName    = Path.GetFileName(filePath);
                ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center);

                //Set IsDocument to true to prevent exception in command service if two files with the
                //  same name, but in different directories, are opened.
                controlInfo.IsDocument = true;

                scriptDocument.ControlInfo = controlInfo;
                scriptDocument.Uri         = uri;
            }

            return(scriptDocument);
        }
        /// <summary>
        ///  Load circuit templates stored in an external file</summary>
        /// <param name="uri">Document URI, or null to present file open dialog to user</param>
        /// <returns>Returns the file path used to load the external templates.
        /// An empty string indicates no templates were loaded</returns>
        protected override ImportedContent LoadExternalTemplateLibrary(Uri uri)
        {
            string filePath = string.Empty;

            if (uri == null)
            {
                var dlg = new OpenFileDialog();
                dlg.Filter          = "Script Template File (*.vscript)|*.vscript".Localize();
                dlg.CheckFileExists = true;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    uri      = new Uri(dlg.FileName, UriKind.RelativeOrAbsolute);
                    filePath = dlg.FileName;
                }
            }
            else
            {
                filePath = uri.LocalPath;
            }

            if (File.Exists(filePath))
            {
                if (TemplatingContext.ValidateNewFolderUri(uri))
                {
                    // read existing document using standard XML reader
                    using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                    {
                        var reader   = new ScriptReader(m_nodeDefinitionManager.NodeTypeManager);
                        var root     = reader.Read(stream, uri);
                        var toFolder = CreateTemplateFolder();
                        reader.ImportTemplates(toFolder.DomNode, root, uri);
                        return(new ImportedContent(toFolder.DomNode, uri));
                    }
                }
            }

            return(new ImportedContent(null, null));
        }
Exemple #5
0
        public async Task <IActionResult> GetDocument(int dProtocolID)
        {
            // throw new Exception();
            string connectionString = configuration.GetConnectionString("DocSysBeta2");
            string sqlGetData       = reader.Read("SqlScripts/RpsBinData/GetData.sql");

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                var permissionError = await CheckPermission(connection, dProtocolID);

                if (!string.IsNullOrEmpty(permissionError))
                {
                    return(RedirectToAction("SendError", "Errors", new { ErrorMessage = permissionError }));
                }

                var data = await connection.QueryFirstOrDefaultAsync <RpsBinDataDto>(sqlGetData, new { dProtocolID });

                return(GetFile(data));
            }
        }
        public override void Up()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_CreateContentRequirements");

            Sql(script);
        }
        public override void Down()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_DropContentRequirements");

            Sql(script);
        }
Exemple #8
0
        public override void Down()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_User_Create");

            Sql(script);
        }
Exemple #9
0
        public override void Down()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_Lessons_Drop");

            Sql(script);
        }
Exemple #10
0
        public override void Up()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_Create_Categorylookup");

            Sql(script);
        }
        public override void Up()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_LanguageLookup_Create");

            Sql(script);
        }
        public override void Down()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_LanguageLookup_DROP");

            Sql(script);
        }
        public override void Up()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_PurshaseContent_Create");

            Sql(script);
        }
        public override void Down()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "Drop_PurchasedContentsView");

            Sql(script);
        }
Exemple #15
0
        /// <summary>
        /// Rescan all referenced template documents </summary>
        protected override void ReloadExternalTemplates()
        {
            // 1st, scan the template hierarchy tree and remember all the existing template's guid -> DomNode map
            var oldNodeGuidDictionary = new Dictionary <string, DomNode>();

            foreach (var node in TemplatingContext.RootFolder.DomNode.Subtree)
            {
                if (node.Is <ScriptTemplate>())
                {
                    var template = node.Cast <ScriptTemplate>();
                    if (template.Guid != Guid.Empty)
                    {
                        oldNodeGuidDictionary[template.Guid.ToString()] = node;
                    }
                }
            }

            // 2nd, scan the template hierarchy tree again and reload all the external templates
            var newNodeGuidDictionary = new Dictionary <string, DomNode>();

            foreach (var node in TemplatingContext.RootFolder.DomNode.Subtree)
            {
                var templateFolder = node.As <Sce.Atf.Dom.TemplateFolder>();
                if (templateFolder == null || templateFolder.Url == null)
                {
                    continue;
                }
                if (File.Exists(templateFolder.Url.LocalPath))
                {
                    using (FileStream stream = new FileStream(templateFolder.Url.LocalPath, FileMode.Open, FileAccess.Read))
                    {
                        var reader   = new ScriptReader(m_nodeDefinitionManager.NodeTypeManager);
                        var rootNode = reader.Read(stream, templateFolder.Url);

                        foreach (var newnode in rootNode.Subtree)
                        {
                            var guidAttr = newnode.Type.GetAttributeInfo("guid");
                            if (guidAttr == null)
                            {
                                continue;
                            }
                            var guidStr = newnode.GetAttribute(guidAttr) as string;
                            if (!string.IsNullOrEmpty(guidStr))
                            {
                                newNodeGuidDictionary[guidStr] = newnode;
                            }
                        }
                        reader.ImportTemplates(templateFolder.DomNode, rootNode, templateFolder.Url);
                    }
                }
            }

            // 3rd, replace original nodes with newly loaded, matched by GUIDs
            foreach (var node in TemplatingContext.RootFolder.DomNode.GetRoot().Subtree)
            {
                // currently two types that reference templates: GroupInstance or ModuleInstance
                DomNode refNode;

                var groupInstance = node.As <VisualScript.ScriptGroupReference>();
                if (groupInstance != null)
                {
                    if (newNodeGuidDictionary.TryGetValue(groupInstance.Template.Guid.ToString(), out refNode))
                    {
                        groupInstance.Template = refNode.As <ScriptTemplate>();

                        // need to reset pin targets due to DomNode replacements
                        var graphContainer = groupInstance.DomNode.Parent.Cast <ICircuitContainer>();
                        foreach (var edge in graphContainer.Wires)
                        {
                            if (edge.OutputElement.DomNode == groupInstance.DomNode)
                            {
                                edge.OutputPinTarget = null;
                            }

                            if (edge.InputElement.DomNode == groupInstance.DomNode)
                            {
                                edge.InputPinTarget = null;
                            }
                        }
                        continue;
                    }
                }

                var moduleReference = node.As <ScriptNodeReference>();
                if (moduleReference != null)
                {
                    if (newNodeGuidDictionary.TryGetValue(moduleReference.Template.Guid.ToString(), out refNode))
                    {
                        moduleReference.Template = refNode.As <ScriptTemplate>();

                        // need to reset pin targets due to DomNode replacements
                        var graphContainer = moduleReference.DomNode.Parent.Cast <ICircuitContainer>();
                        foreach (var edge in graphContainer.Wires)
                        {
                            if (edge.OutputElement.DomNode == moduleReference.DomNode)
                            {
                                edge.OutputPinTarget = null;
                            }

                            if (edge.InputElement.DomNode == moduleReference.DomNode)
                            {
                                edge.InputPinTarget = null;
                            }
                        }
                    }
                }
            }

            // finally, prune the old nodes
            foreach (var keyValue in newNodeGuidDictionary)
            {
                DomNode oldNode;
                if (oldNodeGuidDictionary.TryGetValue(keyValue.Key, out oldNode))
                {
                    oldNode.RemoveFromParent();
                }
            }
        }
Exemple #16
0
        public override void Down()
        {
            string script = ScriptReader.Read(MigrationContext.Read, " VW_Drop_Categorylookup");

            Sql(script);
        }
Exemple #17
0
        public override void Up()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_USER_ALTERMostafa");

            Sql(script);
        }
Exemple #18
0
        /// <summary>
        /// Opens or creates a document at the given URI.
        /// Creates and configures with control adapters D2dAdaptableControl to display subcircuit</summary>
        /// <param name="uri">Document URI</param>
        /// <returns>Document, or null if the document couldn't be opened or created</returns>
        public IDocument Open(Uri uri)
        {
            DomNode node     = null;
            string  filePath = uri.LocalPath;

            if (File.Exists(filePath))
            {
                // read existing document using standard XML reader
                using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    ScriptReader reader = new ScriptReader(m_nodeDefinitionManager.NodeTypeManager);
                    node = reader.Read(stream, uri);
                }
            }
            else
            {
                // create new document by creating a Dom node of the root type defined by the schema
                node = new DomNode(visualScriptDocumentType.Type, new ChildInfo("VScript", visualScriptDocumentType.Type));
                // create an empty root prototype folder
                node.SetChild(
                    visualScriptDocumentType.prototypeFolderChild,
                    new DomNode(prototypeFolderType.Type));
            }

            ScriptDocument circuitCircuitDocument = null;

            if (node != null)
            {
                // now that the data is complete, initialize all other extensions to the Dom data
                node.InitializeExtensions();

                AdaptableControl control = CreateNodeControl(node);
                control.AddHelp("https://github.com/SonyWWS/ATF/wiki/Adaptable-Controls".Localize());

                var viewingContext = node.Cast <ViewingContext>();
                viewingContext.Control = control;

                circuitCircuitDocument = node.Cast <ScriptDocument>();
                string      fileName    = Path.GetFileName(filePath);
                ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center);

                //Set IsDocument to true to prevent exception in command service if two files with the
                //  same name, but in different directories, are opened.
                controlInfo.IsDocument = true;

                circuitCircuitDocument.ControlInfo = controlInfo;
                circuitCircuitDocument.Uri         = uri;

                var editingContext = node.Cast <VisualScriptEditingContext>();
                editingContext.GetLocalBound       = GetLocalBound;
                editingContext.GetWorldOffset      = GetWorldOffset;
                editingContext.GetTitleHeight      = GetTitleHeight;
                editingContext.GetLabelHeight      = GetLabelHeight;
                editingContext.GetSubContentOffset = GetSubContentOffset;

                control.Context = editingContext;
                // Disabled
                //editingContext.SchemaLoader = m_schemaLoader; // schema needed for cut and paste between applications

                m_circuitControlRegistry.RegisterControl(node, control, controlInfo, this);

                // Set the zoom and translation to show the existing items (if any).
                var enumerableContext = editingContext.Cast <IEnumerableContext>();
                if (viewingContext.CanFrame(enumerableContext.Items))
                {
                    viewingContext.Frame(enumerableContext.Items);
                }
            }

            return(circuitCircuitDocument);
        }
Exemple #19
0
        /// <summary>
        /// implementing operate on rows (instead of row) to allow loading of external (file based) scripts to load first
        /// </summary>
        /// <param name="rows"></param>
        /// <returns></returns>
        public override IEnumerable <IRow> Operate(IEnumerable <IRow> rows)
        {
            if (!Run)
            {
                yield break;
            }

            var key = string.Join(':', Context.Process.Id, Context.Entity.Alias, Context.Field.Alias, Context.Operation.Method, Context.Operation.Index);

            if (!_memoryCache.TryGetValue(key, out CachedJintTransform transform))
            {
                transform = new CachedJintTransform();
                var scriptBuilder = new StringBuilder();
                var scriptReader  = new ScriptReader(Context, _reader);

                // to support shorthand script (e.g. t="js(scriptName)")
                if (Context.Operation.Scripts.Count == 0)
                {
                    var script = Context.Process.Scripts.FirstOrDefault(s => s.Name == Context.Operation.Script);
                    if (script != null)
                    {
                        Context.Operation.Script = scriptReader.Read(script);
                    }
                }

                var tester = new ScriptTester(Context);

                if (tester.Passes(Context.Operation.Script))
                {
                    // automatic parameter binding
                    if (!Context.Operation.Parameters.Any())
                    {
                        var parameters = _parameterMatcher.Match(Context.Operation.Script, Context.GetAllEntityFields());
                        foreach (var parameter in parameters)
                        {
                            Context.Operation.Parameters.Add(new Parameter {
                                Field = parameter, Entity = Context.Entity.Alias
                            });
                        }
                    }
                }
                else
                {
                    Run = false;
                }

                // for js, always add the input parameter
                transform.Input = MultipleInput().Union(new[] { Context.Field }).Distinct().ToArray();

                if (Context.Process.Scripts.Any(s => s.Global && (s.Language == "js" || s.Language == Constants.DefaultSetting && s.File != null && s.File.EndsWith(".js", StringComparison.OrdinalIgnoreCase))))
                {
                    // load any global scripts
                    foreach (var sc in Context.Process.Scripts.Where(s => s.Global && (s.Language == "js" || s.Language == Constants.DefaultSetting && s.File != null && s.File.EndsWith(".js", StringComparison.OrdinalIgnoreCase))))
                    {
                        var content = scriptReader.Read(Context.Process.Scripts.First(s => s.Name == sc.Name));
                        if (tester.Passes(content))
                        {
                            scriptBuilder.AppendLine(content);
                        }
                        else
                        {
                            Run = false;
                        }
                    }
                }

                // load any specified scripts
                if (Context.Operation.Scripts.Any())
                {
                    foreach (var sc in Context.Operation.Scripts)
                    {
                        var content = scriptReader.Read(Context.Process.Scripts.First(s => s.Name == sc.Name));
                        if (tester.Passes(content))
                        {
                            scriptBuilder.AppendLine(content);
                        }
                        else
                        {
                            Run = false;
                        }
                    }
                }

                if (scriptBuilder.Length > 0)
                {
                    scriptBuilder.AppendLine(Context.Operation.Script);
                }
                else
                {
                    scriptBuilder.Append(Context.Operation.Script);
                }

                try {
                    transform.Program = new JavaScriptParser(scriptBuilder.ToString(), new ParserOptions()
                    {
                        Tolerant = true
                    }).ParseProgram();
                } catch (ParserException ex) {
                    Context.Error(ex.Message);
                    Utility.CodeToError(Context, scriptBuilder.ToString());
                    Run = false;
                }

                // any changes to content item will invalidate cache
                _memoryCache.Set(key, transform, _signal.GetToken(Common.GetCacheKey(Context.Process.Id)));
            }

            if (!Run)
            {
                yield break;
            }

            foreach (var row in rows)
            {
                foreach (var field in transform.Input)
                {
                    _jint.SetValue(field.Alias, row[field]);
                }
                if (TryFirst)
                {
                    try {
                        TryFirst = false;
                        var obj   = _jint.Execute(transform.Program).GetCompletionValue().ToObject();
                        var value = obj == null ? null : Context.Field.Convert(obj);
                        if (value == null && !_errors.ContainsKey(0))
                        {
                            Context.Error($"Jint transform in {Context.Field.Alias} returns null!");
                            _errors[0] = $"Jint transform in {Context.Field.Alias} returns null!";
                        }
                        else
                        {
                            row[Context.Field] = value;
                        }
                    } catch (Jint.Runtime.JavaScriptException jse) {
                        if (!_errors.ContainsKey(jse.LineNumber))
                        {
                            Context.Error("Script: " + Context.Operation.Script.Replace("{", "{{").Replace("}", "}}"));
                            Context.Error(jse, "Error Message: " + jse.Message);
                            Context.Error("Variables:");
                            foreach (var field in transform.Input)
                            {
                                Context.Error($"{field.Alias}:{row[field]}");
                            }
                            _errors[jse.LineNumber] = jse.Message;
                        }
                    }
                }
                else
                {
                    row[Context.Field] = Context.Field.Convert(_jint.Execute(transform.Program).GetCompletionValue().ToObject());
                }

                yield return(row);
            }
        }
Exemple #20
0
        public override void Up()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_Lessons_Create");

            Sql(script);
        }
Exemple #21
0
        public override void Down()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_DropContentTargetViewers");

            Sql(script);
        }
Exemple #22
0
        public override void Up()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_User_Alter");

            Sql(script);
        }
Exemple #23
0
        public override void Up()
        {
            string script = ScriptReader.Read(MigrationContext.Read, "VW_CreateContentTargetviewers");

            Sql(script);
        }