internal WorkspaceRole(IMetaPopulation metaPopulation, SyncResponseRole syncResponseRole) { var value = syncResponseRole.v; this.RoleType = (IRoleType)metaPopulation.Find(Guid.Parse(syncResponseRole.t)); var objectType = this.RoleType.ObjectType; if (objectType.IsUnit) { this.Value = UnitConvert.Parse(this.RoleType.ObjectType.Id, value); } else { if (this.RoleType.IsOne) { this.Value = value != null?long.Parse(value) : (long?)null; } else { this.Value = value != null ? value.Split(Encoding.Separator).Select(long.Parse).ToArray() : Array.Empty <long>(); } } }
public void UnitGet() { this.Workspace.Sync(Fixture.LoadData); var session = new Session(this.Workspace); var koen = session.Get(1) as Person; Assert.Equal("Koen", koen.FirstName); Assert.Null(koen.MiddleName); Assert.Equal("Van Exem", koen.LastName); Assert.Equal(UnitConvert.Parse(M.Person.BirthDate.ObjectType.Id, "1973-03-27T18:00:00Z"), koen.BirthDate); Assert.True(koen.IsStudent); var patrick = session.Get(2) as Person; Assert.Equal("Patrick", patrick.FirstName); Assert.Equal("De Boeck", patrick.LastName); Assert.Null(patrick.MiddleName); Assert.Null(patrick.BirthDate); Assert.False(patrick.IsStudent); var martien = session.Get(3) as Person; Assert.Equal("Martien", martien.FirstName); Assert.Equal("Knippenberg", martien.LastName); Assert.Equal("van", martien.MiddleName); Assert.Null(martien.BirthDate); Assert.Null(martien.IsStudent); }
public Question(Rectangle position, string UID) : base(position, TextureResources.Get("QuestionBackground"), UID, defaultZPosition) { isConstructed = false; margin = UnitConvert.ToAbsoluteWidth(30); contentRect = new Rectangle(position.X + margin, position.Y + margin, position.Width - margin * 2, position.Height - margin * 2); }
private void DisplayTorrents(List <Torrent> TorrentsAll) { long downloadSpeed = 0; int downs = 0; long uploadSpeed = 0; long seeding = 0; double avgProgress = 0.0; int unfinished = 0; int ActiveTorrents = 0; foreach (Torrent torrent in TorrentsAll) { if (torrent.Started()) { if (torrent.DownloadSpeed > 0 || torrent.UploadSpeed > 0) { ActiveTorrents++; } downloadSpeed += torrent.DownloadSpeed; uploadSpeed += torrent.UploadSpeed; if (torrent.Progress >= 100) { //only seeding seeding = seeding + 1; } else { downs++; } } if (torrent.Progress < 100.0) { avgProgress += torrent.Progress; unfinished += 1; } } UpdateScreen(); GUIPropertyManager.SetProperty("#MyTorrents.IsConnected", TorrentEngine.Instance().IsConnected.ToString()); GUIPropertyManager.SetProperty("#MyTorrents.CombinedDownloadSpeed", UnitConvert.TransferSpeedToString(downloadSpeed)); GUIPropertyManager.SetProperty("#MyTorrents.CombinedUploadSpeed", UnitConvert.TransferSpeedToString(uploadSpeed)); GUIPropertyManager.SetProperty("#MyTorrents.Downloads.Count", string.Format("{0}", downs)); GUIPropertyManager.SetProperty("#MyTorrents.Uploads.Count", string.Format("{0}", seeding)); GUIPropertyManager.SetProperty("#MyTorrents.Active.Count", string.Format("{0}", ActiveTorrents)); //GUIPropertyManager.SetProperty("#MyTorrents.Ready.Count", string.Format("{0}", TorrentsAll.Count - TorrentsActive.Count)); //GUIPropertyManager.SetProperty("#MyTorrents.Unfinished.Count", string.Format("{0}", unfinished)); //GUIPropertyManager.SetProperty("#MyTorrents.AverageProgressOfUnfinished", string.Format("{0:F2}", avgProgress / unfinished)); if (Notifier.Instance() != null && Notifier.Instance().IsNotificationBarAvailable() && (_config.Notify)) { Notifier.Instance().ChangeText(); } }
protected void SetupImpressum() { string text = "Impressum: Developed by Lorenz Gonsa, FHS MMT for MultiMediaProject 1. The great background illustration is designed by vectorpouch / Freepik "; SpriteFont font = FontResources.oldenburg_8; Vector2 textSize = font.MeasureString(text); int margin = UnitConvert.ToAbsoluteWidth(5); Rectangle impressRect = new Rectangle(windowWidth - (int)textSize.X - margin, windowHeight - (int)textSize.Y - margin, (int)textSize.X + margin, (int)textSize.Y + margin); TextBoardElement impressum = new TextBoardElement(impressRect, text, font, "impressum", ColorResources.Black, 21, TextBoardElement.Alignment.LeftTop); CommandQueue.Queue(new AddToBoardCommand(impressum)); }
protected void SetupPlayButton() { Texture2D btnTex = TextureResources.Get("Play"); float aspectR = btnTex.Width / (float)btnTex.Height; int btnWidth = UnitConvert.ToAbsoluteWidth(300); int btnHeight = (int)(btnWidth / aspectR); int btnX = (windowWidth - btnWidth) / 2; int btnY = (windowHeight - btnHeight) * 7 / 8; PlayButtonBoardElement playBtn = new PlayButtonBoardElement(new Rectangle(btnX, btnY, btnWidth, btnHeight), btnTex, "btn_play", 22, "welcomebackground", "welcometitle", "impressum"); CommandQueue.Queue(new AddToBoardCommand(playBtn)); }
public void Test_02_GetGesamtCalorie() { string gesCal; // Umrechnung, z.B. 500 g mit 30 kcal/100g => 150 kcal gesCal = UnitConvert.GetGesamtCalorie("", "g", "30"); Assert.AreEqual(gesCal, ""); gesCal = UnitConvert.GetGesamtCalorie("500", "", "30"); Assert.AreEqual(gesCal, ""); gesCal = UnitConvert.GetGesamtCalorie("", "", "30"); Assert.AreEqual(gesCal, ""); // 500 g Packung mit 30 kcal/100 g gesCal = UnitConvert.GetGesamtCalorie("500", "g", "30"); Assert.AreEqual(gesCal, "150"); gesCal = UnitConvert.GetGesamtCalorie("100", "g", "27"); Assert.AreEqual(gesCal, "27"); gesCal = UnitConvert.GetGesamtCalorie("200", "g", "27"); Assert.AreEqual(gesCal, "54"); gesCal = UnitConvert.GetGesamtCalorie("0.1", "kg", "30"); Assert.AreEqual(gesCal, "30"); gesCal = UnitConvert.GetGesamtCalorie("0.2", "kg", "30"); Assert.AreEqual(gesCal, "60"); gesCal = UnitConvert.GetGesamtCalorie("0.5", "kg", "30"); Assert.AreEqual(gesCal, "150"); // 1 Liter mit 50 kcal/100 ml gesCal = UnitConvert.GetGesamtCalorie("0.5", "l", "120"); Assert.AreEqual(gesCal, "600"); gesCal = UnitConvert.GetGesamtCalorie("0.1", "l", "120"); Assert.AreEqual(gesCal, "120"); gesCal = UnitConvert.GetGesamtCalorie("1", "l", "120"); Assert.AreEqual(gesCal, "1200"); gesCal = UnitConvert.GetGesamtCalorie("500", "ml", "120"); Assert.AreEqual(gesCal, "600"); gesCal = UnitConvert.GetGesamtCalorie("", "ml", "120"); Assert.AreEqual(gesCal, ""); gesCal = UnitConvert.GetGesamtCalorie("500", "ml", ""); Assert.AreEqual(gesCal, ""); }
/// <summary> /// 获取单位数量 /// </summary> /// <param name="ctx"></param> /// <param name="msterID">物料ID</param> /// <param name="sourceUintId">基本单位ID</param> /// <param name="destUnitId">转换的单位Id</param> /// <param name="sourceQty">基本单位数量</param> /// <returns></returns> private decimal GetConvertedQty(Context ctx, long msterID, long sourceUintId, long destUnitId, decimal sourceQty) { UnitConvert convert = Kingdee.BOS.App.ServiceHelper.GetService <IUnitConvertService>().GetUnitConvertRate(ctx, new GetUnitConvertRateArgs() { MasterId = msterID, SourceUnitId = sourceUintId, DestUnitId = destUnitId }); return(convert.ConvertQty(sourceQty)); }
public JsonResult Delete(UnitConvert unitConvert) { int result = unitConvertService.Delete(unitConvert.Id); if (result != 0) { return(Json(new { messageType = "success", note = AppGlobal.DeleteSuccessMessage })); } else { return(Json(new { messageType = "eror", note = AppGlobal.DeleteFailMessage })); } }
public JsonResult Update(UnitConvert unitConvert) { unitConvert.Initialization(ObjectInitType.Update, "", HttpContext); int result = unitConvertService.Update(unitConvert.Id, unitConvert); if (result != 0) { return(Json(new { messageType = "success", note = AppGlobal.UpdateSuccessMessage })); } else { return(Json(new { messageType = "eror", note = AppGlobal.UpdateFailMessage })); } }
// convert dữ liệu trên datagrid về dơn vị trong revit private void Convertdata() { foreach (var item in DataAxisX) { var space = item.space; string bmn; var t = UnitConvert.StringToFeetAndInches(space, out bmn); item.space = t.ToString(); } foreach (var item in DataAxisY) { var space = item.space; string bmn; var t = UnitConvert.StringToFeetAndInches(space, out bmn); item.space = t.ToString(); } }
protected void SetupNamePlates() { int margin = UnitConvert.ToAbsoluteWidth(20); Rectangle namePlateRectFoes = new Rectangle(boardRect.Right + margin, boardRect.Top + margin, ((windowWidth - boardRect.Width) / 2) - margin - margin, windowHeight / 2); NamePlateFoes namePlateFoes = new NamePlateFoes(namePlateRectFoes, FontResources.oldenburg_20, FontResources.oldenburg_30, "namePlateFoes", 1); Rectangle namePlateRectLocal = new Rectangle(margin, boardRect.Top + margin, ((windowWidth - boardRect.Width) / 2) - margin - margin, windowHeight / 4); NamePlateLocal namePlateLocal = new NamePlateLocal(namePlateRectLocal, FontResources.oldenburg_20, FontResources.oldenburg_30, "namePlateLocal", 1); PlayerManager.Instance().AddObserver(namePlateFoes); PlayerManager.Instance().AddObserver(namePlateLocal); MeepleColorClaimer.Instance().AddObserver(namePlateFoes); MeepleColorClaimer.Instance().AddObserver(namePlateLocal); CommandQueue.Queue(new AddToBoardCommand(namePlateFoes, namePlateLocal)); }
private QuestionManager() { int margin = UnitConvert.ToAbsoluteWidth(20); Point size = new Point(Game1.windowHeight + margin * 2, Game1.windowHeight - margin); Point pos = new Point((Game1.windowWidth - size.X) / 2, margin / 2); questionRect = new Rectangle(pos, size); questions = new List <Question>(); ParseQuestions(); random = new Random(); questionElems = new List <QuestionBoardElement>(); floorElems = new List <PyramidFloorBoardElement>(); movingQBEOffset = new Point(1, 1); }
private void UpdateTorrentList(bool timed) { if (torrentList == null) { return; } List <GUIListItem> CurItems = new List <GUIListItem>(torrentList.ListItems); foreach (Torrent torrent in TorrentEngine.Instance().TorrentSession.TorrentsAll) { if (torrent.Progress < 100.0) { GUIListItem item = FindItemByHash(torrentList, torrent); if (item == null) { item = new GUIListItem(string.Format("{0}", Ellipsis(torrent.Name, 75))); item.AlbumInfoTag = torrent; torrentList.Add(item); } else { CurItems.Remove(item); } item.Label2 = string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(torrent.Size), torrent.Progress); //item.Label3 = ((T.fETA == "-1s") || (T.fETA == "0s")) ? "" : T.fETA.ToLower(); } } foreach (var i in CurItems) { torrentList.ListItems.Remove(i); } if (torrentList.ListItems.Count == 0) { GUIPropertyManager.SetProperty("#MyTorrents.Count", "0"); GUIListItem item = new GUIListItem(); item.Label = "No torrents."; torrentList.Add(item); } else { GUIPropertyManager.SetProperty("#MyTorrents.Count", String.Format("{0}", torrentList.ListItems.Count)); } }
private void UpdateSearchResults() { try { SearchResults.Clear(); } catch (Exception ex) { } IconMapping iconMapping = Configuration.Instance().Settings["MyTorrents.GlobalIconMapping"] as IconMapping; Regex re = null; if (_filter != "") { re = new Regex(_filter, RegexOptions.IgnoreCase); } foreach (TorrentMatch match in _matches) { if (re != null) { if (!re.IsMatch(match.Title)) { continue; } } GUIListItem item = new GUIListItem(); //item.PinImage = iconMapping.GetIcon(match.Title); item.PinImage = match.Icon; item.Label = String.Format("{0}- {1} - {2} ({3}:{4})", match.Category, match.SubCategory, match.Title, match.Seed, match.Leech); item.Label2 = match.Date.ToShortDateString(); item.Label3 = UnitConvert.SizeToString(match.Size); item.OnItemSelected += OnSearchResultSelected; item.AlbumInfoTag = match; SearchResults.Add(item); } GUIDialogProgress dlg = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS); dlg.Close(); _progressDlg = null; GUIPropertyManager.SetProperty("#MyTorrents.Count", String.Format("{0}", SearchResults.Count)); }
public void ShowTorrents() { if (torrentList == null) { return; } List <GUIListItem> tl = new List <GUIListItem>(); var TA = TorrentEngine.Instance().GetTorrents(TorrentView, SortOrder, LabelFilter); foreach (Torrent torrent in TA) { GUIListItem item = new GUIListItem(string.Format("{0}", Ellipsis(torrent.Name, 75))); //GUIImage image = new GUIImage(5678); //item.Icon = image; //item.IconImage = System.IO.Path.Combine(GUIGraphicsContext.Skin, @"\Media\icon_empty_focus1.png"); item.AlbumInfoTag = torrent; tl.Add(item); if (item.Label2 != string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(torrent.Size), torrent.Progress)) { item.Label2 = string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(torrent.Size), torrent.Progress); } } torrentList.ListItems = tl; if (torrentList.ListItems.Count == 0) { GUIPropertyManager.SetProperty("#MyTorrents.Count", "0"); GUIListItem item = new GUIListItem(); item.Label = "No items."; torrentList.Add(item); } else { GUIPropertyManager.SetProperty("#MyTorrents.Count", String.Format("{0}", torrentList.ListItems.Count)); } }
public List <GUIListItem> GetTorrentDetails(Torrent utorrent) { List <GUIListItem> fileList = new List <GUIListItem>(); SelectedHash = utorrent.Hash; if (utorrent == null) { //torrent got removed! } List <File> files = TorrentEngine.Instance().TorrentSession.GetFiles(utorrent.Hash); foreach (var file in files) { GUIListItem item = new GUIListItem(); item.Label = file.Filename; item.IconImage = System.IO.Path.Combine(GUIGraphicsContext.Skin, @"\Media\icon_empty_focus1.png"); item.AlbumInfoTag = file; fileList.Add(item); item.Label2 = string.Format("{0} ({1:F2}%)", UnitConvert.SizeToString(file.Filesize), (double)file.Downloaded / file.Filesize * 100.0); } GUIPropertyManager.SetProperty("#MyTorrents.Details.Name", utorrent.Name); GUIPropertyManager.SetProperty("#MyTorrents.Details.Progress", string.Format("{0:F2}", utorrent.Progress)); GUIPropertyManager.SetProperty("#MyTorrents.Details.Ratio", string.Format("{0:F2}", (float)utorrent.Ratio * 0.001)); GUIPropertyManager.SetProperty("#MyTorrents.Details.ETA", UnitConvert.TimeRemainingToString(utorrent.ETA)); GUIPropertyManager.SetProperty("#MyTorrents.Details.UploadSpeed", UnitConvert.TransferSpeedToString(utorrent.UploadSpeed)); GUIPropertyManager.SetProperty("#MyTorrents.Details.DownloadSpeed", UnitConvert.TransferSpeedToString(utorrent.DownloadSpeed)); GUIPropertyManager.SetProperty("#MyTorrents.Details.Peers", string.Format("{0} ({1})", utorrent.PeersConnected, utorrent.PeersInSwarm)); GUIPropertyManager.SetProperty("#MyTorrents.Details.Seeds", string.Format("{0} ({1})", utorrent.SeedsConnected, utorrent.SeedsInSwarm)); GUIPropertyManager.SetProperty("#MyTorrents.Details.Size", UnitConvert.SizeToString(utorrent.Size)); return(fileList); }
// Update is called once per frame void Update() { text.text = UnitConvert.LongConvert(value); }
private int PushRequestRoles(IList<PushRequestRole> pushRequestRoles, IObject obj, PushResponse pushResponse, Dictionary<string, IObject> objectByNewId, bool ignore = false) { var countOutstandingRoles = 0; foreach (var pushRequestRole in pushRequestRoles) { var composite = (Composite)obj.Strategy.Class; var roleTypes = composite.WorkspaceRoleTypes; var acl = this.acls[obj]; var roleType = (IRoleType)this.metaPopulation.Find(Guid.Parse(pushRequestRole.T)); if (roleType != null) { if (acl.CanWrite(roleType)) { if (roleType.ObjectType.IsUnit) { var unitType = (IUnit)roleType.ObjectType; var role = UnitConvert.Parse(unitType.Id, pushRequestRole.S); obj.Strategy.SetUnitRole(roleType.RelationType, role); } else { if (roleType.IsOne) { var roleId = (string)pushRequestRole.S; if (string.IsNullOrEmpty(roleId)) { obj.Strategy.RemoveCompositeRole(roleType.RelationType); } else { var role = this.GetRole(roleId, objectByNewId); if (role == null) { pushResponse.AddMissingError(roleId); } else { obj.Strategy.SetCompositeRole(roleType.RelationType, role); } } } else { // Add if (pushRequestRole.A != null) { var roleIds = pushRequestRole.A; if (roleIds.Length != 0) { var roles = this.GetRoles(roleIds, objectByNewId); if (roles.Length != roleIds.Length) { AddMissingRoles(roles, roleIds, pushResponse); } else { foreach (var role in roles) { obj.Strategy.AddCompositeRole(roleType.RelationType, role); } } } } // Remove if (pushRequestRole.R != null) { var roleIds = pushRequestRole.R; if (roleIds.Length != 0) { var roles = this.GetRoles(roleIds, objectByNewId); if (roles.Length != roleIds.Length) { AddMissingRoles(roles, roleIds, pushResponse); } else { foreach (var role in roles) { obj.Strategy.RemoveCompositeRole(roleType.RelationType, role); } } } } } } } else { if (!ignore) { pushResponse.AddAccessError(obj); } else { countOutstandingRoles++; } } } } return countOutstandingRoles; }
public void Test_01_GetCaloriePerUnit() { string calPerUnit; // Umechnung, z.B. 500 g Packung hat 500 kcal => 100 kcal/100 g calPerUnit = UnitConvert.GetCaloriePerUnit("500", "g", "500"); Assert.AreEqual(calPerUnit, "100"); calPerUnit = UnitConvert.GetCaloriePerUnit("", "g", "500"); Assert.AreEqual(calPerUnit, "---"); calPerUnit = UnitConvert.GetCaloriePerUnit("500", "", "500"); Assert.AreEqual(calPerUnit, "---"); calPerUnit = UnitConvert.GetCaloriePerUnit("", "", "500"); Assert.AreEqual(calPerUnit, "---"); // Umechnung, z.B. 500 g Packung hat 500 kcal => 100 kcal/100 g calPerUnit = UnitConvert.GetCaloriePerUnit("500", "g", "500"); Assert.AreEqual(calPerUnit, "100"); calPerUnit = UnitConvert.GetCaloriePerUnit("500", "g", "250"); Assert.AreEqual(calPerUnit, "50"); calPerUnit = UnitConvert.GetCaloriePerUnit("200", "g", "100"); Assert.AreEqual(calPerUnit, "50"); calPerUnit = UnitConvert.GetCaloriePerUnit("0.1", "kg", "30"); Assert.AreEqual(calPerUnit, "30"); calPerUnit = UnitConvert.GetCaloriePerUnit("0.2", "kg", "30"); Assert.AreEqual(calPerUnit, "15"); calPerUnit = UnitConvert.GetCaloriePerUnit("0.5", "kg", "300"); Assert.AreEqual(calPerUnit, "60"); calPerUnit = UnitConvert.GetCaloriePerUnit("0.1", "l", "120"); Assert.AreEqual(calPerUnit, "120"); // 1 Liter mit 50 kcal/100 ml calPerUnit = UnitConvert.GetCaloriePerUnit("0.5", "l", "120"); Assert.AreEqual(calPerUnit, "24"); calPerUnit = UnitConvert.GetCaloriePerUnit("1", "l", "120"); Assert.AreEqual(calPerUnit, "12"); calPerUnit = UnitConvert.GetCaloriePerUnit("500", "ml", "120"); Assert.AreEqual(calPerUnit, "24"); calPerUnit = UnitConvert.GetCaloriePerUnit("500", "ml", "0"); Assert.AreEqual(calPerUnit, "0"); // Einheit in Großbuchstaben // Umechnung, z.B. 500 g Packung hat 500 kcal => 100 kcal/100 g calPerUnit = UnitConvert.GetCaloriePerUnit("500", "G", "500"); Assert.AreEqual(calPerUnit, "100"); calPerUnit = UnitConvert.GetCaloriePerUnit("500", "G", "250"); Assert.AreEqual(calPerUnit, "50"); calPerUnit = UnitConvert.GetCaloriePerUnit("200", "G", "100"); Assert.AreEqual(calPerUnit, "50"); calPerUnit = UnitConvert.GetCaloriePerUnit("0.1", "Kg", "30"); Assert.AreEqual(calPerUnit, "30"); calPerUnit = UnitConvert.GetCaloriePerUnit("0.2", "KG", "30"); Assert.AreEqual(calPerUnit, "15"); calPerUnit = UnitConvert.GetCaloriePerUnit("0.5", "kG", "300"); Assert.AreEqual(calPerUnit, "60"); calPerUnit = UnitConvert.GetCaloriePerUnit("0.1", "L", "120"); Assert.AreEqual(calPerUnit, "120"); // 1 Liter mit 50 kcal/100 ml calPerUnit = UnitConvert.GetCaloriePerUnit("0.5", "L", "120"); Assert.AreEqual(calPerUnit, "24"); calPerUnit = UnitConvert.GetCaloriePerUnit("1", "L", "120"); Assert.AreEqual(calPerUnit, "12"); calPerUnit = UnitConvert.GetCaloriePerUnit("500", "Ml", "120"); Assert.AreEqual(calPerUnit, "24"); calPerUnit = UnitConvert.GetCaloriePerUnit("500", "ML", "0"); Assert.AreEqual(calPerUnit, "0"); }
public IEnumerator Get(string url) { string[] txts = url.Split('?'); downloadFileName = txts[0].Substring(url.LastIndexOf('/') + 1); downloadFilePath = downloadSaveDir + "/" + downloadFileName; string tempFilePath = downloadFilePath + ".tmp"; curlength = FileUtil.GetFileLength(tempFilePath); isError = false; using (UnityWebRequest headRequest = UnityWebRequest.Head(url)) { yield return(headRequest.SendWebRequest()); if (headRequest.isHttpError || headRequest.isNetworkError) { Debug.LogError("下载文件:" + downloadFileName + " " + headRequest.error); onDownloadError?.Invoke(); isError = true; yield break; } string contentLength = headRequest.GetResponseHeader("Content-Length"); if (!string.IsNullOrEmpty(contentLength)) { totalLength = long.Parse(contentLength); } else { Debug.LogError("无法获取资源大小"); onDownloadError?.Invoke(); isError = true; yield break; } } Debug.Log("开始下载:" + downloadFileName + " 大小:" + UnitConvert.ByteConvert(totalLength) + " 已下载:" + UnitConvert.ByteConvert(curlength)); using (UnityWebRequest request = UnityWebRequest.Get(url)) { request.SetRequestHeader("Range", "bytes=" + curlength + "-"); request.SendWebRequest(); using (FileStream fileStream = new FileStream(tempFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fileStream.Seek(curlength, SeekOrigin.Begin); int index = 0; while (!request.isDone) { yield return(null); byte[] data = request.downloadHandler.data; int writeLength = data.Length - index; fileStream.Write(data, index, writeLength); index = data.Length; curlength += writeLength; downloadProgress = curlength * 1.0f / totalLength; time += Time.deltaTime; unitTotalLength += writeLength; if (time > 1f) { downloadSpeed = unitTotalLength / 1024; time = 0; unitTotalLength = 0; } } if (request.isHttpError || request.isNetworkError) { Debug.LogError(request.error); onDownloadError?.Invoke(); isError = true; yield break; } } if (File.Exists(downloadFilePath)) { File.Delete(downloadFilePath); } File.Move(tempFilePath, downloadFilePath); Debug.Log("下载成功:" + downloadFileName); isCompleted = true; onDownloadCompleted?.Invoke(); } }
public SyncResponse Build() { var objects = this.session.Instantiate(this.syncRequest.Objects); // Prefetch var objectByClass = objects.GroupBy(v => v.Strategy.Class, v => v); foreach (var groupBy in objectByClass) { var prefetchClass = (Class)groupBy.Key; var prefetchObjects = groupBy.ToArray(); var prefetchPolicyBuilder = new PrefetchPolicyBuilder(); prefetchPolicyBuilder.WithWorkspaceRules(prefetchClass); prefetchPolicyBuilder.WithSecurityRules(prefetchClass); var prefetcher = prefetchPolicyBuilder.Build(); this.session.Prefetch(prefetcher, prefetchObjects); } SyncResponseRole CreateSyncResponseRole(IObject @object, IRoleType roleType) { var syncResponseRole = new SyncResponseRole { T = roleType.IdAsString }; if (roleType.ObjectType.IsUnit) { syncResponseRole.V = UnitConvert.ToString(@object.Strategy.GetUnitRole(roleType.RelationType)); } else if (roleType.IsOne) { syncResponseRole.V = @object.Strategy.GetCompositeRole(roleType.RelationType)?.Id.ToString(); } else { var roles = @object.Strategy.GetCompositeRoles(roleType.RelationType); if (roles.Count > 0) { syncResponseRole.V = string.Join( separator: Encoding.Separator, values: roles .Cast <IObject>() .Select(roleObject => roleObject.Id.ToString())); } } return(syncResponseRole); } var syncResponse = new SyncResponse { Objects = objects.Select(v => { var @class = (Class)v.Strategy.Class; var acl = this.acls[v]; return(new SyncResponseObject { I = v.Id.ToString(), V = v.Strategy.ObjectVersion.ToString(), T = v.Strategy.Class.IdAsString, R = @class.WorkspaceRoleTypes .Where(w => acl.CanRead(w) && v.Strategy.ExistRole(w.RelationType)) .Select(w => CreateSyncResponseRole(v, w)) .ToArray(), A = this.accessControlsWriter.Write(v), D = this.permissionsWriter.Write(v), }); }).ToArray(), }; syncResponse.AccessControls = this.acls.EffectivePermissionIdsByAccessControl.Keys .Select(v => new[] { v.Strategy.ObjectId.ToString(), v.Strategy.ObjectVersion.ToString(), }) .ToArray(); return(syncResponse); }
public void CmToPrintTest() { Assert.AreEqual(UnitConvert.CmToPrint(2.54f), 100f); Assert.AreEqual(UnitConvert.CmToPrint_int(2.54f), 100); }
public void PxToCmTest() { Assert.AreEqual(UnitConvert.PxToCm(72f, 72f), 2.54f); }
public void CmToPxTest() { Assert.AreEqual(UnitConvert.CmToPx(2.54f, 72f), 72f); Assert.AreEqual(UnitConvert.CmToPx_int(2.54f, 72f), 72); }
public void SetValue(Document doc, Autodesk.Revit.DB.Line targetx, FamilyInstance familyInstance, string space) { PLane3D pLane3D = new PLane3D(doc.ActiveView.Origin, doc.ActiveView.ViewDirection); string val1 = string.Empty; double kspace = UnitConvert.StringToFeetAndInches(space, out val1); Transform transform = familyInstance.GetTransform(); Line target = Line.CreateBound(pLane3D.ProjectPointOnPlane(targetx.GetStartPoint()), pLane3D.ProjectPointOnPlane(targetx.GetLastPoint())); var list = familyInstance.LinesGeometry(doc); Line maxp = list.Linemax(); Line max = Line.CreateBound(transform.OfPoint(maxp.GetStartPoint()), transform.OfPoint(maxp.GetLastPoint())); Line lineonplane = Line.CreateBound(pLane3D.ProjectPointOnPlane(max.GetStartPoint()), pLane3D.ProjectPointOnPlane(max.GetLastPoint())); XYZ pointintersect = FindIntersectwoline(target, lineonplane); Parameter dim_length = familyInstance.LookupParameter("DIM_LENGTH"); double value = dim_length.AsDouble(); //XYZ start = pLane3D.ProjectPointOnPlane(max.GetStartPoint()); //XYZ end = pLane3D.ProjectPointOnPlane(max.GetLastPoint()); XYZ start = lineonplane.GetStartPoint(); XYZ end = lineonplane.GetLastPoint(); double kc1 = target.Distance(pLane3D.ProjectPointOnPlane(start)); double kc2 = target.Distance(pLane3D.ProjectPointOnPlane(end)); //Line hg = Line.CreateBound(pointintersect, end); //SketchPlane skt = SketchPlane.Create(doc, pLane3D.GetPlane); //var ty = doc.Create.NewModelCurve(lineonplane, skt); //doc.Create.NewModelCurve(target, skt); //doc.Create.NewModelCurve(hg, skt); //doc.ActiveView.SketchPlane = skt; Line targetXX = Line.CreateBound(target.Origin + 10000.0 * target.Direction, target.Origin - 10000.0 * target.Direction); if (kc1 > kc2) { double length1 = (pointintersect - start).GetLength(); if (value / 2 < length1) { if (length1 < value) { double kc = targetXX.Distance(end); //dim_length.Set(value - kc - kspace); double setk = (value - kc - kspace); string sou1 = setk.DoubleRoundFraction(8); string k; double h = UnitConvert.StringToFeetAndInches(sou1, out k); dim_length.Set(h); XYZ direction = (end - start).Normalize() * (kc + kspace); ElementTransformUtils.MoveElement(doc, familyInstance.Id, -direction); } else { double kc = targetXX.Distance(end); //dim_length.Set(value + kc - kspace); double setk = (value + kc - kspace); string sou1 = setk.DoubleRoundFraction(8); string k; double h = UnitConvert.StringToFeetAndInches(sou1, out k); dim_length.Set(h); XYZ direction = (end - start).Normalize() * (kc - kspace); ElementTransformUtils.MoveElement(doc, familyInstance.Id, direction); } } else { if (length1 < value) { double kc = targetXX.Distance(end); //dim_length.Set(value - (kspace - kc)); double setk = (value - (kspace - kc)); string sou1 = setk.DoubleRoundFraction(8); string k; double h = UnitConvert.StringToFeetAndInches(sou1, out k); dim_length.Set(h); XYZ direction = (end - start).Normalize() * (kc - kspace); ElementTransformUtils.MoveElement(doc, familyInstance.Id, direction); } else { double kc = targetXX.Distance(end); dim_length.Set(value - (kspace - kc)); XYZ direction = (end - start).Normalize() * (kc + kspace); ElementTransformUtils.MoveElement(doc, familyInstance.Id, -direction); } } } else { double lengthk = (pointintersect - end).GetLength(); if (lengthk < value) { double kc = targetXX.Distance(pLane3D.ProjectPointOnPlane(start)); //dim_length.Set(value - kc - kspace); double setk = (value - kc - kspace); string sou1 = setk.DoubleRoundFraction(8); string k; double h = UnitConvert.StringToFeetAndInches(sou1, out k); dim_length.Set(h); } else { //double kc = targetXX.Distance(pLane3D.ProjectPointOnPlane(start)); //dim_length.Set(value + kc - kspace); double kc = targetXX.Distance(pLane3D.ProjectPointOnPlane(start)); var setk = (value + kc - kspace); string sou1 = setk.DoubleRoundFraction(8); string k; double h = UnitConvert.StringToFeetAndInches(sou1, out k); dim_length.Set(h); } } }
public void SearchItemClicked(TorrentMatch match) { GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); dlg.SetHeading("Download this torrent?"); dlg.SetLine(1, match.Title); dlg.SetLine(2, UnitConvert.SizeToString(match.Size)); //dlg.SetLine(3, item.Label3); dlg.DoModal(GUIWindowManager.ActiveWindow); if (!dlg.IsConfirmed) { return; } label = DialogAskLabel.Ask(); if (label == null) { return; } Log.Instance().Print("label is " + label.Name); List <DownloadDir> predefined = TorrentEngine.Instance().TorrentSession.ListDirs(); if (predefined == null) { //MyTorrents.Instance().DisplayError("Unable to connect", "Connection error. Please open your Torrent client before retrying."); //return; } GUIDialogMenu chooser = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (chooser == null) { return; } chooser.Reset(); chooser.SetHeading("Download options"); chooser.Add("No change"); //foreach (DownloadDir dir in predefined) //{ // GUIListItem element = new GUIListItem(); // element.Label = dir.path; // element.Label2 = String.Format("{0} MB Free", Convert.ToString(dir.available)); // chooser.Add(element); //} chooser.Add("Browse Folders"); chooser.DoModal(GUIWindowManager.ActiveWindow); if (chooser.SelectedId == -1) { return; } int selecteddirId = chooser.SelectedId; string selectedText = chooser.SelectedLabelText; Log.Instance().Print("download option is " + selectedText); bool ok = false; // KAT hack string dowOption = ""; if (_searchEngine.GetType() == typeof(TorrentSearch_Combiner)) { Log.Instance().Print("Selected engine is Combiner"); TorrentSearch_Combiner _eng = (TorrentSearch_Combiner)_searchEngine; if (_searchEngine.Parameters.ContainsKey("Options")) { dowOption = _eng.Engines.Where(e => e.Name == match.tracker).First().Parameters["Options"].ToString().Replace("%id%", match.Id); } } else { if (_searchEngine.Parameters.ContainsKey("Options")) { dowOption = _searchEngine.Parameters["Options"].ToString().Replace("%id%", match.Id); } } switch (selectedText) { case "Browse Folders": //FolderBrowser ViewFolders = new FolderBrowser(TorrentEngine.Instance().TorrentSession, label, match, dowOption); Log.Instance().Print("Loading file browser"); MyTorrents.ListType = "FolderBrowser"; MyTorrents.Instance().ShowFolderBrowser(); break; case "No change": if (label != null) { Log.Instance().Print("Starting torrent file downloading"); ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, dowOption, ""); } break; default: if (label != null) { Log.Instance().Print("Starting torrent file downloading"); ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, dowOption, String.Format("&download_dir={0}", selecteddirId - 2)); } break; } /* * if (!ok) * { * GUIDialogNotify notify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); * notify.Reset(); * notify.SetHeading("Failed!"); * notify.SetText("Unable to start download."); * notify.DoModal(GUIWindowManager.ActiveWindow); * * Log.Instance().Print("Downloading failed"); * } * */ }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; doc = uidoc.Document; sel = uidoc.Selection; Setting = SettingTopDT.Instance.GetSetting(); listTextnotes = Getmodelelement.GetTextNoteTypes(doc); using (var form = new FrmTopDT(this)) { if (form.ShowDialog() != true && form.check) { while (iscontinue) { Transaction tran = new Transaction(doc, "Callout dimension"); tran.Start(); try { Reference reference = sel.PickObject(ObjectType.Element, new FilterSpotElevation(), "Select Spot Elevation"); var element = doc.GetElement(reference); var top = element.LookupParameter("Single/Upper Value").AsValueString(); string val1 = string.Empty; string n = string.Empty; double val2 = double.MinValue; if (!string.IsNullOrEmpty(form.val) && form.tru == "") { val2 = UnitConvert.StringToFeetAndInches(top, out val1) + UnitConvert.StringToFeetAndInches(form.val, out n); } if (!string.IsNullOrEmpty(form.tru) && form.val == "") { val2 = UnitConvert.StringToFeetAndInches(top, out val1) - UnitConvert.StringToFeetAndInches(form.tru, out n); } var val3 = UnitConvert.DoubleToImperial(val2); string empty = UnitConvert.StringToFeetAndInchesformattext(val3); if (!string.IsNullOrEmpty(form.Suffix) && string.IsNullOrEmpty(form.Prefix)) { CreteaTextnode(doc, empty + " " + form.Suffix, form.TextNoteType); } if (string.IsNullOrEmpty(form.Suffix) && !string.IsNullOrEmpty(form.Prefix)) { CreteaTextnode(doc, form.Prefix + " " + empty, form.TextNoteType); } if (!string.IsNullOrEmpty(form.Suffix) && !string.IsNullOrEmpty(form.Prefix)) { CreteaTextnode(doc, form.Prefix + " " + empty + " " + form.Suffix, form.TextNoteType); } } catch (Exception) { this.iscontinue = false; } tran.Commit(); } } } return(Result.Succeeded); }