コード例 #1
0
        //监听消息的线程函数
        private void recv()
        {
            while (upldRunFlg)
            {
                MyLogger.WriteLine("upldSock 等待服务端下一次同意上传回应....");
                bool   endFlg = false;
                byte[] msgBuf = new byte[64];
                string msg    = null;
                while (!endFlg)
                {
                    try
                    {
                        int count = upldSock.Receive(msgBuf);
                    }
                    catch
                    {
                        MyLogger.WriteLine("upldSock Receive() 接收出错!");
                        return;
                    }
                    msg = Encoding.UTF8.GetString(msgBuf);
                    MyLogger.WriteLine(msg);

                    //接收到服务端 接收文件的响应
                    if (msg.StartsWith("resupld:"))
                    {
                        MyLogger.WriteLine("服务端同意接收:" + msg.Split('#')[1]);

                        //先压缩文件
                        Thread compressTh = new Thread(compress);
                        compressTh.IsBackground = true;
                        compressTh.Start();
                        MyLogger.WriteLine("开始压缩文件...");

                        //弹出一个不可取消的等待框,或者进度条
                        FmCompress fm = new FmCompress(this);
                        fm.Show();

                        //然后用循环检测文件压缩是否完成
                        int index = 0;
                        if (compressCode == ContantInfo.Compress.WAIT)
                        {
                            while (compressCode == ContantInfo.Compress.WAIT)
                            {
                                fm.updateInfo(index);
                                index++;
                                MyLogger.WriteLine("wait compress...");
                                Thread.Sleep(1000);
                            }
                            MyLogger.WriteLine("compress ok!");
                        }
                        fm.updateInfo(-1);                                // 关闭等待压缩进度条

                        if (compressCode == ContantInfo.Compress.PRESSOK) //压缩过程无错
                        {
                            //开始传输 zipFileName 的 .zip 文件
                            Thread upldTh = new Thread(upload);
                            upldTh.IsBackground = true;
                            upldTh.Start();
                            MyLogger.WriteLine("开始文件上传线程....");
                        }
                        else // 压缩出错
                        {
                            MessageBox.Show("压缩出错!", "上传中断");
                            MyLogger.WriteLine("压缩出错!");
                        }
                    }//msg.StartWith("head:");

                    //服务端同意接收文件
                    if (msg.StartsWith("resfile:"))
                    {
                        ifRecv = true;
                        MyLogger.WriteLine("服务端同意接收:" + msg.Split('#')[1]);
                    }

                    //接收到服务端 结束文件接收的响应
                    if (msg.StartsWith("resend:"))
                    {
                        endFlg = true;
                        MyLogger.WriteLine("服务端返回接收结束响应!");
                        MessageBox.Show("上传成功!", "message");

                        //上传完成后,重新设置
                        txtFolder.Text    = "";
                        trialInfo         = new TrialInfo();
                        groupInfo.Visible = false;
                    }

                    //接收服务端返回的错误信息
                    if (msg.StartsWith("errupld:"))
                    {
                        endFlg = true;
                        MessageBox.Show(msg.Split('#')[1], "message");

                        //删除upld 目录中的.upldhist.hist
                        string histNmae = upldPath + "\\.upldhist.hist";
                        if (File.Exists(histNmae))
                        {
                            File.Delete(histNmae);
                        }

                        txtFolder.Text    = "";
                        trialInfo         = new TrialInfo();
                        groupInfo.Visible = false;
                    }
                } //while(!endFlg)
                MyLogger.WriteLine("客户端监听任务结束!");
            }     //while()
        }
コード例 #2
0
        public FmWriteInfo(bool engMode, DataService service, ref TrialInfo trial, bool isNewUpld)
        {
            InitializeComponent();
            StartPosition = FormStartPosition.CenterScreen;

            #region 控件初始化
            infos.Add(combActivator);
            infos.Add(combOperator);
            infos.Add(combPltfm);
            infos.Add(combPdct);

            isEngMode      = engMode;
            this.service   = service;
            trialInfo      = trial;
            this.isNewUpld = isNewUpld;

            if (!isNewUpld) //不是新的上传
            {
                btAsNew.Visible = true;
            }
            else //新上传
            {
                btAsNew.Visible = false;
            }

            if (trialInfo.Activator == null)
            {
                trialInfo.Activator = "";
            }
            if (trialInfo.Operator == null)
            {
                trialInfo.Operator = "";
            }
            if (trialInfo.Pltfm == null)
            {
                trialInfo.Pltfm = "";
            }
            if (trialInfo.Pdct == null)
            {
                trialInfo.Pdct = "";
            }
            if (trialInfo.Info == null)
            {
                trialInfo.Info = "";
            }
            if (trialInfo.Other == null)
            {
                trialInfo.Other = "";
            }

            combActivator.Text = trial.Activator;
            combOperator.Text  = Cache.userId;
            combPltfm.Text     = trial.Pltfm;
            combPdct.Text      = trial.Pdct;
            txtInfo.Text       = trial.Info;
            txtOther.Text      = trial.Other;

            //新的上传
            if (isNewUpld)
            {
                teamList = service.getTeamList();
                if (teamList != null)
                {
                    foreach (string team in teamList)
                    {
                        combTeam.Items.Add(team);
                    }
                    if (combTeam.Text.Equals("") && teamList.Count >= 1)
                    {
                        combTeam.SelectedIndex = 0;
                        combTeam.Refresh();
                    }
                }

                teamUserDict = service.getUserNmDictByTeam(teamList[0]);
                if (teamUserDict != null)
                {
                    combActivator.Items.Clear();
                    foreach (var entry in teamUserDict)
                    {
                        combActivator.Items.Add(entry.Value);
                    }
                    if (combActivator.Text.Equals("") && teamUserDict.Count >= 1)
                    {
                        combActivator.SelectedIndex = 0;
                        combActivator.Refresh();
                    }
                }

                pltfmList = service.getPltfmNames();
                if (pltfmList != null)
                {
                    foreach (string pltfm in pltfmList)
                    {
                        combPltfm.Items.Add(pltfm);
                    }
                    if (combPltfm.Text.Equals("") && pltfmList.Count >= 1)
                    {
                        combPltfm.SelectedIndex = 0;
                        combPltfm.Refresh();
                    }
                }

                pdctList = service.getPdctNamesByPltfm(pltfmList[0]);
                if (pdctList != null)
                {
                    foreach (string pdct in pdctList)
                    {
                        combPdct.Items.Add(pdct);
                    }
                    if (combPdct.Text.Equals("") && pdctList.Count >= 1)
                    {
                        combPdct.Text = pdctList[0];
                    }
                }
            }
            else //不是新的上传
            {
                combTeam.Enabled      = false;
                combActivator.Enabled = false;
                combPltfm.Enabled     = false;
                combPdct.Enabled      = false;
            }
            #endregion
        }
コード例 #3
0
ファイル: XrommFilesystem_1.cs プロジェクト: tsgouros/wv
        private void SetupXromm(string PathFirstIVFile)
        {
            //check that the file exists
            if (!File.Exists(PathFirstIVFile))
            {
                throw new FileNotFoundException("Can not find IV file specified");
            }

            _ivFolderPath = Path.GetDirectoryName(PathFirstIVFile);
            _modelsPath   = Path.GetDirectoryName(_ivFolderPath);
            _subjectPath  = Path.GetDirectoryName(_modelsPath);
            _subject      = Path.GetFileName(_subjectPath);

            string boneFileName            = Path.GetFileName(PathFirstIVFile);
            string boneFileNameNoExtension = Path.GetFileNameWithoutExtension(boneFileName);

            Match m = Regex.Match(boneFileNameNoExtension, @"^(X[a-z]*\d{5})_([a-z0-9]+)_([lr])$", RegexOptions.IgnoreCase);

            if (!m.Success)
            {
                throw new WristException("Initial IV file is not in a valid XROMM format");
            }

            string subjectID = m.Groups[1].Value;
            string boneName  = m.Groups[2].Value.ToLower();
            string side      = m.Groups[3].Value.ToLower();

            if (!String.Equals(_subject, subjectID, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new WristException("Subject specified in IV file name does not match subject folder name");
            }

            //need to now find all of the bones.... (can I limit to IV files only....?)
            List <string> ivFiles     = new List <string>();
            List <string> boneNames   = new List <string>();
            DirectoryInfo ivFolderDir = new DirectoryInfo(_ivFolderPath);

            FileInfo[] ivFilesFileInfo = ivFolderDir.GetFiles(String.Format("{0}*.iv", _subject));
            foreach (FileInfo file in ivFilesFileInfo)
            {
                m = Regex.Match(file.Name, String.Format(@"^{0}_([a-z0-9]+)_[lr]\.iv$", _subject), RegexOptions.IgnoreCase);
                if (!m.Success)
                {
                    continue;
                }

                ivFiles.Add(file.FullName.ToLower());
                boneNames.Add(m.Groups[1].Value.ToLower());
            }
            ivFiles.Sort();
            boneNames.Sort();

            _bnames = boneNames.ToArray();
            _bpaths = ivFiles.ToArray();

            //now to find all of the trials
            List <TrialInfo> trialInfo  = new List <TrialInfo>();
            DirectoryInfo    SubjectDir = new DirectoryInfo(_subjectPath);

            DirectoryInfo[] trials = SubjectDir.GetDirectories("Trial???");
            foreach (DirectoryInfo trialDir in trials)
            {
                m = Regex.Match(trialDir.Name, @"Trial(\d{3})", RegexOptions.IgnoreCase);
                if (!m.Success)
                {
                    continue;
                }

                string trialNumberString = m.Groups[1].Value.ToLower();
                int    trialNumber       = Int32.Parse(trialNumberString);

                string        kinematicFilePattern = String.Format("{0}_Trial{1}_*AbsTforms.csv", _subject, trialNumberString);
                DirectoryInfo kinematicDirectory   = new DirectoryInfo(Path.Combine(trialDir.FullName, "XROMM"));

                //check that there is an XROMM directory
                if (!kinematicDirectory.Exists)
                {
                    continue;
                }

                FileInfo[] possbileFiles = kinematicDirectory.GetFiles(kinematicFilePattern);
                //Danny wants us to report everything we find...
                foreach (FileInfo file in possbileFiles)
                {
                    //we want to grab middle section of the filename to dispaly, so we need a regex
                    string savePattern = String.Format("^{0}_Trial{1}_(.*)AbsTforms.csv$", _subject, trialNumberString);
                    //I don't think this regex can fail, give the filter we used get the files....
                    string subID = Regex.Match(file.Name, savePattern, RegexOptions.IgnoreCase).Groups[1].Value;
                    //remove any trailing '_' that might be there
                    subID = subID.TrimEnd('_');

                    //TODO: Save file information.... e.g. "{0}_Trial{1}_xyzptsBUTTER25_sm125AbsTforms.csv"
                    TrialInfo info = new TrialInfo();
                    info.KinematicFilename = possbileFiles[0].FullName;
                    info.TrialName         = String.Format("T{0:00}", trialNumber);
                    if (subID.Length > 0)
                    {
                        info.TrialName += String.Format("-{0}", subID);
                    }
                    info.TrialNumber = trialNumber;

                    trialInfo.Add(info);
                }
            }
            _info = trialInfo.ToArray();
        }