public Context(UniqueNames names, Func <Node, Optional <ObjectIdentifier> > tryGetTagHash, string projectDirectory, ImmutableHashSet <TypeName> typesDeclaredInUx) { Names = names; TryGetTagHash = tryGetTagHash; ProjectDirectory = projectDirectory; _typesDeclaredInUx = typesDeclaredInUx; }
public virtual void TestCommonCases() { UniqueNames u = new UniqueNames(); Assert.Equal("foo", u.UniqueName("foo")); Assert.Equal("foo-1", u.UniqueName("foo")); }
/// <summary> /// - if not replace input, convert preview to print /// - if replace, if one target and one preview, keep target and replace w/ mesh from preview /// - otherwise remove targets and convert preview to print /// </summary> static void standard_mesh_tool_handler(List <DMeshSO> targets, DMeshSO previewSO, bool replace_input, string newNameStr = null) { if (replace_input) { if (targets.Count == 1) { replace_single(targets[0], previewSO); CC.ActiveScene.RemoveSceneObject(previewSO, true); } else { foreach (DMeshSO so in targets) { CCActions.RemovePrintMesh(so as PrintMeshSO); } if (newNameStr != null) { previewSO.Name = UniqueNames.GetNext(newNameStr); } convert_to_print_mesh(previewSO); } } else { if (newNameStr != null) { previewSO.Name = UniqueNames.GetNext(newNameStr); } convert_to_print_mesh(previewSO); } }
public bool ContainsName(string name) { if (UniqueNames == null || UniqueNames.Length == 0) { return(false); } return(UniqueNames.Contains(name)); }
public virtual void TestCollisions() { UniqueNames u = new UniqueNames(); u.UniqueName("foo"); Assert.Equal("foo-1", u.UniqueName("foo-1")); Assert.Equal("foo-2", u.UniqueName("foo")); Assert.Equal("foo-1-1", u.UniqueName("foo-1")); Assert.Equal("foo-2-1", u.UniqueName("foo-2")); }
public static void OnApply_PurgeSpiralTool(PurgeSpiralTool tool, DMeshSO previewSO) { if (previewSO.Mesh.TriangleCount == 0) { return; } PrintMeshSO printSO = convert_to_print_mesh(previewSO); printSO.Name = UniqueNames.GetNext(previewSO.Name); CC.ActiveScene.History.PushInteractionCheckpoint(); }
public static void OnApply_PlaneCutTool(PlaneCutTool tool, Dictionary <DMeshSO, DMeshSO> result) { standard_multi_so_tool_handler(result, true); if (tool.KeepBothSides) { foreach (var pair in tool.OtherSideMeshes) { PrintMeshSO newSO = emit_new_print_mesh(pair.Value, pair.Key); newSO.Name = UniqueNames.GetNext(pair.Key.Name); } } CC.ActiveScene.History.PushInteractionCheckpoint(); }
static Expression CreateArray(TypeName elementType, UniqueNames names, IEnumerable <Expression> elements) { var list = names.GetUniqueName(); names = names.Reserve(list); return(new CallLambda( new Lambda( Signature.Func(TypeName.Parse("Uno.Object")), new[] { new BindVariable(list, new Instantiate(ObjectList.Parameterize(elementType))), }, elements .Select(e => (Statement) new CallDynamicMethod(new ReadVariable(list), new TypeMemberName("Add"), e)) .Concat(new [] { new Return(new CallDynamicMethod(new ReadVariable(list), new TypeMemberName("ToArray"))) })))); }
public virtual ToolpathSO Create(ToolpathSet toolpaths, SingleMaterialFFFSettings settings, SOMaterial setMaterial) { AssignSOMaterial(setMaterial); // need to do this to setup BaseSO material stack parentGO = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("Toolpath")); Toolpaths = toolpaths; Settings = settings; polylines_valid = false; PolylinePool = new fGameObjectPool <fPolylineGameObject>(allocate_polyline_go); PolylinePool.FreeF = (go) => { //go.SetVertices(EmptyToolpathCurve, false, true); }; return(this); }
public static void OnApply_GenerateGraphSupportsTool(GenerateGraphSupportsTool tool, DMeshSO previewSO) { if (previewSO.Mesh.TriangleCount == 0) { return; } if (tool.Targets.Count() == CC.Objects.PrintMeshes.Count) { CC.Settings.GenerateSupport = false; } PrintMeshSO printSO = convert_to_print_mesh(previewSO); printSO.Name = UniqueNames.GetNext("Tree Support"); printSO.Settings.ObjectType = PrintMeshSettings.ObjectTypes.Support; printSO.AssignSOMaterial(CCMaterials.SupportMeshMaterial); CC.ActiveScene.History.PushInteractionCheckpoint(); }
public static void OnApply_SeparateSolidsTool(SeparateSolidsTool tool, List <DMeshSO> previews) { bool replace_input = tool.Parameters.GetValueBool("replace_input"); if (replace_input) { foreach (DMeshSO so in tool.Targets) { CCActions.RemovePrintMesh(so as PrintMeshSO); } } foreach (var so in previews) { so.Name = UniqueNames.GetNext("SeparatedPart"); convert_to_print_mesh(so); } CC.ActiveScene.History.PushInteractionCheckpoint(); }
public static void OnApply_AddHoleTool(AddHoleTool tool) { if (tool.HoleType == AddHoleTool.HoleTypes.CavityObject) { PrintMeshSO printSO = convert_to_print_mesh(tool.GetOutputSO()); printSO.Name = UniqueNames.GetNext("Hole"); printSO.Settings.ObjectType = PrintMeshSettings.ObjectTypes.Cavity; printSO.AssignSOMaterial(CCMaterials.CavityMeshMaterial); } else { bool replace_input = tool.Parameters.GetValueBool("replace_input"); DMeshSO previewSO = tool.GetOutputSO(); previewSO.EnableSpatial = true; // required because preview has no spatial DS standard_mesh_tool_handler(new List <DMeshSO>() { tool.TargetSO as DMeshSO }, previewSO, replace_input); } CC.ActiveScene.History.PushInteractionCheckpoint(); }
public static void DuplicateSelectedObjects(bool bInteractive) { List <SceneObject> duplicate = new List <SceneObject>(CC.ActiveScene.Selected); foreach (var existingSO in duplicate) { if (existingSO is PrintMeshSO == false) { throw new NotSupportedException("CCActions.DuplicateSelectedObjects: currently can only delete print meshes?"); } PrintMeshSO dupeSO = (existingSO as PrintMeshSO).DuplicateSubtype <PrintMeshSO>(); dupeSO.Name = UniqueNames.GetNext(existingSO.Name); AddNewPrintMesh(dupeSO); // If we have multi-select, then we duplicated relative to a transient group that will // go away. So, update position using scene coords if (existingSO.Parent is FScene == false) { var sceneF = existingSO.GetLocalFrame(CoordSpace.SceneCoords); dupeSO.SetLocalFrame(sceneF, CoordSpace.SceneCoords); Vector3f scaleL = existingSO.GetLocalScale(); Vector3f scaleS = SceneTransforms.ObjectToSceneV(existingSO, scaleL); float scale = scaleS.Length / scaleL.Length; dupeSO.SetLocalScale(scale * Vector3f.One); } if (dupeSO.CanAutoUpdateFromSource() && dupeSO.AutoUpdateOnSourceFileChange == true) { CC.FileMonitor.AddMesh(dupeSO); } } if (bInteractive) { CC.ActiveScene.History.PushInteractionCheckpoint(); } }
public Context With(UniqueNames names = null) { return(new Context(names ?? Names, TryGetTagHash, ProjectDirectory, _typesDeclaredInUx)); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { output.TagName = "thead"; var key = $"{Action}_{Controller}_{Area}"; if (!UniqueNames.ContainsKey(key)) { UniqueNames.Add(key, Guid.NewGuid().ToString("N")); } UniqueName = UniqueNames[key]; TableChildContext parentChildContext = new TableChildContext() { Action = Action, UniqueName = UniqueName, Controller = Controller, Area = Area, }; context.Items.Add(typeof(TableChildContext), parentChildContext); var childs = await output.GetChildContentAsync(); output.Content.SetHtmlContent(childs); StringBuilder builder = new StringBuilder(); builder.AppendLine("<script>"); builder.AppendLine($"function sortBy{UniqueName}(elem ,field, controller, action)"); var url = UrlHelper.Action(Action, Controller, new { area = Area }); builder.AppendLine("{$.ajax({type :\"GET\", url:"); builder.AppendLine($"\"{url}\","); builder.AppendLine("dataType : \"html\","); if (Parameters == null) { builder.AppendLine("data :{sidx: field,customFilter:getAllTableFilters($(elem).closest(\"thead\")},"); } else { builder.AppendLine("data:{"); builder.AppendLine("sidx: field"); foreach (var parameter in Parameters) { if (parameter.Key == "sidx") { continue; } builder.AppendLine(","); if (parameter.Key == "sord") { builder.AppendLine(parameter.Value.Contains("asc") ? $"{parameter.Key}:\"desc\"" : $"{parameter.Key}:\"asc\""); } else { builder.AppendLine($"{parameter.Key}:{parameter.Value}"); } } builder.AppendLine($",customFilter:JSON.stringify(getAllTableFilters($(elem).closest(\"thead\")))"); builder.AppendLine("},"); } builder.AppendLine("success: function(answer){"); if (!string.IsNullOrEmpty(ElementToUpdateId)) { builder.AppendLine($"$('#{ElementToUpdateId}').html(answer);"); } if (!string.IsNullOrEmpty(SuccessCallback)) { builder.AppendLine($"{SuccessCallback}();" + "}"); } else { builder.Append('}'); } builder.AppendLine("});}"); builder.AppendLine("function applyFilters" + UniqueName + "(rootElement) {"); builder.AppendLine("var area = $(rootElement).closest(\"th\").data(\"area\");"); builder.AppendLine("var controller = $(rootElement).closest(\"th\").data(\"controller\");"); builder.AppendLine("var action = $(rootElement).closest(\"th\").data(\"action\");"); builder.AppendLine("var jsObj = getAllTableFilters($(rootElement).closest(\"thead\"));"); builder.AppendLine("$.ajax({"); builder.AppendLine("type: \"GET\","); builder.AppendLine($"url: \"{url}\","); builder.AppendLine(); builder.AppendLine("dataType: \"html\","); builder.AppendLine("data: {"); builder.AppendLine("customFilter:JSON.stringify(jsObj)"); if (Parameters == null) { builder.AppendLine("},"); } else { builder.AppendLine(","); int i = 0; foreach (var parameter in Parameters) { if (i != 0) { builder.AppendLine(","); } builder.AppendLine($"{parameter.Key}:{parameter.Value}"); i++; } builder.AppendLine("},"); } builder.AppendLine("success: function(answer){"); if (!string.IsNullOrEmpty(ElementToUpdateId)) { builder.AppendLine($"$('#{ElementToUpdateId}').html(answer);"); } if (!string.IsNullOrEmpty(SuccessCallback)) { builder.AppendLine($"{SuccessCallback}();" + "}"); } else { builder.Append('}'); } builder.AppendLine("});}</script>"); output.PostContent.SetHtmlContent(builder.ToString()); }
public async Task <ActionResult> PDFtoImage(string fileurl, int maxWidth) { string websitePath = ConfigurationManager.AppSettings["portalPath"]; string LogFilePath = ConfigurationManager.AppSettings["logFilePath"]; var sr = new StreamWriter(LogFilePath + "pdfToImage.log"); string timestampedPDF = "error.pdf"; sr.AutoFlush = true; string outwardPath = ""; string currentPDFPath = ""; List <string> PathedArray = new List <string>(); try { sr.WriteLine("fileurl = " + fileurl); sr.WriteLine("beforeInput"); string inputPath = ConfigurationManager.AppSettings["pdfUploadSpot"] + @"\" + fileurl; sr.WriteLine("beforeoutput"); string filename = "tempImage" + UniqueNames.GetTimestamp(DateTime.Now) + ".jpg"; string outputPath = ConfigurationManager.AppSettings["pdfUploadSpot"] + @"\tempPics\" + filename; sr.WriteLine("inputpath = " + inputPath); sr.WriteLine("outputpath = " + outputPath); List <string> outwardPaths = new List <string>(); for (int i = 1; i < 4; i++) { outputPath = outputPath.Replace(".jpg", i + ".jpg"); GhostscriptWrapper.GeneratePageThumb(inputPath, outputPath, i, 120, 120); if (!System.IO.File.Exists(outputPath)) { break; } outwardPaths.Add(outputPath); } foreach (var path in outwardPaths) { ScaleImage(path, maxWidth, 3000); string newPath = path.Substring(path.LastIndexOf('\\') + 1); newPath = ConfigurationManager.AppSettings["portalPath"] + @"/pdfs/gettemppic/" + newPath; PathedArray.Add(newPath); } currentPDFPath = inputPath; timestampedPDF = DateTime.Now.GetTimestamp() + fileurl; string archivePath = ConfigurationManager.AppSettings["pdfArchive"] + @"\PDFs\" + timestampedPDF; //PDFParser parser = new PDFParser(); //string result = parser.ExtractText(currentPDFPath); //moving file sr.WriteLine("Current PDF Path:" + currentPDFPath); sr.WriteLine("Archive PDF Path:" + archivePath); //System.IO.File.Move(currentPDFPath, archivePath); } catch (Exception e) { sr.WriteLine("message = " + e.Message); sr.WriteLine("stacktrace = " + e.StackTrace); } sr.Close(); Task.Factory.StartNew(() => { UploadPDFToAzure(currentPDFPath, timestampedPDF); }); return(Json(new { PathedArray, timestampedPDF })); }
/// <summary> /// Checks if the plan contains the given unique table name. /// </summary> /// <param name="name"></param> /// <returns> /// Returns <b>true</b> if this table source contains the /// unique table name reference, otherwise <b>false</b>. /// </returns> public bool ContainsUniqueKey(string name) { return(UniqueNames.Any(uniqueName => uniqueName.Equals(name))); }
public ActionResult cropImage(string imagePath, string pdfPath, int leftX, int leftY, int width, int height, int serviceId, string title, string allImagePaths) { // TODO: Pathing! string uniqueName = ""; string LogFilePath = ConfigurationManager.AppSettings["logFilePath"]; var sr = new StreamWriter(LogFilePath + "pdfconvert.log"); sr.AutoFlush = true; bool success = true; try { sr.WriteLine("Orignal Image Path: " + imagePath); int lastSlash = imagePath.LastIndexOf('/'); string serverImagePath = ConfigurationManager.AppSettings["pdfUploadSpot"] + @"\tempPics\" + imagePath.Substring(lastSlash + 1); sr.WriteLine("SeverImagePath = " + serverImagePath); sr.WriteLine("leftx = " + leftX.ToString()); sr.WriteLine("lefty = " + leftY.ToString()); sr.WriteLine("width = " + width.ToString()); sr.WriteLine("height = " + height.ToString()); sr.WriteLine("Before src"); Bitmap src = Image.FromFile(serverImagePath) as Bitmap; if (leftX == 0 && leftY == 0 && width == 0 && height == 0) { //Do nothing but set width and height width = src.Width; height = src.Height; } Rectangle cropRect = new Rectangle(leftX, leftY, width, height); sr.WriteLine("after src"); Bitmap target = new Bitmap(cropRect.Width, cropRect.Height); //Bitmap target = new Bitmap(10, 20); sr.WriteLine("Before using graphics"); using (Graphics g = Graphics.FromImage(target)) { sr.WriteLine("Before draw"); g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), cropRect, GraphicsUnit.Pixel); } sr.WriteLine("Before save"); uniqueName = UniqueNames.GetTimestamp(DateTime.Now) + ".jpg"; string savePath = ConfigurationManager.AppSettings["pdfArchive"] + @"\Thumbnails\" + uniqueName; sr.WriteLine("Save Path: " + savePath); target.Save(savePath); src.Dispose(); target.Dispose(); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("pdf-thumbnails"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(uniqueName); blockBlob.UploadFromFile(savePath); blockBlob.Properties.ContentType = "image/jpeg"; blockBlob.SetProperties(); } catch (Exception e) { sr.WriteLine("Error message= " + e.Message); //sr.WriteLine("INNER message = " + e.InnerException.Message); sr.WriteLine("Stacktrace = " + e.StackTrace); success = false; } sr.Close(); Service service = db.Services.Find(serviceId); PDF dbPdf = new PDF(); if (service.PDF == null) { dbPdf.ServiceId = serviceId; dbPdf.ThumbnailPath = uniqueName; dbPdf.PDFPath = pdfPath; dbPdf.TitleText = title; db.Entry(dbPdf).State = EntityState.Added; db.SaveChanges(); } else { service.PDF.ThumbnailPath = uniqueName; service.PDF.PDFPath = pdfPath; service.PDF.TitleText = title; db.Entry(service.PDF).State = EntityState.Modified; db.SaveChanges(); } string safePdf = pdfPath.Replace(" ", "%20"); string safeUniqueName = uniqueName.Replace('\\', '/'); string outwardPdfPath = ConfigurationManager.AppSettings["portalPath"] + @"/pdfs/displaypdf/" + serviceId; var userId = User.Identity.GetUserId(); if (userId != null) { FuneralHome fh = db.FuneralHomes.Where(x => x.UserId == userId).FirstOrDefault(); if (fh != null) { if (fh.Setting.SEOFriendlyPDF == false) { outwardPdfPath = ConfigurationManager.AppSettings["portalPath"] + @"/pdfs/servepdf/" + serviceId; } } } string outwardThumbnail = ConfigurationManager.AppSettings["portalPath"] + @"/pdfs/displaythumbnail/" + serviceId; allImagePaths = allImagePaths.Substring(2); allImagePaths = allImagePaths.Remove(allImagePaths.Length - 2); allImagePaths = allImagePaths.Replace("]", ""); allImagePaths = allImagePaths.Replace(@"\", ""); allImagePaths = allImagePaths.Replace("\"", ""); string[] allPaths = allImagePaths.Split(','); if (allPaths != null) { foreach (string imageToBeDeleted in allPaths) { int slashPos = imagePath.LastIndexOf('/'); string serverImagePath = ConfigurationManager.AppSettings["rootPath"] + @"\UploadedPDFs\tempPics\" + imageToBeDeleted.Substring(slashPos + 1); if (System.IO.File.Exists(serverImagePath)) { System.IO.File.Delete(serverImagePath); } } } //Save to DB return(Json(new { outwardPdfPath, outwardThumbnail, success })); }
async Task complete_import(string sFilename, DMesh3Builder builder, Action <string> onCompletedF) { AxisAlignedBox3d bounds = AxisAlignedBox3d.Empty; foreach (DMesh3 mesh in builder.Meshes) { bounds.Contain(mesh.CachedBounds); } Vector3d centerPt = bounds.Center; Vector3d basePt = centerPt - bounds.Height * 0.5f * Vector3d.AxisY; Vector3d vTranslate = basePt; await Task.Run(() => { foreach (DMesh3 mesh in builder.Meshes) { MeshTransforms.Translate(mesh, -vTranslate); } }); bool bFirst = (CC.Objects.PrintMeshes.Count == 0); Vector3d postTranslate = Vector3d.Zero; switch (CCPreferences.ImportTransformMode) { case CCPreferences.ImportTransformModes.AutoCenterAll: break; case CCPreferences.ImportTransformModes.AutoCenterFirst: if (bFirst) { CCState.SceneImportTransform = vTranslate; } postTranslate = vTranslate - CCState.SceneImportTransform; break; case CCPreferences.ImportTransformModes.NoAutoCenter: postTranslate = vTranslate; break; } // compact input meshes await Task.Run(() => { gParallel.ForEach(builder.Meshes, (mesh) => { MeshEditor.RemoveUnusedVertices(mesh); }); gParallel.ForEach(Interval1i.Range(builder.Meshes.Count), (k) => { if (builder.Meshes[k].IsCompact == false) { builder.Meshes[k] = new DMesh3(builder.Meshes[k], true); } }); }); string sBaseName = Path.GetFileNameWithoutExtension(sFilename); foreach (DMesh3 mesh in builder.Meshes) { PrintMeshSO meshSO = new PrintMeshSO(); meshSO.Create(mesh, CCMaterials.PrintMeshMaterial); meshSO.UpDirection = UpDirection.ZUp; Frame3f f = meshSO.GetLocalFrame(CoordSpace.ObjectCoords); f.Origin = f.Origin + (Vector3f)postTranslate; meshSO.SetLocalFrame(f, CoordSpace.ObjectCoords); // if only one mesh, we can keep a reference if (builder.Meshes.Count == 1) { meshSO.SourceFilePath = sFilename; meshSO.LastReadFileTimestamp = File.GetLastWriteTime(SourceFilePath).Ticks; } meshSO.Name = UniqueNames.GetNext(sBaseName); CCActions.AddNewPrintMesh(meshSO); } if (onCompletedF != null) { onCompletedF(sFilename); } }