private void cleanup() { stopTimer(); // Make sure timer stopped try { acceptReplies = false; conn?.removeMessage(this); // Empty out any accumuluated replies if (replies != null) { while (replies.Count != 0) { var temp_object = replies[0]; replies.RemoveAt(0); object generatedAux = temp_object; } } } catch (Exception ex) { // nothing } // Let GC clean up this stuff, leave name in case finalized is called conn = null; msg = null; // agent = null; // leave this reference queue = null; //replies = null; //leave this since we use it as a semaphore bindprops = null; }
private void cleanup() { stopTimer(); // Make sure timer stopped try { acceptReplies = false; if (conn != null) { conn.removeMessage(this); } // Empty out any accumuluated replies if (replies != null) { while (!(replies.Count == 0)) { object temp_object; temp_object = replies[0]; replies.RemoveAt(0); var generatedAux = temp_object; } } } catch (Exception ex) { LogManager.GetCurrentClassLogger().Warn("Exception swallowed", ex); } _stackTraceCleanup = Environment.StackTrace; // Let GC clean up this stuff, leave name in case finalized is called conn = null; msg = null; // agent = null; // leave this reference queue = null; //replies = null; //leave this since we use it as a semaphore bindprops = null; }
public virtual void Bind(SaslRequest saslRequest) { if (saslRequest == null) { throw new ArgumentNullException(nameof(saslRequest)); } Hashtable saslBindProperties = null; using (var saslClient = CreateClient(saslRequest.SaslMechanism, saslRequest.AuthorizationId, DefaultSaslClientFactory.ProtocolLdap, Host, saslRequest.Credentials, saslBindProperties)) { if (saslClient == null) { throw new ArgumentException("Unsupported Sasl Authentication mechanism: " + saslRequest.SaslMechanism); } var constraints = saslRequest.Constraints ?? _defSearchCons; try { var bindProps = new BindProperties(LdapV3, saslRequest.AuthorizationId, "sasl", anonymous: false, bindProperties: saslBindProperties); var bindSemId = Connection.AcquireWriteSemaphore(); Connection.SetBindSemId(bindSemId); byte[] clientResponse = null; if (saslClient.HasInitialResponse) { clientResponse = saslClient.EvaluateChallenge(Array.Empty <byte>()); } while (!saslClient.IsComplete) { try { var replyBuf = SendLdapSaslBindRequest(clientResponse, saslClient.MechanismName, bindProps, constraints); if (replyBuf != null) { clientResponse = saslClient.EvaluateChallenge(replyBuf); } else { clientResponse = saslClient.EvaluateChallenge(Array.Empty <byte>()); } } catch (Exception ex) { throw new LdapException("Unexpected SASL error.", LdapException.Other, null, ex); } } } catch (Exception e) { throw new LdapException(e); } } }
private static void ShowModalInternal(BindProperties properties, Func <int, bool> action) { UIComponent uIComponent = UIView.library.Get(PANEL_ID); if (!(uIComponent is null) && uIComponent.objectUserData is Action <Dictionary <string, object>, Func <int, bool> > addAction) { addAction(properties.ToDictionary(), action); }
/// <summary> /// Send a request to the server. A Message class is created /// for the specified request which causes the message to be sent. /// The request is added to the list of messages being managed by /// this agent. /// </summary> /// <param name="conn"> /// the connection that identifies the server. /// </param> /// <param name="msg"> /// the LdapMessage to send. /// </param> /// <param name="timeOut"> /// the interval to wait for the message to complete or. /// <code>null</code> if infinite. /// </param> internal void SendMessage(Connection conn, LdapMessage msg, int timeOut, BindProperties bindProps) { // creating a messageInfo causes the message to be sent // and a timer to be started if needed. var message = new Message(msg, timeOut, conn, this, bindProps); _messages.Add(message); message.SendMessage(); // Now send message to server }
private BindProperties bindprops; // Bind properties if a bind request internal Message(LdapMessage msg, int mslimit, Connection conn, MessageAgent agent, LdapMessageQueue queue, BindProperties bindprops) { InitBlock(); this.msg = msg; this.conn = conn; this.agent = agent; this.queue = queue; this.mslimit = mslimit; msgId = msg.MessageID; this.bindprops = bindprops; }
private bool _waitForReplyRenamedField = true; // true if wait for reply internal Message(LdapMessage msg, int mslimit, Connection conn, MessageAgent agent, BindProperties bindprops) { _conn = conn ?? throw new ArgumentNullException(nameof(conn)); _stackTraceCreation = Environment.StackTrace; _replies = new MessageVector(5); Request = msg; MessageAgent = agent; _mslimit = mslimit; MessageId = msg.MessageId; _bindprops = bindprops; }
public static void ShowModal(BindProperties properties, Func <int, bool> action) { properties.showTextField = false; if (Dispatcher.mainSafe != Dispatcher.currentSafe) { ThreadHelper.dispatcher.Dispatch(() => ShowModalInternal(properties, action)); } else { ShowModalInternal(properties, action); } }
private BindProperties bindprops; // Bind properties if a bind request internal Message(LdapMessage msg, int mslimit, Connection conn, MessageAgent agent, LdapMessageQueue queue, BindProperties bindprops) { if (conn == null) { throw new ArgumentNullException(nameof(conn)); } _stackTraceCreation = Environment.StackTrace; InitBlock(); this.msg = msg; this.conn = conn; this.agent = agent; this.queue = queue; this.mslimit = mslimit; msgId = msg.MessageID; this.bindprops = bindprops; }
private IEnumerator Enqueue(BindProperties properties, Func <int, bool> callback) { yield return(0); lock (this) { if (m_currentCallback == null) { UIView.library.ShowModal(PANEL_ID); SetProperties(properties, callback); } else { string str = properties.ToString(); if (m_modalQueue.Where(x => x.First == str).Count() == 0) { m_modalQueue.Enqueue(Tuple.NewRef(ref str, ref properties, ref callback)); } } } }
private byte[] SendLdapSaslBindRequest(byte[] toWrite, string mechanism, BindProperties bindProps, LdapConstraints constraints) { constraints = constraints ?? _defSearchCons; var msg = new LdapSaslBindRequest(LdapV3, mechanism, constraints.GetControls(), toWrite); var queue = SendRequestToServer(msg, constraints.TimeLimit, null, bindProps); if (!(queue.GetResponse() is LdapResponse ldapResponse)) { throw new LdapException("Bind failure, no response received."); } var bindResponse = (RfcBindResponse)ldapResponse.Asn1Object.get_Renamed(1); lock (_responseCtlSemaphore) { _responseCtls = ldapResponse.Controls; } var serverCreds = bindResponse.ServerSaslCreds; var resultCode = ldapResponse.ResultCode; byte[] replyBuf = null; if (resultCode == LdapException.SaslBindInProgress || resultCode == LdapException.Success) { if (serverCreds != null) { replyBuf = serverCreds.ByteValue(); } } else { ldapResponse.ChkResultCode(); throw new LdapException("SASL Bind Error.", resultCode, null); } return(replyBuf); }
/// <summary> /// Send a request to the server. A Message class is created /// for the specified request which causes the message to be sent. /// The request is added to the list of messages being managed by /// this agent. /// </summary> /// <param name="conn"> /// the connection that identifies the server. /// </param> /// <param name="msg"> /// the LdapMessage to send. /// </param> /// <param name="timeOut"> /// the interval to wait for the message to complete or. /// <code>null</code> if infinite. /// </param> internal Task SendMessageAsync(Connection conn, LdapMessage msg, int timeOut, BindProperties bindProps, CancellationToken cancellationToken) { Debug.WriteLine(msg.ToString()); // creating a messageInfo causes the message to be sent // and a timer to be started if needed. var message = new Message(msg, timeOut, conn, this, bindProps); _messages.Add(message); return(message.SendMessageAsync(cancellationToken)); // Now send message to server }
private void SetProperties(BindProperties propertiesToSet, Func <int, bool> callback) { m_mainPanel.autoLayout = true; if (propertiesToSet.help_isArticle) { if (!Directory.Exists(propertiesToSet.help_fullPathName)) { LogUtils.DoErrorLog($"Invalid tutorial path! {propertiesToSet.help_fullPathName}"); Close(-1); return; } string fullText; if (File.Exists($"{propertiesToSet.help_fullPathName}{Path.DirectorySeparatorChar}texts_{KlyteLocaleManager.CurrentLanguageId}.txt")) { fullText = File.ReadAllText($"{propertiesToSet.help_fullPathName}{Path.DirectorySeparatorChar}texts_{KlyteLocaleManager.CurrentLanguageId}.txt"); } else if (File.Exists($"{propertiesToSet.help_fullPathName}{Path.DirectorySeparatorChar}texts.txt")) { fullText = File.ReadAllText($"{propertiesToSet.help_fullPathName}{Path.DirectorySeparatorChar}texts.txt"); } else { LogUtils.DoErrorLog($"Corrupted tutorial path! File \"texts.txt\" not found at folder {propertiesToSet.help_fullPathName}."); Close(-1); return; } string[] tutorialEntries = Regex.Split(fullText, "<BR>", RegexOptions.Multiline | RegexOptions.ECMAScript); int lastPage = tutorialEntries.Length - 1; int currentPage = Math.Max(0, Math.Min(lastPage, propertiesToSet.help_currentPage)); string targetImg = $"{propertiesToSet.help_fullPathName}{Path.DirectorySeparatorChar}{currentPage.ToString("D3")}.jpg"; string textureImagePath = File.Exists(targetImg) ? targetImg : null; string path = propertiesToSet.help_fullPathName; string feature = propertiesToSet.help_featureName; string[] formatEntries = propertiesToSet.help_formatsEntries; LogUtils.DoLog($"IMG: {targetImg}"); propertiesToSet = new BindProperties { icon = propertiesToSet.icon, title = string.Format(Locale.Get("K45_CMNS_HELP_FORMAT"), propertiesToSet.help_featureName, currentPage + 1, lastPage + 1), message = string.Format(tutorialEntries[currentPage], formatEntries), imageTexturePath = textureImagePath, showClose = true, showButton1 = currentPage != 0, textButton1 = "<<<\n" + Locale.Get("K45_CMNS_PREV"), showButton2 = true, textButton2 = Locale.Get("EXCEPTION_OK"), showButton3 = currentPage != lastPage, textButton3 = ">>>\n" + Locale.Get("K45_CMNS_NEXT"), }; callback = (x) => { if (x == 1) { ShowModalHelpAbsolutePath(path, feature, currentPage - 1, formatEntries); } if (x == 3) { ShowModalHelpAbsolutePath(path, feature, currentPage + 1, formatEntries); } return(true); }; } m_currentCallback = callback; m_properties.FindBinding("title").property.value = propertiesToSet.title; m_properties.FindBinding("icon").property.value = propertiesToSet.icon ?? CommonProperties.ModIcon; m_properties.FindBinding("showClose").property.value = propertiesToSet.showClose || !(propertiesToSet.showButton1 || propertiesToSet.showButton2 || propertiesToSet.showButton3 || propertiesToSet.showButton4); m_properties.FindBinding("message").property.value = propertiesToSet.message; m_properties.FindBinding("messageAlign").property.value = propertiesToSet.messageAlign; m_properties.FindBinding("showButton1").property.value = propertiesToSet.showButton1; m_properties.FindBinding("showButton2").property.value = propertiesToSet.showButton2; m_properties.FindBinding("showButton3").property.value = propertiesToSet.showButton3; m_properties.FindBinding("showButton4").property.value = propertiesToSet.showButton4; m_properties.FindBinding("showButton5").property.value = propertiesToSet.showButton5; m_properties.FindBinding("textButton1").property.value = propertiesToSet.textButton1 ?? ""; m_properties.FindBinding("textButton2").property.value = propertiesToSet.textButton2 ?? ""; m_properties.FindBinding("textButton3").property.value = propertiesToSet.textButton3 ?? ""; m_properties.FindBinding("textButton4").property.value = propertiesToSet.textButton4 ?? ""; m_properties.FindBinding("textButton5").property.value = propertiesToSet.textButton5 ?? ""; m_textField.isVisible = propertiesToSet.showTextField; m_textField.text = propertiesToSet.defaultTextFieldContent ?? ""; if (m_dropDown == null) { KlyteMonoUtils.CreateUIElement(out UIPanel DDpanel, m_mainPanel.transform); DDpanel.maximumSize = new Vector2(m_boxText.minimumSize.x - 10, 40); DDpanel.anchor = UIAnchorStyle.CenterHorizontal; DDpanel.zOrder = m_textField.zOrder + 1; DDpanel.autoLayout = true; m_dropDown = UIHelperExtension.CloneBasicDropDownNoLabel(new string[0], (x) => { }, DDpanel); m_dropDown.name = DD_INPUT_ID; m_dropDown.minimumSize = new Vector2(m_boxText.minimumSize.x - 10, 25); m_dropDown.size = new Vector2(m_boxText.minimumSize.x - 10, 40); m_dropDown.autoSize = false; m_dropDown.processMarkup = true; m_dropDown.verticalAlignment = UIVerticalAlignment.Middle; m_dropDown.horizontalAlignment = UIHorizontalAlignment.Left; } m_dropDown.parent.isVisible = propertiesToSet.showDropDown; m_dropDown.items = propertiesToSet.dropDownOptions?.Split(BindProperties.DD_OPTIONS_SEPARATOR.ToCharArray()) ?? new string[0]; m_dropDown.selectedIndex = propertiesToSet.dropDownCurrentSelection; m_textureSprite.size = default; if (!propertiesToSet.imageTexturePath.IsNullOrWhiteSpace()) { if (File.Exists(propertiesToSet.imageTexturePath)) { byte[] fileData = File.ReadAllBytes(propertiesToSet.imageTexturePath); var tex = new Texture2D(2, 2); if (tex.LoadImage(fileData)) { m_textureSupContainer.isVisible = true; m_textureSprite.texture = tex; m_textureSprite.size = new Vector2(tex.width, tex.height); if (m_textureSprite.height > 400) { float proportion = m_textureSprite.width / m_textureSprite.height; m_textureSprite.height = 400; m_textureSprite.width = proportion * 400; } m_textureSupContainer.height = m_textureSprite.size.y; } else { LogUtils.DoWarnLog($"Failed loading image: {propertiesToSet.imageTexturePath}"); m_textureSupContainer.isVisible = false; } } } else { m_textureSprite.texture = null; m_textureSupContainer.isVisible = false; } float width; if (propertiesToSet.useFullWindowWidth || m_textureSprite.width > 800) { width = UIView.GetAView().fixedWidth - 100; if (width < m_textureSprite.width) { float proportion = m_textureSprite.width / m_textureSprite.height; m_textureSprite.width = width; m_textureSprite.height = width / proportion; } } else { width = 800; } m_mainPanel.width = width; m_closeButton.area = new Vector4(width - 37, 3, 32, 32); width -= m_mainPanel.padding.horizontal; m_titleContainer.width = width; m_boxText.width = width; m_buttonSupContainer.width = width; m_textureSupContainer.width = width; m_mainPanel.autoLayout = !propertiesToSet.showDropDown; }
public void Awake() { BindControls(); m_properties = m_mainPanel.GetComponent <BindPropertyByKey>(); #region Events bindings BindEvents(); KlyteMonoUtils.LimitWidthAndBox(m_title, out UIPanel boxContainerTitle); boxContainerTitle.anchor = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.Top; boxContainerTitle.relativePosition = new Vector3(0, 2); //This action allow centralize all calls to single object, coming from any mod m_mainPanel.objectUserData = new Action <Dictionary <string, object>, Func <int, bool> >((Dictionary <string, object> properties, Func <int, bool> callback) => StartCoroutine(Enqueue(BindProperties.FromDictionary(properties), callback))); m_mainPanel.stringUserData = VERSION; m_closeButton.eventClicked += (x, y) => Close(0); m_mainPanel.enabled = true; #endregion }
public void Awake() { m_mainPanel = GetComponent <UIPanel>(); m_titleContainer = m_mainPanel.Find <UIPanel>("TitleContainer"); m_title = m_titleContainer.Find <UILabel>("Title"); m_modIcon = m_titleContainer.Find <UISprite>("ModIcon"); m_closeButton = m_titleContainer.Find <UIButton>("CloseButton"); m_boxText = m_mainPanel.Find <UILabel>("BoxText"); m_buttonSupContainer = m_mainPanel.Find <UIPanel>("ButtonSupContainer"); m_button1 = m_mainPanel.Find <UIButton>("ButtonAction1"); m_button2 = m_mainPanel.Find <UIButton>("ButtonAction2"); m_button3 = m_mainPanel.Find <UIButton>("ButtonAction3"); m_button4 = m_mainPanel.Find <UIButton>("ButtonAction4"); m_button5 = m_mainPanel.Find <UIButton>("ButtonAction5"); m_textField = m_mainPanel.Find <UITextField>(TEXT_INPUT_ID); m_textureSupContainer = m_mainPanel.Find <UIPanel>("TextureSupContainer"); m_textureSprite = m_mainPanel.Find <UITextureSprite>("TextureSprite"); m_properties = m_mainPanel.GetComponent <BindPropertyByKey>(); #region Events bindings m_mainPanel.enabled = false; m_button1.eventClicked += (x, y) => OnButton1(); m_button2.eventClicked += (x, y) => OnButton2(); m_button3.eventClicked += (x, y) => OnButton3(); m_button4.eventClicked += (x, y) => OnButton4(); m_button5.eventClicked += (x, y) => OnButton5(); KlyteMonoUtils.LimitWidthAndBox(m_title, out UIPanel boxContainerTitle); boxContainerTitle.anchor = UIAnchorStyle.CenterHorizontal | UIAnchorStyle.Top; boxContainerTitle.relativePosition = new Vector3(0, 2); //This action allow centralize all calls to single object, coming from any mod m_mainPanel.objectUserData = new Action <Dictionary <string, object>, Func <int, bool> >((Dictionary <string, object> properties, Func <int, bool> callback) => StartCoroutine(Enqueue(BindProperties.FromDictionary(properties), callback))); m_mainPanel.stringUserData = VERSION; m_closeButton.eventClicked += (x, y) => Close(0); m_mainPanel.enabled = true; #endregion }