public async Task<int> Add(LoadOptions m) { using (var controller = Dependency.Resolve<IDynItemController>()) { return await controller.Add(m.SettingName, m); } }
public async Task PutImage() { using (var client = new HttpClient()) { client.BaseAddress = new Uri(AzureUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); LoadOptions info = new LoadOptions() { LoadType = LoadOptions.ELoadType.Image, AutoScale = true, AutoScaleSizeX = 100, AutoScaleSizeY = 100, MoveSpeed = 450, PenMoveType = LoadOptions.PenType.CommandString, ImageDPIX = 66.7m, ImageDPIY = 66.7m }; Assembly ass = Assembly.GetExecutingAssembly(); string asspath = Path.GetDirectoryName(ass.Location); info.FileName = asspath + @"\TestData\Wendelin_Ait110.png"; info.FileContent = File.ReadAllBytes(info.FileName); HttpResponseMessage response = await client.PostAsJsonAsync(api, info); response.EnsureSuccessStatusCode(); string[] gcode = await response.Content.ReadAsAsync<string[]>(); Assert.IsNotNull(gcode); } }
public async Task Delete(LoadOptions m) { using (var controller = Dependency.Resolve<IDynItemController>()) { await controller.Delete(m.Id); } }
public static LoadBase CallLoad(string filename, byte[] filecontent, LoadOptions opt) { string pathfilename = Path.GetFileName(filename); string tmpfile = Path.GetTempPath() + pathfilename; opt.FileName = tmpfile; opt.ImageWriteToFileName = null; try { File.WriteAllBytes(tmpfile, filecontent); LoadBase load = LoadBase.Create(opt); if (load == null) return null; load.Load(); return load; } finally { File.Delete(tmpfile); } }
public async Task<int> Update(LoadOptions m) { using (var controller = Dependency.Resolve<IDynItemController>()) { await controller.Save(m.Id, m.SettingName, m); return m.Id; } }
public async Task CreateDeleteOption() { using (var client = new HttpClient()) { client.BaseAddress = new Uri(AzureUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var m = new LoadOptions() { SettingName = "Settingname" }; HttpResponseMessage response = await client.PostAsJsonAsync(api, m); Assert.AreEqual(true, response.IsSuccessStatusCode); if (response.IsSuccessStatusCode) { Uri newmUrl = response.Headers.Location; // HTTPGET again HttpResponseMessage responseget = await client.GetAsync(newmUrl); Assert.AreEqual(true, responseget.IsSuccessStatusCode); if (responseget.IsSuccessStatusCode) { LoadOptions mget = await responseget.Content.ReadAsAsync<LoadOptions>(); Assert.AreEqual("Settingname", mget.SettingName); // HTTP PUT mget.SettingName = "ComHA"; var responsePut = await client.PutAsJsonAsync(newmUrl, mget); // HTTPGET again2 HttpResponseMessage responseget2 = await client.GetAsync(newmUrl); Assert.AreEqual(true, responseget2.IsSuccessStatusCode); if (responseget2.IsSuccessStatusCode) { LoadOptions mget2 = await responseget2.Content.ReadAsAsync<LoadOptions>(); Assert.AreEqual("ComHA", mget2.SettingName); } // HTTP DELETE response = await client.DeleteAsync(newmUrl); // HTTPGET again3 HttpResponseMessage responseget3 = await client.GetAsync(newmUrl); Assert.AreEqual(HttpStatusCode.NotFound, responseget3.StatusCode); if (responseget2.IsSuccessStatusCode) { Machine mget3 = await responseget3.Content.ReadAsAsync<Machine>(); Assert.IsNull(mget3); } } } } }
public async Task<int> Add(LoadOptions value) { using (var client = CreateHttpClient()) { HttpResponseMessage response = await client.PostAsJsonAsync(api, value); if (response.IsSuccessStatusCode) return -1; return await response.Content.ReadAsAsync<int>(); } }
public async Task<CommandList> Load(LoadOptions loadinfo, bool azure) { if (azure) { await LoadAzureAsync(loadinfo); } else { LoadLocal(loadinfo); } return Commands; }
public async Task Delete(LoadOptions value) { using (var client = CreateHttpClient()) { HttpResponseMessage response = await client.DeleteAsync(api + "/" + value.Id); if (response.IsSuccessStatusCode) { //return RedirectToAction("Index"); } //return HttpNotFound(); } }
static public LoadBase Create(LoadOptions info) { LoadBase load = null; switch (info.LoadType) { case LoadOptions.ELoadType.GCode: load = new LoadGCode(); break; case LoadOptions.ELoadType.HPGL: load = new LoadHPGL(); break; case LoadOptions.ELoadType.Image: load = new LoadImage(); break; case LoadOptions.ELoadType.ImageHole: load = new LoadImageHole(); break; default: return null; } load.LoadOptions = info; return load; }
private void LoadLocal(LoadOptions loadinfo) { try { LoadBase load = LoadBase.Create(loadinfo); load.LoadOptions = loadinfo; load.Load(); Commands.Clear(); Commands.AddRange(load.Commands); if (!string.IsNullOrEmpty(loadinfo.GCodeWriteToFileName)) { SaveGCode(loadinfo.GCodeWriteToFileName); } WriteCamBam(load, Path.GetDirectoryName(loadinfo.GCodeWriteToFileName) + @"\" + Path.GetFileNameWithoutExtension(loadinfo.GCodeWriteToFileName) + @".cb"); } catch (Exception) { throw; } }
public async Task PutHpgl() { using (var client = new HttpClient()) { client.BaseAddress = new Uri(AzureUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); LoadOptions info = new LoadOptions() { LoadType = LoadOptions.ELoadType.HPGL }; Assembly ass = Assembly.GetExecutingAssembly(); string asspath = Path.GetDirectoryName(ass.Location); info.FileName = asspath + @"\TestData\heikes-mietzi.hpgl"; info.FileContent = File.ReadAllBytes(info.FileName); HttpResponseMessage response = await client.PostAsJsonAsync(api, info); response.EnsureSuccessStatusCode(); string[] gcode = await response.Content.ReadAsAsync<string[]>(); Assert.IsNotNull(gcode); } }
private void _importSettings_Click(object sender, EventArgs e) { using (OpenFileDialog form = new OpenFileDialog()) { form.FileName = @"*.xml"; if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { using (StreamReader sr = new StreamReader(form.FileName)) { XmlSerializer serializer = new XmlSerializer(typeof(LoadOptions)); LoadOptions obj = (LoadOptions) serializer.Deserialize(sr); sr.Close(); _settingName.SelectedItem = null; this.LoadInfo = obj; } } } }
private void _settingName_SelectedIndexChanged(object sender, EventArgs e) { if (_settingName.Focused && _settingName.SelectedItem != null) { LoadOptionDefinition item = (LoadOptionDefinition)_settingName.SelectedItem; LoadInfo = item.Item; } }
private async Task LoadAzureAsync(LoadOptions info) { using (var client = CreateHttpClient()) { info.FileContent = File.ReadAllBytes(info.FileName); HttpResponseMessage response = await client.PostAsJsonAsync(api, info); string[] gcode = await response.Content.ReadAsAsync<string[]>(); if (response.IsSuccessStatusCode) { var load = new LoadGCode(); load.Load(gcode); Commands.Clear(); Commands.AddRange(load.Commands); if (!string.IsNullOrEmpty(info.GCodeWriteToFileName)) { SaveGCode(info.GCodeWriteToFileName); } } } }
public async Task<int> Update(LoadOptions value) { using (var client = CreateHttpClient()) { var response = await client.PutAsJsonAsync(api + "/" + value.Id, value); if (response.IsSuccessStatusCode) { return value.Id; } return -1; } }
public async Task Load() { if (loadinfo.AutoScaleSizeX == 0 || loadinfo.AutoScale == false) { loadinfo.AutoScaleSizeX = Settings.Instance.SizeX; loadinfo.AutoScaleSizeY = Settings.Instance.SizeY; } var arg = new GetLoadInfoArg() { LoadOption = loadinfo, UseAzure = _useAzure }; if ((GetLoadInfo?.Invoke(arg)).GetValueOrDefault(false)) { loadinfo = arg.LoadOption; _useAzure = arg.UseAzure; var ld = new GCodeLoad(); try { _loadingOrSending = true; Commands = await ld.Load(loadinfo, _useAzure); } catch (Exception ex) { MessageBox?.Invoke("Load failed with error: " + ex.Message, "CNCLib", MessageBoxButton.OK, MessageBoxImage.Stop); } finally { _loadingOrSending = false; CommandManager.InvalidateRequerySuggested(); } } }
private void AddCommandX(double x, double y, double size, LoadOptions.EHoleType holetype, int ix) { // x,y left,top corner // size 0..1 size = size * size; // squared area double minholesize = LaserSize; if (LoadOptions.ImageInvert) { size = 1.0 - size; } double pixelX = PixelSizeX * ImageToDotSizeX; double pixelY = PixelSizeY * ImageToDotSizeY; double scaleX = (pixelX - LaserSize) / pixelX; double scaleY = (pixelY - LaserSize) / pixelY; switch (HoleType) { case LoadOptions.EHoleType.Hexagon: size *= 1.0 / 0.86602540378443864676372317075294; break; default: break; } double dotsizeX = size * PixelSizeX * ImageToDotSizeX * scaleX; double dotsizeY = size * PixelSizeY * ImageToDotSizeY * scaleY; double centerX = x + ImageToDotSizeX / 2.0; double centerY = y - ImageToDotSizeY / 2.0; switch (holetype) { case LoadOptions.EHoleType.Hexagon: CreateHexagon(centerX, centerY, dotsizeX / 2.0); break; case LoadOptions.EHoleType.Circle: CreateCircle(centerX, centerY, dotsizeX / 2.0); break; case LoadOptions.EHoleType.Square: CreateSquare(centerX, centerY, dotsizeX / 2.0, dotsizeY / 2.0); break; case LoadOptions.EHoleType.Diamond: CreateDiamond(centerX, centerY, dotsizeX / 2.0, dotsizeY / 2.0); break; case LoadOptions.EHoleType.Heart: CreateHeart(centerX, centerY, dotsizeX / 2.0, dotsizeY / 2.0, RotateHeart && ix%2 == 0); break; } LaserOff(); }