Esempio n. 1
0
        public string[] Preprocess(IFileContent filename, Dictionary <string, bool> defs)
        {
            PreProcessor pp = new PreProcessor();


            pp.SetFileProcessingChain(Plugins);

            Definitions definitions;

            if (defs == null)
            {
                definitions = new Definitions();
            }
            else
            {
                definitions = new Definitions(defs);
            }

            string[] ret;
            try
            {
                ret = pp.Run(new[] { filename }, new Settings(), definitions);
            }
            catch (ProcessorException ex)
            {
                throw
                    new TextProcessingException("Could not preprocess file: " + filename.GetFilePath(), ex);
            }

            return(ret);
        }
Esempio n. 2
0
            public string[] Preprocess(IFileContent filename, Dictionary <string, bool> defs)
            {
                PreProcessor pp = new PreProcessor();

                Logger.VerbosityLevel = VerbosityLevel;


                pp.SetFileProcessingChain(Plugins);

                Definitions definitions;

                if (defs == null)
                {
                    definitions = new Definitions();
                }
                else
                {
                    definitions = new Definitions(defs);
                }

                string[] ret = { "FILE NOT FOUND" };
                try
                {
                    ret = pp.Run(new[] { filename }, new Settings(), definitions);
                }
                catch (ProcessorException ex)
                {
                    DebugHelper.Crash(
                        new TextProcessingException("Could not preprocess file: " + filename.GetFilePath(), ex), true);
                }

                return(ret);
            }
Esempio n. 3
0
 /// <summary>
 /// Returns true if the path is valid relative to the current path(the current script that is processed
 /// </summary>
 /// <param name="currentPath">the current path of the program</param>
 /// <param name="file">the relative file path</param>
 /// <returns>true if the relative path is pointing towards a valid file.</returns>
 public static bool FileExistsRelativeTo(string currentPath, IFileContent file)
 {
     if (file.HasValidFilepath)
     {
         return(FileExistsRelativeTo(currentPath, file.GetFilePath()));
     }
     return(true);
 }
 public FunctionSettings(string moduleName, string functionHandler, IFileContent <string> code, IFileContent <string> requirements, IFileContent <byte[]> assembly)
 {
     ModuleName      = moduleName;
     FunctionHandler = functionHandler;
     Code            = code;
     Requirements    = requirements;
     Assembly        = assembly;
 }
Esempio n. 5
0
 public OpenFile( IFileContent data )
 {
     Data = data;
     Data.PropertyChanged += ( s, e ) => InvokePropertyChanged( "Data" );
     EditCommand = new RelayCommand( InvokeEdit );
     StopEditCommand = new RelayCommand( InvokeStopEdit );
     SaveAsCommand = new RelayCommand( SaveAs );
     CloseCommand = new RelayCommand( InvokeClose );
 }
Esempio n. 6
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="separator">the separator used.</param>
 /// <param name="path">the path to the file</param>
 /// <param name="key">the key of the source file</param>
 /// <param name="pluginCache">the plugin cache that is used.</param>
 public SourceScript(string separator, IFileContent path, ImportResult importInfo, bool isInline) : base(
         ExtPPDebugConfig.Settings,
         ""
         )
 {
     this.importInfo = importInfo;
     IsInline        = isInline;
     filepath        = path;
 }
        public void TestSetup()
        {
            parser = new KeyValueParser();

            contentBuilder = new StringBuilder();

            content = Substitute.For <IFileContent>();
            content.AsStream.Returns(_ => new MemoryStream(Encoding.UTF8.GetBytes(contentBuilder.ToString())));

            fileName = Guid.NewGuid().ToString();
        }
Esempio n. 8
0
        /// <summary>
        /// Loads and preprocesses the file specified
        /// </summary>
        /// <param name="filename">the filepath</param>
        /// <param name="defs">definitions</param>
        /// <returns>the source as string</returns>
        internal static string PreprocessSource(IFileContent filename, Dictionary <string, bool> defs)
        {
            StringBuilder sb = new StringBuilder();

            string[] src = PreprocessLines(filename, defs);
            for (int i = 0; i < src.Length; i++)
            {
                sb.Append(src[i] + "\n");
            }

            return(sb.ToString());
        }
Esempio n. 9
0
        public void TestGetTopWords_FileContentsNull_ValueReturnedNull()
        {
            //Arrange
            fc = null;
            WordCount wc = new WordCount(fc);

            //Act
            var actual = wc.GetTopWords(2);

            //Assert
            Assert.IsNull(actual);
        }
Esempio n. 10
0
        /// <summary>
        /// Convenience wrapper to create a source script without knowing the actual type of the script.
        /// </summary>
        /// <param name="separator">the separator used.</param>
        /// <param name="file">the path of the file</param>
        /// <param name="key">the key of the file</param>
        /// <param name="importInfo">the import info of the key and path importation</param>
        /// <returns>the success state of the operation</returns>
        public bool TryCreateScript(out ISourceScript script, string separator, IFileContent file, ImportResult importInfo)
        {
            if (LockScriptCreation)
            {
                script = null;
                this.Warning("A Plugin is trying to add a file outside of the main stage. Is the configuration correct?");
                return(false);
            }

            script = new SourceScript(separator, file, importInfo);
            return(true);
        }
Esempio n. 11
0
        internal static string[] PreprocessLines(IFileContent file, Dictionary <string, bool> defs)
        {
            string ext = new string(file.GetFilePath().TakeLast(3).ToArray());

            if (_configs.ContainsKey(ext))
            {
                DebugHelper.Log("Found Matching PreProcessor Config for: " + ext, 1 | 1 << 21);
                return(_configs[ext].Preprocess(file, defs));
            }

            DebugHelper.Log("Loading File with Default PreProcessing", 1 | 1 << 21);
            return(_configs["***"].Preprocess(file, defs));
        }
Esempio n. 12
0
        /// <summary>
        /// Convenience wrapper to create a source script without knowing the actual type of the script.
        /// </summary>
        /// <param name="separator">the separator used.</param>
        /// <param name="file">the path of the file</param>
        /// <param name="key">the key of the file</param>
        /// <param name="importInfo">the import info of the key and path importation</param>
        /// <returns>the success state of the operation</returns>
        public bool TryCreateScript(out ISourceScript script, string separator, IFileContent file,
                                    ImportResult importInfo)
        {
            if (lockScriptCreation)
            {
                script = null;
                Logger.Log(PPLogType.Warning, Verbosity.Level3,
                           "A Plugin is trying to add a file outside of the main stage. Is the configuration correct?");
                return(false);
            }

            script = new SourceScript(separator, file, importInfo);
            return(true);
        }
Esempio n. 13
0
        async Task <File> IFileConnector.CreateAsync(string spaceIdOrWikiName, IFileContent fileContent, File file, string folderName)
        {
            if (spaceIdOrWikiName == null)
            {
                throw new ArgumentNullException(nameof(spaceIdOrWikiName));
            }
            if (fileContent == null)
            {
                throw new ArgumentNullException(nameof(fileContent));
            }

            var content = CreateContent(fileContent, folderName, file);

            var createdDocument = await PostAsync <File>("https://bigfiles.assembla.com" + $"/v1/spaces/{spaceIdOrWikiName}/documents", content).ConfigureAwait(false);

            return(createdDocument);
        }
Esempio n. 14
0
        protected object GetFileObjectField(string name, IFileObject file)
        {
            if (name == "is_file")
            {
                return(file.Type == FileType.File);
            }
            if (name == "is_folder")
            {
                return(file.Type == FileType.Folder);
            }
            string fName = file.Name.Replace('\\', '/');

            if (name == "name")
            {
                return(Path.GetFileName(fName));
            }
            if (name == "full_name")
            {
                return(fName);
            }
            if (name == "ext")
            {
                return(Path.GetExtension(fName));
            }
            if (name == "folder_name")
            {
                return(Path.GetDirectoryName(fName));
            }
            IFileContent fContent = file.Content;

            if (name == "size")
            {
                return(fContent.Size);
            }
            if (name == "last_modified")
            {
                return(fContent.LastModifiedTime);
            }
            throw new ArgumentException("Unknown field name: " + name);
        }
Esempio n. 15
0
        public ObjectNode Parse(string name, IFileContent content)
        {
            var index = new Dictionary <string, List <string> >();

            var reader = new StreamReader(content.AsStream, Encoding.UTF8);

            while (!reader.EndOfStream)
            {
                var line = reader.ReadLine()?.Trim(ByteOrderMarks)?.Trim();

                if (string.IsNullOrEmpty(line) || line.StartsWith(CommentToken))
                {
                    continue;
                }

                ParseLine(line, out var key, out var value);

                if (index.TryGetValue(key, out var values))
                {
                    values.Add(value);
                }
                else
                {
                    index[key] = new List <string> {
                        value
                    }
                };
            }

            if (index.Count == 0)
            {
                index.Add(string.Empty, new List <string> {
                    string.Empty
                });
            }

            return(new ObjectNode(name, index.Select(pair => ConvertToNode(pair.Key, pair.Value))));
        }
Esempio n. 16
0
        async Task IFileConnector.UpdateAsync(string spaceIdOrWikiName, File file, IFileContent fileContent)
        {
            if (spaceIdOrWikiName == null)
            {
                throw new ArgumentNullException(nameof(spaceIdOrWikiName));
            }
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }
            if (file.Id == null)
            {
                throw new ArgumentNullException(nameof(file.Id));
            }
            if (fileContent == null)
            {
                throw new ArgumentNullException(nameof(fileContent));
            }

            var content = CreateContent(fileContent, file: file);

            await PutAsync("https://bigfiles.assembla.com" + $"/v1/spaces/{spaceIdOrWikiName}/documents/{file.Id}", content).ConfigureAwait(false);
        }
Esempio n. 17
0
        private HttpContent CreateContent(IFileContent fileContent, string folderName = null, File file = null)
        {
            var content = new MultipartFormDataContent
            {
                { fileContent.ToContent(), "document[file]", fileContent.FileName }
            };

            if (folderName != null)
            {
                content.Add(new StringContent(folderName), "folder_name");
            }
            if (file != null)
            {
                if (file.IsAttachedToTicket() || file.IsAttachedToMessage() || file.IsAttachedToMilestone())
                {
                    content.Add(new StringContent(file.AttachableType.Value.ToString("G")), "document[attachable_type]");
                    content.Add(new StringContent(file.AttachableId), "document[attachable_id]");
                }

                if (file.Description != null)
                {
                    content.Add(new StringContent(file.Description), "document[description]");
                }

                if (file.FileName != null)
                {
                    content.Add(new StringContent(file.FileName), "document[filename]");
                }

                if (file.Name != null)
                {
                    content.Add(new StringContent(file.Name), "document[name]");
                }
            }
            return(content);
        }
Esempio n. 18
0
        internal static string[] PreprocessLines(IFileContent file, Dictionary <string, bool> defs)
        {
            string ext = new string(file.GetFilePath().Reverse().Take(3).Reverse().ToArray());
            string key = "";

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                key = "WIN";
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                key = "OSX";
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                key = "LINUX";
            }

            if (defs == null)
            {
                defs = new Dictionary <string, bool>();
            }
            if (!defs.ContainsKey(key))
            {
                defs.Add(key, true);
            }

            if (Configs.ContainsKey(ext))
            {
                Logger.Log(DebugChannel.Log, "Found Matching PreProcessor Config for: " + ext);
                return(Configs[ext].Preprocess(file, defs));
            }

            Logger.Log(DebugChannel.Log, "Loading File with Default PreProcessing");
            return(Configs["***"].Preprocess(file, defs));
        }
Esempio n. 19
0
 /// <summary>
 /// Constructor Inject the filecontent interface member type
 /// </summary>
 /// <param name="filecontent"></param>
 ///
 public WordCount(IFileContent filecontent)
 {
     this.FileContent = filecontent;
 }
Esempio n. 20
0
 public ObjectNode Parse(string name, IFileContent content) => null;
Esempio n. 21
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="separator">the separator used.</param>
 /// <param name="path">the path to the file</param>
 /// <param name="key">the key of the source file</param>
 /// <param name="pluginCache">the plugin cache that is used.</param>
 public SourceScript(string separator, IFileContent path, ImportResult importInfo) : base(ExtPPDebugConfig
                                                                                          .Settings)
 {
     this.importInfo = importInfo;
     filepath        = path;
 }
Esempio n. 22
0
    // upload the content


    public DoMyAction(IFileContent content, IApplyBusinessLogic doMyThing, IUploadContent uploader)
    {
        _content   = content;
        _doMyThing = doMyThing;
        _uploader  = uploader;
    }
Esempio n. 23
0
 public ObjectNode Parse(string name, IFileContent content)
 => new ObjectNode(name, new [] { new ValueNode(string.Empty, content.AsString) });
Esempio n. 24
0
 public FunctionSettings(string moduleName, string functionHandler, IFileContent <byte[]> assembly)
 {
     ModuleName      = moduleName;
     FunctionHandler = functionHandler;
     Assembly        = assembly;
 }
Esempio n. 25
0
 public DbFileFactory(IFileContent fileContentContext)
 {
     _fileContentContext = fileContentContext;
 }
Esempio n. 26
0
 public ObjectNode Parse(string name, IFileContent content)
 => parser(name, content);
Esempio n. 27
0
 /// <summary>
 /// 创建
 /// </summary>
 /// <param name="fileContent"></param>
 /// <param name="fileIndex"></param>
 public FileManager(IFileContent fileContent, IFileIndex fileIndex)
 {
     FileContent = fileContent;
     FileIndex   = fileIndex;
 }
Esempio n. 28
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="separator">the separator used.</param>
 /// <param name="path">the path to the file</param>
 /// <param name="key">the key of the source file</param>
 /// <param name="pluginCache">the plugin cache that is used.</param>
 public SourceScript(string separator, IFileContent path, ImportResult importInfo)
 {
     this.importInfo = importInfo;
     filepath        = path;
 }
Esempio n. 29
0
 public FunctionSettings(string moduleName, string functionHandler, string assemblyPath, IFileContent <byte[]> assembly)
 {
     this.ModuleName      = moduleName;
     this.FunctionHandler = functionHandler;
     this.AssemblyPath    = assemblyPath;
     this.Assembly        = assembly;
 }
 public void AddFile(IFileContent ifc)
 {
     Files.TryAdd(ifc.FileId, ifc);
 }
Esempio n. 31
0
 public ObjectNode Parse(string name, IFileContent content)
 => new ObjectNode(name, new[] { new ValueNode(string.Empty, Convert.ToBase64String(content.AsBytes)) });