Ejemplo n.º 1
0
        private bool OnWindowCreated(byte[] newVal)
        {
            if (ElementWdwPtr.Read <int>() == 0)
            {
                return(false);
            }

            ElementIdPtr        = SMProcess[SM17Natives.TElWind.ElementIdPtr];
            CurrentConceptIdPtr = SMProcess[SM17Natives.Globals.CurrentConceptIdPtr];
            CurrentRootIdPtr    = SMProcess[SM17Natives.Globals.CurrentRootIdPtr];
            CurrentHookIdPtr    = SMProcess[SM17Natives.Globals.CurrentHookIdPtr];

            ElementIdPtr.RegisterValueChangedEventHandler <int>(OnElementChangedInternal);

            LastElementId = CurrentElementId;

            // TODO: ??? This somehow gets delayed and causes all sorts of troubles
            //OnElementChanged?.Invoke(new SMDisplayedElementChangedArgs(SMA.Instance,
            //                                                   CurrentElement,
            //                                                   null));

            OnAvailable?.Invoke();

            return(true);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public void Dispose()
        {
            LogTo.Debug("Cleaning up {Name}", GetType().Name);

            _controlGroup?.Dispose();
            SMMainWdwPtr?.Dispose();
            ElementWdwPtr?.Dispose();
            ElementIdPtr?.Dispose();
            CurrentConceptIdPtr?.Dispose();
            CurrentConceptGroupIdPtr?.Dispose();
            CurrentRootIdPtr?.Dispose();
            CurrentHookIdPtr?.Dispose();
            LearningModePtr?.Dispose();

            SMMainWdwPtr             = null;
            ElementWdwPtr            = null;
            ElementIdPtr             = null;
            CurrentConceptIdPtr      = null;
            CurrentConceptGroupIdPtr = null;
            CurrentRootIdPtr         = null;
            CurrentHookIdPtr         = null;
            LearningModePtr          = null;

            LogTo.Debug("Cleaning up {Name}... Done", GetType().Name);
        }
Ejemplo n.º 3
0
        public bool SetText(IControl control,
                            string text)
        {
            try
            {
                //SetTextMethod(ElementWdwPtr.Read<IntPtr>(),
                //              control.Id + 1,
                //              new DelphiUString(text));

                //return true;

                return(Core.Natives.ElWind.SetText(ElementWdwPtr.Read <IntPtr>(),
                                                   control,
                                                   text));
            }
            catch (Win32Exception ex)
            {
                LogTo.Warning(ex, "Failed to read ElementWdwPtr");
                return(false);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex, "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 4
0
        public bool GoToElement(int elementId)
        {
            try
            {
                var elem = Core.SM.Registry.Element[elementId];

                if (elem == null || elem.Deleted)
                {
                    return(false);
                }

                return(Core.Natives.ElWind.GoToElement(ElementWdwPtr.Read <IntPtr>(),
                                                       elementId));
            }
            catch (Win32Exception ex)
            {
                LogTo.Warning(ex, "Failed to read ElementWdwPtr");
                return(false);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex, "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 5
0
        public bool GoToElement(int elementId)
        {
            bool ret = false;

            try
            {
                var elem = SMA.SMA.Instance.Registry.Element[elementId];

                if (elem == null || elem.Deleted)
                {
                    return(false);
                }

                /*ret = GoToMethod(ElementWdwPtr.Read<IntPtr>(),
                 *               elementId,
                 *               SMProcess.ThreadFactory.MainThread);*/

                ret = SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.ElWdwGoToElement,
                                                                  ElementWdwPtr.Read <IntPtr>(),
                                                                  elementId) == 1;

                return(ret);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(ret);
            }
        }
Ejemplo n.º 6
0
        private bool OnWindowCreated(byte[] newVal)
        {
            if (ElementWdwPtr.Read <int>() == 0)
            {
                return(false);
            }

            ElementIdPtr             = SMProcess[Core.Natives.ElWind.ElementIdPtr];
            LimitChildrenCountPtr    = SMProcess[Core.Natives.Globals.LimitChildrenCountPtr];
            CurrentConceptIdPtr      = SMProcess[Core.Natives.Globals.CurrentConceptIdPtr];
            CurrentConceptGroupIdPtr = SMProcess[Core.Natives.Globals.CurrentConceptGroupIdPtr];
            CurrentRootIdPtr         = SMProcess[Core.Natives.Globals.CurrentRootIdPtr];
            CurrentHookIdPtr         = SMProcess[Core.Natives.Globals.CurrentHookIdPtr];
            LearningModePtr          = SMProcess[Core.Natives.ElWind.LearningModePtr];

            ElementIdPtr.RegisterValueChangedEventHandler <int>(OnElementChangedInternal);

            LastElementId = CurrentElementId;

            // TODO: ??? This somehow gets delayed and causes all sorts of troubles
            //OnElementChanged?.Invoke(new SMDisplayedElementChangedEventArgs(SMA.Instance,
            //                                                   CurrentElement,
            //                                                   null));

            IsAvailable = true;

            OnAvailableInternal?.Invoke();

            OnAvailable?.InvokeRemote(
                nameof(OnAvailable),
                h => OnAvailable -= h
                );

            return(true);
        }
Ejemplo n.º 7
0
        private async Task OnSMStartedEvent(object sender,
                                            SMProcessArgs e)
        {
            LogTo.Debug($"Initializing {GetType().Name}");

            await Task.Run(() =>
            {
                ElementWdwPtr = SMProcess[SM17Natives.TElWind.InstancePtr];
                ElementWdwPtr.RegisterValueChangedEventHandler <int>(OnWindowCreated);
            });
        }
Ejemplo n.º 8
0
        public bool ApplyTemplate(int templateId, TemplateUseMode applyMode = TemplateUseMode.Apply)
        {
            var template = Core.SM.Registry.Template[templateId];

            if (template == null || template.Empty)
            {
                return(false);
            }

            return(Core.Natives.ElWind.ApplyTemplate(ElementWdwPtr.Read <IntPtr>(), templateId, applyMode));
        }
Ejemplo n.º 9
0
        private async Task OnSMStartingAsync(object sender,
                                             SMEventArgs e)
        {
            LogTo.Debug("Initializing {Name}", GetType().Name);

            // TODO: Why ?
            await Task.Run(() =>
            {
                SMMainWdwPtr  = SMProcess[Core.Natives.SMMain.InstancePtr];
                ElementWdwPtr = SMProcess[Core.Natives.ElWind.InstancePtr];
                ElementWdwPtr.RegisterValueChangedEventHandler <int>(OnWindowCreated);
            }).ConfigureAwait(false);
        }
Ejemplo n.º 10
0
 public int GenerateCloze(bool memorize = true, bool askUserToScheduleInterval = false)
 {
     try
     {
         return(Core.Natives.ElWind.GenerateCloze(
                    ElementWdwPtr.Read <IntPtr>(),
                    memorize,
                    askUserToScheduleInterval));
     }
     catch (Exception ex)
     {
         LogTo.Error(ex, "Native method call threw an exception.");
         return(-1);
     }
 }
Ejemplo n.º 11
0
        public bool NextElementInLearningQueue()
        {
            try
            {
                SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.ElWdwNextElementInLearningQueue,
                                                            ElementWdwPtr.Read <IntPtr>());

                return(true);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 12
0
 public int AppendAndAddElementFromText(ElementType elementType,
                                        string elementDesc)
 {
     try
     {
         return(SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.AppendAndAddElementFromText,
                                                            ElementWdwPtr.Read <IntPtr>(),
                                                            (byte)elementType,
                                                            new DelphiUString(elementDesc)));
     }
     catch (Exception ex)
     {
         LogTo.Error(ex,
                     "SM internal method call threw an exception.");
         return(-1);
     }
 }
Ejemplo n.º 13
0
 public bool NextElementInLearningQueue()
 {
     try
     {
         return(Core.Natives.ElWind.ShowNextElementInLearningQueue(ElementWdwPtr.Read <IntPtr>()));
     }
     catch (Win32Exception ex)
     {
         LogTo.Warning(ex, "Failed to read ElementWdwPtr");
         return(false);
     }
     catch (Exception ex)
     {
         LogTo.Error(ex, "SM internal method call threw an exception.");
         return(false);
     }
 }
Ejemplo n.º 14
0
        public bool Done()
        {
            try
            {
                //return DoneMethod(ElementWdwPtr.Read<IntPtr>(),
                //                  SMProcess.ThreadFactory.MainThread);

                return(SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.ElWdwDone,
                                                                   ElementWdwPtr.Read <IntPtr>()) == 1);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 15
0
 public bool SetElementState(ElementDisplayState state)
 {
     try
     {
         return(Core.Natives.ElWind.SetElementState(ElementWdwPtr.Read <IntPtr>(), state));
     }
     catch (Win32Exception ex)
     {
         LogTo.Warning(ex, "Failed to read ElementWdwPtr");
         return(false);
     }
     catch (Exception ex)
     {
         LogTo.Error(ex, "SM internal method call threw an exception.");
         return(false);
     }
 }
Ejemplo n.º 16
0
        public bool SetElementState(int state)
        {
            try
            {
                SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.ElWdwSetElementState,
                                                            ElementWdwPtr.Read <IntPtr>(),
                                                            state);

                return(true);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 17
0
        public bool PostponeRepetition(int interval)
        {
            try
            {
                SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.PostponeRepetition,
                                                            ElementWdwPtr.Read <IntPtr>(),
                                                            interval);

                return(true);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 18
0
 public bool PostponeRepetition(int interval)
 {
     try
     {
         return(Core.Natives.ElWind.PostponeRepetition(ElementWdwPtr.Read <IntPtr>(),
                                                       interval));
     }
     catch (Win32Exception ex)
     {
         LogTo.Warning(ex, "Failed to read ElementWdwPtr");
         return(false);
     }
     catch (Exception ex)
     {
         LogTo.Error(ex, "SM internal method call threw an exception.");
         return(false);
     }
 }
Ejemplo n.º 19
0
 public bool AddElementFromText(string elementDesc)
 {
     try
     {
         return(Core.Natives.ElWind.AddElementFromText(ElementWdwPtr.Read <IntPtr>(),
                                                       elementDesc));
     }
     catch (Win32Exception ex)
     {
         LogTo.Warning(ex, "Failed to read ElementWdwPtr");
         return(false);
     }
     catch (Exception ex)
     {
         LogTo.Error(ex, "SM internal method call threw an exception.");
         return(false);
     }
 }
Ejemplo n.º 20
0
 public int AppendElement(ElementType elementType)
 {
     try
     {
         return(Core.Natives.ElWind.AppendElement(ElementWdwPtr.Read <IntPtr>(),
                                                  elementType));
     }
     catch (Win32Exception ex)
     {
         LogTo.Warning(ex, "Failed to read ElementWdwPtr");
         return(-1);
     }
     catch (Exception ex)
     {
         LogTo.Error(ex, "SM internal method call threw an exception.");
         return(-1);
     }
 }
Ejemplo n.º 21
0
 public string GetText(IControl control)
 {
     try
     {
         return(Core.Natives.ElWind.GetText(ElementWdwPtr.Read <IntPtr>(),
                                            control));
     }
     catch (Win32Exception ex)
     {
         LogTo.Warning(ex, "Failed to read ElementWdwPtr");
         return(null);
     }
     catch (Exception ex)
     {
         LogTo.Error(ex, "SM internal method call threw an exception.");
         return(null);
     }
 }
Ejemplo n.º 22
0
        public bool QuitSMUpdateLock()
        {
            try
            {
                SM17Natives.Instance.ElWind.QuitUpdateLock.Invoke(
                    ElementWdwPtr.Read <IntPtr>(),
                    true
                    );

                return(true);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 23
0
        public bool ForceRepetitionAndResume(int interval,
                                             bool adjustPriority)
        {
            try
            {
                SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.ForceRepetitionAndResume,
                                                            ElementWdwPtr.Read <IntPtr>(),
                                                            interval,
                                                            adjustPriority);

                return(true);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 24
0
        public bool AddElementFromText(string elementDesc)
        {
            try
            {
                //return AddElementFromTextFunc(ElementWdwPtr.Read<IntPtr>(),
                //                              new DelphiUString(elementDesc),
                //                              SMProcess.ThreadFactory.MainThread) > 0;

                return(SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.ElWdwAddElementFromText,
                                                                   ElementWdwPtr.Read <IntPtr>(),
                                                                   new DelphiUString(elementDesc)) > 0);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 25
0
        public bool QuitSMUpdateLock()
        {
            try
            {
                Core.Natives.ElWind.QuitUpdateLock.Invoke(ElementWdwPtr.Read <IntPtr>(),
                                                          true);

                return(true);
            }
            catch (Win32Exception ex)
            {
                LogTo.Warning(ex, "Failed to read ElementWdwPtr");
                return(false);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex, "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 26
0
 public bool ForceRepetition(int interval,
                             bool adjustPriority)
 {
     try
     {
         return(Core.Natives.ElWind.ForceRepetitionExt(ElementWdwPtr.Read <IntPtr>(),
                                                       interval,
                                                       adjustPriority));
     }
     catch (Win32Exception ex)
     {
         LogTo.Warning(ex, "Failed to read ElementWdwPtr");
         return(false);
     }
     catch (Exception ex)
     {
         LogTo.Error(ex, "SM internal method call threw an exception.");
         return(false);
     }
 }
Ejemplo n.º 27
0
        public int AppendElement(ElementType elementType)
        {
            try
            {
                //return AppendElementFunc(ElementWdwPtr.Read<IntPtr>(),
                //                         (byte)elementType,
                //                         0, // ??
                //                         SMProcess.ThreadFactory.MainThread);

                return(SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.ElWdwAppendElement,
                                                                   ElementWdwPtr.Read <IntPtr>(),
                                                                   (byte)elementType,
                                                                   0 /* ?? */));
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(-1);
            }
        }
Ejemplo n.º 28
0
        public bool SetText(IControl control,
                            string text)
        {
            try
            {
                //SetTextMethod(ElementWdwPtr.Read<IntPtr>(),
                //              control.Id + 1,
                //              new DelphiUString(text));

                //return true;

                return(SMA.SMA.Instance.SMMgmt.ExecuteOnMainThread(NativeMethod.ElWdwSetText,
                                                                   ElementWdwPtr.Read <IntPtr>(),
                                                                   control.Id + 1,
                                                                   new DelphiUString(text)) == 1);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "SM internal method call threw an exception.");
                return(false);
            }
        }
Ejemplo n.º 29
0
 private void OnSMStartedEvent(object sender,
                               SMProcessArgs e)
 {
     ElementWdwPtr = SMProcess[SMNatives.TElWind.InstancePtr];
     ElementWdwPtr.RegisterValueChangedEventHandler <int>(OnWindowCreated);
 }