public static double newtonDecent(func func, dfunc dfunc)
        {
            double x0    = 0;
            double x1    = x0 + 1;
            double step  = 0.0002;
            int    i     = 0;
            bool   first = true;

            while (Math.Abs(func.Invoke(x1) - func.Invoke(x0)) > 0.00000001)
            {
                if (!first)
                {
                    x0    = x1;
                    first = false;
                }
                x1 = x0 + step * dfunc.Invoke(x1);
                if (func.Invoke(x1) < func.Invoke(x0))
                {
                    step /= 2;
                }
                else
                {
                    step *= 2;
                }
                i++;
            }
            return(func.Invoke(x1));
        }
예제 #2
0
 public virtual void CallBack(object o)
 {
     if (Func != null)
     {
         Func.Invoke();
     }
 }
예제 #3
0
 public static void catch_invoke <T1, T2, T3>(func <T1, T2, T3> handler, T1 p1, T2 p2, T3 p3)
 {
     try
     {
         handler?.Invoke(p1, p2, p3);
     }
     catch (System.Exception ec)
     {
         Trace.Fail(ec.Message, ec.StackTrace);
     }
 }
예제 #4
0
 public static void catch_invoke(func handler)
 {
     try
     {
         handler?.Invoke();
     }
     catch (System.Exception ec)
     {
         Trace.Fail(ec.Message, ec.StackTrace);
     }
 }
예제 #5
0
        protected async Task PerformActionWithoutLoader(func <Task> func, bool showPopup = true)
        {
            try
            {
                await func?.Invoke();
            }
            catch (UserNotAuthorizedException ex)
            {
                Log.Warn(ex);

                if (showPopup && !string.IsNullOrEmpty(ex.Error?.Message))
                {
                    NavigateService.Instance.NavigateToLogin();
                }
            }
            catch (InternalServerException ex)
            {
                Log.Warn(ex);

                if (showPopup && !string.IsNullOrEmpty(ex.Error?.Message))
                {
                    ShowNotification(ex.Error.Message, null, null, ApplicationConstants.ButtonWarningColor);
                }
            }
            catch (ApiDataException ex)
            {
                Log.Warn(ex);
                if (showPopup && !string.IsNullOrEmpty(ex.Error?.Message))
                {
                    ShowNotification(ex.Error.Message, null, null, ApplicationConstants.ButtonWarningColor);
                }
            }
            catch (TaskCanceledException ex)
            {
                Log.Warn(ex);
            }
            catch (PrinterLayerException ex)
            {
                Log.Warn(ex);
                if (showPopup)
                {
                    ShowNotification(ApplicationConstants.NoPrinterFound, null, null, ApplicationConstants.ButtonWarningColor);
                }
            }
            catch (Exception ex)
            {
                Log.Info(Message, ex);
                if (showPopup)
                {
                    ShowNotification(ApplicationConstants.SomethingBadHappned, null, null, ApplicationConstants.ButtonWarningColor);
                }
            }
        }
예제 #6
0
    private IEnumerator AnimateNormal(string obj, string an, func cont = null, bool k = false)
    {
        Animation anim = GameObject.Find(obj).GetComponent <Animation>();

        anim.CrossFade(an);
        if (k)
        {
            while (anim.isPlaying)
            {
                yield return(null);
            }
            yield return(new WaitForSeconds(0.5f));

            cont.Invoke();
        }
    }
예제 #7
0
 /// <summary>
 /// Generic Method for Load data to/from API depending on function passed as parameter
 /// </summary>
 /// <param name="func"></param>
 protected async void PerformAction(func <Task> func, string elementNameToSetFocus = "")
 {
     LoadingService.ShowLoadingStatus(true);
     try
     {
         if (func != null)
         {
             await func?.Invoke();
         }
     }
     catch (UserNotAuthorizedException ex)
     {
         Log.Warn(ex);
         NavigateService.Instance.NavigateToLogin();
     }
     catch (InternalServerException ex)
     {
         if (!string.IsNullOrEmpty(ex.Error?.Message))
         {
             Log.Warn(ex);
             ShowNotification(ex.Error.Message,
                              () => { SetFocusOnControl(elementNameToSetFocus); },
                              () => { SetFocusOnControl(elementNameToSetFocus); },
                              ApplicationConstants.ButtonWarningColor);
         }
     }
     catch (ApiDataException ex)
     {
         if (!string.IsNullOrEmpty(ex.Error?.Message))
         {
             Log.Warn(ex);
             ShowNotification(ex.Error.Message,
                              () => { SetFocusOnControl(elementNameToSetFocus); },
                              () => { SetFocusOnControl(elementNameToSetFocus); },
                              ApplicationConstants.ButtonWarningColor);
         }
     }
     catch (TaskCanceledException ex)
     {
         Log.Warn(ex);
         ShowNotification(ApplicationConstants.ApiTimeoutMessage,
                          () => { SetFocusOnControl(elementNameToSetFocus); },
                          () => { SetFocusOnControl(elementNameToSetFocus); },
                          ApplicationConstants.ButtonWarningColor);
     }
     catch (PrinterLayerException ex)
     {
         Log.Warn(ex);
         ShowNotification(ApplicationConstants.NoPrinterFound,
                          () => { SetFocusOnControl(elementNameToSetFocus); },
                          () => { SetFocusOnControl(elementNameToSetFocus); },
                          ApplicationConstants.ButtonWarningColor);
     }
     catch (Exception ex)
     {
         Log.Info(Message, ex);
         ShowNotification(ApplicationConstants.SomethingBadHappned,
                          () => { SetFocusOnControl(elementNameToSetFocus); },
                          () => { SetFocusOnControl(elementNameToSetFocus); },
                          ApplicationConstants.ButtonWarningColor);
     }
     finally
     {
         LoadingService.ShowLoadingStatus(false);
         SetFocusOnControl(elementNameToSetFocus);
     }
 }
예제 #8
0
 public override void OnPointerDown(PointerEventData eventData)
 {
     base.OnPointerDown(eventData);
     Debug.Log(eventData);
     func?.Invoke(gameObject);
 }