Ejemplo n.º 1
0
 protected void LoadInfosFromNet()
 {
     if (!isFetching)
     {
         isFetching = true;
         try {
             mHhiAndroid.FetchInfos();
         } catch (System.Exception ex) {
             HHI_Android.ShowSimpleAlertView(this, "错误", "无法获取数据,错误信息\n" + ex.Message.ToString());
             isFetching = false;
             return;
         }
         UpdateSpinnerWork();
         UpdateSpinnerServer();
         UpdateACTVFolderNameAdapater();
         string workname   = mSpinnerWork.SelectedItem?.ToString();
         string servername = mSpinnerServer.SelectedItem?.ToString();
         mTVMain.Text = mHhiAndroid.GetCurrentHandIn(workname).Desc;
         isFetching   = false;
         Snackbar.Make(this.Window.DecorView, "服务器信息获取成功!", Snackbar.LengthLong).Show();
     }
     else
     {
         Snackbar.Make(mCLMain, "正在获取,请稍后", Snackbar.LengthLong).Show();
     }
 }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            // Initialize HHI_Android
            mHhiAndroid = new HHI_Android();
            mHhiAndroid.InitAll();


            // Initialize All Controllers
            InitDrawLayout();
            InitToolbar();
            InitBtnRefresh();
            InitFABSend();
            InitSpinnerServer();
            InitSpinnerWork();
            InitACTVFolderName();
            InitGridView();
            InitPb();
            mTVMain = FindViewById <TextView>(Resource.Id.id_tv_info);
            InitCLMain();
            //
            LoadInfosFromNet();
        }
Ejemplo n.º 3
0
        void MFABRefresh_LongClick(object sender, View.LongClickEventArgs e)
        {
            string servername = mSpinnerServer.SelectedItem?.ToString();

            if (servername == "")
            {
                return;
            }
            hhi_modules.HHI_ServerInfo serverInfo = mHhiAndroid.GetCurrentServerInfo(servername);

            HHI_Android.ShowSimpleAlertView(this, "服务器信息",
                                            "服务器名:" + servername + "\nIP地址:" + serverInfo.IP + "\n端口号" + serverInfo.Port);
        }
 public void CheckSendingFinished(Android.Content.Context context, CoordinatorLayout cl)
 {
     if (client == null)
     {
         HHI_Android.ShowSimpleAlertView(context, "提示", "本次打开软件到现在还未发送过文件。");
     }
     else
     {
         if (!client.IsServerDisconnected())
         {
             HHI_Android.ShowSimpleAlertView(context, "提示", "目前还在传输中,请等待。");
         }
         else
         {
             HHI_Android.ShowSimpleAlertView(context, "提示", "传输已完成!");
         }
     }
 }
        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);
        }
Ejemplo n.º 6
0
        void MFABSend_Click(object sender, System.EventArgs e)
        {
            // TODO Popup Window Progress
            string workname   = mSpinnerWork.SelectedItem?.ToString();
            string servername = mSpinnerServer.SelectedItem?.ToString();
            string foldername = mACTVFolderName?.Text;
            int    fileCount  = mImageAdapter.mImageViewer.PathList.Count;

            string note = "";

            if (workname == "")
            {
                note += "作业名为空\n";
            }
            if (servername == "")
            {
                note += "没有选择服务器\n";
            }
            if (foldername == "")
            {
                note += "没有填写姓名+学号\n";
            }
            if (fileCount == 0)
            {
                note += "没有添加照片\n";
            }

            if (note != "")
            {
                HHI_Android.ShowSimpleAlertView(this, "提示", note);
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.SetTitle("提示");
            builder.SetMessage("即将开始上传,请确认信息:\n"
                               + "服务器:" + servername
                               + "\n作业:" + workname
                               + "\n文件夹名:" + mACTVFolderName.Text
                               + "\n照片数量" + fileCount.ToString() + "\n\n确认上传?");

            builder.SetPositiveButton(Resource.String.str_cn_confrim, async(ss, ee) => {
                try {
                    mProgressBar.Visibility = ViewStates.Visible;
                    if (await mHhiAndroid.Send(this, mCLMain, workname, servername, foldername, mImageAdapter.mImageViewer.PathList) == 0)
                    {
                        mProgressBar.Visibility = ViewStates.Gone;
                    }
                } catch (Exception ex) {
                    HHI_Android.ShowSimpleAlertView(this, "提示",
                                                    "停止传送,错误信息:" +
                                                    ex.Message.ToString() +
                                                    "\n" +
                                                    ex.Source.ToString() +
                                                    "\n" + ex.TargetSite);
                    mProgressBar.Visibility = ViewStates.Gone;
                }
                mProgressBar.Visibility = ViewStates.Gone;
            });
            builder.SetNegativeButton(Resource.String.str_cn_cancel, (ss, ee) => { });
            builder.Create().Show();
        }