コード例 #1
0
        private Direction PickMoveDirection()
        {
            //check for a forced random value
            var forceRandom = rnd.NextDouble() <= RANDOMNESS;

            if (forceRandom)
            {
                var options = Board.State.PossibleDirections().ToArray();
                var d       = XT.GetRandom(options, rnd);
                RandomMoves++;
                return(d);
            }

            //get the database/policy value
            var canID  = Board.State;
            var policy = PolicyData.GetPolicy(canID)?.Result;

            if (policy != null)
            {
                PolicyMoves++;
                return(GetRecommendation(policy.GetWeights()));
            }

            //It wasn't sufficient, so use the algorithm
            var recDir = GetRecommendation(GetMoveWeights());

            MethodMoves++;
            return(recDir);
        }
コード例 #2
0
        string xtToHtml(XT content)
        {
            var     sb    = new StringBuilder();
            XTColor color = XTColor.Default;
            XTStyle style = XTStyle.Default;

            foreach (XTItem item in content.Items)
            {
                if (item.Color != color)
                {
                    if (color != XTColor.Default)
                    {
                        sb.Append("</span>");
                    }
                    color = item.Color;
                    if (color != XTColor.Default)
                    {
                        sb.Append("<span class=\"jb-log-color-");
                        sb.Append(color.ToString().ToLower());
                        sb.Append("\">");
                    }
                }
                if (item.Style != style)
                {
                    if (style != XTStyle.Default)
                    {
                        sb.Append("</span>");
                    }
                    style = item.Style;
                    if (style != XTStyle.Default)
                    {
                        sb.Append("<span class=\"jb-log-style-");
                        sb.Append(style.ToString().ToLower());
                        sb.Append("\">");
                    }
                }
                if (item.Text.Contains("\n"))
                {
                    sb.Append("<br/>");
                }
                else
                {
                    sb.Append(item.Text);
                }
            }
            if (color != XTColor.Default)
            {
                sb.Append("</span>");
            }
            if (style != XTStyle.Default)
            {
                sb.Append("</span>");
            }
            return(sb.ToString());
        }
コード例 #3
0
 private void TX_MouseDown(object sender, MouseButtonEventArgs e)
 {
     if (osx == 0)
     {
         XT.BeginAnimation(OpacityProperty, new DoubleAnimation(0, TimeSpan.FromSeconds(0.2))); osx = 1;
     }
     else if (osx == 1)
     {
         osx = 0;
         XT.BeginAnimation(OpacityProperty, new DoubleAnimation(1, TimeSpan.FromSeconds(0.2)));
     }
 }
コード例 #4
0
        public XT ToXT()
        {
            switch (Mode)
            {
            case MDBSubsetFilterMode.Whitelist:
            {
                return(XT.Format("SubsetFilter [{0}] <green>{1} <cyan>{2} <magenta>{3}", ID, Mode, Type, Text));
            }

            default:
            {
                return(XT.Format("SubsetFilter [{0}] <red>{1} <cyan>{2} <magenta>{3}", ID, Mode, Type, Text));
            }
            }
        }
コード例 #5
0
 public void Run()
 {
     while (!Board.Lost)
     {
         PrintBoardState();
         var moveWeights   = GetMoveWeights();
         var highestWeight = moveWeights.Values.Max();
         var highestDirs   = moveWeights.Where(kvp => kvp.Value == highestWeight)
                             .Select(kvp => kvp.Key);
         var recDir = highestDirs.Count() == 1 ? highestDirs.First()
                                               : XT.GetRandom(XT.EnumVals <Direction>().ToArray(), rnd);
         Board.Move(recDir);
         PrintMoveResults(moveWeights, recDir);
     }
     return;
 }
コード例 #6
0
        private async void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            osx = 9;
            var dt = new Computer().Info.AvailablePhysicalMemory;

            XT.BeginAnimation(OpacityProperty, new DoubleAnimation(0, TimeSpan.FromSeconds(0.2)));
            RotateTransform rtf = new RotateTransform();

            TX.RenderTransform = rtf;
            DoubleAnimation dbAscending = new DoubleAnimation(0, 3600, new Duration
                                                                  (TimeSpan.FromSeconds(3)));

            dbAscending.Completed += delegate { XT.BeginAnimation(OpacityProperty, new DoubleAnimation(1, TimeSpan.FromSeconds(0.2))); };
            rtf.BeginAnimation(RotateTransform.AngleProperty, dbAscending);
            await Task.Run(new Action(delegate {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                Process[] processes = Process.GetProcesses();
                foreach (Process process in processes)
                {
                    if ((process.ProcessName == "System") && (process.ProcessName == "Idle"))
                    {
                        continue;
                    }
                    try { EmptyWorkingSet(process.Handle); } catch { }
                }
            }));

            var dtf = new Computer().Info.AvailablePhysicalMemory;
            var v   = dtf - dt;
            await Task.Delay(3000);

            Tbi.Text = "已清理内存:" + HumanReadableFilesize(v);
            await Task.Delay(3000);

            Tbi.Text = "";
            osx      = 0;
        }
コード例 #7
0
        /// <summary>Writes the specified log message.</summary>
        /// <param name="dateTime">The date time.</param>
        /// <param name="level">The level.</param>
        /// <param name="source">The source.</param>
        /// <param name="content">The content.</param>
        protected override void Write(DateTime dateTime, LogLevel level, string source, XT content)
        {
            if (eventLog == null)
            {
                return;
            }

            if (level > logLevel)
            {
                return;
            }

            var type = EventLogEntryType.Information;

            if (level <= LogLevel.Warning)
            {
                type = EventLogEntryType.Warning;
            }

            if (level <= LogLevel.Error)
            {
                type = EventLogEntryType.Error;
            }

            lock (currentMessage)
            {
                if (type != currentType || currentMessage.Length > 16384)
                {
                    Flush();
                }
                currentType = type;
                currentMessage.Append(dateTime.ToLocalTime().ToString());
                currentMessage.Append(" Source: ");
                currentMessage.Append(source);
                currentMessage.Append(" Message: ");
                currentMessage.Append(content.Text.Trim('\r', '\n'));
                currentMessage.AppendLine();
            }

            if (flushTask == null)
            {
                flushTask = Task.Factory.StartNew(() =>
                {
                    if (!Monitor.TryEnter(this))
                    {
                        return;
                    }

                    Thread.Sleep(1000);
                    flushTask = null;
                    Flush();
                    Monitor.Exit(this);
                });
            }
        }
コード例 #8
0
        /// <summary>Provides an eXtended Text string for this object.</summary>
        /// <returns>Returns a new XT instance with the description of this object.</returns>
        public XT ToXT()
        {
			return XT.Format("AudioFile [{0}] <cyan>{1}", FileID, Title);
        }
コード例 #9
0
ファイル: LogSyslog.cs プロジェクト: CaveSystems/cave-service
        /// <summary>Writes the specified log message.</summary>
        /// <param name="dateTime">The date time.</param>
        /// <param name="level">The level.</param>
        /// <param name="source">The source.</param>
        /// <param name="content">The content.</param>
        protected override void Write(DateTime dateTime, LogLevel level, string source, XT content)
        {
            var severity = (SyslogSeverity)Math.Min((int)level, (int)SyslogSeverity.Debug);

            Syslog.Write(severity, Facility, content.Text);
        }
コード例 #10
0
 public XT ToXT()
 {
     return(XT.Format("Category [{0}] <cyan>{1}", ID, Name));
 }
コード例 #11
0
ファイル: MDBSubset.cs プロジェクト: CaveSystems/cave-jukebob
 /// <summary>Provides an eXtended Text string for this object.</summary>
 /// <returns>Returns a new XT instance with the description of this object.</returns>
 public XT ToXT()
 {
     return(XT.Format("Subset [{0}] <cyan>{1}", ID, Name));
 }
コード例 #12
0
 /// <summary>Provides an eXtended Text string for this object.</summary>
 /// <returns>Returns a new XT instance with the description of this object.</returns>
 public XT ToXT()
 {
     return(XT.Format("Artist [{0}] <cyan>{1} <default>{2}", ID, Name, MusicBrainzArtistGuid));
 }
コード例 #13
0
 /// <summary>Provides an eXtended Text string for this object.</summary>
 /// <returns>Returns a new XT instance with the description of this object.</returns>
 public XT ToXT()
 {
     return(XT.Format("Image [{0}] <cyan>{1} <magenta>{2}<default>x<magenta>{3}", FileID, Type, Width, Height));
 }
コード例 #14
0
 public XT ToXT()
 {
     return(XT.Format("Folder [{0}] <cyan>{1}", ID, Name));
 }
コード例 #15
0
ファイル: RandomPlay.cs プロジェクト: dipique/2048
 public override Dictionary <Direction, float> GetMoveWeights() => XT.EnumVals <Direction>().ToDictionary(k => k, k => 0f);
コード例 #16
0
 /// <summary>Provides an eXtended Text string for this object.</summary>
 /// <returns>Returns a new XT instance with the description of this object.</returns>
 public XT ToXT()
 {
     return(XT.Format("NowPlaying [{0}]", Position.FormatTimeSpan(1)));
 }
コード例 #17
0
 /// <summary>
 /// Adds a CSS reference to a view if it has not been added already.
 /// </summary>
 /// <param name="name">An name to use to represent this resource.  Typically this should be the file name and extension of the resource (minus any path information).
 /// You can use the other overloaded method to skip adding a name, and the resource path and file name (if any) will be used instead.
 /// If the name or resource path contains the typical ".min." name part, it will be ignored to make comparisons more consistent.
 /// </param>
 /// <param name="cssPath">A URI to the script to add to the page.</param>
 /// <param name="renderTarget">Where to render the script.</param>
 public ResourceInfo CSS(string name, string cssPath, RenderTargets renderTarget = RenderTargets.Header)
 {
     return(XT.RequireResource(name, cssPath, ResourceTypes.CSS, renderTarget));
 }
コード例 #18
0
        // --------------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Adds a script (usually JavaScript) to a view if it has not been added already.
        /// </summary>
        /// <param name="name">An name to use to represent this resource.  Typically this should be the file name and extension of the resource (minus any path information).
        /// You can use the other overloaded method to skip adding a name, and the resource path and file name (if any) will be used instead.
        /// If the name or resource path contains the typical ".min." name part, it will be ignored to make comparisons more consistent.
        /// </param>
        /// <param name="scriptPath">A URI to the script to add to the page.</param>
        /// <param name="renderTarget">Where to render the script.</param>
        public ResourceInfo Script(string name, string scriptPath, RenderTargets renderTarget = RenderTargets.Header)
        {
            return(XT.RequireResource(name, scriptPath, ResourceTypes.Script, renderTarget));
        }
コード例 #19
0
        void Run(Arguments args)
        {
            ILogReceiver console = null;

            if (args.IsOptionPresent("debug"))
            {
                if (console == null)
                {
                    console = LogConsole.Create();
                }
                console.Level = LogLevel.Debug;
            }
            if (args.IsOptionPresent("verbose"))
            {
                if (console == null)
                {
                    console = LogConsole.Create();
                }
                console.Level = LogLevel.Verbose;
            }

            LoadConfig();

            List <XT> results = new List <XT>();

            foreach (string dir in Directory.GetDirectories(Path.Combine(LetsEncryptPath, "live")))
            {
                string domainName = Path.GetFileName(dir);

                var conf = Path.Combine(LetsEncryptPath, "renewal", domainName + ".conf");
                if (!File.Exists(conf))
                {
                    continue;
                }

                if (domainName.Split('.').Length != 2)
                {
                    continue;
                }
                if (!domains.TryGetStruct(nameof(Domain.Name), domainName, out Domain domain))
                {
                    var x = XT.Format("<red>Error: <default>Domain <red>{0}<default> removed from imscp!", domainName);
                    results.Add(x);
                    SystemConsole.WriteLine(x);
                    File.Delete(conf);
                    continue;
                }

                string certText  = File.ReadAllText(Path.Combine(dir, "cert.pem")).GetValidChars(ASCII.Strings.Printable + '\n') + "\n";
                string keyText   = File.ReadAllText(Path.Combine(dir, "privkey.pem")).GetValidChars(ASCII.Strings.Printable + '\n') + "\n";
                string chainText = File.ReadAllText(Path.Combine(dir, "chain.pem")).GetValidChars(ASCII.Strings.Printable + '\n') + "\n";

                var sslCerts = ssl_certs.GetStructs(nameof(SslCerts.DomainID), domain.ID);
                if (sslCerts.Count > 1)
                {
                    var x = XT.Format("<red>Error: <default>Multiple ssl certs for domain {0}!", domain);
                    results.Add(x);
                    SystemConsole.WriteLine(x);
                    continue;
                }
                var newCert = PEM.ReadCert(certText.SplitNewLine());
                if (sslCerts.Count == 1)
                {
                    //already got one, check for update
                    var sslCert = sslCerts[0];
                    var oldCert = PEM.ReadCert(sslCert.Certificate.SplitNewLine());
                    if (newCert.Equals(oldCert))
                    {
                        this.LogInfo("Domain <green>{0}<default> valid till <green>{1}", domainName, oldCert.GetExpirationDateString());
                        //no change
                        continue;
                    }
                    if (!oldCert.Issuer.Contains("O=Let's Encrypt"))
                    {
                        //do not override users own certs
                        continue;
                    }
                    sslCert.Certificate = certText;
                    sslCert.PrivateKey  = keyText;
                    sslCert.CaBundle    = chainText;
                    sslCert.Status      = "tochange";
                    ssl_certs.Update(sslCert);
                }
                else
                {
                    var sslCert = new SslCerts()
                    {
                        AllowHsts             = "off",
                        CaBundle              = chainText,
                        Certificate           = certText,
                        DomainID              = (int)domain.ID,
                        DomainType            = "dmn",
                        HstsIncludeSubdomains = "off",
                        HstsMaxAge            = 31536000,
                        PrivateKey            = keyText,
                        Status = "tochange",
                    };
                    ssl_certs.Insert(sslCert);
                }
                domain.Status = "tochange";
                domains.Update(domain);
                {
                    var x = XT.Format("<green>Certificate: <default>Domain {0} new certificate {1} valid till {2}!", domain, newCert.Subject, newCert.GetExpirationDateString());
                    results.Add(x);
                    SystemConsole.WriteLine(x);
                }
            }
            this.LogInfo("Completed.");
            if (results.Count > 0)
            {
                MailMessage msg = new MailMessage(mailSender, "*****@*****.**")
                {
                    Subject    = "CaveSystems LetsEncrypt",
                    IsBodyHtml = true,
                    Body       = results.ToHtml()
                };
                smtpClient.Send(msg);
            }
            Logger.Flush();
            Logger.CloseAll();
            console?.Dispose();
        }
コード例 #20
0
        public XT ToXT()
        {
            string progress = Progress.ToString("p");

            return(XT.Format("[{0}] <cyan>{1} <yellow>{2} <green>{3}", ID, Source, Type, progress));
        }
コード例 #21
0
 public XT ToXT()
 {
     return(XT.Format("Genre [{0}] <cyan>{1}", ID, Name));
 }
コード例 #22
0
ファイル: MDBFile.cs プロジェクト: CaveSystems/cave-jukebob
 public XT ToXT()
 {
     return(XT.Format("File [{0}] <cyan>{1}{2}", ID, Name, Extension));
 }