Removed ReadOnly list added Index of to SafeList
This commit is contained in:
parent
0a0df8ca80
commit
60a56af419
6 changed files with 32 additions and 21 deletions
|
|
@ -40,9 +40,19 @@ namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
var imageWidget = new ImageWidget(image);
|
var imageWidget = new ImageWidget(image);
|
||||||
var index = 0;
|
var index = 0;
|
||||||
using (var list = this.Children.ReadOnly())
|
foreach (var child in this.Children)
|
||||||
{
|
{
|
||||||
index = list.IndexOf(labelTextWidget);
|
if (child == labelTextWidget)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index >= this.Children.Count)
|
||||||
|
{
|
||||||
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.AddChild(imageWidget, index);
|
this.AddChild(imageWidget, index);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
public static void ReplaceChild(this GuiWidget widget, GuiWidget existingChild, GuiWidget replacement)
|
public static void ReplaceChild(this GuiWidget widget, GuiWidget existingChild, GuiWidget replacement)
|
||||||
{
|
{
|
||||||
int index = widget.GetChildIndex(existingChild);
|
int index = widget.Children.IndexOf(existingChild);
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
{
|
{
|
||||||
widget.RemoveChild(existingChild);
|
widget.RemoveChild(existingChild);
|
||||||
|
|
|
||||||
|
|
@ -150,11 +150,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
|
|
||||||
tumbleCubeControl = view3DWidget.InteractionLayer.Children<TumbleCubeControl>().FirstOrDefault();
|
tumbleCubeControl = view3DWidget.InteractionLayer.Children<TumbleCubeControl>().FirstOrDefault();
|
||||||
|
|
||||||
var position = 0;
|
var position = view3DWidget.InteractionLayer.Children.IndexOf(trackball);
|
||||||
using (var list = view3DWidget.InteractionLayer.Children.ReadOnly())
|
|
||||||
{
|
|
||||||
position = list.IndexOf(trackball);
|
|
||||||
}
|
|
||||||
|
|
||||||
gcodePanel = new GCodePanel(this, printer, sceneContext, theme)
|
gcodePanel = new GCodePanel(this, printer, sceneContext, theme)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -268,8 +268,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
||||||
public override void AddTab(GuiWidget tabWidget, int tabIndex = -1)
|
public override void AddTab(GuiWidget tabWidget, int tabIndex = -1)
|
||||||
{
|
{
|
||||||
// Default position if tabIndex == -1 is just before the tabTrailer
|
// Default position if tabIndex == -1 is just before the tabTrailer
|
||||||
var widgetPosition = this.TabBar.ActionArea.GetChildIndex(tabTrailer);
|
var widgetPosition = this.TabBar.ActionArea.Children.IndexOf(tabTrailer);
|
||||||
var firstTabPosition = this.TabBar.ActionArea.GetChildIndex(leadingTabAdornment) + 1;
|
var firstTabPosition = this.TabBar.ActionArea.Children.IndexOf(leadingTabAdornment) + 1;
|
||||||
|
|
||||||
if (tabIndex != -1)
|
if (tabIndex != -1)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ namespace MatterHackers.MatterControl
|
||||||
this.SetBackgroundColor();
|
this.SetBackgroundColor();
|
||||||
|
|
||||||
// find out where the contents we put in last time are
|
// find out where the contents we put in last time are
|
||||||
int thisIndex = GetChildIndex(panel);
|
int thisIndex = Children.IndexOf(panel);
|
||||||
this.RemoveAllChildren();
|
this.RemoveAllChildren();
|
||||||
|
|
||||||
// make new content with the possibly changed theme
|
// make new content with the possibly changed theme
|
||||||
|
|
|
||||||
|
|
@ -37,19 +37,19 @@ namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
public class RequestManager
|
public class RequestManager
|
||||||
{
|
{
|
||||||
public string LastResponse { protected set; get; }
|
public string LastResponse { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the time-out value in milliseconds
|
/// Gets the time-out value in milliseconds
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The timeout.</value>
|
/// <value>The timeout.</value>
|
||||||
public int Timeout { get; internal set; } = 100000;
|
public int Timeout { get; internal set; } = 100000;
|
||||||
|
|
||||||
private CookieContainer cookies = new CookieContainer();
|
private CookieContainer cookies = new CookieContainer();
|
||||||
|
|
||||||
internal string GetCookieValue(Uri SiteUri, string name)
|
internal string GetCookieValue(Uri siteUri, string name)
|
||||||
{
|
{
|
||||||
Cookie cookie = cookies.GetCookies(SiteUri)[name];
|
Cookie cookie = cookies.GetCookies(siteUri)[name];
|
||||||
return (cookie == null) ? null : cookie.Value;
|
return (cookie == null) ? null : cookie.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,7 +68,7 @@ namespace MatterHackers.MatterControl
|
||||||
using (Stream dataStream = response.GetResponseStream())
|
using (Stream dataStream = response.GetResponseStream())
|
||||||
{
|
{
|
||||||
// Open the stream using a StreamReader for easy access.
|
// Open the stream using a StreamReader for easy access.
|
||||||
using (StreamReader reader = new StreamReader(dataStream))
|
using (var reader = new StreamReader(dataStream))
|
||||||
{
|
{
|
||||||
// Read the content.
|
// Read the content.
|
||||||
responseFromServer = reader.ReadToEnd();
|
responseFromServer = reader.ReadToEnd();
|
||||||
|
|
@ -84,6 +84,7 @@ namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
response.Close();
|
response.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
LastResponse = responseFromServer;
|
LastResponse = responseFromServer;
|
||||||
return responseFromServer;
|
return responseFromServer;
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +97,7 @@ namespace MatterHackers.MatterControl
|
||||||
|
|
||||||
public HttpWebResponse SendGETRequest(string uri, string signIn, string password, bool allowAutoRedirect)
|
public HttpWebResponse SendGETRequest(string uri, string signIn, string password, bool allowAutoRedirect)
|
||||||
{
|
{
|
||||||
HttpWebRequest request = GenerateRequest (uri, null, "GET", null, null, allowAutoRedirect);
|
HttpWebRequest request = GenerateRequest(uri, null, "GET", null, null, allowAutoRedirect);
|
||||||
return GetResponse(request);
|
return GetResponse(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,8 +107,9 @@ namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("uri");
|
throw new ArgumentNullException("uri");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a request using a URL that can receive a post.
|
// Create a request using a URL that can receive a post.
|
||||||
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
|
var request = (HttpWebRequest)HttpWebRequest.Create(uri);
|
||||||
request.Method = method;
|
request.Method = method;
|
||||||
|
|
||||||
request.Timeout = this.Timeout;
|
request.Timeout = this.Timeout;
|
||||||
|
|
@ -134,10 +136,9 @@ namespace MatterHackers.MatterControl
|
||||||
// Set the ContentLength property of the WebRequest.
|
// Set the ContentLength property of the WebRequest.
|
||||||
request.ContentLength = byteArray.Length;
|
request.ContentLength = byteArray.Length;
|
||||||
// Get the request stream.
|
// Get the request stream.
|
||||||
Stream dataStream = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dataStream = request.GetRequestStream();
|
Stream dataStream = request.GetRequestStream();
|
||||||
// Write the data to the request stream.
|
// Write the data to the request stream.
|
||||||
dataStream.Write(byteArray, 0, byteArray.Length);
|
dataStream.Write(byteArray, 0, byteArray.Length);
|
||||||
// Close the Stream object.
|
// Close the Stream object.
|
||||||
|
|
@ -145,10 +146,11 @@ namespace MatterHackers.MatterControl
|
||||||
}
|
}
|
||||||
catch (WebException ex)
|
catch (WebException ex)
|
||||||
{
|
{
|
||||||
if(ex.Status == WebExceptionStatus.Timeout)
|
if (ex.Status == WebExceptionStatus.Timeout)
|
||||||
{
|
{
|
||||||
LastResponse = JsonConvert.SerializeObject(new { status = "error", statuscode = 408 });
|
LastResponse = JsonConvert.SerializeObject(new { status = "error", statuscode = 408 });
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Web exception occurred. Status code: {0}", ex.Status);
|
Console.WriteLine("Web exception occurred. Status code: {0}", ex.Status);
|
||||||
}
|
}
|
||||||
catch (IOException ioException)
|
catch (IOException ioException)
|
||||||
|
|
@ -160,6 +162,7 @@ namespace MatterHackers.MatterControl
|
||||||
System.Diagnostics.Trace.WriteLine(e.Message);
|
System.Diagnostics.Trace.WriteLine(e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,6 +172,7 @@ namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpWebResponse response = null;
|
HttpWebResponse response = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -185,6 +189,7 @@ namespace MatterHackers.MatterControl
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.Message);
|
Console.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue