Exemple #1
0
        private void btn_ok_Click(Object sender, EventArgs e)
        {
            if (default_path == folderBrow.SelectedPath)
            {
                MessageBox.Show(cn_strs.err_no_path);
                return;
            }
            if (textbox_workname.Text == null)
            {
                MessageBox.Show(cn_strs.err_no_name);
                return;
            }
            foreach (var item in HHI_Module.listHandInData)
            {
                if (item.Name == textbox_workname.Text)
                {
                    MessageBox.Show("已存在方案 " + item.Name);
                    return;
                }
            }

            HHI_HandIn hi = new HHI_HandIn();

            hi.ID = HHI_Module.listHandInData.Count;
            hi.IsSubItemFolder = checkbox_IsFolder.Checked;
            hi.Name            = textbox_workname.Text;
            hi.Path            = folderBrow.SelectedPath;
            hi.Regex           = textbox_regex.Text;
            hi.PrefixName      = combox_prefix.Text;

            HHI_Module.listHandInData.Add(hi);
            this.Close();
        }
Exemple #2
0
        private async void btn_attach_Click(Object sender, EventArgs e)
        {
            string     m_path = null;
            HHI_HandIn hi     = GetCurrentHandIn();

            if (hi.IsSubItemFolder)
            {
                m_path = stLib_CS.HastyFoo.Dialog.GetFolderPath();
            }
            else
            {
                m_path = stLib_CS.HastyFoo.Dialog.GetFileName();
            }
            if (m_path == null)
            {
                return;
            }
            string name = m_path.Substring(m_path.LastIndexOf('\\') + 1);
            string index;

            if (!HHI_Module.IndexExist(name, GetCurrentHandInsPrefix(), out index))
            {
                return;
            }

            if (hi.IsSubItemFolder)
            {
                await SendFiles(m_path);
            }
            else
            {
                await SendFile(m_path);
            }
        }
Exemple #3
0
        private void ReloadList()
        {
            HHI_HandIn    hi  = GetCurrentHandIn();
            DirectoryInfo dir = new DirectoryInfo(hi.Path);

            m_fileinfo           = dir.GetFileSystemInfos();
            lb_folder.DataSource = m_fileinfo;
        }
Exemple #4
0
        private void btn_detailsofhhi_Click(object sender, EventArgs e)
        {
            HHI_HandIn hhi = GetCurrentHandIn();

            MessageBox.Show(
                "作业名称:" + hhi.Name +
                "\n作业路径:" + hhi.Path +
                "\n作业预设方案:" + hhi.PrefixName
                );
        }
Exemple #5
0
        private void btn_openfolderinexplore_Click(object sender, EventArgs e)
        {
            HHI_HandIn hi = GetCurrentHandIn();

            if (!Directory.Exists(hi.Path))
            {
                MessageBox.Show("错误:作业路径不存在\n" + "当前该方案的路径为" + hi.Path + "\n请检查错误");
                return;
            }
            System.Diagnostics.Process.Start("explorer.exe", hi.Path);
        }
Exemple #6
0
        private HHI_Prefix GetCurrentHandInsPrefix()
        {
            HHI_HandIn hi = GetCurrentHandIn();

            foreach (var prefix in HHI_Module.listPrefixes)
            {
                if (prefix.Name == hi.PrefixName)
                {
                    return(prefix);
                }
            }
            return(null);
        }
Exemple #7
0
        private void btn_attach_Click(object sender, EventArgs e)
        {
            HHI_HandIn hi     = GetCurrentHandIn();
            HHI_Prefix prefix = GetCurrentHandInsPrefix();
            string     name;
            string     studentIndex;
            string     srcPath;

            if (hi.IsSubItemFolder)
            {
                folderBrowserDialog1.ShowDialog();
                srcPath = folderBrowserDialog1.SelectedPath;
                name    = folderBrowserDialog1.SelectedPath.Substring(folderBrowserDialog1.SelectedPath.LastIndexOf('\\') + 1);
            }
            else
            {
                openFileDialog1.ShowDialog();
                srcPath = openFileDialog1.FileName;
                name    = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf('\\') + 1);
            }
            if (srcPath == "")
            {
                return;
            }
            if (!HHI_Module.IndexExist(name, prefix, out studentIndex))
            {
                return;
            }

            if (!ListHelper.IsIn(HHI_Module.GetUnAttachedWorkIndexs(hi, prefix), Convert.ToInt32(studentIndex)))
            {
                if (MessageBox.Show("学号: " + studentIndex + " 已经提交,是否要覆盖?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    // Yes
                    CopyHelper.Copy(srcPath, hi.Path, hi.IsSubItemFolder);
                }
                else
                {
                    // No
                    return;
                }
            }
            else
            {
                CopyHelper.Copy(srcPath, hi.Path, hi.IsSubItemFolder);
            }
            ReloadList();
            m_output += "\n" + "[" + System.DateTime.Now.ToString() + "]" + "学号为: " + studentIndex + " 的同学,已提交作业!\n";
            MessageBox.Show(m_output);
            m_log += m_output;
        }
Exemple #8
0
        private void ProcessCheck()
        {
            HHI_Prefix tprefix = GetCurrentHandInsPrefix();
            HHI_HandIn hi      = GetCurrentHandIn();

            if (!Directory.Exists(hi.Path))
            {
                MessageBox.Show("错误:作业路径不存在\n" + "当前该方案的路径为" + hi.Path + "\n请检查错误");
                return;
            }

            if (tprefix == null)
            {
                m_output += "错误:无该预设\n";
            }

            List <int> digit = HHI_Module.GetUnAttachedWorkIndexs(hi, tprefix);

            m_output += "\n" + "[" + System.DateTime.Now.ToString() + "]" + "\n" + "作业名: " + hi.Name + "\n\n";
            // !process file
            if (digit.Count == 0)
            {
                m_output += "已全部收齐!";
            }
            else
            {
                m_output += "以下编号尚未交作业:" + "\n";
                foreach (var d in digit)
                {
                    m_output += d.ToString() + "   ";
                }
                m_output += "\n" + "共" + digit.Count.ToString() + "人";
            }

            MessageBox.Show(m_output);
            return;
        }
        public async Task <int> Send(Android.Content.Context context, CoordinatorLayout cl, string workName, string serverName, string folderName, List <string> paths)
        {
            HHI_HandIn     hi         = GetCurrentHandIn(workName);
            HHI_ServerInfo serverInfo = GetCurrentServerInfo(serverName);

            if (client == null)
            {
                client = new stLib_CS.Net.Client(serverInfo.IP, serverInfo.Port);
            }
            else
            {
                if (client.Connected())
                {
                    if (!client.IsServerDisconnected())
                    {
                        HHI_Android.ShowSimpleAlertView(context, "提示", "上一次传输还未完成,请稍后尝试。");
                        return(-1);
                    }
                }
                client.Disconnect();
                client = new stLib_CS.Net.Client(serverInfo.IP, serverInfo.Port);
            }

            //--- Connect ---
            try {
                if (1 == await client.Connect())
                {
                    HHI_Android.ShowSimpleAlertView(context, "错误", "IP地址不合法");
                }
            } catch (Exception ex) {
                HHI_Android.ShowSimpleAlertView(context, "错误", "连接错误,错误信息:\n" + ex.Message.ToString());
                return(-1);
            }
            // Update state Connected
            Snackbar.Make(cl, "连接成功!", Snackbar.LengthShort).Show();

            // Prepare for zip
            // Create path for tmp
            string targetFolderPath = System.IO.Path.Combine(stLib_CS.Compress.tmppath, folderName);

            if (Directory.Exists(stLib_CS.Compress.tmppath))
            {
                DeleteFolder(stLib_CS.Compress.tmppath);
            }
            Directory.CreateDirectory(stLib_CS.Compress.tmppath);
            if (!Directory.Exists(targetFolderPath))
            {
                Directory.CreateDirectory(targetFolderPath);
            }

            // Update state creating cache
            try {
                foreach (var path in paths)
                {
                    // TODO compress images
                    // Compress and Save
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.InJustDecodeBounds = false;
                    options.InSampleSize       = 4;
                    Bitmap bitmap     = BitmapFactory.DecodeFile(path, options);
                    var    fileStream = new FileStream(System.IO.Path.Combine(targetFolderPath, System.IO.Path.GetFileName(path)), FileMode.Create);
                    bitmap.Compress(Bitmap.CompressFormat.Png, 100, fileStream);
                    fileStream.Close();
                    // File.Copy( path, System.IO.Path.Combine( targetFolderPath, fileName ) );
                }
            } catch (Exception ex) {
                client.Disconnect();
                HHI_Android.ShowSimpleAlertView(context, "错误", "临时文件复制错误,错误信息:\n" + ex.Message.ToString());
                return(-1);
            }
            Snackbar.Make(cl, "临时文件创建成功!", Snackbar.LengthShort).Show();
            // Compress Zip File
            if (!Compress.DoZipFile(Compress.tmpname, targetFolderPath))
            {
                client.Disconnect();
                HHI_Android.ShowSimpleAlertView(context, "错误", "打包临时文件时出现错误");
                return(-1);
            }
            Snackbar.Make(cl, "缓存压缩成功!", Snackbar.LengthShort).Show();

            // Check Zip File openable
            FileInfo   zip = new FileInfo(Compress.tmpname);
            FileStream zipStream;

            try {
                zipStream = zip.OpenRead();
            } catch (Exception ex) {
                client.Disconnect();
                HHI_Android.ShowSimpleAlertView(context, "错误", "压缩包缓存无法打开,错误信息:\n" + ex.Message.ToString());
                return(-1);
            }
            Snackbar.Make(cl, "压缩缓存校验成功!", Snackbar.LengthShort).Show();
            // Send File
            NStream stream = client.stream;

            try {
                await stream.WriteString(System.IO.Path.Combine(hi.Path, folderName));

                System.Threading.Thread.Sleep(10);
                await stream.WriteInt64(zip.Length);

                System.Threading.Thread.Sleep(10);
                await stream.WriteBigFrom(zipStream);

                System.Threading.Thread.Sleep(50);
            } catch (Exception ex) {
                client.Disconnect();
                HHI_Android.ShowSimpleAlertView(context, "错误", "网络流写错误,错误信息:\n" + ex.Message.ToString());
                return(-1);
            }
            Snackbar.Make(cl, "传输完成,等待服务器接受完毕!结果可长按按钮查看!", Snackbar.LengthLong).Show();
            return(0);
        }