private ModifierCollection GetNoDirModifiers(string moduleRootDir, DirectoryInfo dir)
        {
            ModifierCollection list = new ModifierCollection();

            Modifier m = new Modifier();

            m.ActionMode = ActionType.UpdateFile;
            m.FileMode   = FileType.Directory;
            m.Path       = PathHelper.GetServerPath(moduleRootDir, dir.FullName);
            list.Add(m);

            foreach (FileInfo file in dir.GetFiles())
            {
                Modifier fm = new Modifier();
                fm.FileMode   = FileType.File;
                fm.ActionMode = ActionType.UpdateFile;
                fm.Path       = file.FullName;
                list.Add(fm);
            }

            foreach (DirectoryInfo sub in dir.GetDirectories())
            {
                list.Import(GetNoDirModifiers(moduleRootDir, sub));
            }

            return(list);
        }
        internal ModuleStatus CheckItemStatus()
        {
            if (string.IsNullOrWhiteSpace(this.LocalPath))
            {
                SetItemWarning(this.Node);
                return(ModuleStatus.LocalPathDoNotExist);
            }

            DirectoryInfo dir = new DirectoryInfo(this.LocalPath);

            if (!dir.Exists)
            {
                SetItemWarning(this.Node, "指定路徑不存在 : " + this.LocalPath);
                return(ModuleStatus.LocalPathDoNotExist);
            }

            ModifierCollection mc = this.CheckUploadModifier();

            if (mc.Count > 0)
            {
                this.Node.ImageKey         = "reload";
                this.Node.SelectedImageKey = "reload";
                this.Node.ToolTipText      = "本機檔案已變更, 可進行同步處理";
                return(ModuleStatus.Modified);
            }
            this.Node.ImageKey         = "module";
            this.Node.SelectedImageKey = "module";
            this.Node.ToolTipText      = "已完成同步";
            return(ModuleStatus.Nomal);
        }
 public void Import(ModifierCollection list)
 {
     foreach (Modifier m in list)
     {
         this.Add(m);
     }
 }
        public ModifierCollection CheckUploadModifier()
        {
            ModifierCollection modifiers = new ModifierCollection();

            if (string.IsNullOrWhiteSpace(this.LocalPath))
            {
                return(modifiers);
            }

            XmlElement    dirElement = this.Source.GetElement("Directory");
            DirectoryInfo dir        = new DirectoryInfo(this.LocalPath);

            return(this.CompareDir(dir, dirElement));
        }
        private ModifierCollection CompareDir(DirectoryInfo dir, XmlElement dirElement)
        {
            ModifierCollection list = new ModifierCollection();

            XmlHelper h = new XmlHelper(dirElement);

            foreach (XmlElement subDir in h.GetElements("Directory"))
            {
                string        name = subDir.GetAttribute("Name");
                DirectoryInfo sd   = null;
                foreach (DirectoryInfo sub in dir.GetDirectories())
                {
                    if (sub.Name == name)
                    {
                        sd = sub;
                        break;
                    }
                }
                if (sd == null)
                {
                    Modifier m = new Modifier();
                    m.ActionMode = ActionType.SendDelete;
                    m.FileMode   = FileType.Directory;
                    m.Path       = PathHelper.GetServerPath(this, subDir);
                    list.Add(m);
                }
                else
                {
                    ModifierCollection mc = CompareDir(sd, subDir);
                    list.Import(mc);
                }
            }

            foreach (DirectoryInfo sub in dir.GetDirectories())
            {
                if (h.GetElement("Directory[@Name='" + sub.Name + "']") == null)
                {
                    ModifierCollection mc = this.GetNoDirModifiers(this.LocalPath, sub);
                    list.Import(mc);
                }
            }

            foreach (XmlElement subFile in h.GetElements("File"))
            {
                string   name = subFile.GetAttribute("Name");
                FileInfo file = null;
                foreach (FileInfo sub in dir.GetFiles())
                {
                    if (sub.Name != name)
                    {
                        continue;
                    }
                    file = sub;
                    break;
                }
                if (file == null)
                {
                    Modifier m = new Modifier();
                    m.ActionMode = ActionType.SendDelete;
                    m.FileMode   = FileType.File;
                    m.Path       = PathHelper.GetServerPath(this, subFile);
                    list.Add(m);
                }
                else
                {
                    string md5     = subFile.GetAttribute("MD5");
                    string fileMD5 = this.ComputeFileMD5(file);

                    if (md5 != fileMD5)
                    {
                        Modifier m = new Modifier();
                        m.ActionMode = ActionType.UpdateFile;
                        m.FileMode   = FileType.File;
                        m.Path       = file.FullName;
                        list.Add(m);
                    }
                }
            }

            foreach (FileInfo sub in dir.GetFiles())
            {
                if (h.GetElement("File[@Name='" + sub.Name + "']") == null)
                {
                    Modifier m = new Modifier();
                    m.ActionMode = ActionType.UpdateFile;
                    m.FileMode   = FileType.File;
                    m.Path       = sub.FullName;
                    list.Add(m);
                }
            }
            return(list);
        }
        public void Upload()
        {
            string msg = "確定要「上傳」差異檔案到主機?這會覆蓋主機的檔案。";

            if (MessageBox.Show(msg, "檔案同步", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }


            if (!ModuleHandler.LocalPathExists)
            {
                return;
            }

            string moduleName = ModuleHandler.Name;

            ModifierCollection list  = ModuleHandler.CheckUploadModifier();
            List <UploadFile>  files = new List <UploadFile>();
            XmlHelper          req   = new XmlHelper();

            req.AddElement(".", "ModuleName", moduleName);

            foreach (Modifier m in list)
            {
                if (m.ActionMode == ActionType.SendDelete)
                {
                    ModuleHandler.DeletePath(m.Path);
                }
                else if (m.ActionMode == ActionType.UpdateFile && m.FileMode == FileType.Directory)
                {
                    req.AddElement(".", "Path", m.Path);
                }
                else if (m.ActionMode == ActionType.UpdateFile && m.FileMode == FileType.File)
                {
                    UploadFile f    = new UploadFile();
                    FileInfo   file = new FileInfo(m.Path);
                    f.File       = file;
                    f.ServerPath = PathHelper.GetServerPath(ModuleHandler.LocalPath, m.Path);
                    files.Add(f);
                }
            }

            if (req.GetElement("Path") != null)
            {
                MainForm.LoginArgs.SendModuleRequest("PrepareDirectory", new Envelope(req));
            }

            if (files.Count > 0)
            {
                string       ftp = PathHelper.GetFtpPath(MainForm.LoginArgs.FtpURL, MainForm.LoginArgs.GreeningID, moduleName);
                ProgressForm pf  = new ProgressForm(files.ToArray(), ftp, MainForm.LoginArgs.FtpUser, MainForm.LoginArgs.FtpPassword);
                pf.ShowDialog();
            }

            ModuleHandler.Reload();

            //if (NeedUploadChanged != null)
            //    NeedUploadChanged.Invoke(this, new NeedStatusEventArgs(false));

            FileEditable fe = CurrentEditor as FileEditable;
            FileUIEditor ui = fe.Editor as FileUIEditor;

            ui.Reload();
        }