Пример #1
0
        /// <summary>
        /// Get path
        /// </summary>
        /// <param name="pathName"></param>
        /// <returns></returns>
        public static string GetPathValue(PathName pathName)
        {
            string strRootPath = ConfigurationManager.AppSettings["RootPath"];
            string pathNameVal = ConfigurationManager.AppSettings[pathName.ToString()];

            if (string.IsNullOrEmpty(pathNameVal))
            {
                if (pathName == PathName.ReportTempatePathOldCompany)
                {
                    return(GetPathValue(PathName.ReportTempatePath));
                }
                else
                {
                    throw new ConfigurationErrorsException(string.Format("Missing configuration for {0}", pathName.ToString()));
                }
            }
            else
            {
                string pathValue = Path.Combine(@strRootPath, @pathNameVal);

                if (Directory.Exists(pathValue) == false)
                {
                    Directory.CreateDirectory(pathValue);
                }

                return(pathValue);
            }
        }
Пример #2
0
        /*----< test copying file from category to staging folder >----*/

        public bool testRetrieveFile(DirName category)
        {
            TestUtilities.vbtitle("testing retrieveFile");

            PathName path = storage.storagePath(category);

            FileSpec[] files = Directory.GetFiles(path);
            if (files.Length == 0)
            {
                TestUtilities.putLine(string.Format("can't find file in \"{0}\"", category));
                return(false);
            }

            FileName testFile1 = Path.GetFileName(files[fileIndex]);

            TestUtilities.putLine(string.Format("retrieving file \"{0}\"", testFile1));
            bool result1 = storage.retrieveFile(category, testFile1);

            fileIndex = (++fileIndex) % files.Length;
            TestUtilities.checkResult(result1, "Storage.retrieveFile");

            FileName testFile2 = Path.GetFileName(files[fileIndex]);

            TestUtilities.putLine(string.Format("retrieving file \"{0}\"", testFile2));
            bool result2 = storage.retrieveFile(category, testFile2);

            fileIndex = (++fileIndex) % files.Length;
            TestUtilities.checkResult(result2, "Storage.retrieveFile");

            return(result1 && result2);
        }
Пример #3
0
        public ZipFileDirectory(PathName pathName)
        {
            Name   = DirectoryName.GetDirectoryName(pathName);
            _parse = Parse;

            _parse();
        }
Пример #4
0
        protected override void Execute(CodeActivityContext context)
        {
            string      pathName    = PathName.Get(context);
            MimeMessage mailMessage = MimeMessageAttachs.Get(context);

            try
            {
                if (!Directory.Exists(pathName))
                {
                    Directory.CreateDirectory(pathName);
                }
                List <string> list = new List <string>();
                foreach (MimePart attachment in mailMessage.Attachments)
                {
                    using (var cancel = new System.Threading.CancellationTokenSource())
                    {
                        string fileName = attachment.FileName;
                        string filePath = pathName + "\\" + fileName;
                        using (var stream = File.Create(filePath))
                        {
                            attachment.Content.DecodeTo(stream, cancel.Token);
                            list.Add(filePath);
                        }
                    }
                }
                AttachFiles.Set(context, list.ToArray());
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "保存附件失败", e.Message);
            }
        }
Пример #5
0
        /// <summary>
        /// Initialize the save preset form.
        /// </summary>
        /// <param name="presetPath"></param>
        /// <param name="config"></param>
        /// <param name="IWAD"></param>
        /// <param name="sourcePort"></param>
        /// <param name="renderer"></param>
        /// <param name="saveWithPreset"></param>
        /// <param name="commandLine"></param>
        /// <param name="pwads"></param>
        /// <param name="presetName"></param>
        public SavePresetForm(string presetPath,
                              PathName config,
                              PathName IWAD,
                              PathName sourcePort,
                              KeyValuePair <int, string> renderer,
                              List <string> saveWithPreset,
                              string commandLine,
                              List <PathName> pwads,
                              string presetName
                              )
        {
            InitializeComponent();
            this.Text          += " - DML v" + SharedVar.LOCAL_VERSION;
            this.presetPath     = presetPath;
            this.config         = config;
            this.IWAD           = IWAD;
            this.renderer       = renderer;
            this.saveWithPreset = saveWithPreset;
            this.commandLine    = commandLine.Trim();
            this.pwads          = pwads;
            this.sourcePort     = sourcePort;
            this.presetName     = presetName;
            txtPresetName.Text  = presetName;

            if (presetName == null || presetName.Trim() == string.Empty)
            {
                cmdSavePreset.Visible = false;
                cmdSavePlay.Text      = "SAVE AND PLAY";
                isUpdate = false;
            }

            saveWithPresetBackup = saveWithPreset;
        }
Пример #6
0
        public ZipFileDirectory(PathName pathName)
        {
            Name = DirectoryName.GetDirectoryName(pathName);
            _parse = Parse;

            _parse();
        }
        public AssemblyFileDirectory(PathName pathName)
        {
            Name = DirectoryName.GetDirectoryName(pathName);
            _parse = parse;

            _parse();
        }
Пример #8
0
		public override PathName Combine(PathName child)
		{
			if (child is AbsolutePathName)
				return child;

			return new AbsolutePathName(Path.Combine(_path, child.GetPath()));
		}
Пример #9
0
        public static TableName[] GetTableNames(ApplicationCommand cmd, PathManager mgr)
        {
            var pt = mgr.current;

            if (!(pt.Item is Locator) && !(pt.Item is TableName))
            {
                if (cmd.arg1 != null)
                {
                    PathName path = new PathName(cmd.arg1);
                    var      node = mgr.Navigate(path);
                    if (node != null)
                    {
                        var dname = mgr.GetPathFrom <DatabaseName>(node);
                        if (dname != null)
                        {
                            if (cmd.wildcard != null)
                            {
                                var m = new MatchedDatabase(dname, cmd);
                                return(m.TableNames());
                            }
                            else
                            {
                                var _tname = mgr.GetPathFrom <TableName>(node);
                                if (_tname != null)
                                {
                                    return new TableName[] { _tname }
                                }
                                ;
                                else
                                {
                                    cerr.WriteLine("invalid path");

                                    return(null);
                                }
                            }
                        }
                        else
                        {
                            cerr.WriteLine("database is unavailable");
                            return(null);
                        }
                    }
                    else
                    {
                        cerr.WriteLine("invalid path");
                        return(null);
                    }
                }
            }


            if (pt.Item is TableName)
            {
                var tname = (TableName)pt.Item;
                return(new TableName[] { tname });
            }

            return(null);
        }
Пример #10
0
        public void RecursiveBindMount(PathName source, PathName target)
        {
            var bind = MountRun($"mount --verbose --rbind {source} {target}");

            this.mountPoints.Push(new MountPoint(target, true));

            Bash.ThrowOnError(bind);
        }
        public override DirectoryName Combine(PathName child)
        {
            var pathName = Name.Combine(child) as AbsolutePathName;
            if (pathName == null)
                throw new InvalidOperationException("Unable to combine " + Name + " with " + child);

            return new AbsoluteDirectoryName(pathName);
        }
Пример #12
0
        static DirectoryName InternalCombine(PathName combinedPathName)
        {
            var pathName = combinedPathName as RelativePathName;
            if (pathName == null)
                throw new InvalidOperationException("Unable to combine relative paths: " + combinedPathName);

            return new RelativeDirectoryName(pathName);
        }
Пример #13
0
        public void ProcfsMount(PathName target)
        {
            var bind = MountRun($"mount --verbose --types proc proc {target}");

            this.mountPoints.Push(new MountPoint(target, false));

            Bash.ThrowOnError(bind);
        }
Пример #14
0
        public OpcFileDirectory(PathName pathName)
        {
            _directories = new Dictionary <string, OpcDirectory>();
            _files       = new Dictionary <string, OpcFile>();

            Name = DirectoryName.GetDirectoryName(pathName);

            Parse();
        }
Пример #15
0
        public OpcFileDirectory(PathName pathName)
        {
            _directories = new Dictionary<string, OpcDirectory>();
            _files = new Dictionary<string, OpcFile>();

            Name = DirectoryName.GetDirectoryName(pathName);

            Parse();
        }
Пример #16
0
        public static Bash RemoveDirectory(PathName directory)
        {
            var bash = new Bash()
                       .Command($"rm --recursive --force --verbose \"{directory}\"")
                       .WithProgress()
            ;

            return(bash.Run());
        }
Пример #17
0
        protected PathName(PathName path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            this.NormalizedPath = path.NormalizedPath;
        }
Пример #18
0
        public override PathName Combine(PathName child)
        {
            if (child is AbsolutePathName)
            {
                return(child);
            }

            return(new RelativePathName(Path.Combine(_path, child.GetPath())));
        }
Пример #19
0
        public bool Execute()
        {
            Uri uri = _uriString.ToUri("The from URI was invalid");

            AbsolutePathName fullPath = PathName.GetAbsolutePathName(_name, Environment.CurrentDirectory);

            _log.DebugFormat("Using output path name: {0}", fullPath);

            string directoryName = Path.GetDirectoryName(fullPath.GetPath());

            if (!System.IO.Directory.Exists(directoryName))
            {
                System.IO.Directory.CreateDirectory(directoryName);
            }

            IInboundTransport fromTransport = Program.Transports.GetInboundTransport(uri);

            ITextBlock text = new TextBlock()
                              .BeginBlock("Save messages from URI: " + uri, "");

            int lastCount;
            int saveCount = 0;

            do
            {
                lastCount = saveCount;

                fromTransport.Receive(receiveContext =>
                {
                    if (saveCount >= _count)
                    {
                        return(null);
                    }

                    string body = Encoding.UTF8.GetString(receiveContext.BodyStream.ReadToEnd());

                    text.BodyFormat("Message-Id: {0}", receiveContext.MessageId ?? "");

                    WriteMessageToFile(fullPath.ToString(), receiveContext, body);

                    saveCount++;

                    if (_remove)
                    {
                        return context => { }
                    }
                    ;

                    return(null);
                }, 5.Seconds());
            } while (_remove && saveCount < _count && saveCount != lastCount);

            _log.Info(text.ToString());

            return(true);
        }
Пример #20
0
        public static Bash TarExtract(PathName archivePath, PathName extractPath)
        {
            var bash = new Bash()
                       .Command($"tar --extract --verbose --owner=0 --group=0 --file \"{archivePath}\"")
                       .Directory(extractPath)
                       .WithProgress()
            ;

            return(bash.Run());
        }
Пример #21
0
		public override PathName Combine(PathName child)
		{
			if (child is AbsolutePathName)
				throw new InvalidOperationException("Cannot combine an absolute path with a zip path");

			if (child is ZipPathName)
				throw new IOException("Cannot combine a zip file path with a zip file path");

			return new ZipPathName(_zipFilePath, Path.Combine(_contentFilePath, child.GetPath()));
		}
Пример #22
0
        public override PathName Combine(PathName child)
        {
            if (child is AbsolutePathName)
                throw new InvalidOperationException("Cannot combine an absolute path with a zip path");

            if (child is ZipPathName)
                throw new IOException("Cannot combine a zip file path with a zip file path");

            return new ZipPathName(_zipFilePath, Path.Combine(_contentFilePath, child.GetPath()));
        }
Пример #23
0
        private bool SetSource(string source, string sourceText)
        {
            if (source == null)
            {
                cerr.WriteLine("invalid argument");
                return(false);
            }

            var path = new PathName(source);

            node = mgr.Navigate(path);
            if (node == null)
            {
                cerr.WriteLine("invalid path:" + path);
                return(false);
            }

            dname = mgr.GetPathFrom <DatabaseName>(node);
            if (dname == null)
            {
                cerr.WriteLine($"warning: {sourceText} database is unavailable");
                return(false);
            }

            var server = mgr.GetPathFrom <ServerName>(node);

            side = new Side(dname);

            T = new TableName[] { };

            if (path.wildcard != null)
            {
                var m1 = new MatchedDatabase(dname, path.wildcard)
                {
                    Includedtables = cmd.Includes,
                    Excludedtables = cmd.Excludes
                };

                T = m1.TableNames();
            }
            else
            {
                TableName tname = mgr.GetPathFrom <TableName>(node);
                if (tname == null)
                {
                    T = dname.GetTableNames();
                }
                else
                {
                    T = new TableName[] { tname };
                }
            }

            return(true);
        }
Пример #24
0
        public override DirectoryName Combine(PathName child)
        {
            var pathName = Name.Combine(child) as AbsolutePathName;

            if (pathName == null)
            {
                throw new InvalidOperationException("Unable to combine " + Name + " with " + child);
            }

            return(new AbsoluteDirectoryName(pathName));
        }
Пример #25
0
        static DirectoryName InternalCombine(PathName combinedPathName)
        {
            var pathName = combinedPathName as RelativePathName;

            if (pathName == null)
            {
                throw new InvalidOperationException("Unable to combine relative paths: " + combinedPathName);
            }

            return(new RelativeDirectoryName(pathName));
        }
Пример #26
0
        /*----< create directory for storing packages >----------------*/

        public bool createStorage(DirName category = "")
        {
            PathName      path = Path.Combine(RepoEnvironment.storagePath, category);
            DirectoryInfo di   = Directory.CreateDirectory(path);

            if (di.Exists)
            {
                return(true);
            }
            return(false);
        }
Пример #27
0
        /*----< delete all staged files >------------------------------*/

        public void deleteStagedFiles()
        {
            PathName path = RepoEnvironment.stagingPath;

            FileSpec[] files = Directory.GetFiles(path);
            int        count = files.Length;

            for (int i = 0; i < count; ++i)
            {
                System.IO.File.Delete(files[i]);
            }
        }
Пример #28
0
 public FormMod(string presetPath, PathName IWAD, KeyValuePair <int, string> renderer, PathName config, List <string> saveWithPreset, string commandLine, string parameters)
 {
     InitializeComponent();
     this.presetPath     = presetPath;
     this.config         = config;
     this.IWAD           = IWAD;
     this.renderer       = renderer;
     this.saveWithPreset = saveWithPreset;
     this.commandLine    = commandLine.Trim();
     this.parameters     = parameters;
     this.Text          += " - DML v" + SharedVar.LOCAL_VERSION;
 }
Пример #29
0
        public TreeNode <IDataPath> chdir(string path)
        {
            PathName             pathName = new PathName(path);
            TreeNode <IDataPath> node     = mgr.Navigate(pathName);

            if (node != null)
            {
                mgr.current = node;
                PathChanged?.Invoke(this, new EventArgs <TreeNode <IDataPath> >(node));
            }

            return(node);
        }
Пример #30
0
        public bool Execute()
        {
            Uri uri = _uriString.ToUri("The from URI was invalid");

            AbsolutePathName fullPath = PathName.GetAbsolutePathName(_name, Environment.CurrentDirectory);

            _log.DebugFormat("Using output path name: {0}", fullPath);

            string directoryName = Path.GetDirectoryName(fullPath.GetPath());

            if (!System.IO.Directory.Exists(directoryName))
            {
                System.IO.Directory.CreateDirectory(directoryName);
            }

            IOutboundTransport toTransport = Program.Transports.GetOutboundTransport(uri);

            ITextBlock text = new TextBlock()
                              .BeginBlock("Load messages to URI: " + uri, "");

            string[] files =
                System.IO.Directory.GetFiles(directoryName, fullPath.GetName() + "*.msg", SearchOption.TopDirectoryOnly)
                .OrderBy(x => x).ToArray();

            int loadCount = 0;

            for (int i = 0; i < files.Length && loadCount < _count; i++)
            {
                string file = files[i];

                string fileName = Path.Combine(directoryName, file);

                text.BodyFormat("Message File: {0}", file);

                ISendContext context = LoadMessageFromFile(fileName);

                toTransport.Send(context);

                if (_remove)
                {
                    System.IO.File.Delete(fileName);
                }

                loadCount++;
            }

            _log.Info(text.ToString());

            return(true);
        }
        public static string FixJobName(string jobName)
        {
            while (!PathName.IsValid(jobName))
            {
                var idx = jobName.IndexOfAny(Path.GetInvalidPathChars());
                if (idx < 0)
                {
                    idx = jobName.IndexOfAny(Path.GetInvalidFileNameChars());
                }
                jobName = jobName.Replace(jobName[idx], ' ');
            }

            return(jobName);
        }
Пример #32
0
        public void SymbolicLink(PathName path, string value, bool force)
        {
            if (force)
            {
                var file = path.ExistsFile();
                if (path.ExistsFile())
                {
                    path.DeleteFile();
                }
            }
            var retval = Syscall.symlink(value, path.Full);

            UnixMarshal.ThrowExceptionForLastErrorIf(retval);
        }
Пример #33
0
        public override bool Execute()
        {
            Uri uri = _uri.ToUri("The from URI was invalid");

            AbsolutePathName fullPath = PathName.GetAbsolutePathName(_sourcePath, Environment.CurrentDirectory);

            _log.DebugFormat("Using output path name: {0}", fullPath);

            string directoryName = Path.GetDirectoryName(fullPath.GetPath());

            if (!System.IO.Directory.Exists(directoryName))
            {
                System.IO.Directory.CreateDirectory(directoryName);
            }

            IOutboundTransport toTransport = GetOutboundTransport(_uri);

            _log.InfoFormat("Loading messages from '{0}' to {1}", _sourcePath, _uri);

            string[] files =
                System.IO.Directory.GetFiles(directoryName, fullPath.GetName() + "*.msg", SearchOption.TopDirectoryOnly)
                .OrderBy(x => x).ToArray();

            int loadCount = 0;

            for (int i = 0; i < files.Length && loadCount < _count; i++)
            {
                string file = files[i];

                string fileName = Path.Combine(directoryName, file);

                _log.DebugFormat("Message-Id: '{0}'", file);

                ISendContext context = LoadMessageFromFile(fileName);

                toTransport.Send(context);

                if (_remove)
                {
                    System.IO.File.Delete(fileName);
                }

                loadCount++;
            }

            _log.InfoFormat("Loading messages from '{0}' to {1}", _sourcePath, _uri);

            return(true);
        }
Пример #34
0
        /// <summary>
        /// Get path
        /// </summary>
        /// <param name="pathName"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetPathValue(PathName pathName, string fileName)
        {
            string pathValue = GetPathValue(pathName);

            string fullPath = string.IsNullOrEmpty(fileName) ? pathValue : Path.Combine(@pathValue, @fileName);

            FileInfo fileInfo = new FileInfo(fullPath);

            if (Directory.Exists(fileInfo.DirectoryName) == false)
            {
                Directory.CreateDirectory(fileInfo.DirectoryName);
            }

            return(fullPath);
        }
Пример #35
0
 void ProcessNewFile(FileCreated message)
 {
     if (message.Path.EndsWith("bottle"))
     {
         Directory dir = new ZipFileDirectory(PathName.GetPathName(message.Path));
         try
         {
             _actionToTake(dir);
         }
         catch (Exception ex)
         {
             string msg = "There was an error processing the bottle '{0}'".FormatWith(message.Path);
             throw new BottleException(msg, ex);
         }
     }
 }
Пример #36
0
        /*----< return list of staged files >--------------------------*/

        public List <FileName> stagedFiles(bool showPath = false)
        {
            PathName path = RepoEnvironment.stagingPath;

            FileSpec[] files = Directory.GetFiles(path);
            for (int i = 0; i < files.Length; ++i)
            {
                if (showPath)
                {
                    files[i] = Path.GetFullPath(files[i]); // now an absolute FileSpec
                }
                else
                {
                    files[i] = Path.GetFileName(files[i]); // now a FileName
                }
            }
            return(files.ToList <FileName>());
        }
Пример #37
0
        public static Morphs Populate(Pogo pogo, PathName dataDir)
        {
            var morphs = new Morphs(pogo);

            foreach (var file in dataDir.EnumerateFiles())
            {
                if (file.Name.StartsWith("."))
                {
                    continue;
                }

                var recipe = Recipes.RecipeParser.Parse(file.Full);
                var morph  = new Morph(pogo, recipe);
                morphs.Add(morph);
            }

            return(morphs);
        }
Пример #38
0
        /*----< return list of files in storage/category >-------------*/

        public List <FileName> files(DirName category, bool showPath = false)
        {
            PathName path = Path.Combine(RepoEnvironment.storagePath, category);

            FileSpec[] files = Directory.GetFiles(path);
            for (int i = 0; i < files.Length; ++i)
            {
                if (showPath)
                {
                    files[i] = Path.GetFullPath(files[i]); // now an absolute FileSpec
                }
                else
                {
                    files[i] = Path.GetFileName(files[i]); // now a FileName
                }
            }
            return(files.ToList <FileName>());
        }
Пример #39
0
 public override DirectoryName Combine(PathName child)
 {
     return InternalCombine(Name.Combine(child));
 }