Ejemplo n.º 1
0
            private void incrSuffix(ref StSuffix active)
            {
                int origNodeId, begin, end;

                origNodeId = active.OriginNode.Id;
                begin      = active.BeginIndex;
                end        = active.EndIndex;

                if (active.OriginNode.IsRoot())
                {
                    active.BeginIndex++;
                }
                else
                {
                    active.OriginNode = active.OriginNode.SuffixNode;
                }
                active.Canonicalize();

                if (origNodeId != active.OriginNode.Id ||
                    begin != active.BeginIndex ||
                    end != active.EndIndex)
                {
                    StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                                         "  incrSuffix: Active suffix changed from {0:s} to {1:s}",
                                         StSuffix.ToSuffixString(origNodeId, begin, end),
                                         StSuffix.ToSuffixString(active.OriginNode.Id, active.BeginIndex, active.EndIndex)));
                }
            }
Ejemplo n.º 2
0
 private void setSuffixLink(StNode node, StNode suffixNode)
 {
     if ((node != null) && (node != root))
     {
         if (node.SuffixNode == null)
         {
             StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                                  "  New suffix link from N{0:d} to N{1:d}",
                                  node.Id, suffixNode.Id));
         }
         else
         {
             if (node.SuffixNode.Id == suffixNode.Id)
             {
                 StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                                      "  Suffix link (N{0:d} to N{1:d}) retaining same value",
                                      node.Id, node.SuffixNode.Id));
             }
             else
             {
                 StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                                      "  Suffix link (N{0:d} to N{1:d}) set to new value (N{0:d} to N{2:d})",
                                      node.Id, node.SuffixNode.Id, suffixNode.Id));
             }
         }
         node.SuffixNode = suffixNode;
     }
 }
Ejemplo n.º 3
0
 // Rule 1: Try to find matching edge for the parent node.
 private ExtensionResult extendSuffixByRuleOne(
     ref StSuffix active, ref StNode parentNode, int endIndex)
 {
     if (active.IsExplicit)
     {
         StEdge edge = active.OriginNode.GetChildEdge(text[endIndex]);
         if (edge != null && edge.IsSet())
         {
             return(ExtensionResult.Done);
         }
     }
     else    // active suffix is implicit
     {
         StEdge edge = active.OriginNode.GetChildEdge(text[active.BeginIndex]);
         int    span = active.EndIndex - active.BeginIndex;
         if (text[edge.BeginIndex + span + 1] == text[endIndex])
         {
             return(ExtensionResult.Done);
         }
         StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                              "  Rule #1: About to split edge E{0:d} (\"{1:s}\") at suffix {2:s}",
                              edge.Id, edge.GetText(), active.ToString()));
         parentNode = edge.Split(active);
     }
     return(ExtensionResult.NotDone);
 }
Ejemplo n.º 4
0
 internal virtual void SetHook(int hookId, StUtil.Native.Internal.NativeCallbacks.HookProc callback)
 {
     hHook = SetHookInternal(hookId, callback);
     if (hHook.ToInt32() == 0)
     {
         throw new System.ComponentModel.Win32Exception();
     }
 }
Ejemplo n.º 5
0
 protected override IntPtr SetHookInternal(int hookId, StUtil.Native.Internal.NativeCallbacks.HookProc callback)
 {
     return StUtil.Native.Internal.NativeMethods.SetWindowsHookEx(
         hookId,
         callback,
         Process.GetCurrentProcess().MainModule.BaseAddress,
         0);
 }
 private void DispatchMessage(StUtil.Native.Internal.NativeEnums.WM message, IntPtr wParam, IntPtr lParam)
 {
     if (DispatchMethod == MessageDispatchMethod.Post)
     {
         StUtil.Native.Internal.NativeMethods.PostMessage(Handle, (int)message, wParam, lParam);
     }
     else
     {
         StUtil.Native.Internal.NativeMethods.SendMessage(Handle, (int)message, wParam, lParam);
     }
 }
Ejemplo n.º 7
0
            // Rule 2: Create a new edge and add it to the tree at the parent's position.
            //     Part of this is inserting the new edge into the hash table,
            //     and creating a suffix link to the new node from the last one visited.
            private void extendSuffixByRuleTwo(
                ref StSuffix active, StNode parentNode, ref StNode prevParentNode, int endIndex)
            {
                StEdge newEdge = new StEdge(this, parentNode, endIndex, this.text.Length - 1);

                newEdge.Add();
                StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                                     "  Rule #2: New edge E{0:d} (\"{1:s}\") connects N{2:d} (old parent) to N{3:d} (new child)",
                                     newEdge.Id,
                                     newEdge.GetText(),
                                     newEdge.ParentNode.Id,
                                     newEdge.ChildNode.Id
                                     ));
                setSuffixLink(prevParentNode, parentNode);
                prevParentNode = parentNode;
            }
Ejemplo n.º 8
0
            public SuffixTree(string text)
            {
                this.text = text;
                this.root = new StNode(this, null);

                StUtil.WriteLine(StVerbosityLevel.Verbose, "Creating the active (longest proper) suffix pointer");
                StSuffix active = new StSuffix(this, root, 0, InfiniteIndex);

                for (int endIndex = 0; endIndex < text.Length; endIndex++)
                {
                    StUtil.WriteLine(StVerbosityLevel.Verbose, this.ToString());
                    StUtil.WriteLine(StVerbosityLevel.Verbose, String.Format(
                                         "Calling extendSuffixes() with endIndex = {0:d} ('{1:c}') and active suffix = {2:s}",
                                         endIndex, text[endIndex], active.ToString()));
                    extendSuffixes(ref active, endIndex);
                }
                StUtil.Write(StVerbosityLevel.Normal, this.ToString());
            }
Ejemplo n.º 9
0
            public StNode Split(StSuffix s)
            {
                Remove();
                StEdge newEdge = new StEdge(tree, s.OriginNode, BeginIndex, BeginIndex + s.Span);

                newEdge.Add();
                newEdge.ChildNode.SuffixNode = s.OriginNode;
                BeginIndex += s.Span + 1;
                ParentNode  = newEdge.ChildNode;
                Add();
                StUtil.WriteLine(StVerbosityLevel.Normal, String.Format(
                                     "  Split E{0:d} into E{1:d} + E{0:d} = \"{2:s}\" + \"{3:s}\"",
                                     Id, newEdge.Id,
                                     newEdge.GetText(),
                                     this.GetText()
                                     ));
                return(newEdge.ChildNode);
            }
Ejemplo n.º 10
0
            public void Canonicalize()
            {
                if (IsImplicit)
                {
                    bool          haveValuesChanged = false;
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("  Canonicalize: Entering");
                    // sb.AppendLine(tree.ToString());

                    int origNodeId, begin, end;
                    origNodeId = this.OriginNode.Id;
                    begin      = this.beginIndex;
                    end        = this.endIndex;

                    StEdge edge = OriginNode.GetChildEdge(tree.Text[BeginIndex]);
                    while (edge.Span <= Span)
                    {
                        sb.Append(String.Format(
                                      "    Canonicalize: Active suffix changed from {0:s}",
                                      ToSuffixString(origNodeId, begin, end)));
                        this.beginIndex  += edge.Span + 1;
                        this.OriginNode   = edge.ChildNode;
                        haveValuesChanged = true;
                        sb.AppendLine(String.Format(" to {0:s}",
                                                    ToSuffixString(OriginNode.Id, beginIndex, endIndex)));
                        if (Span >= 0)
                        {
                            edge = edge.ChildNode.GetChildEdge(tree.Text[BeginIndex]);
                        }
                    }
                    sb.AppendLine("  Canonicalize: Exiting");
                    if (haveValuesChanged)
                    {
                        StUtil.Write(StVerbosityLevel.Verbose, sb.ToString());
                    }
                }
            }
Ejemplo n.º 11
0
 protected abstract IntPtr SetHookInternal(int hookId, StUtil.Native.Internal.NativeCallbacks.HookProc callback);
Ejemplo n.º 12
0
 /// <summary>
 /// Sets the state color of the progress bar.
 /// </summary>
 /// <param name="control">The control.</param>
 /// <param name="state">The state.</param>
 public static void SetState(this ProgressBar control, StUtil.Native.Internal.NativeEnums.ProgressBarState state)
 {
     StUtil.Native.Internal.NativeMethods.SendMessage(control.Handle, (int)StUtil.Native.Internal.NativeEnums.PBM.PBM_SETSTATE, new IntPtr((int)state), IntPtr.Zero);
 }
Ejemplo n.º 13
0
 public static void WriteLine(StVerbosityLevel v, string message)
 {
     StUtil.Write(v, message + Environment.NewLine);
 }
Ejemplo n.º 14
0
 // For debugging.  Currently unused
 public static void Exiting()
 {
     TraceDepth--;
     Console.WriteLine(Indentation + String.Format("Exiting {0:s}....", StUtil.GetCurrentMethodName(2)));
 }
Ejemplo n.º 15
0
 // For debugging.  Currently unused
 public static void Entering()
 {
     Console.WriteLine(Indentation + String.Format("Entering {0:s}....", StUtil.GetCurrentMethodName(2)));
     TraceDepth++;
 }
Ejemplo n.º 16
0
        private void provider_ProcessDownloads(object sender, StUtil.Generic.EventArgs<IEnumerable<Download>> e)
        {
            DownloadProvider provider = (DownloadProvider)sender;
            var downloads = e.Value.Select(dl => (PreparedDownload)Activator.CreateInstance(provider.PreparedDownloadType, dl)).ToArray();
            DownloadsAdded.RaiseEvent(this, downloads);

            foreach (var dl in downloads)
            {
                dl.StateChanged += dl_StateChanged;
                registered.Add(dl);
                try
                {
                    dl.State = DownloadState.Processing;
                    dl.Prepare(DownloadDirectory).ContinueWith(t =>
                    {
                        if (t.IsFaulted)
                        {
                            dl.LastError = t.Exception.InnerException ?? t.Exception;
                            dl.State = DownloadState.Failed;
                        }
                        else
                        {
                            try
                            {
                                if (string.IsNullOrWhiteSpace(dl.FilePath))
                                {
                                    throw new FormatException("Download FilePath must be set to a valid path");
                                }
                                Path.GetFullPath(dl.FilePath);
                            }
                            catch (Exception ex)
                            {
                                dl.LastError = ex;
                                dl.State = DownloadState.Failed;
                                return;
                            }
                            dl.State = DownloadState.Queued;
                            ProcessQueue();
                        }
                    });
                }
                catch (Exception ex)
                {
                    dl.LastError = ex;
                    dl.State = DownloadState.Failed;
                }
            }
        }