示例#1
0
        public static byte[] ReadAllBytes(this Stream fr)
        {
            var ms = new MemoryStream();

            IOTool.CopyStream(fr, ms);
            return(ms.ToArray());
        }
示例#2
0
        public override string GetHtml()
        {
            var hg = new HtmlGenerator();

            hg.BeginHtml("s_saved_jobs", HtmlGenerator.HtmlObjectViewStyle);
            hg.Heading("s_saved_jobs", 1);
            foreach (string fn in Directory.GetFiles(Core.JobsDirectory, "*.djb", SearchOption.AllDirectories).Sorted())
            {
                string relfn = IOTool.RelativePathTo(Core.JobsDirectory, fn);
                try
                {
                    Job job = Job.LoadFromFile(fn);
                    hg.Heading(relfn, 2);
                    hg.Write("<a href=\"callback://runjob?job:{0}\">{1}</a>", HttpUtility.UrlEncode(fn), Texts.Get("s_run"));
                    hg.Write(" | <a href=\"callback://deletejob?job:{0}\">{1}</a>", HttpUtility.UrlEncode(fn), Texts.Get("s_delete"));
                    RenderCommand(hg, fn, job.Root);
                    hg.HorizontalRule();
                }
                catch (Exception err)
                {
                    hg.Heading(relfn, 2);
                    hg.Write("{0}:{1}", Texts.Get("s_error"), err.Message);
                }
            }
            hg.EndHtml();
            return(hg.HtmlText);
        }
示例#3
0
 public static bool CheckAbsoluteOutputFileName(string fn, string extensions)
 {
     try
     {
         if (!Path.IsPathRooted(fn))
         {
             StdDialog.ShowError("s_please_enter_full_path_to_file");
             return(false);
         }
         string dir = Path.GetDirectoryName(fn);
         if (!Directory.Exists(dir))
         {
             StdDialog.ShowError("s_output_directory_does_not_exist");
             return(false);
         }
         if (!IOTool.FileHasOneOfExtension(fn, extensions))
         {
             StdDialog.ShowError(Texts.Get("s_incorrect_file$extension", "extension", extensions.ToLower()));
             return(false);
         }
     }
     catch (Exception err)
     {
         StdDialog.ShowError(err.Message);
         return(false);
     }
     if (File.Exists(fn) && !StdDialog.ReallyOverwriteFile(fn))
     {
         return(false);
     }
     return(true);
 }
示例#4
0
 public byte[] GetBinary()
 {
     using (FileStream fr = new FileStream(m_dataFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         return(IOTool.ReadToEnd(fr));
     }
 }
示例#5
0
        public IEnumerable <string> GetFiles()
        {
            var    files  = new HashSetEx <string>();
            string libdir = GetLibDirectory();

            if (Directory.Exists(libdir))
            {
                foreach (string fn in Directory.GetFiles(libdir, "*" + FileExtension))
                {
                    string ofn = Path.Combine(GetDirectory(), Path.GetFileName(fn));
                    if (File.Exists(ofn))
                    {
                        files.Add(IOTool.NormalizePath(ofn));
                        yield return(ofn);
                    }
                    else
                    {
                        yield return(fn);
                    }
                }
            }
            foreach (string fn in Directory.GetFiles(GetDirectory(), "*" + FileExtension))
            {
                if (files.Contains(IOTool.NormalizePath(fn)))
                {
                    continue;
                }
                yield return(fn);
            }
        }
示例#6
0
 public override string ToString()
 {
     if (IOTool.FileIsLink(m_path))
     {
         return(Path.GetFileNameWithoutExtension(m_path));
     }
     return(Path.GetFileName(m_path));
 }
示例#7
0
        public override ITreeNode CreateNode(ITreeNode parent)
        {
            var appobj = new FavoriteAppObject {
                FileName = IOTool.RelativePathTo(Core.FavoritesDirectory, m_file.DataDiskPath)
            };

            return(new FavoriteItemTreeNode(parent, this, appobj.LoadHolder()));
        }
示例#8
0
        private static void _AddFile(string path, HashSetEx <string> deleted, string indexFile)
        {
            var files = new HashSetEx <string>(IOTool.LoadLines(indexFile));

            files.Add(path);
            IOTool.SaveLines(indexFile, files);
            deleted.Add(path.ToLower());
        }
示例#9
0
 public SaveJobForm()
 {
     InitializeComponent();
     foreach (string file in Directory.GetFiles(Core.JobsDirectory, "*.djb", SearchOption.AllDirectories))
     {
         lbxJobs.Items.Add(IOTool.RelativePathTo(Core.JobsDirectory, file));
     }
 }
示例#10
0
        public static byte[] ZlibDecompress(byte[] data)
        {
            MemoryStream src = new MemoryStream(data);
            var          fr  = new Ionic.Zlib.ZlibStream(src, Ionic.Zlib.CompressionMode.Decompress);
            MemoryStream fw  = new MemoryStream();

            IOTool.CopyStream(fr, fw);
            return(fw.ToArray());
        }
示例#11
0
 public void ScheduleJob()
 {
     SystemSchedulerTool.ScheduleTask(
         GetTaskName(),
         System.IO.Path.Combine(Core.ProgramDirectory, "daci.exe"),
         "runjob " + System.IO.Path.ChangeExtension(IOTool.RelativePathTo(Core.JobsDirectory, FileSystemPath), null).Replace("\\", "/")
         );
     CallRefresh();
 }
示例#12
0
        public override void OpenAction()
        {
            var con = CreateStoredConnection();

            con.DbFilename = DiskPath;
            string ufn = IOTool.GetUniqueFileName(Path.Combine(Core.DataDirectory, Path.GetFileNameWithoutExtension(DiskPath) + ".con"));

            con.FileName = ufn;
            con.Save();
        }
示例#13
0
        protected string GetItemName(string file)
        {
            if (file == null)
            {
                return(null);
            }
            string dir     = m_adtype.GetDirectory();
            string relfile = IOTool.RelativePathTo(dir, file);

            return(Path.ChangeExtension(relfile, null));
        }
示例#14
0
 private void InitializeDataFile()
 {
     if (IOTool.FileIsLink(DiskPath) && File.Exists(DiskPath))
     {
         m_dataFilePath = IOTool.GetLinkContent(DiskPath);
     }
     else
     {
         m_dataFilePath = DiskPath;
     }
 }
示例#15
0
 private void InitializeLink()
 {
     if (IOTool.FileIsLink(DiskPath))
     {
         m_folderPath = IOTool.GetLinkContent(DiskPath);
     }
     else
     {
         m_folderPath = DiskPath;
     }
 }
示例#16
0
        protected override void AfterWriteAction(string file)
        {
            var req = CreateRequest();

            req.Method = WebRequestMethods.Ftp.UploadFile;
            using (var fw = req.GetRequestStream())
            {
                using (var fr = new FileStream(file, FileMode.Open, FileAccess.Read))
                {
                    IOTool.CopyStream(fr, fw);
                }
            }
        }
示例#17
0
 public static string FileNameToDataTreeName(string filename)
 {
     if (filename == null)
     {
         return(null);
     }
     filename = filename.Replace("/", "\\");
     if (filename != null && IOTool.FileIsInDirectory(filename, Core.DataDirectory))
     {
         return(IOTool.RelativePathTo(Core.DataDirectory, filename).ToLower().Replace("\\", "/"));
     }
     return(null);
 }
示例#18
0
        public override void RenameTo(string newname)
        {
            string dir = Path.GetDirectoryName(DiskPath);
            string dst = Path.Combine(dir, newname);

            if (IOTool.FileIsLink(DiskPath))
            {
                File.Move(DiskPath, dst + ".lnk");
            }
            else
            {
                Directory.Move(DiskPath, dst);
            }
        }
示例#19
0
        protected override void PrepareReadFileContent(string file)
        {
            var req = WebRequest.Create(Url);

            using (var resp = req.GetResponse())
            {
                using (var fr = resp.GetResponseStream())
                {
                    using (var fw = new FileStream(file, FileMode.Create))
                    {
                        IOTool.CopyStream(fr, fw);
                    }
                }
            }
        }
示例#20
0
 public virtual bool Create(ITreeNode parent, string name)
 {
     if (name != null)
     {
         try
         {
             string fn = System.IO.Path.Combine(parent.FileSystemPath, IOTool.AddFirstExtension(name, FileExtensions));
             return(CreateFile(fn));
         }
         catch (Exception e)
         {
             Errors.Report(e);
         }
     }
     return(false);
 }
示例#21
0
文件: Core.cs 项目: janproch/datadmin
        //public static void ShowHelp(Control parent, string topic)
        //{
        //    Help.ShowHelp(parent, "datadmin-" + Texts.Language + ".chm", topic + "-" + Texts.Language + ".html");
        //}

        //public static void ShowHelp(Control parent)
        //{
        //    Help.ShowHelp(parent, "datadmin-" + Texts.Language + ".chm");
        //}

        public static void CopyDefaultData()
        {
            if (!IsMono)
            {
                return;
            }
            Logging.Debug("Copying default data");
            try
            {
                IOTool.CopyDirectory("/etc/datadmin/.config", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
            }
            catch (Exception e)
            {
                Logging.Root.LogError(e);
            }
        }
示例#22
0
        public static bool Run(Action closesplash)
        {
            // debug version, don't check auto-update
            if (!VersionInfo.IsRelease && !VersionInfo.IsBeta)
            {
                return(false);
            }

            if (Framework.Instance.GetCheckNewVersion() == CheckNewVersions.CheckAndDownload)
            {
                if (File.Exists(VersionFile) && File.Exists(InstallExeFile))
                {
                    string   newver = IOTool.LoadTextFile(VersionFile).Trim();
                    DateTime newverdt;
                    try { newverdt = DateTime.ParseExact(IOTool.LoadTextFile(InstallTimestampFile).Trim(), "s", CultureInfo.InvariantCulture); }
                    catch { newverdt = new DateTime(1900, 1, 1); }
                    if (CompareVersions(newver, VersionInfo.VERSION) > 0)
                    {
                        closesplash();
                        var lst = new List <string>();
                        foreach (var lic in LicenseTool.ValidLicenses)
                        {
                            if (lic.UpdatesTo < newverdt)
                            {
                                lst.Add(lic.LongText);
                            }
                        }
                        string msg = Texts.Get("s_install_version$version", "version", newver);
                        if (lst.Count > 0)
                        {
                            msg += "\n" + Texts.Get("s_license_update_expire_warning") + "\n" + lst.CreateDelimitedText("\n");
                        }
                        if (MessageBox.Show(msg, VersionInfo.ProgramTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            System.Diagnostics.Process.Start(InstallExeFile);
                            return(true);
                        }
                    }
                }
            }
            Thread t = new Thread(RunCheckThread);

            t.IsBackground = true;
            t.Start();
            return(false);
        }
示例#23
0
        protected override void PrepareReadFileContent(string file)
        {
            var req = CreateRequest();

            req.Method = WebRequestMethods.Ftp.DownloadFile;

            using (var resp = req.GetResponse())
            {
                using (var fr = resp.GetResponseStream())
                {
                    using (var fw = new FileStream(file, FileMode.Create))
                    {
                        IOTool.CopyStream(fr, fw);
                    }
                }
            }
        }
示例#24
0
        protected override void PostprocessChildren(List <ITreeNode> children)
        {
            var node = children.Find(n => IOTool.NormalizePath(n.FileSystemPath) == IOTool.NormalizePath(Core.DataSamplesDirectory));

            if (node != null)
            {
                children.Remove(node);
                if (!GlobalSettings.Pages.Tree().HideDataSamplesFolder)
                {
                    children.Insert(0, new DataSamplesFolderTreeNode(this, Core.DataSamplesDirectory));
                }
            }
            if (VersionInfo.DatabaseSamplesFolder != null && Directory.Exists(VersionInfo.DatabaseSamplesFolder))
            {
                children.Insert(0, new DataSamplesFolderTreeNode(this, VersionInfo.DatabaseSamplesFolder));
            }
        }
示例#25
0
        public override string CreateHtml(AppObject appobj, ConnectionPack connpack, IDictionary <string, object> outnames)
        {
            var           fav    = (FavoriteAppObject)appobj;
            var           holder = fav.LoadHolder();
            HtmlGenerator gen    = new HtmlGenerator();

            gen.BeginHtml(holder.Name, HtmlGenerator.HtmlObjectViewStyle);
            gen.Heading(holder.Name, 2);
            gen.PropsTableBegin();
            gen.PropTableRow("s_name", IOTool.RelativePathTo(Core.FavoritesDirectory, fav.FileName));
            holder.Favorite.DisplayProps((n, v) => gen.PropTableRow(n, v));
            gen.PropsTableEnd();
            gen.BeginUl();
            gen.Li(String.Format("<a href='callback://open'>{0}</a>", Texts.Get("s_execute")));
            gen.EndUl();
            gen.EndHtml();
            outnames["open"] = (Action) delegate() { holder.Favorite.Open(); };
            return(gen.HtmlText);
        }
示例#26
0
 public override void Remove()
 {
     if (IOTool.FileIsLink(DiskPath))
     {
         File.Delete(DiskPath);
     }
     else
     {
         try
         {
             Directory.Delete(DiskPath, true);
         }
         catch (Exception err)
         {
             StdDialog.ShowError("s_path_cannot_be_deleted_delete_scheduled");
             DeletedFileRegistrer.AddPath(DiskPath, true);
             throw new DeleteError(DiskPath, err);
         }
     }
 }
示例#27
0
 private void btbrowse_Click(object sender, EventArgs e)
 {
     if (SelectedDriver == null)
     {
         return;
     }
     if (edfile.Text != "")
     {
         openFileDialog1.FileName = Path.Combine(Core.ProgramDirectory, edfile.Text);
     }
     else
     {
         openFileDialog1.InitialDirectory = Core.ProgramDirectory;
     }
     if (openFileDialog1.ShowDialogEx() == DialogResult.OK)
     {
         m_typesLoaded = false;
         edfile.Text   = IOTool.RelativePathTo(Core.ProgramDirectory, openFileDialog1.FileName);
         SelectedDriver.AssemblyPath = edfile.Text;
     }
 }
示例#28
0
        public List <IVirtualFile> LoadFiles()
        {
            List <IVirtualFile> res = new List <IVirtualFile>();

            if (!Directory.Exists(m_folderPath))
            {
                return(res);
            }
            foreach (string file in Directory.GetFiles(m_folderPath))
            {
                if (IOTool.FileIsLink(file))
                {
                    if (!IOTool.FileLinkExists(file))
                    {
                        continue;
                    }
                }
                res.Add(new DiskFile(m_fileSystem, IOTool.RelativePathTo(m_fileSystem.RootPath, file)));
            }
            return(res);
        }
示例#29
0
        private void tree_DragDrop(object sender, DragEventArgs e)
        {
            if (!TreeBehaviour.AllowDragDrop)
            {
                return;
            }
            try
            {
                TreeNode            dropNode = tree.GetNodeAt(tree.PointToClient(new Point(e.X, e.Y)));
                DragObjectContainer cnt      = (DragObjectContainer)e.Data.GetData(typeof(DragObjectContainer));
                if (cnt != null && dropNode != null && cnt.Data is AppObject[])
                {
                    ITreeNode   targetNode  = ((DATreeNode)dropNode).m_node;
                    AppObject[] draggedObjs = (AppObject[])cnt.Data;
                    targetNode.DragDrop(draggedObjs);
                    //MacroManager.DragDropNode(targetNode, draggedObjs);
                }

                try
                {
                    IDataObject obj   = e.Data;
                    string[]    files = (string[])obj.GetData("FileDrop");
                    foreach (string f in files)
                    {
                        string fn = IOTool.GetUniqueFileName(Path.Combine(Root.FileSystemPath, Path.GetFileNameWithoutExtension(f) + ".lnk"));
                        using (StreamWriter sw = new StreamWriter(fn)) sw.Write(f);
                        RefreshRoot();
                        MacroManager.DropFileIntoTree(tree, f);
                    }
                }
                catch (Exception) { }

                tree.SelectedNode = dropNode;
            }
            catch (Exception ex)
            {
                Errors.Report(ex);
            }
        }
示例#30
0
 private static void _Initialize(string indexFile, HashSetEx <string> files)
 {
     foreach (string line in IOTool.LoadLines(indexFile))
     {
         try
         {
             if (File.Exists(line))
             {
                 File.Delete(line);
             }
             if (Directory.Exists(line))
             {
                 Directory.Delete(line, true);
             }
         }
         catch
         {
             files.Add(line.ToLower());
         }
     }
     IOTool.SaveLines(indexFile, files);
 }