Example #1
0
        public BitmapImage GetImage(string imagePath)
        {
            BitmapImage bi = new BitmapImage();

            try
            {
                if (imagePath == null)
                {
                    return(bi);
                }


                //string filePath = string.Format("/Resources;component/image/face/{0}", imagePath);

                //string strPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string strPath  = System.Windows.Forms.Application.StartupPath;
                string filePath = strPath + "\\" + imagePath;


                if (File.Exists(filePath) == true)
                {
                    FileInfo fileInfo = new FileInfo(filePath);

                    //bi = new BitmapImage();

                    bi.BeginInit();
                    bi.UriSource = new Uri(fileInfo.FullName, UriKind.RelativeOrAbsolute);
                    bi.EndInit();
                }
                else
                {
                    //Uri uriSource = new Uri(Login._ServerPath + imagePath, UriKind.RelativeOrAbsolute);
                    ////string uri = Login._ServerPath + imagePath;

                    ////Stopwatch stopWatch = new Stopwatch();
                    ////stopWatch.Start();

                    //WebClient webClient = new WebClient();
                    //webClient.Proxy = null;

                    //Stream stream = new MemoryStream(webClient.DownloadData(uriSource.AbsoluteUri));

                    //using (FileStream fileStream = System.IO.File.Create(filePath, (int)stream.Length))
                    //{
                    //    // Fill the bytes[] array with the stream data
                    //    byte[] bytesInStream = new byte[stream.Length];
                    //    stream.Read(bytesInStream, 0, (int)bytesInStream.Length);

                    //    // Use FileStream object to write to the specified file
                    //    fileStream.Write(bytesInStream, 0, bytesInStream.Length);
                    //}

                    ////stopWatch.Stop();
                    ////double elpased = stopWatch.Elapsed.TotalMilliseconds;

                    ////Byte[] buffer = new Byte[response.ContentLength];
                    ////int offset = 0, actuallyRead = 0;

                    ////do
                    ////{
                    ////    actuallyRead = stream.Read(buffer, offset, buffer.Length - offset);
                    ////    offset += actuallyRead;
                    ////}
                    ////while (actuallyRead > 0);

                    ////File.WriteAllBytes(filePath, buffer);

                    //// bi = new BitmapImage();

                    //bi.BeginInit();
                    //bi.StreamSource = stream;
                    //bi.EndInit();

                    bi.BeginInit();
                    bi.UriSource = new Uri(strPath + "\\image\\face\\noimage.png", UriKind.RelativeOrAbsolute);
                    bi.EndInit();
                }
            }
            catch (Exception ex)
            {
                //MessageBoxCommon.Show("봉사기가 응답이 없습니다. 프로그램을 종료합니다.", MessageBoxType.Ok);
                //Login.ShowError(ChatEngine.ErrorType.Notrespond_Server);

                //if (Login.main != null)
                //    Login.main.Image_MouseUp(null, null);
                //else
                //    Application.Current.Shutdown();
                string strPath = System.Windows.Forms.Application.StartupPath;

                bi.BeginInit();
                bi.UriSource = new Uri(strPath + "\\image\\face\\noimage.png", UriKind.RelativeOrAbsolute);
                bi.EndInit();


                string strError = ex.ToString() + imagePath;
                ErrorCollection.GetInstance().SetErrorInfo(strError);
            }

            return(bi);
        }
Example #2
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            //string filePath = "C:\\Record\\" + Login._UserInfo.Id + ".avi";

            //Microsoft.Win32.OpenFileDialog open = new Microsoft.Win32.OpenFileDialog();

            //open.Multiselect = false;
            //open.FileName = filePath;
            //open.Filter = "AVI Files (*.avi)|*.avi";

            //if ((bool)open.ShowDialog())
            //{
            //    if (filePath == open.FileName)
            //    {
            //        Uploader(open.FileName, open.OpenFile());
            //    }

            //}

            try
            {
                //System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
                //fileDialog.Multiselect = false;
                //fileDialog.Filter = "AVI Files (*.avi)|*.avi|WMV Files (*.wmv)|*.wmv|ALL Files (*.*)|*.*";
                //fileDialog.Title = "비디오파일선택";

                //if (System.Windows.Forms.DialogResult.OK == fileDialog.ShowDialog())
                //{
                //string fileName = fileDialog.FileName;
                string             fileName = _strRecordFilePath;
                System.IO.FileInfo fileSize = new System.IO.FileInfo(fileName);
                if (fileSize.Length > 1024 * 10 * 10 * 10 * 10 / 2)
                {
                    TempWindowForm tempWindowForm = new TempWindowForm();
                    QQMessageBox.Show(tempWindowForm, "文件大小必须小于 5MB.", "提示", QQMessageBoxIcon.Error, QQMessageBoxButtons.OK);

                    return;
                }

                string strImageFile = fileName.Replace(".mp4", ".jpg");

                string strUri = Login._ServerPath;
                if (strUri[strUri.Length - 1] != '/')
                {
                    strUri = strUri + "/";
                }

                // 2014-02-09: GReenRose
                Dispatcher.BeginInvoke(new System.Threading.ThreadStart(delegate
                {
                    if (Main.loadWnd == null)
                    {
                        Main.loadWnd       = new LoadingWnd();
                        Main.loadWnd.Owner = myHome;
                        Main.loadWnd.ShowDialog();
                    }
                }));

                strUri += "FaceUpload.php";
                WebUploader.GetInstance().UploadFile(fileName, strUri, FileUploadComplete, this);

                _strImageFile = strImageFile;
                _strUri       = strUri;
                //WebUploader.GetInstance().UploadFile(strImageFile, strUri, ImageFileUploadComplete, this);

                this.Close();
                //if (UpdateFile(fileName))
                //{
                //    if (UpdateFile(strImageFile))
                //    {
                //        byte[] bit = new byte[0];

                //        VideoInfo videoInfo = new VideoInfo();
                //        videoInfo.Data = bit;
                //        videoInfo.UserId = Login._UserInfo.Id;
                //        videoInfo.ImgData = bit;
                //        int nIndex = fileName.LastIndexOf("\\");
                //        videoInfo.ImgName = fileName.Substring(nIndex + 1);
                //        Login._ClientEngine.Send(NotifyType.Request_VideoUpload, videoInfo);
                //    }
                //}
            }
            catch (Exception ex)
            {
                string strError = ex.ToString();
                ErrorCollection.GetInstance().SetErrorInfo(strError);
            }
        }
        /// <summary>
        /// Download the data using HttpWebRequest. It will read a buffer of bytes from the
        /// response stream, and store the buffer to a MemoryStream cache first.
        /// If the cache is full, or the download is paused, canceled or completed, write
        /// the data in cache to local file.
        /// </summary>
        void DownloadInternal(object obj)
        {
            if (this.Status != DownloadStatus.Waiting)
            {
                return;
            }

            HttpWebRequest  webRequest     = null;
            HttpWebResponse webResponse    = null;
            Stream          responseStream = null;
            MemoryStream    downloadCache  = null;

            this.lastStartTime = DateTime.Now;

            try
            {
                if (!HasChecked)
                {
                    string filename = string.Empty;
                    CheckUrlAndFile();
                }

                this.EnsurePropertyValid();

                // Set the status.
                this.Status = DownloadStatus.Downloading;

                // Create a request to the file to be  downloaded.
                webRequest = DownloaderHelper.InitializeHttpWebRequest(this);

                // Specify the block to download.
                if (EndPoint != int.MaxValue)
                {
                    webRequest.AddRange((int)(StartPoint + DownloadedSize), (int)EndPoint);
                }
                else
                {
                    webRequest.AddRange((int)(StartPoint + DownloadedSize));
                }

                // Retrieve the response from the server and get the response stream.
                webResponse = (HttpWebResponse)webRequest.GetResponse();

                responseStream = webResponse.GetResponseStream();


                // Cache data in memory.
                downloadCache = new MemoryStream(this.MaxCacheSize);

                byte[] downloadBuffer = new byte[this.BufferSize];

                int bytesSize = 0;
                CachedSize = 0;
                int receivedBufferCount = 0;

                // Download the file until the download is paused, canceled or completed.
                while (true)
                {
                    // Read a buffer of data from the stream.
                    bytesSize = responseStream.Read(downloadBuffer, 0, downloadBuffer.Length);

                    // If the cache is full, or the download is paused, canceled or
                    // completed, write the data in cache to local file.
                    if (this.Status != DownloadStatus.Downloading ||
                        bytesSize == 0 ||
                        this.MaxCacheSize < CachedSize + bytesSize)
                    {
                        try
                        {
                            // Write the data in cache to local file.
                            WriteCacheToFile(downloadCache, CachedSize);

                            this.DownloadedSize += CachedSize;

                            // Stop downloading the file if the download is paused,
                            // canceled or completed.
                            if (this.Status != DownloadStatus.Downloading ||
                                bytesSize == 0)
                            {
                                break;
                            }

                            // Reset cache.
                            downloadCache.Seek(0, SeekOrigin.Begin);
                            CachedSize = 0;
                        }
                        catch (Exception ex)
                        {
                            string strError = ex.ToString();
                            ErrorCollection.GetInstance().SetErrorInfo(strError);

                            // Fire the DownloadCompleted event with the error.
                            this.OnDownloadCompleted(
                                new DownloadCompletedEventArgs(
                                    null,
                                    this.DownloadedSize,
                                    this.TotalSize,
                                    this.TotalUsedTime,
                                    ex));
                            return;
                        }
                    }

                    // Write the data from the buffer to the cache in memory.
                    downloadCache.Write(downloadBuffer, 0, bytesSize);

                    CachedSize += bytesSize;

                    receivedBufferCount++;

                    // Fire the DownloadProgressChanged event.
                    if (receivedBufferCount == this.BufferCountPerNotification)
                    {
                        InternalDownloadProgressChanged(CachedSize);
                        receivedBufferCount = 0;
                    }
                }


                // Update the used time when the current doanload is stopped.
                usedTime = usedTime.Add(DateTime.Now - lastStartTime);

                // Update the status of the client. Above loop will be stopped when the
                // status of the client is pausing, canceling or completed.
                if (this.Status == DownloadStatus.Pausing)
                {
                    this.Status = DownloadStatus.Paused;
                }
                else if (this.Status == DownloadStatus.Canceling)
                {
                    this.Status = DownloadStatus.Canceled;
                }
                else
                {
                    this.Status = DownloadStatus.Completed;
                    return;
                }
            }
            catch (Exception ex)
            {
                string strError = ex.ToString();
                ErrorCollection.GetInstance().SetErrorInfo(strError);

                // Fire the DownloadCompleted event with the error.
                this.OnDownloadCompleted(
                    new DownloadCompletedEventArgs(
                        null,
                        this.DownloadedSize,
                        this.TotalSize,
                        this.TotalUsedTime,
                        ex));
                return;
            }
            finally
            {
                // When the above code has ended, close the streams.
                if (responseStream != null)
                {
                    responseStream.Close();
                }
                if (webResponse != null)
                {
                    webResponse.Close();
                }
                if (downloadCache != null)
                {
                    downloadCache.Close();
                }
            }
        }
Example #4
0
        private void openFile_Click(object sender, RoutedEventArgs e)
        {
            //// Create OpenFileDialog
            //Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            //// Set filter for file extension and default file extension
            //dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";
            //Nullable<bool> result = dlg.ShowDialog();
            //// Get the selected file name and display in a TextBox
            //if (result == true)
            //{
            //    Image myImg = new Image();

            //    BitmapImage myBit = new BitmapImage();
            //    myBit.BeginInit();
            //    myBit.UriSource = new Uri(dlg.FileName, UriKind.Absolute);
            //    myBit.EndInit();
            //    /*********************************/
            //    char[] delimiterChars = { ':', '\\' };
            //    string[] words = dlg.FileName.Split(delimiterChars);
            //    int count = words.Length;
            //    JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            //    encoder.Frames.Add(BitmapFrame.Create(myBit));

            //    byte[] bit = new byte[0];

            //    using (MemoryStream stream = new MemoryStream())
            //    {
            //        encoder.Save(stream);
            //        bit = stream.ToArray();
            //        stream.Close();


            //        if (bit.Length >= 120000)
            //        {
            //            //MessageBoxCommon.Show("文件过大上传失败.请上传100KB以下的文件.", MessageBoxType.Ok);
            //            TempWindowForm tempWindowForm = new TempWindowForm();
            //            QQMessageBox.Show(tempWindowForm, "文件过大上传失败.请上传100KB以下的文件.", "提示", QQMessageBoxIcon.Error, QQMessageBoxButtons.OK);
            //        }
            //        else
            //        {
            //            VideoInfo videoInfo = new VideoInfo();
            //            videoInfo.Data = bit;
            //            videoInfo.UserId = words[count - 1].ToString();
            //            videoInfo.ImgData = bit;
            //            videoInfo.ImgName = words[count - 1].ToString();

            //            Login._ClientEngine.Send(NotifyType.Request_IconUpload, videoInfo);
            //        }

            //    }
            //    /*************************************/


            //}

            try
            {
                System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
                fileDialog.Multiselect = false;
                fileDialog.Filter      = "ALL Files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";
                fileDialog.Title       = "请选择图片文件.";

                if (System.Windows.Forms.DialogResult.OK == fileDialog.ShowDialog())
                {
                    foreach (string fileName in fileDialog.FileNames)
                    {
                        System.IO.FileInfo fileSize = new System.IO.FileInfo(fileName);
                        if (fileSize.Length > 1024 * 10 * 10 * 10 * 10 / 2)
                        {
                            continue;
                        }

                        string strUri = Login._ServerPath;
                        if (strUri[strUri.Length - 1] != '/')
                        {
                            strUri = strUri + "/";
                        }

                        strUri += "FaceUpload.php";

                        WebUploader.GetInstance().ctrlAlbum = this;
                        progressUpdate.Visibility = Visibility.Visible;
                        WebUploader.GetInstance().UploadFile(fileName, strUri, FileUploadComplete, this);

                        //if (UpdateFile(fileName))
                        //{
                        //    byte[] bit = new byte[0];

                        //    VideoInfo videoInfo = new VideoInfo();
                        //    videoInfo.Data = bit;
                        //    videoInfo.UserId = Login._UserInfo.Id;
                        //    videoInfo.ImgData = bit;
                        //    int nIndex = fileName.LastIndexOf("\\");
                        //    videoInfo.ImgName = fileName.Substring(nIndex + 1);
                        //    Login._ClientEngine.Send(NotifyType.Request_IconUpload, videoInfo);
                        //}

                        nTotalFileCount++;
                    }


                    if (nTotalFileCount == 0)
                    {
                        TempWindowForm tempWindowForm = new TempWindowForm();
                        QQMessageBox.Show(tempWindowForm, "文件大小必须小于 5MB.", "提示", QQMessageBoxIcon.Error, QQMessageBoxButtons.OK);
                    }
                }
            }
            catch (Exception ex)
            {
                string strError = ex.ToString();
                ErrorCollection.GetInstance().SetErrorInfo(strError);
            }
        }
Example #5
0
        void DownloadInternal(object obj)
        {
            if (this.Status != DownloadStatus.Waiting)
            {
                return;
            }

            try
            {
                this.EnsurePropertyValid();

                // Set the status.
                this.Status = DownloadStatus.Downloading;

                if (!this.HasChecked)
                {
                    this.CheckUrlAndFile();
                }



                // If the file does not support "Accept-Ranges" header, then create one
                // HttpDownloadClient to download the file in a single thread, else create
                // multiple HttpDownloadClients to download the file.
                if (!IsRangeSupported)
                {
                    HttpDownloadClient client = new HttpDownloadClient(
                        this.Url.AbsoluteUri,
                        0,
                        long.MaxValue,
                        this.BufferSize,
                        this.BufferCountPerNotification * this.BufferSize,
                        this.BufferCountPerNotification);

                    // Set the HasChecked flag, so the client will not check the URL again.
                    client.TotalSize    = this.TotalSize;
                    client.DownloadPath = this.DownloadPath;
                    client.HasChecked   = true;
                    client.Credentials  = this.Credentials;
                    client.Proxy        = this.Proxy;

                    this.downloadClients.Add(client);
                }
                else
                {
                    // Calculate the block size for each client to download.
                    int maxSizePerThread =
                        (int)Math.Ceiling((double)this.TotalSize / this.MaxThreadCount);

                    if (maxSizePerThread < this.MaxCacheSize)
                    {
                        maxSizePerThread = this.MaxCacheSize;
                    }

                    long leftSizeToDownload = this.TotalSize;

                    // The real threads count number is the min value of MaxThreadCount and
                    // TotalSize / MaxCacheSize.
                    int threadsCount =
                        (int)Math.Ceiling((double)this.TotalSize / maxSizePerThread);

                    for (int i = 0; i < threadsCount; i++)
                    {
                        long endPoint       = maxSizePerThread * (i + 1) - 1;
                        long sizeToDownload = maxSizePerThread;

                        if (endPoint > this.TotalSize)
                        {
                            endPoint       = this.TotalSize - 1;
                            sizeToDownload = endPoint - maxSizePerThread * i;
                        }

                        // Download a block of the whole file.
                        HttpDownloadClient client = new HttpDownloadClient(
                            this.Url.AbsoluteUri,
                            maxSizePerThread * i,
                            endPoint);

                        // Set the HasChecked flag, so the client will not check the URL again.
                        client.DownloadPath = this.DownloadPath;
                        client.HasChecked   = true;
                        client.TotalSize    = sizeToDownload;
                        client.Credentials  = this.Credentials;
                        client.Proxy        = this.Proxy;
                        this.downloadClients.Add(client);
                    }
                }

                // Set the lastStartTime to calculate the used time.
                lastStartTime = DateTime.Now;

                // Start all HttpDownloadClients.
                foreach (var client in this.downloadClients)
                {
                    if (this.Proxy != null)
                    {
                        client.Proxy = this.Proxy;
                    }

                    // Register the events of HttpDownloadClients.
                    client.DownloadProgressChanged += client_DownloadProgressChanged;
                    client.StatusChanged           += client_StatusChanged;
                    client.DownloadCompleted       += client_DownloadCompleted;


                    client.BeginDownload();
                }
            }
            catch (Exception ex)
            {
                this.Cancel();
                this.OnDownloadCompleted(new DownloadCompletedEventArgs(
                                             null,
                                             this.DownloadedSize,
                                             this.TotalSize,
                                             this.TotalUsedTime,
                                             ex));

                string strError = ex.ToString();
                ErrorCollection.GetInstance().SetErrorInfo(strError);
            }
        }
        public void markInfo(UserDetailInfo userDetail)
        {
            try
            {
                DisplayLabel(userDetail.EvalHistories);
                markPan.Children.Clear();

                Microsoft.Windows.Controls.DataGrid moneyGrid = new Microsoft.Windows.Controls.DataGrid();
                moneyGrid.Height              = 300;
                moneyGrid.HeadersVisibility   = Microsoft.Windows.Controls.DataGridHeadersVisibility.Column;
                moneyGrid.GridLinesVisibility = Microsoft.Windows.Controls.DataGridGridLinesVisibility.Horizontal;

                moneyGrid.IsReadOnly        = true;
                moneyGrid.Style             = (Style)FindResource("DataGridStyle");
                moneyGrid.CellStyle         = (Style)FindResource("cellStyle");
                moneyGrid.RowStyle          = (Style)FindResource("rowStyle");
                moneyGrid.ColumnHeaderStyle = (Style)FindResource("columnHeaderStyle");
                moneyGrid.Background        = new SolidColorBrush(Colors.Transparent);

                moneyGrid.SelectionMode = Microsoft.Windows.Controls.DataGridSelectionMode.Single;
                moneyGrid.SelectionUnit = Microsoft.Windows.Controls.DataGridSelectionUnit.FullRow;
                moneyGrid.LoadingRow   += dataGrid_LoadingRow;

                Microsoft.Windows.Controls.DataGridTextColumn col1 = new Microsoft.Windows.Controls.DataGridTextColumn();
                col1.Width = 130;
                Microsoft.Windows.Controls.DataGridTextColumn col2 = new Microsoft.Windows.Controls.DataGridTextColumn();
                col2.Width = 130;
                Microsoft.Windows.Controls.DataGridTextColumn col3 = new Microsoft.Windows.Controls.DataGridTextColumn();
                col3.Width = new Microsoft.Windows.Controls.DataGridLength(133, Microsoft.Windows.Controls.DataGridLengthUnitType.Star);

                moneyGrid.Columns.Add(col1);
                moneyGrid.Columns.Add(col2);
                moneyGrid.Columns.Add(col3);


                col1.Binding = new Binding("buyId");
                col2.Binding = new Binding("content");
                col3.Binding = new Binding("time");

                if (userDetail != null)
                {
                    for (int j = 0; j < userDetail.EvalHistories.Count; j++)
                    {
                        if (userDetail.EvalHistories[j].Value == 0)
                        {
                            contents = "不好";
                        }
                        else
                        {
                            contents = "好";
                        }

                        moneyGrid.Items.Add(new EvalData
                        {
                            buyId   = userDetail.EvalHistories[j].BuyerId,
                            content = contents,
                            time    = userDetail.EvalHistories[j].EvalTime.ToString("yy/MM/dd HH:mm"),
                            value   = userDetail.EvalHistories[j].Value
                        });
                    }
                }
                col1.Header = "会员账号";
                col2.Header = "评价";
                col3.Header = "日期";


                markPan.Children.Add(moneyGrid);
            }
            catch (Exception ex)
            {
                string strError = ex.ToString();
                ErrorCollection.GetInstance().SetErrorInfo(strError);
            }
        }