Esempio n. 1
0
        private void BtnFiles_Click(object sender, RoutedEventArgs e)
        {
            WinForms.OpenFileDialog openFileDialog = new WinForms.OpenFileDialog();
            string fliter = TxtFilter.Text;

            if (openFileDialog.ShowDialog() == WinForms.DialogResult.OK)//注意,此处一定要手动引入System.Window.Forms空间,否则你如果使用默认的DialogResult会发现没有OK属性
            {
                string[] path = openFileDialog.FileNames;
                TreeNode node = treeList.SelectedItem as TreeNode;
                if (node != null)
                {
                    foreach (string f in path)
                    {
                        if (!string.IsNullOrEmpty(fliter))
                        {
                            if (f.EndsWith(fliter))
                            {
                                continue;
                            }
                        }
                        FileInfo fileInfo = new FileInfo(f);
                        DLLFile  dLLFile  = new DLLFile()
                        {
                            LocalFile = fileInfo.FullName, Name = fileInfo.Name
                        };
                        node.Files.Add(dLLFile);
                    }
                }
            }
        }
Esempio n. 2
0
        private void MenuGridDel_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection <DLLFile> vf = gridData.ItemsSource as ObservableCollection <DLLFile>;
            DLLFile dll = gridData.SelectedItem as DLLFile;

            vf.Remove(dll);
            if (dll.ID > 0)
            {
                deleteFileList.Add(dll.ID);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 查询是否已经存在文件
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        private int QueryStoreID(DLLFile f)
        {
            string sql = string.Format("select id from largestore where localname='{0}' and md5='{1}'",
                                       f.Name, f.MD5);
            object v = ManagerPool.Singleton.ExecuteScalar(sql);

            if (v == null)
            {
                return(-1);
            }
            else
            {
                return(Convert.ToInt32(v));
            }
        }
Esempio n. 4
0
        private void BtnDirectory_Click(object sender, RoutedEventArgs e)
        {
            WinForms.FolderBrowserDialog fbd = new WinForms.FolderBrowserDialog();
            fbd.Description = "pls select a folder";
            string filter = TxtFilter.Text;

            if (fbd.ShowDialog() == WinForms.DialogResult.OK)
            {
                string        path = fbd.SelectedPath;
                DirectoryInfo info = new DirectoryInfo(path);
                TreeNode      node = treeList.SelectedItem as TreeNode;
                if (node != null)
                {
                    foreach (var dir in node.ChildNodes)
                    {
                        if (info.Name == dir.NodeName)
                        {
                            System.Windows.MessageBox.Show("已经存在该目录");
                            return;
                        }
                    }
                    //
                    var child = new TreeNode()
                    {
                        NodeName = info.Name
                    };
                    foreach (var f in info.GetFiles())
                    {
                        if (!string.IsNullOrEmpty(filter))
                        {
                            if (f.Extension == filter)
                            {
                                continue;
                            }
                        }
                        DLLFile dLLFile = new DLLFile()
                        {
                            LocalFile = f.FullName, Name = f.Name
                        };
                        child.Files.Add(dLLFile);
                    }
                    node.ChildNodes.Add(child);
                }
            }
        }
Esempio n. 5
0
        private ObservableCollection <TreeNode> GetChildNodes(int parentID, ObservableCollection <TreeNode> nodes)
        {
            ObservableCollection <TreeNode> mainNodes  = new ObservableCollection <TreeNode>(nodes.Where(x => x.ParentID == parentID).ToList());
            ObservableCollection <TreeNode> otherNodes = new ObservableCollection <TreeNode>(nodes.Where(x => x.ParentID != parentID).ToList());

            foreach (TreeNode node in mainNodes)
            {
                var child = GetChildNodes(node.NodeID, otherNodes);
                node.ChildNodes = new ObservableCollection <TreeNode>(child.Where(x => x.IsDirectory));
                var files = child.Where(x => !x.IsDirectory);
                foreach (var f in files)
                {
                    DLLFile dLLFile = new DLLFile()
                    {
                        DLLPath = f.NodeName, ID = f.ID, MD5 = f.MD5, Name = f.NodeName, NodeID = f.NodeID, ParentID = f.ParentID, Version = f.Version, StoreID = f.SoreID
                    };
                    node.Files.Add(dLLFile);
                }
            }
            return(mainNodes);
        }
Esempio n. 6
0
        /// <summary>
        /// 添加节点
        /// </summary>
        /// <param name="path"></param>
        /// <param name="node"></param>
        private void AddDirectory(string path, TreeNode node)
        {
            DirectoryInfo info   = new DirectoryInfo(path);
            var           dirs   = info.GetDirectories();
            string        filter = TxtFilter.Text;

            if (dirs.Length > 0)
            {
                foreach (var sub in dirs)
                {
                    TreeNode child = new TreeNode
                    {
                        NodeName = sub.Name
                    };
                    node.ChildNodes.Add(child);
                    AddDirectory(sub.FullName, child);
                    //
                    var files = sub.GetFiles();
                    foreach (var f in files)
                    {
                        if (!string.IsNullOrEmpty(filter))
                        {
                            if (f.Extension == filter)
                            {
                                continue;
                            }
                        }
                        DLLFile dLLFile = new DLLFile()
                        {
                            LocalFile = f.FullName, Name = f.Name
                        };
                        child.Files.Add(dLLFile);
                    }
                }
                //
                var cur = info.GetFiles();
                foreach (var f in cur)
                {
                    if (!string.IsNullOrEmpty(filter))
                    {
                        if (f.Extension == filter)
                        {
                            continue;
                        }
                    }
                    DLLFile dLLFile = new DLLFile()
                    {
                        LocalFile = f.FullName, Name = f.Name
                    };
                    node.Files.Add(dLLFile);
                }
            }
            else
            {
                var files = info.GetFiles();
                foreach (var f in files)
                {
                    if (!string.IsNullOrEmpty(filter))
                    {
                        if (f.Extension == filter)
                        {
                            continue;
                        }
                    }
                    DLLFile dLLFile = new DLLFile()
                    {
                        LocalFile = f.FullName, Name = f.Name
                    };
                    node.Files.Add(dLLFile);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 传输每个文件
        /// </summary>
        /// <param name="f"></param>
        /// <param name="node"></param>
        private void UpdateFile(DLLFile f, TreeNode node)
        {
            string version = "";

            Dispatcher.Invoke(() =>
            {
                version = TxtVsersion.Text;
            });
            StringBuilder sbr = new StringBuilder();
            string        cmd = "";
            //比较
            string cmdCpoy = "";

            if (string.IsNullOrEmpty(f.LocalFile) && version != node.Version && f.ID > 0)
            {
                //说明该文件已经存在;直接拷贝;
                //发布版本
                cmdCpoy = string.Format("insert into updatesoft(id,nodeid,path,name,md5,parentid,content,version,isdirectory,storeid)   select {0},nodeid,path,name,md5,parentid,content,'{2}',isdirectory,storeid from updatesoft where id={1}", dbseq, f.ID, version);
            }
            else if (!string.IsNullOrEmpty(f.LocalFile))
            {
                //有文件:新增版本,新增文件
                if (!string.IsNullOrEmpty(f.MD5))
                {
                    //说明是有文件的;比较文件变化,覆盖文件
                    string curv = MD5.GetMD5HashFromFile(f.LocalFile);
                    if (f.MD5 == curv)
                    {
                        if (version != node.Version)
                        {
                            //直接,发布新版本拷贝
                            cmdCpoy = string.Format("insert into updatesoft(id,nodeid,path,name,md5,parentid,content,version,isdirectory,storeid)   select {0},nodeid,path,name,md5,parentid,content,'{2}',isdirectory,storeid from updatesoft where id={1}", dbseq, f.ID, version);
                        }
                        else
                        {
                            //说明该文件既没有参与发布新版本,也不需要修改,直接不操作
                            //上传文件选中有变化的,没有变化的不处理
                            return;
                        }
                    }
                    else
                    {
                        f.MD5 = curv;//文件已经变化
                    }
                }
                else
                {
                    //完全新增
                    f.MD5 = MD5.GetMD5HashFromFile(f.LocalFile);
                }
            }
            else if (string.IsNullOrEmpty(f.LocalFile))
            {
                //说明是不需要操作文件,保持不动
                return;
            }
            //
            if (string.IsNullOrEmpty(cmdCpoy))
            {
                //新增
                cmd        = "insert into updatesoft(id,nodeid,path,name,md5,parentid,content,version,isdirectory,storeid)values(";
                cmd       += "@id,@nodeid,@path,@name,@md5,@parentid,@content,@version,@isdirectory,@storeid)";
                sbr.Length = 0;
                byte[] fbyte   = null;
                long   size    = FileLen(f.LocalFile);
                int    storeid = -1;
                if (size < MaxFileSize)
                {
                    fbyte = ReadFile(f.LocalFile);
                }
                else
                {
                    //检测已经存在的文件是否有
                    storeid = QueryStoreID(f);
                    if (storeid < 0)
                    {
                        //则需要提交
                        storeid = QuerySeqId();
                        string remoteName = "";
                        string remotePath = store.CommitFile(storeid, f.LocalFile, out remoteName);
                        LagreFile(storeid, remotePath, f.MD5, remoteName, f.Name);
                    }
                }
                Dictionary <string, object> dic = new Dictionary <string, object>
                {
                    ["id"]          = QuerySeqId(),
                    ["nodeid"]      = QueryNodeId(),
                    ["path"]        = f.Name,
                    ["name"]        = f.Name,
                    ["md5"]         = f.MD5,
                    ["parentid"]    = node.NodeID,
                    ["content"]     = fbyte,
                    ["version"]     = version,
                    ["isdirectory"] = false,
                    ["storeid"]     = storeid
                };
                CmdExecute(cmd, dic);
                sbr.Length   = 0;
                isUpdateFile = true;
            }
            else
            {
                CmdExecute(cmdCpoy);
            }
        }