public ProgressBar(GraphicsDevice device, Rectangle bounds) : base(device, bounds) { InitEvents(); data = new ProgressData(0); BorderStyle = BorderStyle.FixedSingle; ForeColor = DefaultForeColor; }
public Slider(GraphicsDevice device, Rectangle bounds) : base(device, bounds) { InitEvents(); SliderBarDimentions = new Rectangle(bounds.X, bounds.Y, Bounds.Width / 10, Bounds.Height); data = new ProgressData(0); BorderStyle = BorderStyle.FixedSingle; ForeColor = Color.Gray; }
private void updateSlotIndividualParadigm(ProgressData.SlotWrapper[] slots) { if (this.SlotId >= slots.Length) { SlotObject.sprite = this.LockedSlotSprite; SlotContentsObject.sprite = this.EmptySlotSprite; return; } SlotObject.sprite = this.UnlockedSlotSprite; configureSprite(slots[this.SlotId].SlotType); }
/// <devdoc> /// <para>Sets up async delegates, we need to create these on every instance when async</para> /// </devdoc> private void InitWebClientAsync() { if (!m_InitWebClientAsync) { openReadOperationCompleted = new SendOrPostCallback(OpenReadOperationCompleted); openWriteOperationCompleted = new SendOrPostCallback(OpenWriteOperationCompleted); downloadStringOperationCompleted = new SendOrPostCallback(DownloadStringOperationCompleted); downloadDataOperationCompleted = new SendOrPostCallback(DownloadDataOperationCompleted); downloadFileOperationCompleted = new SendOrPostCallback(DownloadFileOperationCompleted); uploadStringOperationCompleted = new SendOrPostCallback(UploadStringOperationCompleted); uploadDataOperationCompleted = new SendOrPostCallback(UploadDataOperationCompleted); uploadFileOperationCompleted = new SendOrPostCallback(UploadFileOperationCompleted); uploadValuesOperationCompleted = new SendOrPostCallback(UploadValuesOperationCompleted); reportDownloadProgressChanged = new SendOrPostCallback(ReportDownloadProgressChanged); reportUploadProgressChanged = new SendOrPostCallback(ReportUploadProgressChanged); m_Progress = new ProgressData(); m_InitWebClientAsync = true; } }
public static List<MeshGroup> ParseFileContents(Stream amfStream, ReportProgressRatio reportProgress) { Stopwatch time = new Stopwatch(); time.Start(); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; double parsingFileRatio = .5; if (amfStream == null) { return null; } List<MeshGroup> meshGroups = null; // do the loading try { using (Stream amfCompressedStream = GetCompressedStreamIfRequired(amfStream)) { XmlReader xmlTree = XmlReader.Create(amfCompressedStream); while (xmlTree.Read()) { if (xmlTree.Name == "amf") { break; } } double scale = GetScaling(xmlTree); ProgressData progressData = new ProgressData(amfStream, reportProgress); meshGroups = new List<MeshGroup>(); while (xmlTree.Read()) { if (xmlTree.Name == "object") { using (XmlReader objectTree = xmlTree.ReadSubtree()) { meshGroups.Add(ReadObject(objectTree, scale, progressData)); if (progressData.LoadCanceled) { return null; } } } } xmlTree.Dispose(); } } catch (Exception e) { Debug.Print(e.Message); BreakInDebugger(); return null; } #if true // merge all the vetexes that are in the same place together int totalMeshes = 0; foreach (MeshGroup meshGroup in meshGroups) { foreach (Mesh mesh in meshGroup.Meshes) { totalMeshes++; } } double currentMeshProgress = 0; double ratioLeftToUse = 1 - parsingFileRatio; double progressPerMesh = 1.0 / totalMeshes * ratioLeftToUse; foreach (MeshGroup meshGroup in meshGroups) { foreach (Mesh mesh in meshGroup.Meshes) { bool keepProcessing = true; mesh.CleanAndMergMesh( (double progress0To1, string processingState, out bool continueProcessing) => { if (reportProgress != null) { double currentTotalProgress = parsingFileRatio + currentMeshProgress; reportProgress(currentTotalProgress + progress0To1 * progressPerMesh, processingState, out continueProcessing); keepProcessing = continueProcessing; } else { continueProcessing = true; } } ); if (!keepProcessing) { amfStream.Close(); return null; } currentMeshProgress += progressPerMesh; } } #endif time.Stop(); Debug.WriteLine(string.Format("AMF Load in {0:0.00}s", time.Elapsed.TotalSeconds)); amfStream.Close(); bool hasValidMesh = false; foreach (MeshGroup meshGroup in meshGroups) { foreach (Mesh mesh in meshGroup.Meshes) { if (mesh.Faces.Count > 0) { hasValidMesh = true; } } } if (hasValidMesh) { return meshGroups; } else { return null; } }
void BindMonitor (SvnClientArgs args, IProgressMonitor monitor) { notifyData = new NotifData (); progressData = new ProgressData (); updateMonitor = monitor; }
IntPtr TryStartOperation (IProgressMonitor monitor) { lock (sync) { if (inProgress) { LoggingService.LogError ("Old: {0}", oldStacktrace); LoggingService.LogError ("Current: {1}", Environment.StackTrace); throw new SubversionException ("Another Subversion operation is already in progress."); } oldStacktrace = Environment.StackTrace; inProgress = true; updatemonitor = monitor; progressData = new ProgressData (); return newpool (pool); } }
static void ProgressWork (SvnProgressEventArgs e, ProgressData data, IProgressMonitor monitor) { if (monitor == null) return; int currentProgress = (int)e.Progress; if (currentProgress == 0) return; int totalProgress = (int)e.TotalProgress; if (totalProgress != -1 && currentProgress >= totalProgress) { data.LogTimer.Close (); return; } data.Bytes = currentProgress; if (data.LogTimer.Enabled) return; data.LogTimer.Interval = 1000; data.LogTimer.Elapsed += delegate { data.Seconds += 1; monitor.Log.WriteLine ("{0} bytes in {1} seconds", data.Bytes, data.Seconds); }; data.LogTimer.Start (); }
static void ProgressWork (SvnProgressEventArgs e, ProgressData data, IProgressMonitor monitor) { if (monitor == null) return; long currentProgress = e.Progress; if (currentProgress <= data.KBytes) { if (data.SavedProgress < data.KBytes) { data.SavedProgress += data.KBytes; } return; } long totalProgress = e.TotalProgress; if (totalProgress != -1 && currentProgress >= totalProgress) { data.LogTimer.Dispose (); return; } data.Remainder += currentProgress % 1024; if (data.Remainder >= 1024) { data.SavedProgress += data.Remainder / 1024; data.Remainder = data.Remainder % 1024; } data.KBytes = data.SavedProgress + currentProgress / 1024; if (data.LogTimer.Enabled) return; data.LogTimer.Interval = 1000; data.LogTimer.Elapsed += delegate { data.Seconds += 1; monitor.Log.WriteLine ("Transferred {0} in {1} seconds.", BytesToSize (data.KBytes), data.Seconds); }; data.LogTimer.Start (); }
private void PostProgressChanged(AsyncOperation asyncOp, ProgressData progress) { if (asyncOp != null && progress.BytesSent + progress.BytesReceived > 0) { int progressPercentage; if (progress.HasUploadPhase) { if (progress.TotalBytesToReceive < 0 && progress.BytesReceived == 0) { progressPercentage = progress.TotalBytesToSend < 0 ? 0 : progress.TotalBytesToSend == 0 ? 50 : (int)((50 * progress.BytesSent) / progress.TotalBytesToSend); } else { progressPercentage = progress.TotalBytesToSend < 0 ? 50 : progress.TotalBytesToReceive == 0 ? 100 : (int) ((50 * progress.BytesReceived) / progress.TotalBytesToReceive + 50); } asyncOp.Post(reportUploadProgressChanged, new UploadProgressChangedEventArgs(progressPercentage, asyncOp.UserSuppliedState, progress.BytesSent, progress.TotalBytesToSend, progress.BytesReceived, progress.TotalBytesToReceive)); } else { progressPercentage = progress.TotalBytesToReceive < 0 ? 0 : progress.TotalBytesToReceive == 0 ? 100 : (int) ((100 * progress.BytesReceived) / progress.TotalBytesToReceive); asyncOp.Post(reportDownloadProgressChanged, new DownloadProgressChangedEventArgs(progressPercentage, asyncOp.UserSuppliedState, progress.BytesReceived, progress.TotalBytesToReceive)); } } }
private static Mesh ReadVolume(XmlReader xmlTree, List<Vector3> vertices, ProgressData progressData) { Mesh newMesh = new Mesh(); while (xmlTree.Read()) { if (xmlTree.Name == "triangle") { using (XmlReader triangleTree = xmlTree.ReadSubtree()) { while (triangleTree.Read()) { int[] indices = new int[3]; while (triangleTree.Read()) { switch (triangleTree.Name) { case "v1": string v1 = triangleTree.ReadString(); indices[0] = int.Parse(v1); break; case "v2": string v2 = triangleTree.ReadString(); indices[1] = int.Parse(v2); break; case "v3": string v3 = triangleTree.ReadString(); indices[2] = int.Parse(v3); break; case "map": using (XmlReader mapTree = triangleTree.ReadSubtree()) { } // a texture map, has u1...un and v1...vn break; default: break; } } if (indices[0] != indices[1] && indices[0] != indices[2] && indices[1] != indices[2] && vertices[indices[0]] != vertices[indices[1]] && vertices[indices[1]] != vertices[indices[2]] && vertices[indices[2]] != vertices[indices[0]]) { Vertex[] triangle = new Vertex[] { newMesh.CreateVertex(vertices[indices[0]], CreateOption.CreateNew, SortOption.WillSortLater), newMesh.CreateVertex(vertices[indices[1]], CreateOption.CreateNew, SortOption.WillSortLater), newMesh.CreateVertex(vertices[indices[2]], CreateOption.CreateNew, SortOption.WillSortLater), }; newMesh.CreateFace(triangle, CreateOption.CreateNew); } bool continueProcessing; progressData.ReportProgress0To50(out continueProcessing); if (!continueProcessing) { // this is what we should do but it requires a bit more debugging. return null; } } } } } return newMesh; }
public void UpdateSlots(ProgressData.SlotWrapper[] slots) { updateSlotParadigm(slots); }
private void postProgressChanged(AsyncOperation asyncOp, ProgressData progress) { if ((asyncOp != null) && progress.TotalBytesToSend > 0) { var _pct = (int)((progress.BytesSent * 100) / progress.TotalBytesToSend); asyncOp.Post(this.m_UploadProgressChanged, new UploadFileProgressEventArgs(_pct, asyncOp.UserSuppliedState, progress.BytesSent, progress.TotalBytesToSend)); } }
private void initUploadClientState() { if (!this.m_InitUploadClientAsync) { this.m_UploadOperationCompleted = new SendOrPostCallback(this.OnUploadCompleted); this.m_UploadProgressChanged = new SendOrPostCallback(this.OnUploadProgressChanged); this.m_ProgressData = new ProgressData(); this.m_InitUploadClientAsync = true; } }
public UploadResults PostImage(Image image, ImageFormat format) { MemoryStream imageDataStream = new MemoryStream(); image.Save(imageDataStream, format); // get the raw bytes byte[] imageDataBytes; imageDataBytes = imageDataStream.ToArray(); // construct the post string string base64img = System.Convert.ToBase64String(imageDataBytes); StringBuilder sb = new StringBuilder(); for (int i = 0; i < base64img.Length; i += MAX_URI_LENGTH) { sb.Append(Uri.EscapeDataString(base64img.Substring(i, Math.Min(MAX_URI_LENGTH, base64img.Length - i)))); } string uploadRequestString = "image=" + sb.ToString() + "&key=" + apiKey; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(POST_URL); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ServicePoint.Expect100Continue = false; Stream reqStream = webRequest.GetRequestStream(); byte[] reqBuffer = Encoding.UTF8.GetBytes(uploadRequestString); // send the bytes in chunks so we can check the progress int overflow = reqBuffer.Length % UPDATE_CHUNKS; ProgressData progress = new ProgressData(); progress.max_value = reqBuffer.Length; progress.value = 0; int size = UPDATE_CHUNKS; for (int i = 0; i < reqBuffer.Length; i += UPDATE_CHUNKS) { if (i + UPDATE_CHUNKS > reqBuffer.Length-1) size = overflow; reqStream.Write(reqBuffer, i, size); // update the progress progress.value = i + size; if (_uploadprogressUpdateProperty != null) _uploadprogressUpdateProperty(progress); } reqStream.Close(); WebResponse response = webRequest.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader responseReader = new StreamReader(responseStream); string responseString = responseReader.ReadToEnd(); UploadResults results = ParseResponse(responseString); if (_uploadCompleteProperty != null) _uploadCompleteProperty(results); return results; }
internal DownloadBitsState(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp, ProgressData progress, WebClient webClient) { WriteStream = writeStream; Request = request; AsyncOp = asyncOp; CompletionDelegate = completionDelegate; WebClient = webClient; Progress = progress; }
private static MeshGroup ReadObject(XmlReader xmlTree, double scale, ProgressData progressData) { MeshGroup meshGroup = new MeshGroup(); while (xmlTree.Read()) { if (xmlTree.Name == "mesh") { using (XmlReader meshTree = xmlTree.ReadSubtree()) { ReadMesh(meshTree, meshGroup, scale, progressData); if (progressData.LoadCanceled) { return null; } } } } return meshGroup; }
public void WriteFile(System.IO.Stream file, FileOrDirectory src) { FtpClient ftp = null; try { if (file == null) return; ftp = FtpConnections.Open(IsSource, ref url); var path = Url.Path() + "/" + src.Name; var start = DateTime.Now; if (!UseFXP) { if (ftp.FileTransferType != TransferType.Binary) ftp.FileTransferType = TransferType.Binary; if (TransferProgress) { progress[ftp] = new ProgressData { ElapsedTime = new TimeSpan(0), Path = path, Size = src.Size }; ftp.TransferProgress += ShowProgress; } ftp.PutFile(file, src.Name, FileAction.Create); } else { // use FXP for direct server to server transfer. var srcftp = (FtpStream)file; srcftp.Client.FxpCopy(src.Name, ftp); } ftp.SetDateTime(src.Name, src.ChangedUtc); Log.Upload(path, src.Size, DateTime.Now - start); } catch (Exception e) { Sync.Failure(src, e, ftp); } finally { if (ftp != null) { if (TransferProgress) { ftp.TransferProgress -= ShowProgress; progress.Remove(ftp); } FtpConnections.Pass(ftp); } } }
private static void ReadMesh(XmlReader xmlTree, MeshGroup meshGroup, double scale, ProgressData progressData) { List<Vector3> vertices = new List<Vector3>(); while (xmlTree.Read()) { switch (xmlTree.Name) { case "vertices": using (XmlReader verticesTree = xmlTree.ReadSubtree()) { ReadVertices(verticesTree, vertices, scale, progressData); if (progressData.LoadCanceled) { return; } } break; case "volume": string materialId = xmlTree["materialid"]; Mesh loadedMesh = null; using (XmlReader volumeTree = xmlTree.ReadSubtree()) { loadedMesh = ReadVolume(volumeTree, vertices, progressData); if (progressData.LoadCanceled) { return; } meshGroup.Meshes.Add(loadedMesh); } if (loadedMesh != null && materialId != null) { MeshMaterialData material = MeshMaterialData.Get(loadedMesh); material.MaterialIndex = int.Parse(materialId); } break; } } }
IntPtr TryStartOperation (IProgressMonitor monitor) { lock (sync) { if (inProgress) { var se = new SubversionException ("Another Subversion operation is already in progress."); se.Data.Add ("OldStacktrace", oldStacktrace); se.Data.Add ("CurrentStackTrace", Environment.StackTrace); throw se; } oldStacktrace = Environment.StackTrace; inProgress = true; updatemonitor = monitor; progressData = new ProgressData (); return newpool (pool); } }
private static void ReadVertices(XmlReader xmlTree, List<Vector3> vertices, double scale, ProgressData progressData) { while (xmlTree.Read()) { if (xmlTree.Name == "vertices") { using (XmlReader verticesTree = xmlTree.ReadSubtree()) { while (verticesTree.Read()) { if (xmlTree.Name == "vertex") { using (XmlReader vertexTree = verticesTree.ReadSubtree()) { while (vertexTree.Read()) { if (vertexTree.Name == "coordinates") { using (XmlReader coordinatesTree = vertexTree.ReadSubtree()) { Vector3 position = new Vector3(); while (coordinatesTree.Read()) { switch (coordinatesTree.Name) { case "x": string x = coordinatesTree.ReadString(); position.x = double.Parse(x); break; case "y": string y = coordinatesTree.ReadString(); position.y = double.Parse(y); break; case "z": string z = coordinatesTree.ReadString(); position.z = double.Parse(z); break; default: break; } } position *= scale; vertices.Add(position); } bool continueProcessing; progressData.ReportProgress0To50(out continueProcessing); } } } } } } } } }
internal UploadBitsState(WebRequest request, Stream readStream, byte [] buffer, byte [] header, byte [] footer, CompletionDelegate completionDelegate, AsyncOperation asyncOp, ProgressData progress, WebClient webClient) { InnerBuffer = buffer; Header = header; Footer = footer; ReadStream = readStream; Request = request; AsyncOp = asyncOp; CompletionDelegate = completionDelegate; if (AsyncOp != null) { Progress = progress; Progress.HasUploadPhase = true; Progress.TotalBytesToSend = request.ContentLength < 0 ? -1 : request.ContentLength; } WebClient = webClient; }
/// <summary> /// �i���l�̐ݒ� /// </summary> private void SetProgress() { ProgressData data = GetProgressValue(); int progress = data.progress; transactionTime += updateTimer.Interval; if (0 < progress) { double remaining = (data.maxProgress - progress) / (double) progress; TimeSpan restTransactionTime = TimeSpan.FromMilliseconds(transactionTime * remaining); string restTransValue = GetTimeSpanToFormat(restTransactionTime); this.Text = string.Format(Properties.Resources.RestTimeTitle, restTransValue); restTimeLabel.Text = restTransValue; } if (preProgressData.Equals(data) == false) { progressBar.Value = (progress * 100) / data.maxProgress; targetFolderLabel.Text = string.Format(Properties.Resources.FolderInfoMessage, data.maxProgress); targetLabel.Text = data.targetFolderName; currentLabel.Text = data.currentFileName; if (progress == data.maxProgress) { this.Close(); } preProgressData = data; } }
private void updateSlotLevelParadigm(ProgressData.SlotWrapper[] slots) { ProgressData.SmartSlot smartSlot = ProgressData.GetSmartSlot(slots, this.SlotId); updateSlotHelper(smartSlot.SlotType, smartSlot.Ammo, smartSlot.Level); }
void BindMonitor (IProgressMonitor monitor) { notifyData = new NotifData (); progressData = new ProgressData (); updateMonitor = monitor; }
private void SetProgress(ProgressData data) { try { if(!InvokeRequired) { progress.Value = (int) data.Percentage; if(spi.Checked && _xsvfFlasher == null) statuslbl.Text = string.Format("Processed block 0x{0:X} of 0x{1:X}", data.Current, data.Maximum); else { statuslbl.Text = string.Format("Processed {0} of {1} ({2}/s)", GetSizeReadable(data.Current), GetSizeReadable(data.Maximum), GetSizeReadable((long) (data.Current / _sw.Elapsed.TotalSeconds))); } } else Invoke(new MethodInvoker(() => SetProgress(data))); } catch { } }
void BindMonitor (SvnClientArgs args, IProgressMonitor monitor) { NotifData data = new NotifData (); progressData = new ProgressData (); args.Notify += delegate (object o, SvnNotifyEventArgs e) { Notify (e, data, monitor); }; args.SvnError += delegate (object o, SvnErrorEventArgs a) { monitor.ReportError (a.Exception.Message, a.Exception.RootCause); }; updateMonitor = monitor; }
IntPtr TryStartOperation (IProgressMonitor monitor) { lock (sync) { if (inProgress) throw new SubversionException ("Another Subversion operation is already in progress."); inProgress = true; updatemonitor = monitor; progressData = new ProgressData (); return newpool (pool); } }
IntPtr TryStartOperation (ProgressMonitor monitor) { Monitor.Enter (svn); updatemonitor = monitor; progressData = new ProgressData (); return newpool (pool); }
private void InitWebClientAsync() { if (!this.m_InitWebClientAsync) { this.openReadOperationCompleted = new SendOrPostCallback(this.OpenReadOperationCompleted); this.openWriteOperationCompleted = new SendOrPostCallback(this.OpenWriteOperationCompleted); this.downloadStringOperationCompleted = new SendOrPostCallback(this.DownloadStringOperationCompleted); this.downloadDataOperationCompleted = new SendOrPostCallback(this.DownloadDataOperationCompleted); this.downloadFileOperationCompleted = new SendOrPostCallback(this.DownloadFileOperationCompleted); this.uploadStringOperationCompleted = new SendOrPostCallback(this.UploadStringOperationCompleted); this.uploadDataOperationCompleted = new SendOrPostCallback(this.UploadDataOperationCompleted); this.uploadFileOperationCompleted = new SendOrPostCallback(this.UploadFileOperationCompleted); this.uploadValuesOperationCompleted = new SendOrPostCallback(this.UploadValuesOperationCompleted); this.reportDownloadProgressChanged = new SendOrPostCallback(this.ReportDownloadProgressChanged); this.reportUploadProgressChanged = new SendOrPostCallback(this.ReportUploadProgressChanged); this.m_Progress = new ProgressData(); this.m_InitWebClientAsync = true; } }